OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp_option.c versions 1.24 and 1.25
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/lmtp2nntp_option.c 1.24 -> 1.25

--- lmtp2nntp_option.c   2003/02/10 14:24:16     1.24
+++ lmtp2nntp_option.c   2003/02/11 09:02:42     1.25
@@ -357,7 +357,7 @@
             }
         }
         catch(ex) {
-            rethrow;
+            rc = OPTION_ERR_TRY;
         }
     }
     popt_freecontext(poptCon);
@@ -418,42 +418,46 @@
 
 static lmtp2nntp_option_rc_t includeit(optionval_t *oc, char *arg, char *cbctx)
 {
+    lmtp2nntp_option_rc_t rc = OPTION_OK;
     lmtp2nntp_option_t *o;
     volatile char *cpBuf = NULL;
     int argc = 0;
     char **argv = NULL;
+    const char *filename = arg;
+    struct stat sb;
+    volatile int fd = -1;
+    ex_t ex;
 
     if ((o = oc->parent) == NULL)
         return OPTION_ERR_USE;
 
     stdsyntax(oc, arg, cbctx);
-    {
-        const char *filename = arg;
-        struct stat sb;
-        volatile int fd = -1;
-        ex_t ex;
-
-        try {
-            if (stat(filename, &sb) == -1)
-                throw(includeit, oc, "stat");
-            cpBuf = (char *)mallocex((size_t)sb.st_size + 1);
-            if ((fd = open(filename, O_RDONLY)) == -1)
-                throw(includeit, oc, "open");
-            if (read(fd, (void *)cpBuf, (size_t)sb.st_size) != (ssize_t)sb.st_size)
-                throw(includeit, oc, "read");
-            cpBuf[(int)sb.st_size] = '\0';
-        }
-        cleanup {
-            if (fd != -1) close(fd);
-        }
-        catch (ex) {
-            if (cpBuf != NULL)
-                free((char *)cpBuf);
-            rethrow;
-        }
+
+    try {
+        if (stat(filename, &sb) == -1)
+            throw(includeit, oc, "stat");
+        if (sb.st_size == 0)
+            throw(includeit, oc, "size");
+        cpBuf = (char *)mallocex((size_t)sb.st_size + 1);
+        if ((fd = open(filename, O_RDONLY)) == -1)
+            throw(includeit, oc, "open");
+        if (read(fd, (void *)cpBuf, (size_t)sb.st_size) != (ssize_t)sb.st_size)
+            throw(includeit, oc, "read");
+        cpBuf[(int)sb.st_size] = '\0';
+    }
+    cleanup {
+        if (fd != -1) close(fd);
+    }
+    catch (ex) {
+        if (ex.ex_class == (void *)includeit && ex.ex_value != NULL) {
+            fprintf(stderr, "ERROR: problem with \"%s\" while including \"%s\"\n", (char *)ex.ex_value, filename);
+        }
+        if (cpBuf != NULL)
+            free((char *)cpBuf);
+        return OPTION_ERR_TRY;
     }
 
-    {
+    try {
         char *cpI;  /* pointer to next character to be read */
         char *cpO;  /* pointer to next character to be written. Used for eliminating
                        backslash+newline at a line continuation */
@@ -504,37 +508,30 @@
                             Newarg.as = 0;
                             Newarg.az = NULL;
                             if ((option = str_token(&cp, " \t", "\"'", "#", STR_STRIPQUOTES|STR_BACKSLASHESC)) == NULL)
-                                /*printf("DEBUG: no command - comment only\n")*/
-                                ;/* don't care about comments */
+                                ;/* no option? comment only! don't care about that. */
                             else {
-                                /*printf("DEBUG:    option = ***%s***\n", option);*/
+                                /* create fake argv[0] */
                                 if (argv == NULL) {
-                                    if ((argv = (char **)malloc(   (   1 + 1) * sizeof(char **))) == NULL)
-                                        return OPTION_ERR_MEM;
-                                    argc = 0;
-                                    argv[argc++] = "include";
+                                    argv = (char **)mallocex((1 + 1) * sizeof(char **)); /* argv[0] + NULL */
+                                    argv[argc++] = strdupex("include");
                                     argv[argc] = NULL;
                                 }
-
-                                if ((cpNew = (char *)malloc(2 + strlen(option) + 1)) == NULL)
-                                    return OPTION_ERR_MEM;
+                                /* handle option */
+                                cpNew = (char *)mallocex(2 + strlen(option) + 1); /* dash dash option[] NUL */
                                 cpNew[0]=NUL;
                                 strcat(cpNew, "--");
                                 strcat(cpNew, option);
-                                if ((argv = (char **)realloc(argv, (argc + 1 + 1) * sizeof(char **))) == NULL)
-                                    return OPTION_ERR_MEM;
+                                argv = (char **)reallocex(argv, (1 + argc + 1) * sizeof(char **)); /* argv[0] + argv[1...argc] + NULL */
                                 argv[argc++] = cpNew;
                                 argv[argc] = NULL;
 
                                 if ((value = str_token(&cp, " \t", "\"'", "#", STR_STRIPQUOTES|STR_BACKSLASHESC)) == NULL)
-                                    ;/*printf("DEBUG: no value - section\n");*/
+                                    ;/* no value? optional anyway */
                                 else {
                                     while(isspace((int)*value)) value++;
-                                    /*printf("DEBUG:     value = ***%s***\n", value);*/
-                                    if ((cpNew = strdup(value)) == NULL)
-                                        return OPTION_ERR_MEM;
-                                    if ((argv = (char **)realloc(argv, (argc + 1 + 1) * sizeof(char **))) == NULL)
-                                        return OPTION_ERR_MEM;
+                                    /* handle value */
+                                    cpNew = strdupex(value);
+                                    argv = (char **)reallocex(argv, (1 + argc + 1 + 1) * sizeof(char **)); /* argv[0] + argv[1...argc] + NULL */
                                     argv[argc++] = cpNew;
                                     argv[argc] = NULL;
                                 }
@@ -548,8 +545,20 @@
             }
             p = c;
         }
+        rc = option_parse_internal(o, argc, argv);
+    }
+    cleanup {
+        int i;
+        if (argv != NULL) {
+            for (i = 0; argv[i] != NULL; i++)
+                free(argv[i]);
+            free(argv);
+        }
     }
-    return option_parse_internal(o, argc, argv);
+    catch(ex) {
+        rc = OPTION_ERR_TRY;
+    }
+    return rc;
 }
 
 /* this public function catches all underlying exceptions and properly returns a code */

CVSTrac 2.0.1