diff options
| author | epoch <epoch@enzo.thebackupbox.net> | 2022-02-02 08:31:18 +0000 | 
|---|---|---|
| committer | epoch <epoch@enzo.thebackupbox.net> | 2022-02-02 08:31:18 +0000 | 
| commit | 80340157c680fd1b68ea44c9363fa2f535fbc779 (patch) | |
| tree | 6f41463cc6c7bbf71d2a7cf234e8f9f663e13a80 | |
| parent | da5080c53ce8e9e520187e19eeb907c46607b4f0 (diff) | |
| download | uritools-80340157c680fd1b68ea44c9363fa2f535fbc779.tar.gz uritools-80340157c680fd1b68ea44c9363fa2f535fbc779.zip | |
added better config line parsing. a -v for verbose. and debug messages for helping find config errors.
| -rw-r--r-- | urigetline.c | 21 | 
1 files changed, 16 insertions, 5 deletions
| diff --git a/urigetline.c b/urigetline.c index 92fa124..4c5c7b4 100644 --- a/urigetline.c +++ b/urigetline.c @@ -42,27 +42,38 @@ int main(int argc,char *argv[]) {//argument needs to be the URI    char *a,*b,*c;    char *command;    char all=0; +  int verbose=0;    if(argc > 1) {      if(!strcmp(argv[1],"-a")) {        all=1;        argv++;        argc--;      } +    if(!strcmp(argv[1],"-v")) { +      verbose++; +      argv++; +      argc--; +    }    }    if(argc < 2) {     fprintf(stderr,"usage: urigetline [-a] uri < uristart.conf\n");     return 1;    }    urifromline(&u,argv[1]);//only argv[1] is a URI? -  while(fgets(line,LINE_LENGTH-1,stdin)) {//each line comes from the config. we need to split it on spaces. +  for(;fgets(line,LINE_LENGTH-1,stdin);) {//each line comes from the config. we need to split it on spaces.      if(strchr(line,'\r')) *strchr(line,'\r')=0;      if(strchr(line,'\n')) *strchr(line,'\n')=0;      if(*line == '#') continue; //skip this line too. comment. -    if((command=strchr(line,':'))) { +    if(strlen(line) == 0) continue; //skip empty lines. +    if((command=strstr(line,":\t"))) {//this is the "real" separator between match pattern and command        *command=0;        command++; -      while(*command == '\t') command++; -    } else continue;//skip this line. needs at least one : to work.. +      while(*command == '\t') command++;//and command may have leading tabs that are ignored. +      if(verbose) fprintf(stderr,"loading config line: '%s'\n",line); +    } else { +      fprintf(stderr,"invalid line: '%s'\n",line); +      continue;//skip this line. needs at least one ":\t" to work. +    }      a=line;      matches=1;      for(;a;) { @@ -78,7 +89,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI        c=0;        if(rule != MATCH_UNEXIST) {          if(!(b=strchr(a,' '))) { -          fprintf(stderr,"argument '%s' wants a value in the next argument and didn't get it. throwing a fit.\n",a); +          fprintf(stderr,"argument '%s' wants a value in the next argument and didn't get it. throwing a fit. (pass -v to urigetline to help debug)\n",a);            return 2;          }          *b=0; b++; | 
