From 655f2fbfc8d9734e20ee36e1161611a46548e57a Mon Sep 17 00:00:00 2001 From: Stephan Boettcher Date: Mon, 2 Jan 2012 22:48:33 +0100 Subject: [PATCH 2/2] gnetlist: parameter substitution extensions. allow digits in hierarchy parameter names. Allow parameter references with arbitrary names in ${braces}. --- gnetlist/src/s_hierarchy.c | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gnetlist/src/s_hierarchy.c b/gnetlist/src/s_hierarchy.c index b6e5198..d1d6053 100644 --- a/gnetlist/src/s_hierarchy.c +++ b/gnetlist/src/s_hierarchy.c @@ -705,30 +705,45 @@ gchar *s_hierarchy_apply_parameters_to_text(const gchar *s, GList *parameters) int plen = 0; gchar *pstart = g_utf8_find_next_char (dollar, NULL); gchar *pend = pstart; + gunichar pchar = g_utf8_get_char(pend); // skip a double $$ - if (g_utf8_get_char(pend) == g_utf8_get_char("$")) + if (pchar == g_utf8_get_char("$")) pend = g_utf8_find_next_char (pend, NULL); + else if (pchar == g_utf8_get_char("{")) { + // a parameter name in ${BRACES} + pstart = g_utf8_find_next_char (pend, NULL); + pend = pstart; + while (*pend && g_utf8_get_char(pend) != g_utf8_get_char("}")) { + plen++; + pend = g_utf8_find_next_char (pend, NULL); + } + plen = pend - pstart; + if (*pend) + pend = g_utf8_find_next_char (pend, NULL); + } else - // count the number of UTF-8 uppercase letters - while (g_unichar_isupper (g_utf8_get_char(pend))) { + // count the number of UTF-8 uppercase letters and numbers + while (g_unichar_isupper (pchar) + || g_unichar_isdigit(pchar)) { plen++; pend = g_utf8_find_next_char (pend, NULL); + pchar = g_utf8_get_char(pend); + plen = pend - pstart; } if (plen) { // find the first parameter definition that matches the // parameter. A colon separates the parameter name from the value // in the definition const GList *iter; - int pnlen = pend - pstart; for (iter = parameters; iter != NULL; iter = g_list_next (iter)) - if (!strncmp(pstart, iter->data, pnlen)) - if (g_utf8_get_char(iter->data+pnlen)==g_utf8_get_char (":")) + if (!strncmp(pstart, iter->data, plen)) + if (g_utf8_get_char(iter->data+plen)==g_utf8_get_char (":")) break; if (iter) { // copy the prefix and substitution into new, and // resume with the remaining s gchar *nnew = new; - gchar *nval = g_utf8_find_next_char(iter->data+pnlen, NULL); + gchar *nval = g_utf8_find_next_char(iter->data+plen, NULL); gchar *opre = g_strndup(s, dollar-s); if (new) new = g_strconcat(new, opre, nval, NULL); -- 1.7.3.GIT