]> andersk Git - moira.git/commitdiff
Redo argument parsing to be more consistant with other applications.
authorzacheiss <zacheiss>
Sat, 10 Aug 2002 09:36:00 +0000 (09:36 +0000)
committerzacheiss <zacheiss>
Sat, 10 Aug 2002 09:36:00 +0000 (09:36 +0000)
Gain ability to specify non-default server in the process.

clients/mrcheck/mrcheck.c

index e82856880d9ce30520e51409453fef457b609e9f..0a0202a44428c1cb494477da358f44f389a8b19b 100644 (file)
@@ -17,6 +17,8 @@
 #include <string.h>
 #include <time.h>
 
+#define argis(a, b) (!strcmp(*arg + 1, a) || !strcmp(*arg + 1, b))
+
 RCSID("$Header$");
 
 char *atot(char *itime);
@@ -165,18 +167,37 @@ int main(int argc, char *argv[])
   struct save_queue *sq;
   int status;
   int auth_required = 1;
+  char **arg = argv;
+  char *server = NULL;
 
   if ((whoami = strrchr(argv[0], '/')) == NULL)
     whoami = argv[0];
   else
     whoami++;
 
-  if (argc == 2 && !strcmp(argv[1], "-noauth"))
-    auth_required = 0;
-  else if (argc > 1)
-    usage();
+  /* parse our command line options */
+  while (++arg - argv < argc)
+    {
+      if (**arg == '-')
+       {
+         if (argis("n", "noauth"))
+           auth_required = 0;
+         else if (argis("db", "database"))
+           {
+             if (arg - argv < argc - 1)
+               {
+                 ++arg;
+                 server = *arg;
+               }
+             else
+               usage();
+           }
+       }
+      else
+       usage();
+    }
 
-  if (mrcl_connect(NULL, NULL, 2, 0) != MRCL_SUCCESS)
+  if (mrcl_connect(server, NULL, 2, 0) != MRCL_SUCCESS)
     exit(2);
   status = mr_auth("mrcheck");
   if (status && auth_required)
@@ -216,6 +237,7 @@ punt:
 
 void usage(void)
 {
-  fprintf(stderr, "Usage: %s [-noauth]\n", whoami);
+  fprintf(stderr, "Usage: %s [-noauth] [-db|-database server[:port]]\n",
+         whoami);
   exit(1);
 }
This page took 0.033969 seconds and 5 git commands to generate.