From 2c1d2dad865623851a8a81268e604ca6f1a3f4e4 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 28 Jan 2012 01:49:12 +0200 Subject: [PATCH] fixed idiotic bug in variable expansion --- TODO | 1 + src/expand.c | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index ece6be4..fb2e382 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,3 @@ [*] add "-=" 'assign' (to exclude elements from list) + [*] $(>[2:S=.tiles]) -- bugs us out (adds extra char) [.] replace regexp library with new one (from Tcl?) diff --git a/src/expand.c b/src/expand.c index f5fa99f..49504d8 100644 --- a/src/expand.c +++ b/src/expand.c @@ -47,7 +47,7 @@ typedef struct { } VAR_EDITS; -static void var_edit_parse (const char *mods, VAR_EDITS *edits); +static void var_edit_parse (char *mods, VAR_EDITS *edits); static void var_edit_file (const char *in, char *out, VAR_EDITS *edits); static void var_edit_shift (char *out, VAR_EDITS *edits); static void var_edit_quote (char *out); @@ -77,8 +77,8 @@ LIST *var_expand (LIST *l, const char *in, const char *end, LOL *lol, int cancop // if (DEBUG_VAREXP) printf("expand '%.*s'\n", (int)(end-in), in); /* this gets alot of cases: $(<) and $(>) */ - if (end - in == 4 && in[0] == '$' && in[1] == '(' && in[3] == ')') { - switch(in[2]) { + if (end-in == 4 && in[0] == '$' && in[1] == '(' && in[3] == ')') { + switch (in[2]) { case '1': case '<': return list_copy(l, lol_get(lol, 0)); case '2': case '>': return list_copy(l, lol_get(lol, 1)); } @@ -282,7 +282,7 @@ expand: * * var_edit_file() below and path_build() obligingly follow this convention. */ -static void var_edit_parse (const char *mods, VAR_EDITS *edits) { +static void var_edit_parse (char *mods, VAR_EDITS *edits) { int havezeroed = 0; // memset((char *)edits, 0, sizeof(*edits)); @@ -327,15 +327,21 @@ strval: if (*mods != '=') { fp->ptr = ""; fp->len = 0; - } else if ((p = strchr(mods, MAGIC_COLON))) { - *p = 0; - fp->ptr = ++mods; - fp->len = p-mods; - mods = p+1; } else { - fp->ptr = ++mods; - fp->len = strlen(mods); - mods += fp->len; + //FIXME: ugly hack to allow things like $(>[2:S=.tiles]) (they are bad, but...) + p = mods; + while (*p && *p != MAGIC_COLON && *p != MAGIC_LEFT && *p != MAGIC_RIGHT) ++p; + if (*p) { + *p = 0; + fp->ptr = ++mods; + fp->len = p-mods; + mods = p+1; + } else { + fp->ptr = ++mods; + fp->len = strlen(fp->ptr); + mods += fp->len; + //fprintf(stderr, "len=%d [", fp->len); fwrite(fp->ptr, 1, fp->len, stderr); fprintf(stderr, "]\n"); + } } } } -- 2.11.4.GIT