summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@alpinelinux.org>2008-04-09 00:12:41 +0000
committerNathan Angelacos <nangel@alpinelinux.org>2008-04-09 00:12:41 +0000
commitef1e6197212624d629602763711ec99d23fe3542 (patch)
treedb6f1cf16001c1c24ef823e4ba15688ce88da328
parent1ec3de271c10397a288d059cbf05df5db2cec913 (diff)
downloadhaserl-ef1e6197212624d629602763711ec99d23fe3542.tar.bz2
haserl-ef1e6197212624d629602763711ec99d23fe3542.tar.xz
scott's stuff, but process_token_list is wedged
-rw-r--r--src/config.h.in4
-rw-r--r--src/h_bash.c394
-rw-r--r--src/h_bash.h21
-rw-r--r--src/h_script.c215
-rw-r--r--src/h_script.h4
-rw-r--r--src/haserl.c83
-rw-r--r--src/haserl.h45
-rw-r--r--src/rfc2388.c2
8 files changed, 737 insertions, 31 deletions
diff --git a/src/config.h.in b/src/config.h.in
index f3ff098..215b591 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -1,7 +1,7 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */
-/* prefix for user supplied data */
-#undef HASERL_VAR_PREFIX
+/* Include bash extensions */
+#undef BASHEXTENSIONS
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
diff --git a/src/h_bash.c b/src/h_bash.c
index 063a2c5..a3f3f55 100644
--- a/src/h_bash.c
+++ b/src/h_bash.c
@@ -179,6 +179,400 @@ bash_eval (buffer_t * buf, char *str, size_t len)
buffer_add (buf, echo_end, strlen (echo_end));
}
+#ifdef BASHEXTENSIONS
+/* generate an IF statment */
+void
+bash_if (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for if'\nexit 99\n";
+ static char if_start[] = "if [[ ";
+ static char if_end[] = " ]]\nthen\n";
+ static char ex_start[] = "if ";
+ static char ex_end[] = "\nthen\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else if (str[0] == '|')
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ } else {
+ buffer_add (buf, if_start, strlen (if_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, if_end, strlen (if_end));
+ }
+}
+
+
+/* generate an ELIF statment */
+void
+bash_elif (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for elif'\nexit 99\n";
+ static char elif_start[] = "elif [[ ";
+ static char elif_end[] = " ]]\nthen\n";
+ static char ex_start[] = "elif ";
+ static char ex_end[] = "\nthen\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else if (str[0] == '|')
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ } else {
+ buffer_add (buf, elif_start, strlen (elif_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, elif_end, strlen (elif_end));
+ }
+}
+
+
+/* generate an ELSE statment */
+void
+bash_else (buffer_t * buf, char *str, size_t len)
+{
+ static char else_start[] = "else";
+ static char else_start2[] = "else #";
+ static char else_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, else_start, strlen (else_start));
+ } else {
+ buffer_add (buf, else_start2, strlen (else_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, else_end, strlen (else_end));
+}
+
+
+/* generate a FI statment */
+void
+bash_endif (buffer_t * buf, char *str, size_t len)
+{
+ static char fi_start[] = "fi";
+ static char fi_start2[] = "fi #";
+ static char fi_end[] = "\n";
+
+ if (len == 0 )
+ {
+ buffer_add (buf, fi_start, strlen (fi_start));
+ } else {
+ buffer_add (buf, fi_start2, strlen (fi_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, fi_end, strlen (fi_end));
+}
+
+
+/* generate a CASE statment */
+void
+bash_case (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for case'\nexit 99\n";
+ static char case_start[] = "case ";
+ static char case_end[] = " in\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ } else {
+ buffer_add (buf, case_start, strlen (case_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, case_end, strlen (case_end));
+ }
+}
+
+
+/* generate a WHEN statment */
+void
+bash_when (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for when'\nexit 99\n";
+ static char elif_end[] = ")\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ } else {
+ buffer_add (buf, str, len-1);
+ buffer_add (buf, elif_end, strlen (elif_end));
+ }
+}
+
+
+/* generate an OTHERWISE statment */
+void
+bash_otherwise (buffer_t * buf, char *str, size_t len)
+{
+ static char otherwise_start[] = "*)";
+ static char otherwise_start2[] = "*) #";
+ static char otherwise_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, otherwise_start, strlen (otherwise_start));
+ } else {
+ buffer_add (buf, otherwise_start2, strlen (otherwise_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, otherwise_end, strlen (otherwise_end));
+}
+
+
+/* generate a ENDCASE statment */
+void
+bash_endcase (buffer_t * buf, char *str, size_t len)
+{
+ static char endcase_start[] = "esac";
+ static char endcase_start2[] = "esac #";
+ static char endcase_end[] = "\n";
+
+ if (len == 0 )
+ {
+ buffer_add (buf, endcase_start, strlen (endcase_start));
+ } else {
+ buffer_add (buf, endcase_start2, strlen (endcase_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, endcase_end, strlen (endcase_end));
+}
+
+
+/* generate a WHILE statment */
+void
+bash_while (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for while'\nexit 99\n";
+ static char while_start[] = "while [[ ";
+ static char while_end[] = " ]]\ndo\n";
+ static char ex_start[] = "while ";
+ static char ex_end[] = "\ndo\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else if (str[0] == '|')
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ } else {
+ buffer_add (buf, while_start, strlen (while_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, while_end, strlen (while_end));
+ }
+}
+
+
+/* generate an ENDWHILE statment */
+void
+bash_endwhile (buffer_t * buf, char *str, size_t len)
+{
+ static char endwhile_start[] = "done";
+ static char endwhile_start2[] = "done #";
+ static char endwhile_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, endwhile_start, strlen (endwhile_start));
+ } else {
+ buffer_add (buf, endwhile_start2, strlen (endwhile_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, endwhile_end, strlen (endwhile_end));
+}
+
+
+/* generate an UNTIL statment */
+void
+bash_until (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for until'\nexit 99\n";
+ static char until_start[] = "until [[ ";
+ static char until_end[] = " ]]\ndo\n";
+ static char ex_start[] = "until ";
+ static char ex_end[] = "\ndo\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else if (str[0] == '|')
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ } else {
+ buffer_add (buf, until_start, strlen (until_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, until_end, strlen (until_end));
+ }
+}
+
+
+/* generate an ENDUNTIL statment */
+void
+bash_enduntil (buffer_t * buf, char *str, size_t len)
+{
+ static char enduntil_start[] = "done";
+ static char enduntil_start2[] = "done #";
+ static char enduntil_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, enduntil_start, strlen (enduntil_start));
+ } else {
+ buffer_add (buf, enduntil_start2, strlen (enduntil_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, enduntil_end, strlen (enduntil_end));
+}
+
+
+/* generate a FOR statment */
+void
+bash_for (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for for'\nexit 99\n";
+ static char for_start[] = "for ";
+ static char for_end[] = "\ndo\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ } else {
+ buffer_add (buf, for_start, strlen (for_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, for_end, strlen (for_end));
+ }
+}
+
+
+/* generate an ENDFOR statment */
+void
+bash_endfor (buffer_t * buf, char *str, size_t len)
+{
+ static char endfor_start[] = "done";
+ static char endfor_start2[] = "done #";
+ static char endfor_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, endfor_start, strlen (endfor_start));
+ } else {
+ buffer_add (buf, endfor_start2, strlen (endfor_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, endfor_end, strlen (endfor_end));
+}
+
+
+/* generate an UNLESS statment */
+void
+bash_unless (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for unless'\nexit 99\n";
+ static char unless_start[] = "if [[ ! ( ";
+ static char unless_end[] = " ) ]]\nthen\n";
+ static char ex_start[] = "if ! ";
+ static char ex_end[] = "\nthen\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else if (str[0] == '|')
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ } else {
+ buffer_add (buf, unless_start, strlen (unless_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, unless_end, strlen (unless_end));
+ }
+}
+
+
+/* generate an ELUN statment */
+void
+bash_elun (buffer_t * buf, char *str, size_t len)
+{
+ static char err_msg[] = "echo 'error: missing expression for elun'\nexit 99\n";
+ static char elun_start[] = "elif [[ ! ( ";
+ static char elun_end[] = " ) ]]\nthen\n";
+ static char ex_start[] = "elif ! ";
+ static char ex_end[] = "\nthen\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else if (str[0] == '|')
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ } else {
+ buffer_add (buf, elun_start, strlen (elun_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, elun_end, strlen (elun_end));
+ }
+}
+
+
+/* generate an UNELSE statment */
+void
+bash_unelse (buffer_t * buf, char *str, size_t len)
+{
+ static char unelse_start[] = "else";
+ static char unelse_start2[] = "else #";
+ static char unelse_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, unelse_start, strlen (unelse_start));
+ } else {
+ buffer_add (buf, unelse_start2, strlen (unelse_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, unelse_end, strlen (unelse_end));
+}
+
+
+/* generate a ENDUNLESS statment */
+void
+bash_endunless (buffer_t * buf, char *str, size_t len)
+{
+ static char endunless_start[] = "fi";
+ static char endunless_start2[] = "fi #";
+ static char endunless_end[] = "\n";
+
+ if (len == 0)
+ {
+ buffer_add (buf, endunless_start, strlen (endunless_start));
+ } else {
+ buffer_add (buf, endunless_start2, strlen (endunless_start2));
+ buffer_add (buf, str, len);
+ }
+ buffer_add (buf, endunless_end, strlen (endunless_end));
+}
+#endif
void
bash_doscript (buffer_t * script, char *name)
diff --git a/src/h_bash.h b/src/h_bash.h
index 7d7e7a6..d827aa6 100644
--- a/src/h_bash.h
+++ b/src/h_bash.h
@@ -17,6 +17,25 @@ void bash_eval(buffer_t *buf, char *str, size_t len);
void bash_setup(char *shell, list_t *env);
void bash_doscript(buffer_t *script, char *name);
-
+#ifdef BASHEXTENSIONS
+void bash_if(buffer_t *buf, char *str, size_t len);
+void bash_elif(buffer_t *buf, char *str, size_t len);
+void bash_else(buffer_t *buf, char *str, size_t len);
+void bash_endif(buffer_t *buf, char *str, size_t len);
+void bash_case(buffer_t *buf, char *str, size_t len);
+void bash_when(buffer_t *buf, char *str, size_t len);
+void bash_otherwise(buffer_t *buf, char *str, size_t len);
+void bash_endcase(buffer_t *buf, char *str, size_t len);
+void bash_while(buffer_t *buf, char *str, size_t len);
+void bash_endwhile(buffer_t *buf, char *str, size_t len);
+void bash_until(buffer_t *buf, char *str, size_t len);
+void bash_enduntil(buffer_t *buf, char *str, size_t len);
+void bash_for(buffer_t *buf, char *str, size_t len);
+void bash_endfor(buffer_t *buf, char *str, size_t len);
+void bash_unless(buffer_t *buf, char *str, size_t len);
+void bash_elun(buffer_t *buf, char *str, size_t len);
+void bash_unelse(buffer_t *buf, char *str, size_t len);
+void bash_endunless(buffer_t *buf, char *str, size_t len);
+#endif
#endif /* !H_SUBSHELL_H */
diff --git a/src/h_script.c b/src/h_script.c
index 218792d..12aa0a9 100644
--- a/src/h_script.c
+++ b/src/h_script.c
@@ -37,7 +37,13 @@
#include "h_bash.h"
#include "haserl.h"
-/* HTML, RUN, INCLUDE, EVAL, COMMENT, NOOP }; */
+#ifdef BASHEXTENSIONS
+/* HTML, RUN, INCLUDE, EVAL, COMMENT, IF, ELIF, ELSE, ENDIF, CASE, WHEN,
+ OTHERWISE, ENDCASE, WHILE, ENDWHILE, UNTIL, ENDUNTIL, FOR, ENDFOR,
+ UNLESS, ELUN, UNELSE, ENDUNLESS, NOOP }; */
+#else
+/* HTML, RUN, INCLUDE, EVAL, COMMENT, NOOP */
+#endif
const char *g_tag[] = {
"",
@@ -45,6 +51,26 @@ const char *g_tag[] = {
"in",
"=",
"#",
+#ifdef BASHEXTENSIONS
+ "if",
+ "elif",
+ "else",
+ "endif",
+ "case",
+ "when",
+ "otherwise",
+ "endcase",
+ "while",
+ "endwhile",
+ "until",
+ "enduntil",
+ "for",
+ "endfor",
+ "unless",
+ "elun",
+ "unelse",
+ "endunless",
+#endif
""
};
@@ -340,12 +366,141 @@ preprocess_token_list (token_t * tokenlist)
newscript = load_script (me->buf, me->script);
build_token_list (newscript, me);
}
- if (memcmp (cp, g_tag[EVAL], 1) == 0)
+ else if (memcmp (cp, g_tag[EVAL], 1) == 0)
+
{
me->tag = EVAL;
me->buf = find_whitespace (me->buf);
me->len = strlen (me->buf);
}
+#ifdef BASHEXTENSIONS
+ else if (memcmp (cp, g_tag[IF], 2) == 0)
+ {
+ me->tag = IF;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ELIF], 4) == 0)
+ {
+ me->tag = ELIF;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ELSE], 4) == 0)
+ {
+ me->tag = ELSE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ENDIF], 5) == 0)
+ {
+ me->tag = ENDIF;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[CASE], 4) == 0)
+ {
+ me->tag = CASE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[WHEN], 4) == 0)
+ {
+ me->tag = WHEN;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[OTHERWISE], 9) == 0)
+ {
+ me->tag = OTHERWISE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ENDCASE], 7) == 0)
+ {
+ me->tag = ENDCASE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[WHILE], 5) == 0)
+ {
+ me->tag = WHILE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ENDWHILE], 8) == 0)
+ {
+ me->tag = ENDWHILE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[UNTIL], 5) == 0)
+ {
+ me->tag = UNTIL;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ENDUNTIL], 8) == 0)
+ {
+ me->tag = ENDUNTIL;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[FOR], 3) == 0)
+ {
+ me->tag = FOR;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ENDFOR], 6) == 0)
+ {
+ me->tag = ENDFOR;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[UNLESS], 6) == 0)
+ {
+ me->tag = UNLESS;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ELUN], 4) == 0)
+ {
+ me->tag = ELUN;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[UNELSE], 6) == 0)
+ {
+ me->tag = UNELSE;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+ else if (memcmp (cp, g_tag[ENDUNLESS], 9) == 0)
+ {
+ me->tag = ENDUNLESS;
+ me->buf = find_whitespace (me->buf);
+ me->buf = skip_whitespace (me->buf);
+ me->len = strlen (me->buf);
+ }
+#endif /* BASHEXTENSIONS */
if (isspace (*cp))
{
me->tag = RUN;
@@ -390,6 +545,62 @@ process_token_list (buffer_t * buf, token_t * token)
case EVAL:
shell_eval (buf, token->buf, token->len);
break;
+#ifdef BASHEXTENSIONS
+ case IF:
+ shell_if (buf, token->buf, token->len);
+ break;
+ case ELIF:
+ shell_elif (buf, token->buf, token->len);
+ break;
+ case ELSE:
+ shell_else (buf, token->buf, token->len);
+ break;
+ case ENDIF:
+ shell_endif (buf, token->buf, token->len);
+ break;
+ case CASE:
+ shell_case (buf, token->buf, token->len);
+ break;
+ case WHEN:
+ shell_when (buf, token->buf, token->len);
+ break;
+ case OTHERWISE:
+ shell_otherwise (buf, token->buf, token->len);
+ break;
+ case ENDCASE:
+ shell_endcase (buf, token->buf, token->len);
+ break;
+ case WHILE:
+ shell_while (buf, token->buf, token->len);
+ break;
+ case ENDWHILE:
+ shell_endwhile (buf, token->buf, token->len);
+ break;
+ case UNTIL:
+ shell_until (buf, token->buf, token->len);
+ break;
+ case ENDUNTIL:
+ shell_enduntil (buf, token->buf, token->len);
+ break;
+ case FOR:
+ shell_for (buf, token->buf, token->len);
+ break;
+ case ENDFOR:
+ shell_endfor (buf, token->buf, token->len);
+ break;
+ case UNLESS:
+ shell_unless (buf, token->buf, token->len);
+ break;
+ case ELUN:
+ shell_elun (buf, token->buf, token->len);
+ break;
+ case UNELSE:
+ shell_unelse (buf, token->buf, token->len);
+ break;
+ case ENDUNLESS:
+ shell_endunless (buf, token->buf, token->len);
+ break;
+#endif
default:
break;
}
diff --git a/src/h_script.h b/src/h_script.h
index fa80b26..e1098fe 100644
--- a/src/h_script.h
+++ b/src/h_script.h
@@ -17,7 +17,11 @@ typedef struct {
} script_t;
/* tag types */
+#ifdef BASHEXTENSIONS
+enum tag_t { HTML, RUN, INCLUDE, EVAL, COMMENT, IF, ELIF, ELSE, ENDIF, CASE, WHEN, OTHERWISE, ENDCASE, WHILE, ENDWHILE, UNTIL, ENDUNTIL, FOR, ENDFOR, UNLESS, ELUN, UNELSE, ENDUNLESS, NOOP };
+#else
enum tag_t { HTML, RUN, INCLUDE, EVAL, COMMENT, NOOP };
+#endif
/* token structure */
diff --git a/src/haserl.c b/src/haserl.c
index ed14b91..aa841ef 100644
--- a/src/haserl.c
+++ b/src/haserl.c
@@ -91,14 +91,33 @@ haserl_t global;
/* declare the shell_ function pointers here */
-void (*shell_exec) (buffer_t * buf, char *str);
-void (*shell_echo) (buffer_t * buf, char *str, size_t len);
-void (*shell_eval) (buffer_t * buf, char *str, size_t len);
+void (*shell_exec) (buffer_t *buf, char *str);
+void (*shell_echo) (buffer_t *buf, char *str, size_t len);
+void (*shell_eval) (buffer_t *buf, char *str, size_t len);
void (*shell_setup) (char *, list_t *);
void (*shell_doscript) (buffer_t *, char *);
void (*shell_destroy) (void);
-
+#ifdef BASHEXTENSIONS
+void (*shell_if) (buffer_t *buf, char *str, size_t len);
+void (*shell_elif) (buffer_t *buf, char *str, size_t len);
+void (*shell_else) (buffer_t *buf, char *str, size_t len);
+void (*shell_endif) (buffer_t *buf, char *str, size_t len);
+void (*shell_case) (buffer_t *buf, char *str, size_t len);
+void (*shell_when) (buffer_t *buf, char *str, size_t len);
+void (*shell_otherwise) (buffer_t *buf, char *str, size_t len);
+void (*shell_endcase) (buffer_t *buf, char *str, size_t len);
+void (*shell_while) (buffer_t *buf, char *str, size_t len);
+void (*shell_endwhile) (buffer_t *buf, char *str, size_t len);
+void (*shell_until) (buffer_t *buf, char *str, size_t len);
+void (*shell_enduntil) (buffer_t *buf, char *str, size_t len);
+void (*shell_for) (buffer_t *buf, char *str, size_t len);
+void (*shell_endfor) (buffer_t *buf, char *str, size_t len);
+void (*shell_unless) (buffer_t *buf, char *str, size_t len);
+void (*shell_elun) (buffer_t *buf, char *str, size_t len);
+void (*shell_unelse) (buffer_t *buf, char *str, size_t len);
+void (*shell_endunless) (buffer_t *buf, char *str, size_t len);
+#endif
/* global shell execution function pointers. These point to the actual functions
that do the job, based on the language */
@@ -206,11 +225,13 @@ myputenv (list_t * cur, char *str, char *prefix)
int array = 0;
int len;
- keylen = (size_t) ((char *) memchr (str, '=', strlen (str)) - (char *) str);
- if (keylen <= 0)
- {
- return (NULL);
- }
+ temp = memchr (str, '=', strlen(str));
+ /* if we don't have an equal sign, exit early */
+ if (temp == 0 ) {
+ return (cur);
+ }
+
+ keylen = (size_t) (temp - str);
/* is this an array */
if (memcmp (str + keylen - 2, "[]", 2) == 0)
@@ -341,6 +362,7 @@ CookieVars (list_t * env)
token++;
}
myputenv (env, token, global.var_prefix);
+ myputenv (env, token, global.cookie_prefix);
token = strtok (NULL, ";");
}
free (qs);
@@ -424,6 +446,7 @@ ReadCGIQueryString (list_t * env)
{
unescape_url (token);
myputenv (env, token, global.var_prefix);
+ myputenv (env, token, global.get_prefix);
token = strtok (NULL, "&;");
}
free (qs);
@@ -509,6 +532,7 @@ ReadCGIPOSTValues (list_t * env)
}
unescape_url ((char *) data);
myputenv (env, (char *) data, global.var_prefix);
+ myputenv (env, (char *) data, global.post_prefix);
if (token.data)
{
buffer_reset (&token);
@@ -573,7 +597,8 @@ parseCommandLine (int argc, char *argv[])
case 'v':
case 'h':
printf ("This is " PACKAGE_NAME " version " PACKAGE_VERSION ""
- "(http://haserl.sourceforge.net)\n");
+ "(http://haserl.sourceforge.net)\n"
+ "Extended by simnux (unsupported)");
exit (0);
break;
}
@@ -613,7 +638,10 @@ assignGlobalStartupValues ()
global.debug = FALSE; /* Not in debug mode. */
global.acceptall = FALSE; /* don't allow POST data for GET method */
global.uploadlist = NULL; /* we don't have any uploaded files */
- global.var_prefix = HASERL_VAR_PREFIX;
+ global.var_prefix = "FORM_";
+ global.get_prefix = "GET_";
+ global.post_prefix = "POST_";
+ global.cookie_prefix = "COOKIE_";
global.nul_prefix = "";
}
@@ -674,7 +702,8 @@ main (int argc, char *argv[])
/* we were run, instead of called as a shell script */
puts ("This is " PACKAGE_NAME " version " PACKAGE_VERSION "\n"
"This program runs as a cgi interpeter, not interactively\n"
- "Please see: http://haserl.sourceforge.net");
+ "Please see: http://haserl.sourceforge.net\n"
+ "Extended by simnux (unsupported)");
return (0);
break;
case 2:
@@ -714,6 +743,28 @@ main (int argc, char *argv[])
shell_setup = &bash_setup;
shell_doscript = &bash_doscript;
shell_destroy = &bash_destroy;
+
+#ifdef BASH_EXTENSIONS
+ shell_if = &bash_if;
+ shell_elif = &bash_elif;
+ shell_else = &bash_else;
+ shell_endif = &bash_endif;
+ shell_case = &bash_case;
+ shell_when = &bash_when;
+ shell_otherwise = &bash_otherwise;
+ shell_endcase = &bash_endcase;
+ shell_while = &bash_while;
+ shell_endwhile = &bash_endwhile;
+ shell_until = &bash_until;
+ shell_enduntil = &bash_enduntil;
+ shell_for = &bash_for;
+ shell_endfor = &bash_endfor;
+ shell_unless = &bash_unless;
+ shell_elun = &bash_elun;
+ shell_unelse = &bash_unelse;
+ shell_endunless = &bash_endunless;
+#endif
+
#else
die_with_message (NULL, NULL, "Bash shell is not enabled.");
#endif
@@ -785,12 +836,14 @@ main (int argc, char *argv[])
}
}
- /* build a copy of the script to send to the shell */
+/* build a copy of the script to send to the shell */
#ifndef JUST_LUACSHELL
if (strcmp (global.shell, "luac"))
{
- process_token_list (&script_text, tokenchain);
- }
+ printf ("Process_token_list is %p\n", process_token_list);
+ printf ("script text is %p and tokenchain is %p\n", &script_text, tokenchain);
+ process_token_list (&script_text, tokenchain);
+ }
#endif
/* run the script */
diff --git a/src/haserl.h b/src/haserl.h
index 8cd5a9e..e7b0e1f 100644
--- a/src/haserl.h
+++ b/src/haserl.h
@@ -5,16 +5,20 @@
/* Just a silly construct to contain global variables */
typedef struct
{
- unsigned long uploadkb; /* how big an upload do we allow (0 for none) */
- char *shell; /* The shell we use */
- char *uploaddir; /* where we upload to */
- char *uploadhandler; /* a handler for uploads */
- char *var_prefix; /* what name we give to FORM variables */
- char *nul_prefix; /* what name we give to environment variables */
- token_t *uploadlist; /* a linked list of pathspecs */
- int debug; /* true if in "debug" mode */
- int acceptall; /* true if we'll accept POST data on GETs and vice versa */
- int silent; /* true if we never print errors */
+ unsigned long uploadkb; /* how big an upload do we allow (0 for none)*/
+ char *shell; /* The shell we use */
+ char *uploaddir; /* where we upload to */
+ char *uploadhandler; /* a handler for uploads */
+ char *var_prefix; /* what name we give to FORM variables */
+ char *get_prefix; /* what name we give to POST variables */
+ char *post_prefix; /* what name we give to POST variables */
+ char *cookie_prefix; /* what name we give to COOKIE variables */
+ char *nul_prefix; /* what name we give to environment variables*/
+ token_t *uploadlist; /* a linked list of pathspecs */
+ int debug; /* true if in "debug" mode */
+ int acceptall; /* true if we'll accept POST data on
+ GETs and vice versa */
+ int silent; /* true if we never print errors */
} haserl_t;
extern haserl_t global;
@@ -49,6 +53,25 @@ extern void (*shell_setup)( char *, list_t *);
extern void (*shell_doscript)( buffer_t *, char *);
extern void (*shell_destroy) (void);
+#ifdef BASHEXTENSIONS
+extern void (*shell_if)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_elif)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_else)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_endif)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_case)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_when)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_otherwise)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_endcase)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_while)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_endwhile)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_until)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_enduntil)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_for)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_endfor)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_unless)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_elun)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_unelse)(buffer_t *buf, char *str, size_t len);
+extern void (*shell_endunless)(buffer_t *buf, char *str, size_t len);
+#endif
#endif /* !_HASERL_H */
-
diff --git a/src/rfc2388.c b/src/rfc2388.c
index 8fd626d..757a01e 100644
--- a/src/rfc2388.c
+++ b/src/rfc2388.c
@@ -166,6 +166,7 @@ mime_var_putenv (list_t * env, mime_var_t * obj)
buffer_add (&buf, (char *) obj->value.data,
strlen ((char *) obj->value.data) + 1);
myputenv (env, (char *) buf.data, global.var_prefix);
+ myputenv (env, (char *) buf.data, global.post_prefix);
buffer_reset (&buf);
}
if (obj->filename)
@@ -174,6 +175,7 @@ mime_var_putenv (list_t * env, mime_var_t * obj)
buffer_add (&buf, "_name=", 6);
buffer_add (&buf, obj->filename, strlen (obj->filename) + 1);
myputenv (env, (char *) buf.data, global.var_prefix);
+ myputenv (env, (char *) buf.data, global.post_prefix);
buffer_reset (&buf);
}
buffer_destroy (&buf);