From 93a2e6144f7009a3c19ed91eec44cbf8aa6ccd89 Mon Sep 17 00:00:00 2001 From: Robert Kiraly Date: Wed, 19 May 2021 00:20:43 -0700 Subject: [PATCH] Use "strtok_r" instead of "strtok" to fix lexer issues. --- src/lexer.c | 614 ++++++++++++++++++++++++++++------------------------ 1 file changed, 335 insertions(+), 279 deletions(-) diff --git a/src/lexer.c b/src/lexer.c index 1013cdb..fcd6dc0 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -15,43 +15,45 @@ #include "inc/network.h" #include "inc/search.h" #include "inc/inset.h" + // For slidescript compression algorithm #include "inc/tar.h" #include "inc/compression.h" -char *process_line(char *line) +#define strtok_next(s) strtok_r (NULL, s, &strtok_save) + +char *process_line (char *line) { + char *strtok_save; char *tok_srch, *retbuf, *filebuf, *compbuf, *loopbuf; - //printf("%s", &line[strlen(line)-2]); + static char dirpathbuf [MAX_STRING_BUFSIZE]; - static char dirpathbuf[MAX_STRING_BUFSIZE]; - - tok_srch = strtok(line, "=\" ;"); + tok_srch = strtok_r (line, "=\" ;", &strtok_save); /* reuse function */ - /*else if(strncmp("temp",tok_srch,4) == 0) + /*else if (strncmp("temp",tok_srch,4) == 0) { - tok_srch = strtok(NULL, " "); + tok_srch = strtok_next (" "); }*/ /* if line starts with a comment, skip */ - if(strncmp("#",tok_srch,1) == 0) + if (strncmp("#",tok_srch,1) == 0) { return NULL; } // Check for main calls from user in interactive - else if(strncmp("exit", tok_srch, 4) == 0) + else if (strncmp("exit", tok_srch, 4) == 0) x_error("ss:exit called"); - else if(strncmp("version", tok_srch, 7) == 0) + else if (strncmp("version", tok_srch, 7) == 0) { x_warn(":ss:version: %s, type 'help' for function list\n", VERSION); return NULL; } - else if(strncmp("help", tok_srch, 4) == 0) + else if (strncmp("help", tok_srch, 4) == 0) { x_warn(":ss:help:\n%s", FUNCTION_HELP); return NULL; @@ -61,22 +63,22 @@ char *process_line(char *line) // Somewhat usable as a language in other instances // If statement, processes string if first arg is true - else if(strncmp("if:", tok_srch, 3) == 0) + else if (strncmp("if:", tok_srch, 3) == 0) { char *proc_return; char *dobuf; // We have an if statement - tok_srch = strtok(NULL, ";"); + tok_srch = strtok_next (";"); - if(tok_srch == NULL) + if (tok_srch == NULL) { x_warn("ss:warn:if statement requires arguments"); return NULL; } // Check if there's anything after the first quote - if(strcmp(tok_srch, "\n") == 0 || + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0 || strcmp(tok_srch, " ") == 0) { @@ -88,8 +90,9 @@ char *process_line(char *line) *compbuf = '\0'; strcat(compbuf, parse_vars(tok_srch)); - tok_srch = strtok(NULL, ";"); - if(tok_srch == NULL) + tok_srch = strtok_next (";"); + + if (tok_srch == NULL) { x_warn("ss:warn:if syntax error, missing last argument?"); return NULL; @@ -99,7 +102,7 @@ char *process_line(char *line) *dobuf = '\0'; strcat(dobuf, parse_vars(tok_srch)); - if((strncmp("true", compbuf, 4) == 0) || (strncmp("1", compbuf, 1) == 0)) + if ((strncmp("true", compbuf, 4) == 0) || (strncmp("1", compbuf, 1) == 0)) { proc_return = process_line(parse_vars(dobuf)); printf("%s\n", proc_return); @@ -109,53 +112,106 @@ char *process_line(char *line) return NULL; } - else if(strncmp("ifn:", tok_srch, 4) == 0) +//@@@ + else if (strncmp("ifn:", tok_srch, 4) == 0) { char *proc_return; char *dobuf; // We have an if statement - tok_srch = strtok(NULL, ";"); + tok_srch = strtok_next (";"); - if(tok_srch == NULL) + if (tok_srch == NULL) { x_warn("ss:warn:ifn statement requires a compare argument."); return NULL; } // Check if there's anything after the first quote - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || - strcmp(tok_srch, " ") == 0) + + if (strcmp(tok_srch, "\n") == 0 || + strcmp(tok_srch, " \n") == 0 || + strcmp(tok_srch, " ") == 0) { x_warn("ss:warn:ifn syntax error, missing function call?"); return NULL; } - compbuf = qmalloc(QM_SS, (strlen(tok_srch) + 1)); + compbuf = qmalloc(QM_SS, (strlen(tok_srch) + 1)); *compbuf = '\0'; - strcat(compbuf, tok_srch); - printf("toksrch: %s\n", tok_srch); - tok_srch = strtok(NULL, ";"); - printf("toksrch: %s\n", tok_srch); + 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)) + +//-------------------------------------------------------------------- - if( (strncmp("false", parse_vars(parse_bq(compbuf)), 5) == 0) - || (strncmp("0", parse_vars(parse_bq(compbuf)), 1) == 0)) { - while(tok_srch != NULL) - { - dobuf = qmalloc(QM_SS, (strlen(tok_srch) + 1)); - *dobuf = '\0'; - strcat(dobuf, tok_srch); +// Example of "tok_srch[]" at this point: +// +// ifn: false; print "Hello"; print "World" +// ^ Here ^ This has been replaced with EOS - //proc_return = process_line(parse_vars(dobuf)); - //if(proc_return != NULL) { - // printf("%s\n", proc_return); - // fflush(stdout); - //} - printf("toksrch: %s\n", tok_srch); - tok_srch = strtok(NULL, ";"); + 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) + { + printf ("%s\n", proc_return); + 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 } } @@ -163,23 +219,23 @@ char *process_line(char *line) } // Loop - else if(strncmp("loop:", tok_srch, 5) == 0) + else if (strncmp("loop:", tok_srch, 5) == 0) { int loop_count, ii; char *proc_return; char *countbuf; // We have an if statement - tok_srch = strtok(NULL, ";"); + tok_srch = strtok_next (";"); - if(tok_srch == NULL) + if (tok_srch == NULL) { x_warn("ss:warn:loop statement requires arguments"); return NULL; } // Check if there's anything after the first quote - if(strcmp(tok_srch, "\n") == 0 || + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0 || strcmp(tok_srch, " ") == 0) { @@ -192,8 +248,8 @@ char *process_line(char *line) strcat(countbuf, parse_vars(tok_srch)); loop_count = atoi(countbuf); - tok_srch = strtok(NULL, ";"); - if(tok_srch == NULL) + tok_srch = strtok_next (";"); + if (tok_srch == NULL) { x_warn("ss:warn:loop syntax error, missing last argument?"); return NULL; @@ -206,7 +262,7 @@ char *process_line(char *line) for(ii = 0; ii < loop_count; ii++) { proc_return = process_line(parse_vars(loopbuf)); - if(proc_return != NULL) + if (proc_return != NULL) { printf("%s\n", proc_return); fflush(stdout); @@ -217,25 +273,25 @@ char *process_line(char *line) } // IF statement - else if(strncmp("comp:", tok_srch, 5) == 0) + else if (strncmp("comp:", tok_srch, 5) == 0) { // We have an if statement - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:if statement requires arguments"); return NULL; } // Check if there's anything after the first quote - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:if syntax error, missing first argument?"); return NULL; } // Make sure the end quote exists - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:if syntax error, missing quote?"); return NULL; @@ -244,28 +300,28 @@ char *process_line(char *line) compbuf = qmalloc(QM_SS, (strlen(parse_vars(tok_srch)) + 1)); strcpy(compbuf, parse_vars(tok_srch)); - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:if statement requires two compared arguments"); return NULL; } // Check if there's anything after the first quote - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:if syntax error, missing second argument?"); return NULL; } // Make sure the end quote exists - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:if syntax error, missing end quote?"); return NULL; } - if(atoi(compbuf) == atoi(parse_vars(tok_srch)) && + if (atoi(compbuf) == atoi(parse_vars(tok_srch)) && strncmp(compbuf, parse_vars(tok_srch), strlen(compbuf)) == 0) { return "true"; @@ -277,18 +333,18 @@ char *process_line(char *line) } // Unset variable function - else if(strncmp("unset", tok_srch, 5) == 0) + else if (strncmp("unset", tok_srch, 5) == 0) { char *varname; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:unset syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:unset syntax error, missing end quote?"); return NULL; @@ -300,33 +356,33 @@ char *process_line(char *line) } // Change directory - else if(strncmp("backdir", tok_srch, 7) == 0) + else if (strncmp("backdir", tok_srch, 7) == 0) { int chdir_return = chdir(".."); - if(chdir_return < 0) + if (chdir_return < 0) { x_warn("ss:warn:backdir, failed to move directory location"); } } // Move files using rename() - else if(strncmp("move",tok_srch,4) == 0 || strncmp("mv", tok_srch, 2) == 0) + else if (strncmp("move",tok_srch,4) == 0 || strncmp("mv", tok_srch, 2) == 0) { char orig_fn[MAX_STRING_BUFSIZE]; // Should never be more than 6 characters - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:move syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:move syntax error, missing filename?"); return NULL; } - if(strlen(parse_vars(tok_srch)) < MAX_STRING_LEN) + if (strlen(parse_vars(tok_srch)) < MAX_STRING_LEN) { strcpy(orig_fn, parse_vars(tok_srch)); } @@ -337,29 +393,28 @@ char *process_line(char *line) } /* strtok to the content that will be written to file */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:move syntax error, missing quote?"); return NULL; } - - tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + tok_srch = strtok_next ("\""); + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:move syntax error, missing second filename?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:move syntax error, missing quote?"); return NULL; } int rename_return = rename(orig_fn, parse_vars(tok_srch)); - if(rename_return < 0) + if (rename_return < 0) { x_warn("ss:warn:move, failed to move file"); } @@ -369,7 +424,7 @@ char *process_line(char *line) // Show current directory. - else if(strncmp("showpath", tok_srch, 8) == 0 || strncmp("pwd", tok_srch, 3) == 0) + else if (strncmp("showpath", tok_srch, 8) == 0 || strncmp("pwd", tok_srch, 3) == 0) { // Get current directory, if it errors, return NULL if (getcwd(retbuf, sizeof(dirpathbuf)) == NULL) { @@ -380,19 +435,19 @@ char *process_line(char *line) } // Change directory - else if(strncmp("chdir", tok_srch, 5) == 0 || strncmp("cd", tok_srch, 2) == 0) + else if (strncmp("chdir", tok_srch, 5) == 0 || strncmp("cd", tok_srch, 2) == 0) { char *dirname; int chdir_return; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:chdir syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:chdir syntax error, missing end quote?"); return NULL; @@ -402,7 +457,7 @@ char *process_line(char *line) chdir_return = chdir(dirname); - if(chdir_return < 0) + if (chdir_return < 0) { x_warn("ss:warn:chdir, error changing directory"); } @@ -410,23 +465,23 @@ char *process_line(char *line) } - else if(strncmp("showdir", tok_srch, 7) == 0 || strncmp("ls", tok_srch, 2) == 0) + else if (strncmp("showdir", tok_srch, 7) == 0 || strncmp("ls", tok_srch, 2) == 0) { char *dirname; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { dirname = "."; } - if(strtok(NULL, "\"")==NULL && dirname == NULL) + if (strtok_next ("\"")==NULL && dirname == NULL) { x_warn("ss:warn:showdir syntax error, missing end quote?"); return NULL; } - if(dirname == NULL) + if (dirname == NULL) dirname = parse_vars(tok_srch); struct dirent **files; @@ -466,21 +521,21 @@ char *process_line(char *line) } /* COMPRESSION AND DECOMPRESSION */ - else if(strncmp("decompress",tok_srch,10) == 0) + else if (strncmp("decompress",tok_srch,10) == 0) { char *filename; struct tar_t *archive = NULL; int fd; tar_free_pool(); - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:decompress syntax error, missing quote?"); + x_warn("ss:warn:decompress syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"")==NULL) + if (strtok_next ("\"")==NULL) { x_warn("ss:warn:decompress syntax error, missing end quote?"); return NULL; @@ -494,7 +549,7 @@ char *process_line(char *line) char filedecout[MAX_FILENAME_LEN+5]; in = fopen(filename, "rb"); - if(in == NULL) + if (in == NULL) { x_warn("ss:warn:compress, failed to open tar for compression"); return NULL; @@ -524,7 +579,7 @@ char *process_line(char *line) } // perform operation - if(tar_extract(fd, archive, 0, NULL, '1') < 0) { // extract entries + if (tar_extract(fd, archive, 0, NULL, '1') < 0) { // extract entries x_warn("ss:warn:decompress, error occured"); return NULL; } @@ -542,7 +597,7 @@ char *process_line(char *line) } /* Compression function of tar */ - else if(strncmp("compress",tok_srch,8) == 0) + else if (strncmp("compress",tok_srch,8) == 0) { char filename[MAX_FILENAME_LEN+1]; // Files to be added into the archive char comp_size[128]; @@ -550,21 +605,21 @@ char *process_line(char *line) int fd; tar_free_pool(); - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:compress syntax error, missing quote?"); + x_warn("ss:warn:compress syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:compress syntax error, missing archive name..."); return NULL; } // Save tarball filename - if(strlen(parse_vars(tok_srch)) < MAX_FILENAME_LEN) + if (strlen(parse_vars(tok_srch)) < MAX_FILENAME_LEN) { sprintf(filename, "%s", parse_vars(tok_srch)); } @@ -579,44 +634,44 @@ char *process_line(char *line) return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:compress syntax error, missing quote?"); + x_warn("ss:warn:compress syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:compress syntax error, missing quote?"); + x_warn("ss:warn:compress syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:compress, missing file path (what are we gonna compress?)"); return NULL; } - if(strtok(NULL, "\"")==NULL) + if (strtok_next ("\"")==NULL) { x_warn("ss:warn:compress syntax error, missing end quote?"); return NULL; } int argc = 0; - char *argv[MAX_FILES]; + char *argv [MAX_FILES]; + char *alt_save; + char *p2 = strtok_r (tok_srch, " ", &alt_save); - char *p2 = strtok(tok_srch, " "); while (p2 && argc < MAX_FILES-1) { argv[argc++] = p2; - p2 = strtok(NULL, " "); + p2 = strtok_r (NULL, " ", &alt_save); } argv[argc] = 0; - const char **tarin = (const char **) &argv[0]; if (tar_write(fd, &archive, argc, tarin, '1') < 0) { @@ -635,7 +690,7 @@ char *process_line(char *line) char filedecout[MAX_FILENAME_LEN+10]; in = fopen(filename, "rb"); - if(in == NULL) + if (in == NULL) { x_warn("ss:warn:compress, failed to open tar for compression"); return NULL; @@ -653,7 +708,7 @@ char *process_line(char *line) { uint32_t comp_return = ss_compress(filename, file_comp, i); uint32_t deco_return = ss_decompress(file_comp, filedecout); - if(atoi(comp_size) < (int)comp_return && comp_return != 0 && deco_return != 0 && i != 1) + if (atoi(comp_size) < (int)comp_return && comp_return != 0 && deco_return != 0 && i != 1) { retbuf = qmalloc(QM_SS, sizeof(deco_return) + sizeof(comp_return) + strlen(file_comp) + 40); sprintf(retbuf, "ss: %s: compressed: %u -> %u", file_comp, deco_return, comp_return); @@ -673,24 +728,24 @@ char *process_line(char *line) } /* mkdir function, and mkfile functions */ - else if(strncmp("mkdir",tok_srch,5) == 0) + else if (strncmp("mkdir",tok_srch,5) == 0) { int parsed; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:mkdir syntax error, missing quote?"); + x_warn("ss:warn:mkdir syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"")==NULL) + if (strtok_next ("\"")==NULL) { x_warn("ss:warn:mkdir syntax error, missing end quote?"); return NULL; } parsed = file_exists(parse_vars(tok_srch)); - if(parsed == 1) + if (parsed == 1) { x_warn("ss:warn:mkdir, file exists"); return NULL; @@ -699,30 +754,30 @@ char *process_line(char *line) // Create directory if need pe int mkpret = mkpath(parse_vars(tok_srch), 0755); - if(mkpret == -1) + if (mkpret == -1) x_warn("ss:warn:mkdir, failed to make directory"); - + return NULL; } - else if(strncmp("mkfile",tok_srch,5) == 0) + else if (strncmp("mkfile",tok_srch,5) == 0) { int parsed; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:mkfile syntax error, missing quote?"); + x_warn("ss:warn:mkfile syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"")==NULL) + if (strtok_next ("\"")==NULL) { x_warn("ss:warn:mkfile syntax error, missing end quote?"); return NULL; } parsed = file_exists(parse_vars(tok_srch)); - if(parsed == 1) + if (parsed == 1) { x_warn("ss:warn:mkfile, file exists"); return NULL; @@ -731,11 +786,11 @@ char *process_line(char *line) // Create directory if need pe int mkpret = mkpath(parse_vars(tok_srch), 0755); - if(mkpret == -1) + if (mkpret == -1) x_warn("ss:warn:mkfile, failed to form parent path, attempting to write file."); FILE *cfile = fopen(parse_vars(tok_srch), "w"); - if(cfile == NULL) + if (cfile == NULL) { x_warn("ss:warn:mkfile, failed to open file"); return NULL; @@ -748,7 +803,7 @@ char *process_line(char *line) /* time function */ - else if(strncmp("time",tok_srch,4) == 0) + else if (strncmp("time",tok_srch,4) == 0) { char *parsed; parsed = ss_time(); @@ -756,24 +811,24 @@ char *process_line(char *line) } /* isfile function */ - else if(strncmp("isfile",tok_srch,5) == 0) + else if (strncmp("isfile",tok_srch,5) == 0) { int parsed; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:isfile syntax error, missing quote?"); + x_warn("ss:warn:isfile syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"")==NULL) + if (strtok_next ("\"")==NULL) { x_warn("ss:warn:isfile syntax error, missing end quote?"); return NULL; } parsed = file_exists(parse_vars(tok_srch)); - if(parsed == 1) + if (parsed == 1) { return "1"; } @@ -784,24 +839,24 @@ char *process_line(char *line) } /* isdir function */ - else if(strncmp("isdir",tok_srch,5) == 0) + else if (strncmp("isdir",tok_srch,5) == 0) { int parsed; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:isdir syntax error, missing quote?"); + x_warn("ss:warn:isdir syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"")==NULL) + if (strtok_next ("\"")==NULL) { x_warn("ss:warn:isdir syntax error, missing end quote?"); return NULL; } parsed = is_dir(parse_vars(tok_srch)); - if(parsed < 1) + if (parsed < 1) { return "0"; } @@ -812,18 +867,18 @@ char *process_line(char *line) } /* print function */ - else if(strncmp("print",tok_srch,5) == 0) + else if (strncmp("print",tok_srch,5) == 0) { char *parsed; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { - x_warn("ss:warn:print syntax error, missing quote?"); + x_warn("ss:warn:print syntax error, missing quote?"); return NULL; } parsed = parse_vars(tok_srch); - if(parsed != NULL) + if (parsed != NULL) { return parsed; } @@ -835,23 +890,23 @@ char *process_line(char *line) } /* sleep function */ - else if(strncmp("sleep",tok_srch,5) == 0) + else if (strncmp("sleep",tok_srch,5) == 0) { - tok_srch = strtok(NULL, " "); - if(tok_srch == NULL) + tok_srch = strtok_next (" "); + if (tok_srch == NULL) { x_warn("ss:warn:sleep syntax error, need trailing integer for operation"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:sleep syntax error, need trailing integer for operation"); return NULL; } /* if there is a new line, remove it */ - if(tok_srch[strlen(tok_srch)-1] == '\n') + if (tok_srch[strlen(tok_srch)-1] == '\n') { tok_srch[strlen(tok_srch)-1] = 0; } @@ -860,52 +915,52 @@ char *process_line(char *line) } // Calc function, some math involved! // - else if(strncmp("calc",tok_srch,5) == 0) + else if (strncmp("calc",tok_srch,5) == 0) { char *expr_return; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:calc syntax error, missing quotes around equation"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || (strcmp(tok_srch, " \n") == 0)) + if (strcmp(tok_srch, "\n") == 0 || (strcmp(tok_srch, " \n") == 0)) { x_warn("ss:warn:calc syntax error, missing equation?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:calc syntax error, missing ending quote?"); return NULL; } expr_return = ss_expr(parse_vars(tok_srch)); - + return expr_return; } /* Networking, listen */ - else if(strncmp("netlisten",tok_srch,9) == 0) + else if (strncmp("netlisten",tok_srch,9) == 0) { char srch[MAX_NETSRCH_BUF]; char port[7]; // Should never be more than 6 characters - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:netlisten syntax error, missing beginning quote"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:netlisten syntax error, missing address?"); return NULL; } - if(strlen(parse_vars(tok_srch)) < 7) + if (strlen(parse_vars(tok_srch)) < 7) { strcpy(port, parse_vars(tok_srch)); } @@ -916,21 +971,21 @@ char *process_line(char *line) } /* strtok to the content that will be written to file */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:netlisten syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:netlisten syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:netlisten syntax error, missing search string?"); return NULL; @@ -939,27 +994,27 @@ char *process_line(char *line) strcpy(srch, parse_vars(tok_srch)); /* strtok to the socket response */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:netlisten syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:netlisten syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:netlisten syntax error, missing return string?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:netlisten syntax error, missing end quote?"); return NULL; @@ -970,23 +1025,23 @@ char *process_line(char *line) } /* Networking, listen */ - else if(strncmp("nethttp",tok_srch,7) == 0) + else if (strncmp("nethttp",tok_srch,7) == 0) { char port[7]; // Should never be more than 6 characters - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:nethttp syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:nethttp syntax error, missing port value?"); return NULL; } - if(strlen(parse_vars(tok_srch)) < 7) + if (strlen(parse_vars(tok_srch)) < 7) { strcpy(port, parse_vars(tok_srch)); } @@ -997,28 +1052,28 @@ char *process_line(char *line) } /* strtok to the content that will be written to file */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:nethttp syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + tok_srch = strtok_next ("\""); + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:nethttp syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:nethttp syntax error, missing quote?"); return NULL; } - if(atoi(parse_vars(tok_srch)) == 1 || atoi(parse_vars(tok_srch)) == 0) + if (atoi(parse_vars(tok_srch)) == 1 || atoi(parse_vars(tok_srch)) == 0) { snet_http(atoi(port), atoi(parse_vars(tok_srch))); } @@ -1033,14 +1088,14 @@ char *process_line(char *line) } /* Networking, connect */ - else if(strncmp("nettoss",tok_srch,10) == 0) + else if (strncmp("nettoss",tok_srch,10) == 0) { char address[MAX_ADDRESS_BUF]; char data[MAX_STRING_BUFSIZE]; char port[7]; /* strtok to filename of function */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:nettoss syntax error, missing quote?"); return NULL; @@ -1048,7 +1103,7 @@ char *process_line(char *line) /* Check to see if syntax is correct */ - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:nettoss syntax error, missig address?"); return NULL; @@ -1058,21 +1113,21 @@ char *process_line(char *line) strcpy(address, parse_vars(tok_srch)); /* strtok to the content that will be written to file */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:nettoss syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + tok_srch = strtok_next ("\""); + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:nettoss syntax error, missing quote?"); return NULL; } - if(strlen(parse_vars(tok_srch)) > 6) + if (strlen(parse_vars(tok_srch)) > 6) { x_warn("ss:warn:nettoss syntax error, port too long"); return NULL; @@ -1080,27 +1135,27 @@ char *process_line(char *line) strcpy(port, parse_vars(tok_srch)); - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:nettoss syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:nettoss syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:nettoss syntax error, send string"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:nettoss syntax error, missing end quote?"); return NULL; @@ -1113,17 +1168,17 @@ char *process_line(char *line) } /* ss encrypt function */ - else if(strncmp("encode", tok_srch,6) == 0) + else if (strncmp("encode", tok_srch,6) == 0) { char *var_conv; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:encode syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:encode syntax error, encode string?"); return NULL; @@ -1131,7 +1186,7 @@ char *process_line(char *line) var_conv = parse_vars(tok_srch); - if(var_conv != NULL) + if (var_conv != NULL) { char *encrp; encrp = ss_encrypt(var_conv); @@ -1146,25 +1201,25 @@ char *process_line(char *line) } /* ss decrypt function */ - else if(strncmp("decode", tok_srch,6) == 0) + else if (strncmp("decode", tok_srch,6) == 0) { char *var_conv; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:decode syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:decode syntax error, missing decode data?"); return NULL; } var_conv = parse_vars(tok_srch); - if(var_conv != NULL) + if (var_conv != NULL) { char *decrp; decrp = ss_decrypt(var_conv); @@ -1178,18 +1233,18 @@ char *process_line(char *line) } /* builtin md5 function */ - else if(strncmp("md5",tok_srch,3) == 0) + else if (strncmp("md5",tok_srch,3) == 0) { char *file_line, *catfile, *file_md5_val; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:md5 syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:md5 syntax error, need filename"); return NULL; @@ -1198,7 +1253,7 @@ char *process_line(char *line) file_line = parse_vars(tok_srch); file_md5_val = md5_file(file_line); catfile = ss_concat(file_md5_val, file_line); - + retbuf = qmalloc(QM_SS, strlen(catfile)+1); strcpy(retbuf, catfile); free(catfile); @@ -1206,24 +1261,24 @@ char *process_line(char *line) } /* system execute function */ - else if(strncmp("exec", tok_srch, 4) == 0 || strncmp("~", tok_srch, 1) == 0) + else if (strncmp("exec", tok_srch, 4) == 0 || strncmp("~", tok_srch, 1) == 0) { char *cmd_line; int return_val; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:exec syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:exec syntax error, missing execution switch?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:exec syntax error, missing quote?"); return NULL; @@ -1231,13 +1286,13 @@ char *process_line(char *line) cmd_line = parse_vars(tok_srch); return_val = system(cmd_line); - if(return_val != 0) + if (return_val != 0) x_warn("ss:warn:exec returned error code"); return NULL; } - else if(strncmp("search",tok_srch,6) == 0) + else if (strncmp("search",tok_srch,6) == 0) { char filename[MAX_FILENAME_BUFSIZE]; char *search_str, *retval; @@ -1246,22 +1301,22 @@ char *process_line(char *line) bzero(filename, MAX_FILENAME_LEN); - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:search syntax error, missing quote?"); return NULL; } /* Check to see if syntax is correct */ - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:search syntax error, missing filename"); return NULL; } /* open file */ - if(MAX_FILENAME_LEN < atoi(parse_vars(tok_srch))) + if (MAX_FILENAME_LEN < atoi(parse_vars(tok_srch))) { x_warn("ss:warn:search, filename too long"); return NULL; @@ -1270,37 +1325,37 @@ char *process_line(char *line) strcat(filename, parse_vars(tok_srch)); search_file = fopen(filename, "r"); /* Check if file exists and can be opened */ - if(search_file == NULL) + if (search_file == NULL) { x_warn("ss:warn:search, failed to open file"); return NULL; } /* strtok to the content that will be written to file */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { fclose(search_file); x_warn("ss:warn:search syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { fclose(search_file); x_warn("ss:warn:search syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { fclose(search_file); x_warn("ss:warn:search syntax error, missing write data?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { fclose(search_file); x_warn("ss:warn:search syntax error, missing end quote?"); @@ -1315,22 +1370,22 @@ char *process_line(char *line) /* write */ - else if(strncmp("write",tok_srch,5) == 0) + else if (strncmp("write",tok_srch,5) == 0) { char *filename; char *file_content; FILE* write_file = NULL; /* strtok to filename of function */ - - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:write syntax error, missing quote?"); return NULL; } /* Check to see if syntax is correct */ - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:write syntax error, missing filename"); return NULL; @@ -1340,37 +1395,37 @@ char *process_line(char *line) filename = parse_vars(tok_srch); write_file = fopen(filename, "w"); /* Check if file exists and can be opened */ - if(write_file == NULL) + if (write_file == NULL) { x_warn("ss:warn:write, failed to open file"); return NULL; } /* strtok to the content that will be written to file */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { fclose(write_file); x_warn("ss:warn:write syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { fclose(write_file); x_warn("ss:warn:write syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { fclose(write_file); x_warn("ss:warn:write syntax error, missing write data?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { fclose(write_file); x_warn("ss:warn:write syntax error, missing end quote?"); @@ -1384,7 +1439,7 @@ char *process_line(char *line) } /* write function */ /* read function */ - else if(strncmp("read",tok_srch,4) == 0) + else if (strncmp("read",tok_srch,4) == 0) { unsigned long read_size; char read_line[1024]; @@ -1392,26 +1447,26 @@ char *process_line(char *line) FILE *read_file = NULL; /* strtok to filename of function */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:read syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:read syntax error, missing quote?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:read syntax error, missing quote?"); return NULL; } - /* Pull any variables out of the file name + /* Pull any variables out of the file name that may be, and BAM, variable fill! */ filename = parse_vars(tok_srch); @@ -1420,7 +1475,7 @@ char *process_line(char *line) read_file = fopen(filename, "r"); /* Check if file was opened successfully */ - if(read_file == NULL) + if (read_file == NULL) { x_warn("ss:warn:read, failed to open '%s'", filename); return NULL; @@ -1435,7 +1490,7 @@ char *process_line(char *line) char *nullbyte = "\0"; strcpy(dynfile, nullbyte); - while(fgets(read_line, sizeof(read_line), read_file) != NULL) + while(fgets(read_line, sizeof(read_line), read_file) != NULL) { strcat(dynfile, read_line); } @@ -1446,7 +1501,7 @@ char *process_line(char *line) } /* read function */ /* Cat function, writes to end of file specified */ - else if(strncmp("cat",tok_srch,3) == 0) + else if (strncmp("cat",tok_srch,3) == 0) { unsigned long read_size; char read_line[1024]; @@ -1454,20 +1509,20 @@ char *process_line(char *line) FILE *read_file = NULL; /* strtok to filename of function */ - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:cat syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:cat syntax error, missing filename?"); return NULL; } - if(strlen(parse_vars(tok_srch)) < 2048) + if (strlen(parse_vars(tok_srch)) < 2048) { strcpy(filename, parse_vars(tok_srch)); } @@ -1482,36 +1537,36 @@ char *process_line(char *line) read_file = fopen(filename, "r"); /* strtok to the content that will be written to file */ - if(read_file == NULL) + if (read_file == NULL) { x_warn("ss:warn:cat, failed to open file"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { fclose(read_file); x_warn("ss:warn:cat syntax error, missing quote?"); return NULL; } - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { fclose(read_file); x_warn("ss:warn:cat syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { fclose(read_file); x_warn("ss:warn:cat syntax error, missing write data?"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { fclose(read_file); x_warn("ss:warn:cat syntax error, missing end quote?"); @@ -1526,7 +1581,7 @@ char *process_line(char *line) strcpy(dynfile, "\0"); - while(fgets(read_line, sizeof(read_line), read_file) != NULL) + while(fgets(read_line, sizeof(read_line), read_file) != NULL) { strcat(dynfile, read_line); } @@ -1541,22 +1596,22 @@ char *process_line(char *line) return NULL; } /* cat function */ - else if(strncmp("delete", tok_srch, 6) == 0) { + else if (strncmp("delete", tok_srch, 6) == 0) { char *del_filename; - tok_srch = strtok(NULL, "\""); - if(tok_srch == NULL) + tok_srch = strtok_next ("\""); + if (tok_srch == NULL) { x_warn("ss:warn:delete syntax error, missing quote?"); return NULL; } - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + if (strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { x_warn("ss:warn:delete syntax error, missing filename"); return NULL; } - if(strtok(NULL, "\"") == NULL) + if (strtok_next ("\"") == NULL) { x_warn("ss:warn:delete syntax error, missing quote?"); return NULL; @@ -1564,9 +1619,9 @@ char *process_line(char *line) /* Pull variables out of filename if any */ del_filename = parse_vars(tok_srch); - if(access(del_filename, F_OK) == 0) + if (access(del_filename, F_OK) == 0) { - if(access(del_filename, W_OK) == 0) + if (access(del_filename, W_OK) == 0) { remove(del_filename); return NULL; @@ -1585,8 +1640,9 @@ char *process_line(char *line) } } - else if(strcmp(tok_srch, "\n") != 0 && strcmp(tok_srch, "") != 0) { - if(tok_srch[strlen(tok_srch)-1] == '\n') + else if (strcmp(tok_srch, "\n") != 0 && strcmp(tok_srch, "") != 0) + { + if (tok_srch[strlen(tok_srch)-1] == '\n') { return NULL; } @@ -1595,7 +1651,7 @@ char *process_line(char *line) int varc = get_var_count(); char *varname_tmp = tok_srch; char *bq_check; - tok_srch = strtok(NULL, "="); + tok_srch = strtok_next ("="); // Check for back quotes, return string with backquotes processed bq_check = strip_nl(parse_vars(parse_bq(tok_srch)));