Multi function processing from if / ifn
This commit is contained in:
parent
93a2e6144f
commit
315244fc91
106
src/lexer.c
106
src/lexer.c
@ -73,7 +73,7 @@ char *process_line (char *line)
|
|||||||
|
|
||||||
if (tok_srch == NULL)
|
if (tok_srch == NULL)
|
||||||
{
|
{
|
||||||
x_warn("ss:warn:if statement requires arguments");
|
x_warn("ss:warn:if statement requires a compare argument");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,34 +82,41 @@ char *process_line (char *line)
|
|||||||
strcmp(tok_srch, " \n") == 0 ||
|
strcmp(tok_srch, " \n") == 0 ||
|
||||||
strcmp(tok_srch, " ") == 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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
compbuf = qmalloc(QM_SS, (strlen(parse_vars(tok_srch)) + 1));
|
compbuf = qmalloc(QM_SS, (strlen(tok_srch) + 1));
|
||||||
*compbuf = '\0';
|
*compbuf = '\0';
|
||||||
strcat(compbuf, parse_vars(tok_srch));
|
strcat(compbuf, tok_srch);
|
||||||
|
|
||||||
tok_srch = strtok_next (";");
|
tok_srch = strtok_next (";");
|
||||||
|
|
||||||
if (tok_srch == NULL)
|
if ((strncmp ("true" ,
|
||||||
{
|
parse_vars (parse_bq (compbuf)), 4) == 0) ||
|
||||||
x_warn("ss:warn:if syntax error, missing last argument?");
|
(strncmp ("1" ,
|
||||||
return NULL;
|
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));
|
while (tok_srch != NULL)
|
||||||
printf("%s\n", proc_return);
|
{
|
||||||
fflush(stdout);
|
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;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@@@
|
//@@@
|
||||||
@ -133,7 +140,7 @@ char *process_line (char *line)
|
|||||||
strcmp(tok_srch, " \n") == 0 ||
|
strcmp(tok_srch, " \n") == 0 ||
|
||||||
strcmp(tok_srch, " ") == 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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,60 +148,20 @@ char *process_line (char *line)
|
|||||||
*compbuf = '\0';
|
*compbuf = '\0';
|
||||||
|
|
||||||
strcat (compbuf, tok_srch);
|
strcat (compbuf, tok_srch);
|
||||||
printf ("toksrch: %s\n", tok_srch);
|
|
||||||
|
|
||||||
tok_srch = strtok_next (";");
|
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" ,
|
if ((strncmp ("false" ,
|
||||||
parse_vars (parse_bq (compbuf)), 5) == 0) ||
|
parse_vars (parse_bq (compbuf)), 5) == 0) ||
|
||||||
(strncmp ("0" ,
|
(strncmp ("0" ,
|
||||||
parse_vars (parse_bq (compbuf)), 1) == 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)
|
while (tok_srch != NULL)
|
||||||
{
|
{
|
||||||
dobuf = qmalloc (QM_SS, (strlen (tok_srch) + 1));
|
dobuf = qmalloc (QM_SS, (strlen (tok_srch) + 1));
|
||||||
*dobuf = '\0';
|
*dobuf = '\0';
|
||||||
strcat (dobuf, tok_srch);
|
strcat (dobuf, tok_srch);
|
||||||
|
|
||||||
// In the cited example, on the first pass here, "dobuf[]" now con-
|
|
||||||
// tains:
|
|
||||||
// print "Hello"<EOS>
|
|
||||||
|
|
||||||
proc_return = process_line (parse_vars (dobuf));
|
proc_return = process_line (parse_vars (dobuf));
|
||||||
|
|
||||||
if (proc_return != NULL)
|
if (proc_return != NULL)
|
||||||
@ -203,15 +170,7 @@ char *process_line (char *line)
|
|||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("toksrch: %s dobuf: %s\n", tok_srch, dobuf);
|
|
||||||
tok_srch = strtok_next (";");
|
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 (";");
|
tok_srch = strtok_next (";");
|
||||||
if (tok_srch == NULL)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
loopbuf = qmalloc(QM_SS, (strlen(parse_vars(tok_srch)) + 1));
|
loopbuf = qmalloc (QM_SS, (strlen (tok_srch) + 1));
|
||||||
*loopbuf = '\0';
|
*loopbuf = '\0';
|
||||||
strcat(loopbuf, parse_vars(tok_srch));
|
strcat (loopbuf, tok_srch);
|
||||||
|
|
||||||
for(ii = 0; ii < loop_count; ii++)
|
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)
|
if (proc_return != NULL)
|
||||||
{
|
{
|
||||||
printf("%s\n", proc_return);
|
printf ("%s\n", proc_return);
|
||||||
fflush(stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tok_srch = strtok_next (";");
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user