-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: uritools
action: commit
revision:
path_from:
revision_from: 80340157c680fd1b68ea44c9363fa2f535fbc779:
path_to:
revision_to:

git.thebackupbox.net

uritools

git://git.thebackupbox.net/uritools

commit 80340157c680fd1b68ea44c9363fa2f535fbc779
Author: epoch <epoch@enzo.thebackupbox.net>
Date:   Wed Feb 2 08:31:18 2022 +0000

    added better config line parsing. a -v for verbose. and debug messages for helping find config errors.

diff --git a/urigetline.c b/urigetline.c

index 92fa1247ebb93a365a4dc4508496d8b0d5efe028..

index ..4c5c7b4acc135765d7d78074b3c4ce7117eafb6b 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++;

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 16:37:40 2024