From: Pierre Habouzit Date: Thu, 14 Dec 2006 00:05:54 +0000 (+0100) Subject: implement $-vars substitution. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=2d0afa54b647f32caa7a4bf3917e50f5d3e8c1e2;p=apps%2Fmadmutt.git implement $-vars substitution. Signed-off-by: Pierre Habouzit --- diff --git a/init.c b/init.c index 8f6070c..2889e5e 100644 --- a/init.c +++ b/init.c @@ -2527,6 +2527,7 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) segment s2 = {"toto", 4 }; segment s3 = {"titi", 4 }; segment s4 = {"\"", 1 }; + segment s5 = {"index_format", 12 }; mutt_endwin(NULL); @@ -2542,6 +2543,9 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) rcparse(parser, RCTK_SPACE, s1, &state); rcparse(parser, RCTK_ATOM, s3, &state); rcparse(parser, RCTK_DQUOTE, s4, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_DOLLAR, s1, &state); + rcparse(parser, RCTK_ATOM, s5, &state); rcparse(parser, RCTK_NL, s1, &state); rcparse(parser, 0, s1, &state); diff --git a/lib-lib/buffer.c b/lib-lib/buffer.c index b442721..7131cb6 100644 --- a/lib-lib/buffer.c +++ b/lib-lib/buffer.c @@ -28,7 +28,7 @@ #include "lib-lib.h" -#define BUFSIZ_INCREMENT 1024 +#define BUFSIZ_INCREMENT 256 void buffer_resize(buffer_t *buf, ssize_t newsize) { diff --git a/rcparser.y b/rcparser.y index 4f5c572..c2f1567 100644 --- a/rcparser.y +++ b/rcparser.y @@ -80,6 +80,23 @@ buffer_add(buf, s, len); return buf; } + + static void substvar(buffer_t *buf, const segment seg) { + const char *res; + char tmp[STRING]; + char var[STRING]; + + if (m_strncpy(var, sizeof(var), seg.s, seg.len) <= 0) + return; + + if ((res = getenv(var))) { + buffer_addstr(buf, res); + return; + } + if (mutt_option_value(var, tmp, sizeof(tmp))) { + buffer_addstr(buf, tmp); + } + } } %name rcparse @@ -111,6 +128,10 @@ to_eol ::= sp to_eol_aux . /* Our macro tokens */ /****************************************************************************/ +%type svar { segment } +svar(Z) ::= DOLLAR ATOM(B) . { Z = B; } +svar(Z) ::= DOLLAR LBRACE ATOM(B) RBRACE . { Z = B; } + /* '-quoted tokens */ %type sqtok { buffer_t* } %destructor sqtok { buffer_delete(&$$); } @@ -134,16 +155,7 @@ dqtok(Z) ::= dqtok(A) BSLASH non_nl(B) . { Z = buffer_escape(A, B.s, B.len); } dqtok(Z) ::= dqtok(A) ATOM|SPACE|SHARP|EQUAL|LBRACE|RBRACE(B) . { buffer_add(Z = A, B.s, B.len); } -dqtok(Z) ::= dqtok(A) DOLLAR ATOM(B) . { - // FIXME - B = B; - Z = A; -} -dqtok(Z) ::= dqtok(A) DOLLAR LBRACE ATOM(B) RBRACE . { - // FIXME - B = B; - Z = A; -} +dqtok(Z) ::= dqtok(A) svar(B) . { substvar(Z = A, B); } /* unquoted tokens */ %type uqtok { buffer_t* } @@ -152,6 +164,7 @@ uqtok(Z) ::= ATOM|EQUAL|LBRACE|RBRACE(A) . { buffer_add(Z = buffer_new(), A.s, A uqtok(Z) ::= BSLASH non_nl(A) . { buffer_add(Z = buffer_new(), A.s, A.len); } uqtok(Z) ::= QUOTE sqtok(A) QUOTE . { Z = A; } uqtok(Z) ::= DQUOTE dqtok(A) DQUOTE . { Z = A; } +uqtok(Z) ::= svar(B) . { substvar(Z = buffer_new(), B); } /* token accumulator */ %type token { buffer_t* } @@ -183,7 +196,12 @@ rclines ::= . rclines ::= rclines rcline . rcline ::= ALTERNATIVE_ORDER simple_list(L) to_eol . { + string_list_t *l; string_list_append(&AlternativeOrderList, string_list_rev(L)); + printf("toto\n"); + for (l = AlternativeOrderList; l; l = l->next) { + printf("%s\n", l->data); + } } rcline ::= AUTO_VIEW simple_list(L) to_eol . { string_list_append(&AutoViewList, string_list_rev(L));