From 315244fc910f6cd1db21ae13d533a485833cd18b Mon Sep 17 00:00:00 2001 From: Pentium44 Date: Wed, 19 May 2021 01:07:55 -0700 Subject: [PATCH] Multi function processing from if / ifn --- src/lexer.c | 106 +++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 72 deletions(-) diff --git a/src/lexer.c b/src/lexer.c index fcd6dc0..d24b830 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -73,7 +73,7 @@ char *process_line (char *line) if (tok_srch == NULL) { - x_warn("ss:warn:if statement requires arguments"); + x_warn("ss:warn:if statement requires a compare argument"); return NULL; } @@ -82,34 +82,41 @@ char *process_line (char *line) strcmp(tok_srch, " \n") == 0 || strcmp(tok_srch, " ") == 0) { - x_warn("ss:warn:if syntax error, missing argument?"); + x_warn("ss:warn:if syntax error, missing function call(s)?"); return NULL; } - compbuf = qmalloc(QM_SS, (strlen(parse_vars(tok_srch)) + 1)); + compbuf = qmalloc(QM_SS, (strlen(tok_srch) + 1)); *compbuf = '\0'; - strcat(compbuf, parse_vars(tok_srch)); + strcat(compbuf, tok_srch); tok_srch = strtok_next (";"); - if (tok_srch == NULL) - { - x_warn("ss:warn:if syntax error, missing last argument?"); - return NULL; - } + if ((strncmp ("true" , + parse_vars (parse_bq (compbuf)), 4) == 0) || + (strncmp ("1" , + parse_vars (parse_bq (compbuf)), 1) == 0)) - dobuf = qmalloc(QM_SS, (strlen(parse_vars(tok_srch)) + 1)); - *dobuf = '\0'; - strcat(dobuf, parse_vars(tok_srch)); - - if ((strncmp("true", compbuf, 4) == 0) || (strncmp("1", compbuf, 1) == 0)) { - proc_return = process_line(parse_vars(dobuf)); - printf("%s\n", proc_return); - fflush(stdout); + while (tok_srch != NULL) + { + dobuf = qmalloc (QM_SS, (strlen (tok_srch) + 1)); + *dobuf = '\0'; + strcat (dobuf, tok_srch); + proc_return = process_line (parse_vars (dobuf)); + + if (proc_return != NULL) + { + printf ("%s\n", proc_return); + fflush (stdout); + } + + tok_srch = strtok_next (";"); + } } return NULL; + } //@@@ @@ -133,7 +140,7 @@ char *process_line (char *line) strcmp(tok_srch, " \n") == 0 || strcmp(tok_srch, " ") == 0) { - x_warn("ss:warn:ifn syntax error, missing function call?"); + x_warn("ss:warn:ifn syntax error, missing function call(s)?"); return NULL; } @@ -141,60 +148,20 @@ char *process_line (char *line) *compbuf = '\0'; strcat (compbuf, tok_srch); - printf ("toksrch: %s\n", tok_srch); tok_srch = strtok_next (";"); - printf ("toksrch: %s\n", tok_srch); - -//-------------------------------------------------------------------- - -// Possible examples of "compbuf[]" at this point: -// -// false // or 0 -// true // or 1 -// `comp: "1" "1"` -// `comp: "1" "2"` -// %foo% // which *contains* one of the preceding - -// The "parse_bq" calls below return copies of "compbuf[]" that re- -// placed quoted `things` with the return values of the corresponding -// functions. - -// In the context of this calling routine (process_line) that needs to -// be a single false, 0, true, or 1 [if backquotes are used]. - -// "parse_vars" replaces %foo% with the value of the specified variab- -// le. Which, if a variable is used, needs to work out to a single -// false, 0, true, or 1. - -// The bottom line is that we expect to end up with "false", "0", -// "true", or "1" being passed to "strncmp" as the 2nd argument. As -// this is code that implements "ifn", only the values "false" and "0" -// will then lead to further processing. if ((strncmp ("false" , parse_vars (parse_bq (compbuf)), 5) == 0) || (strncmp ("0" , parse_vars (parse_bq (compbuf)), 1) == 0)) -//-------------------------------------------------------------------- - { -// Example of "tok_srch[]" at this point: -// -// ifn: false; print "Hello"; print "World" -// ^ Here ^ This has been replaced with EOS - while (tok_srch != NULL) { dobuf = qmalloc (QM_SS, (strlen (tok_srch) + 1)); *dobuf = '\0'; strcat (dobuf, tok_srch); - -// In the cited example, on the first pass here, "dobuf[]" now con- -// tains: -// print "Hello" - proc_return = process_line (parse_vars (dobuf)); if (proc_return != NULL) @@ -203,15 +170,7 @@ char *process_line (char *line) fflush (stdout); } - printf ("toksrch: %s dobuf: %s\n", tok_srch, dobuf); tok_srch = strtok_next (";"); - -// In the cited example, on the first pass here, "tok_srch[]" now -// points to: -// -// ifn: false; print "Hello"; print "World" -// ^ Here ^ -// This has been replaced with EOS } } @@ -251,22 +210,25 @@ char *process_line (char *line) tok_srch = strtok_next (";"); if (tok_srch == NULL) { - x_warn("ss:warn:loop syntax error, missing last argument?"); + x_warn("ss:warn:loop syntax error, missing function call?"); return NULL; } - loopbuf = qmalloc(QM_SS, (strlen(parse_vars(tok_srch)) + 1)); + loopbuf = qmalloc (QM_SS, (strlen (tok_srch) + 1)); *loopbuf = '\0'; - strcat(loopbuf, parse_vars(tok_srch)); + strcat (loopbuf, tok_srch); for(ii = 0; ii < loop_count; ii++) { - proc_return = process_line(parse_vars(loopbuf)); + proc_return = process_line (parse_vars (loopbuf)); + if (proc_return != NULL) { - printf("%s\n", proc_return); - fflush(stdout); + printf ("%s\n", proc_return); + fflush (stdout); } + + tok_srch = strtok_next (";"); } return NULL;