-diff -purN bb.old/editors/awk.c bb.dev/editors/awk.c
---- bb.old/editors/awk.c 2007-03-06 19:38:07.278092000 +0100
-+++ bb.dev/editors/awk.c 2007-03-11 05:14:11.776304544 +0100
+diff -urN bb.old/editors/awk.c bb.dev/editors/awk.c
+--- bb.old/editors/awk.c 2007-05-20 04:17:05.002197784 +0200
++++ bb.dev/editors/awk.c 2007-05-20 22:40:48.183743936 +0200
@@ -30,6 +30,11 @@
/* these flags are static, don't change them when value is changed */
#define VF_DONTTOUCH (VF_ARRAY | VF_SPECIAL | VF_WALK | VF_CHILD | VF_DIRTY)
/* Variable */
typedef struct var_s {
unsigned short type; /* flags */
-@@ -50,10 +55,15 @@ typedef struct chain_s {
+@@ -50,10 +55,15 @@
char *programname;
} chain;
} func;
/* I/O stream */
-@@ -1312,7 +1322,8 @@ static void parse_program(char *p)
+@@ -1312,7 +1322,8 @@
next_token(TC_FUNCTION);
pos++;
f = newfunc(t.string);
f->nargs = 0;
while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) {
v = findvar(ahash, t.string);
-@@ -1321,7 +1332,7 @@ static void parse_program(char *p)
+@@ -1321,7 +1332,7 @@
if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
break;
}
chain_group();
clear_array(ahash);
-@@ -2260,7 +2271,8 @@ static var *evaluate(node *op, var *res)
+@@ -2260,7 +2271,8 @@
break;
case XC( OC_FUNC ):
runtime_error(EMSG_UNDEF_FUNC);
X.v = R.v = nvalloc(op->r.f->nargs+1);
-@@ -2277,7 +2289,11 @@ static var *evaluate(node *op, var *res)
+@@ -2277,7 +2289,11 @@
fnargs = X.v;
L.s = programname;
programname = L.s;
nvfree(fnargs);
-@@ -2637,6 +2653,11 @@ static rstream *next_input_file(void)
+@@ -2637,6 +2653,11 @@
return &rsm;
}
int awk_main(int argc, char **argv)
{
int i, j, flen;
-@@ -2693,6 +2714,10 @@ int awk_main(int argc, char **argv)
+@@ -2693,6 +2714,10 @@
free(s);
}
programname = NULL;
while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
switch (c) {
-diff -purN bb.old/editors/awx.c bb.dev/editors/awx.c
+diff -urN bb.old/editors/awx.c bb.dev/editors/awx.c
--- bb.old/editors/awx.c 1970-01-01 01:00:00.000000000 +0100
-+++ bb.dev/editors/awx.c 2007-03-14 02:03:50.566202928 +0100
-@@ -0,0 +1,589 @@
++++ bb.dev/editors/awx.c 2007-05-23 22:37:38.547183608 +0200
+@@ -0,0 +1,633 @@
+/*
+ * awk web extension
+ *
+
+#include <cgi.h>
+#include <glob.h>
++#include "awx_parser.h"
+
+#define LINE_BUF 2048
+#define HASH_MAX 1536
+#define TR_START "@TR<<"
+#define TR_END ">>"
+#define MAX_TR 32
-+#define SSI_START "<%"
-+#define SSI_END "%>"
+
+#undef fputs
+
+static char *translate_line(char *line)
+{
+ char *tok[MAX_TR * 3];
-+ char *l, *p, *p2, *res;
-+ int len = 0, _pos = 0, i;
++ char *l, *p, *p2 = NULL, *res;
++ int len = 0, _pos = 0, i, tr_abort = 0;
++ static char *backlog = NULL;
++
++ if (backlog && line) {
++ backlog = xrealloc(backlog, strlen(backlog) + strlen(line) + 1);
++ sprintf(backlog + strlen(backlog), line);
++ l = backlog;
++ } else {
++ l = line;
++ }
+
-+ l = line;
+ while (l != NULL) {
+ if ((p = strstr(l, TR_START)) == NULL) {
+ len += strlen((tok[_pos++] = l));
+ }
+
+ p2 = strstr(p, TR_END);
-+ if (p2 == NULL)
++ if (p2 == NULL) {
++ p2 = xstrdup(l);
++ tr_abort = 1;
+ break;
++ }
+
+ *p = 0;
-+ *p2 = 0;
+ len += strlen((tok[_pos++] = l));
++ *p2 = 0;
+ len += strlen((tok[_pos++] = translate_lookup(p + strlen(TR_START))));
+
+ l = p2;
+ strcat(p, tok[i]);
+ p += strlen(tok[i]);
+ }
-+
++ if (backlog) {
++ free(backlog);
++ backlog = NULL;
++ }
++ if (tr_abort && p2)
++ backlog = p2;
++
+ return res;
+}
+
+ chain *initseq = NULL;
+ chain tmp;
+ func *f;
-+ var *v, tv;
++ var *v, *tv;
+
++ tv = nvalloc(1);
+ memset(&tmp, 0, sizeof(tmp));
+ pos = p;
+ t.lineno = 1;
+ }
+ }
+ if (initseq && initseq->first)
-+ evaluate(initseq->first, &tv);
++ tv = evaluate(initseq->first, tv);
++ nvfree(tv);
+}
+
+
+ return res;
+}
+
-+
-+/* parse and evaluate an awk expression and return the result as string */
-+static char *render_lookup(char *fname, int lnr, char *str)
++/* parse an awk expression */
++static var *parse_awk(char *str, var *tv)
+{
+ chain body;
-+ var tv;
++ node *n;
+
+ memset(&body, 0, sizeof(body));
-+ zero_out_var(&tv);
+ pos = str;
+ seq = &body;
+
+ /* end of expression, assume that there's going to be a free byte
+ * at the end of the string that can be used for the ')' */
-+ strcat(str + strlen(str), ")");
-+ return getvar_s(evaluate(parse_expr(TC_SEQTERM), &tv));
++ strcat(str + strlen(str), "}");
++ n = parse_expr(TC_GRPTERM);
++ if (!n)
++ return NULL;
++
++ return evaluate(n, tv);
+}
+
+static inline void print_translate(char *s)
+ free(str);
+}
+
-+/* process awk calls in a template line and print the output to stdout */
-+static void render_line(char *fname, int lnr, char *line)
++static void render_element(struct template_cb *tcb, struct template_element *e)
+{
-+ char *tok[MAX_TR * 3];
-+ char *l, *p, *p2, *res;
-+ int len = 0, _pos = 0, i;
-+
-+ l = line;
-+ while (l != NULL) {
-+ if ((p = strstr(l, SSI_START)) == NULL) {
-+ len += strlen((tok[_pos++] = l));
++ var *v;
++ char *s, *s2;
++ int i;
++
++ if (!e || !e->var)
++ return;
++ lineno = e->line;
++ switch (e->t) {
++ case T_TEXT:
++ s = malloc(strlen(e->var) + 2);
++ strcpy(s, e->var);
++ print_translate(s);
++ free(s);
+ break;
-+ }
-+
-+ p2 = strstr(p, SSI_END);
-+ if (p2 == NULL) {
-+ fprintf(stderr, "Parse error in '%s', line '%d', unmatched %s\n", fname, lnr, SSI_END);
++ case T_CODE:
++ s = malloc(strlen(e->var) + 2);
++ strcpy(s, e->var);
++ v = nvalloc(1);
++ s2 = strdup(getvar_s(parse_awk(s, v)));
++ nvfree(v);
++ print_translate(s2);
++ free(s);
++ free(s2);
++ break;
++ case T_IF:
++ s = malloc(strlen(e->var) + 2);
++ strcpy(s, e->var);
++ v = nvalloc(1);
++ i = istrue(parse_awk(s, v));
++ nvfree(v);
++ free(s);
++
++ if (i)
++ execute_template(tcb, e->sub);
++ else if (e->sub2)
++ execute_template(tcb, e->sub2);
++ break;
++ case T_FOR: {
++ v = newvar(e->var);
++ hashwalk_init(v, iamarray(findvar(vhash, e->in)));
++ while (hashwalk_next(v)) {
++ execute_template(tcb, e->sub);
++ }
++ clrvar(v);
++ }
++ break;
++ default:
+ break;
-+ }
-+
-+ *p = 0;
-+ *p2 = 0;
-+
-+ len += strlen((tok[_pos++] = l));
-+ len += strlen((tok[_pos++] = render_lookup(fname, lnr, p + strlen(SSI_START))));
-+
-+ l = p2;
-+ l += strlen(SSI_END);
-+ }
-+ len++;
-+
-+ p = xmalloc(len + 1);
-+ *p = 0;
-+ res = p;
-+ for (i = 0; i < _pos; i++) {
-+ strcat(p, tok[i]);
-+ p += strlen(tok[i]);
+ }
-+ print_translate(res);
-+ free(res);
+}
+
+/* awk method render(), which opens a template file and processes all awk ssi calls */
+static void render_file(char *filename)
+{
-+ int lnr = 0;
++ struct template_cb tcb;
++ struct template_element *e;
+ FILE *f;
-+ char *buf1;
-+
++ char *oldprg;
++ int oldlnr;
++
++ if (!filename)
++ return;
++
++ oldlnr = lineno;
++ oldprg = programname;
++ programname = filename;
++
+ f = fopen(filename, "r");
+ if (!f)
+ return;
+
-+ buf1 = xmalloc(LINE_BUF);
-+ while (!feof(f) && (fgets(buf1, LINE_BUF - 1, f) != NULL)) {
-+ render_line(filename, ++lnr, buf1);
-+ }
++ memset(&tcb, 0, sizeof(tcb));
++ tcb.handle_element = render_element;
++ e = parse_template(&tcb, f);
++ execute_template(&tcb, e);
++ free_template(&tcb, e);
++ fclose(f);
++ programname = oldprg;
++ lineno = oldlnr;
+}
+
+static var *render(var *res, var *args, int nargs)
+ return awk_main(argc, argv);
+}
+
-diff -purN bb.old/editors/Config.in bb.dev/editors/Config.in
---- bb.old/editors/Config.in 2007-01-24 22:34:50.000000000 +0100
-+++ bb.dev/editors/Config.in 2007-03-11 06:19:51.469380160 +0100
-@@ -12,6 +12,13 @@ config AWK
+diff -urN bb.old/editors/awx_parser.h bb.dev/editors/awx_parser.h
+--- bb.old/editors/awx_parser.h 1970-01-01 01:00:00.000000000 +0100
++++ bb.dev/editors/awx_parser.h 2007-05-20 22:30:31.380512280 +0200
+@@ -0,0 +1,38 @@
++#ifndef __TEMPLATE_PARSER_H
++#define __TEMPLATE_PARSER_H
++
++enum type {
++ T_TEXT,
++ T_FOR,
++ T_IF,
++ T_CODE
++};
++
++struct template_element;
++struct template_cb;
++
++struct template_cb {
++ void *(*prepare_code)(struct template_element *);
++ void (*handle_element)(struct template_cb *, struct template_element *);
++ void (*free_code)(struct template_element *);
++};
++
++struct template_element {
++ enum type t;
++ char *var;
++ char *in;
++ int line;
++ void *priv;
++ struct template_element *parent;
++ struct template_element *sub;
++ struct template_element *sub2;
++ struct template_element *prev;
++ struct template_element *next;
++};
++
++
++struct template_element *parse_template(struct template_cb *cb, FILE *in);
++void execute_template(struct template_cb *cb, struct template_element *e);
++void free_template(struct template_cb *cb, struct template_element *e);
++
++#endif
+diff -urN bb.old/editors/awx_parser.l bb.dev/editors/awx_parser.l
+--- bb.old/editors/awx_parser.l 1970-01-01 01:00:00.000000000 +0100
++++ bb.dev/editors/awx_parser.l 2007-05-23 19:13:40.459655704 +0200
+@@ -0,0 +1,302 @@
++%{
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++#include "busybox.h"
++#include "awx_parser.h"
++
++enum {
++ S_INIT,
++ S_TEXT,
++ S_CODE,
++ S_IF_START,
++ S_FOR_START,
++ S_FOR_IN,
++ S_END,
++ S_ELSE,
++ S_EOF
++};
++int state;
++
++#undef DEBUG
++#ifdef DEBUG
++char *statestr[] = {
++ [S_INIT] = "S_INIT",
++ [S_TEXT] = "S_TEXT",
++ [S_CODE] = "S_CODE",
++ [S_IF_START] = "S_IF_START",
++ [S_FOR_START] = "S_FOR_START",
++ [S_FOR_IN] = "S_FOR_IN",
++ [S_EOF] = "S_EOF"
++};
++
++char *typestr[] = {
++ [T_TEXT] = "T_TEXT",
++ [T_FOR] = "T_FOR",
++ [T_IF] = "T_IF",
++ [T_CODE] = "T_CODE"
++};
++#endif
++
++static struct template_cb *parse_cb;
++static struct template_element *cur, *head;
++static char *textbuf;
++static unsigned int buflen;
++static unsigned int buf_offset;
++static int _lnr = 0;
++
++static void buf_realloc(void)
++{
++ buflen *= 2;
++ textbuf = xrealloc(textbuf, buflen);
++}
++
++static void parse_error(char *str)
++{
++ fprintf(stderr, "Parse error%s%s\n", (str ? ": " : "!"), (str ?: ""));
++ exit(255);
++}
++
++
++static struct template_element *new_template_element(struct template_element *parent)
++{
++ struct template_element *ptr;
++
++ ptr = xzalloc(sizeof(struct template_element));
++ ptr->parent = parent;
++ return ptr;
++}
++
++static inline void next_template_element(void)
++{
++ cur->next = new_template_element(cur->parent);
++ cur->next->prev = cur;
++ cur = cur->next;
++}
++
++static void addtext(char *text)
++{
++ while(buf_offset + strlen(text) + 1 > buflen)
++ buf_realloc();
++
++ buf_offset += sprintf(&textbuf[buf_offset], "%s", text);
++}
++
++static void set_state(int newstate)
++{
++ char *ptr;
++
++#ifdef DEBUG
++ static int _rec = 0;
++ fprintf(stderr, "DEBUG(%d): %s => %s: %s\n", _rec, statestr[state], statestr[newstate], textbuf);
++#endif
++ ptr = xstrdup(textbuf);
++ if (state == S_FOR_IN)
++ cur->in = ptr;
++ else
++ cur->var = ptr;
++
++ if (parse_cb && (cur->t == T_CODE) && parse_cb->prepare_code)
++ parse_cb->prepare_code(cur);
++
++ buf_offset = 0;
++ *textbuf = 0;
++
++ switch(newstate) {
++#if 0
++ case S_EOF:
++ if (cur->parent)
++ parse_error();
++ break;
++#endif
++ case S_FOR_START:
++ if (ptr || !cur->prev)
++ next_template_element();
++ cur->t = T_FOR;
++ break;
++ case S_IF_START:
++ if (ptr || !cur->prev)
++ next_template_element();
++ cur->t = T_IF;
++ break;
++ case S_ELSE:
++ cur = cur->parent;
++ if (!cur)
++ parse_error("'@else' without parent element");
++ cur->sub2 = new_template_element(cur);
++ cur = cur->sub2;
++ newstate = S_TEXT;
++ break;
++ case S_END:
++#ifdef DEBUG
++ _rec--;
++#endif
++ cur = cur->parent;
++ if (!cur)
++ parse_error("'@end' without parent element");
++
++ next_template_element();
++ cur->t = T_TEXT;
++ newstate = S_TEXT;
++ break;
++ case S_TEXT:
++ switch (cur->t) {
++ case T_CODE:
++ next_template_element();
++ break;
++ case T_IF:
++ case T_FOR:
++#ifdef DEBUG
++ _rec++;
++#endif
++ cur->sub = new_template_element(cur);
++ cur = cur->sub;
++ break;
++ default:
++ break;
++ }
++ cur->t = T_TEXT;
++ break;
++ case S_CODE:
++ if (ptr || !cur->prev)
++ next_template_element();
++ cur->t = T_CODE;
++ break;
++ default:
++ break;
++ }
++ cur->line = _lnr;
++ state = newstate;
++}
++
++%}
++
++%%
++"<%"[ \n\t]*"@if"[ \n\t]+ {
++ if (state == S_TEXT)
++ set_state(S_IF_START);
++ else
++ REJECT;
++}
++
++"<%"[ \n\t]*"@for"[ \n\t]+ {
++ if (state == S_TEXT)
++ set_state(S_FOR_START);
++ else
++ REJECT;
++}
++
++[ \n\t]+"in"[ \n\t]+ {
++ if (state == S_FOR_START)
++ set_state(S_FOR_IN);
++ else
++ REJECT;
++}
++
++"<%"[ \n\t]*"@end"[ \n\t]*%> {
++ if (state != S_TEXT)
++ REJECT;
++ set_state(S_END);
++}
++
++"<%"[ \n\t]*"@else"[ \n\t]*%> {
++ if (state != S_TEXT)
++ REJECT;
++ set_state(S_ELSE);
++}
++
++"<%" {
++ if (state != S_TEXT)
++ parse_error("'<%' cannot be nested");
++ set_state(S_CODE);
++}
++
++[ \n\t]"%>" {
++ if (state == S_TEXT)
++ REJECT;
++ set_state(S_TEXT);
++}
++
++\n {
++ _lnr++;
++ if (state == S_TEXT)
++ addtext(yytext);
++}
++. {
++ addtext(yytext);
++}
++
++
++%%
++
++
++void execute_template(struct template_cb *cb, struct template_element *e)
++{
++ static int rec = 0;
++
++ while (e) {
++#ifdef DEBUG
++ fprintf(stderr, "DEBUG: execute(%d)\t%s\n", rec, typestr[e->t]);
++#endif
++ rec++;
++ if (cb->handle_element)
++ cb->handle_element(cb, e);
++ rec--;
++ e = e->next;
++ }
++}
++
++int yywrap()
++{
++ set_state(S_EOF);
++ return 1;
++}
++
++struct template_element *parse_template(struct template_cb *cb, FILE *in)
++{
++ _lnr = 1;
++ buf_offset = 0;
++ state = S_TEXT;
++ parse_cb = cb;
++
++ buflen = 4096;
++ textbuf = xzalloc(buflen);
++
++ head = xzalloc(sizeof(struct template_element));
++ head->t = T_TEXT;
++ cur = head;
++
++ yyin = in;
++ yylex();
++
++ return head;
++}
++
++void free_template(struct template_cb *cb, struct template_element *e)
++{
++ struct template_element *next;
++ return;
++ if (!e)
++ return;
++
++ switch (e->t) {
++ case T_CODE:
++ if (cb->free_code)
++ cb->free_code(e);
++ break;
++ case T_FOR:
++ case T_IF:
++ free_template(cb, e->sub);
++ break;
++ default:
++ break;
++ }
++ if (e->var)
++ free(e->var);
++ if (e->in)
++ free(e->in);
++
++ next = e->next;
++ free(e);
++ return free_template(cb, next);
++}
+diff -urN bb.old/editors/Config.in bb.dev/editors/Config.in
+--- bb.old/editors/Config.in 2007-05-20 04:17:05.003197632 +0200
++++ bb.dev/editors/Config.in 2007-05-20 22:30:31.380512280 +0200
+@@ -12,6 +12,13 @@
Awk is used as a pattern scanning and processing language. This is
the BusyBox implementation of that programming language.
config FEATURE_AWK_MATH
bool "Enable math functions (requires libm)"
default y
-diff -purN bb.old/include/applets.h bb.dev/include/applets.h
---- bb.old/include/applets.h 2007-03-06 19:38:07.355081000 +0100
-+++ bb.dev/include/applets.h 2007-03-07 02:12:24.280681880 +0100
-@@ -60,6 +60,7 @@ USE_ARP(APPLET(arp, _BB_DIR_SBIN, _BB_SU
+diff -urN bb.old/editors/Kbuild bb.dev/editors/Kbuild
+--- bb.old/editors/Kbuild 2007-03-18 17:59:37.000000000 +0100
++++ bb.dev/editors/Kbuild 2007-05-20 22:30:31.381512128 +0200
+@@ -10,3 +10,12 @@
+ lib-$(CONFIG_PATCH) += patch.o
+ lib-$(CONFIG_SED) += sed.o
+ lib-$(CONFIG_VI) += vi.o
++lib-$(CONFIG_AWX) += awx_parser.o
++
++editors/awx_parser.c: editors/awx_parser.l editors/awx_parser.h
++ @flex $<
++ @mv lex.yy.c $@
++
++editors/awx_parser.o: editors/awx_parser.c FORCE
++ $(call cmd,force_checksrc)
++ $(call if_changed_rule,cc_o_c)
+diff -urN bb.old/include/applets.h bb.dev/include/applets.h
+--- bb.old/include/applets.h 2007-05-20 04:17:05.003197632 +0200
++++ bb.dev/include/applets.h 2007-05-20 22:30:31.381512128 +0200
+@@ -60,6 +60,7 @@
USE_ARPING(APPLET(arping, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_ASH(APPLET_NOUSAGE(ash, ash, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_AWK(APPLET(awk, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_BASENAME(APPLET(basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER))
//USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER))
-diff -purN bb.old/include/cgi.h bb.dev/include/cgi.h
+diff -urN bb.old/include/cgi.h bb.dev/include/cgi.h
--- bb.old/include/cgi.h 1970-01-01 01:00:00.000000000 +0100
-+++ bb.dev/include/cgi.h 2007-03-11 18:58:10.708444448 +0100
++++ bb.dev/include/cgi.h 2007-05-20 22:30:31.381512128 +0200
@@ -0,0 +1,8 @@
+#ifndef CGI_H
+#define CGI_H
+int cgi_init(var_handler);
+
+#endif
-diff -purN bb.old/libbb/cgi.c bb.dev/libbb/cgi.c
+diff -urN bb.old/libbb/cgi.c bb.dev/libbb/cgi.c
--- bb.old/libbb/cgi.c 1970-01-01 01:00:00.000000000 +0100
-+++ bb.dev/libbb/cgi.c 2007-03-11 19:02:04.691873560 +0100
++++ bb.dev/libbb/cgi.c 2007-05-20 22:30:31.382511976 +0200
@@ -0,0 +1,457 @@
+/* --------------------------------------------------------------------------
+ * functions for processing cgi form data
+
+ return retval;
+}
-diff -purN bb.old/libbb/Kbuild bb.dev/libbb/Kbuild
---- bb.old/libbb/Kbuild 2007-03-06 19:38:07.361080000 +0100
-+++ bb.dev/libbb/Kbuild 2007-03-11 18:40:51.384445712 +0100
-@@ -118,3 +118,6 @@ lib-$(CONFIG_GREP) += xregcomp.o
+diff -urN bb.old/libbb/Kbuild bb.dev/libbb/Kbuild
+--- bb.old/libbb/Kbuild 2007-05-20 04:17:05.004197480 +0200
++++ bb.dev/libbb/Kbuild 2007-05-20 22:30:31.382511976 +0200
+@@ -118,3 +118,6 @@
lib-$(CONFIG_MDEV) += xregcomp.o
lib-$(CONFIG_LESS) += xregcomp.o
lib-$(CONFIG_DEVFSD) += xregcomp.o