diff options
-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++; |