OSSP CVS Repository

ossp - Check-in [3626]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3626
Date: 2003-Sep-25 15:12:06 (local)
2003-Sep-25 13:12:06 (UTC)
User:thl
Branch:
Comment: enhance command line parsing and add "-s sleepsec" option
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2tool.c      1.4 -> 1.5     30 inserted, 6 deleted

ossp-pkg/l2/l2tool.c 1.4 -> 1.5

--- l2tool.c     2003/01/06 11:41:52     1.4
+++ l2tool.c     2003/09/25 13:12:06     1.5
@@ -31,6 +31,11 @@
 #include <stdio.h>
 #include "l2.h"
 
+#include <unistd.h>
+extern int getopt(int, char *const *, const char *);
+extern int optind;
+extern char *optarg;
+
 static void die(l2_env_t *env, l2_result_t rv, char *fmt, ...)
 {
     va_list ap;
@@ -45,6 +50,13 @@
     exit(1);
 }
 
+static void usage(void)
+{
+    fprintf(stderr, "l2tool:ERROR: invalid command line\n");
+    fprintf(stderr, "l2tool:USAGE: l2tool [-s sleepsec] <specification>\n");
+    exit(1);
+}
+
 int main(int argc, char *argv[])
 {
     l2_channel_t *ch;
@@ -57,14 +69,23 @@
     char *cpMsg;
     char *cp;
     unsigned int nLevel;
+    int option;
+    int nSleep = 0;
 
-    /* minimal command line parsing */
-    if (argc != 2) {
-        fprintf(stderr, "l2tool:ERROR: invalid command line\n");
-        fprintf(stderr, "l2tool:USAGE: l2tool <specification>\n");
-        exit(1);
+    /* command line parsing */
+    while ((option = getopt(argc, argv, "s:")) != EOF) {
+        switch ((char) option) {
+            case 's':
+                nSleep = atoi(optarg);
+                break;
+            default:
+                usage();
+        /* NOTREACHED */
+        }
     }
-    spec = argv[1];
+    if (argc - optind != 1)
+        usage();
+    spec = argv[optind];
 
     /* create environment */
     if ((rv = l2_env_create(&env)) != L2_OK)
@@ -101,6 +122,9 @@
         /* perform log operation(s) */
         if ((rv = l2_channel_log(ch, nLevel, "%s", cpMsg)) != L2_OK)
             die(env, rv, "failed to log message to channel tree");
+
+        /* artifical delay */
+        sleep(nSleep);
     }
 
     /* destroy channel tree */

CVSTrac 2.0.1