[augeas-devel] [PATCH 2 of 3] augtool, augparse: add --nostdinc option

David Lutterkort lutter at redhat.com
Mon Sep 8 23:39:08 UTC 2008


5 files changed, 49 insertions(+), 22 deletions(-)
src/augeas.c   |   42 +++++++++++++++++++++++-------------------
src/augeas.h   |    4 +++-
src/augparse.c |   13 +++++++++++--
src/augtool.c  |   10 ++++++++++
src/syntax.c   |    2 ++


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1220916859 25200
# Node ID 23f8be079bbab4e16c3a7b112308f9a149d4d0b7
# Parent  aa37514c950092720ed1af022eb35ca1b76009a5
augtool, augparse: add --nostdinc option

diff -r aa37514c9500 -r 23f8be079bba src/augeas.c
--- a/src/augeas.c	Mon Sep 08 16:30:36 2008 -0700
+++ b/src/augeas.c	Mon Sep 08 16:34:19 2008 -0700
@@ -499,28 +499,32 @@
     if (env != NULL) {
         argz_add_sep(&result->modpathz, &result->nmodpath, env, PATH_SEP_CHAR);
     }
-    argz_add(&result->modpathz, &result->nmodpath, AUGEAS_LENS_DIR);
+    if (!(flags & AUG_NO_STDINC)) {
+        argz_add(&result->modpathz, &result->nmodpath, AUGEAS_LENS_DIR);
+    }
     /* Clean up trailing slashes */
-    argz_stringify(result->modpathz, result->nmodpath, PATH_SEP_CHAR);
-    char *s, *t;
-    for (s = result->modpathz, t = result->modpathz; *s != '\0'; s++) {
-        char *p = s;
-        if (*p == '/') {
-            while (*p == '/') p += 1;
-            if (*p == '\0' || *p == PATH_SEP_CHAR)
-                s = p;
+    if (result->nmodpath > 0) {
+        argz_stringify(result->modpathz, result->nmodpath, PATH_SEP_CHAR);
+        char *s, *t;
+        for (s = result->modpathz, t = result->modpathz; *s != '\0'; s++) {
+            char *p = s;
+            if (*p == '/') {
+                while (*p == '/') p += 1;
+                if (*p == '\0' || *p == PATH_SEP_CHAR)
+                    s = p;
+            }
+            if (t != s)
+                *t++ = *s;
+            else
+                t += 1;
         }
-        if (t != s)
-            *t++ = *s;
-        else
-            t += 1;
+        if (t != s) {
+            *t = '\0';
+        }
+        s = result->modpathz;
+        argz_create_sep(s, PATH_SEP_CHAR, &result->modpathz, &result->nmodpath);
+        free(s);
     }
-    if (t != s) {
-        *t = '\0';
-    }
-    s = result->modpathz;
-    argz_create_sep(s, PATH_SEP_CHAR, &result->modpathz, &result->nmodpath);
-    free(s);
 
     /* We report the root dir in AUGEAS_META_ROOT, but we only use the
        value we store internally, to avoid any problems with
diff -r aa37514c9500 -r 23f8be079bba src/augeas.h
--- a/src/augeas.h	Mon Sep 08 16:30:36 2008 -0700
+++ b/src/augeas.h	Mon Sep 08 16:34:19 2008 -0700
@@ -38,8 +38,10 @@
                                      extension .augnew, and do not
                                      overwrite the original file. Takes
                                      precedence over AUG_SAVE_BACKUP */
-    AUG_TYPE_CHECK   = (1 << 2)   /* Typecheck lenses; since it can be very
+    AUG_TYPE_CHECK   = (1 << 2),  /* Typecheck lenses; since it can be very
                                      expensive it is not done by default */
+    AUG_NO_STDINC    = (1 << 3),  /* Do not use the builtin load path for
+                                     modules */
 };
 
 /* Initialize the library.
diff -r aa37514c9500 -r 23f8be079bba src/augparse.c
--- a/src/augparse.c	Mon Sep 08 16:30:36 2008 -0700
+++ b/src/augparse.c	Mon Sep 08 16:34:19 2008 -0700
@@ -36,6 +36,8 @@
     fprintf(stderr, "Evaluate MODULE. Generally, MODULE should contain unit tests.\n");
     fprintf(stderr, "\nOptions:\n\n");
     fprintf(stderr, "  -I, --include DIR  search DIR for modules; can be given mutiple times\n");
+    fprintf(stderr, "  --nostdinc         do not search the builtin default directories for modules\n");
+
     exit(EXIT_FAILURE);
 }
 
@@ -44,13 +46,17 @@
     struct augeas *aug;
     char *loadpath = NULL;
     size_t loadpathlen = 0;
+    enum {
+        VAL_NO_STDINC = CHAR_MAX + 1
+    };
     struct option options[] = {
         { "help",      0, 0, 'h' },
         { "include",   1, 0, 'I' },
+        { "nostdinc",  0, 0, VAL_NO_STDINC },
         { 0, 0, 0, 0}
     };
     int idx;
-
+    unsigned int flags = AUG_TYPE_CHECK|AUG_NO_DEFAULT_LOAD;
     progname = argv[0];
 
     while ((opt = getopt_long(argc, argv, "hI:", options, &idx)) != -1) {
@@ -60,6 +66,9 @@
             break;
         case 'h':
             usage();
+            break;
+        case VAL_NO_STDINC:
+            flags |= AUG_NO_STDINC;
             break;
         default:
             usage();
@@ -73,7 +82,7 @@
     }
 
     argz_stringify(loadpath, loadpathlen, PATH_SEP_CHAR);
-    aug = aug_init(NULL, loadpath, AUG_TYPE_CHECK|AUG_NO_DEFAULT_LOAD);
+    aug = aug_init(NULL, loadpath, flags);
     if (__aug_load_module_file(aug, argv[optind]) == -1) {
         fprintf(stderr, "%s: error: Loading failed\n", argv[optind]);
         exit(EXIT_FAILURE);
diff -r aa37514c9500 -r 23f8be079bba src/augtool.c
--- a/src/augtool.c	Mon Sep 08 16:30:36 2008 -0700
+++ b/src/augtool.c	Mon Sep 08 16:34:19 2008 -0700
@@ -28,6 +28,7 @@
 #include <readline/history.h>
 #include <argz.h>
 #include <getopt.h>
+#include <limits.h>
 
 struct command {
     const char *name;
@@ -486,12 +487,17 @@
                     "                     leave original unchanged\n");
     fprintf(stderr, "  -r, --root ROOT    use ROOT as the root of the filesystem\n");
     fprintf(stderr, "  -I, --include DIR  search DIR for modules; can be given mutiple times\n");
+    fprintf(stderr, "  --nostdinc         do not search the builtin default directories for modules\n");
+
     exit(EXIT_FAILURE);
 }
 
 static void parse_opts(int argc, char **argv) {
     int opt;
     size_t loadpathlen = 0;
+    enum {
+        VAL_NO_STDINC = CHAR_MAX + 1
+    };
     struct option options[] = {
         { "help",      0, 0, 'h' },
         { "typecheck", 0, 0, 'c' },
@@ -499,6 +505,7 @@
         { "new",       0, 0, 'n' },
         { "root",      1, 0, 'r' },
         { "include",   1, 0, 'I' },
+        { "nostdinc",  0, 0, VAL_NO_STDINC },
         { 0, 0, 0, 0}
     };
     int idx;
@@ -522,6 +529,9 @@
             break;
         case 'I':
             argz_add(&loadpath, &loadpathlen, optarg);
+            break;
+        case VAL_NO_STDINC:
+            flags |= AUG_NO_STDINC;
             break;
         default:
             usage();
diff -r aa37514c9500 -r 23f8be079bba src/syntax.c
--- a/src/syntax.c	Mon Sep 08 16:30:36 2008 -0700
+++ b/src/syntax.c	Mon Sep 08 16:34:19 2008 -0700
@@ -1869,6 +1869,8 @@
     glob_t globbuf;
     int gl_flags = GLOB_NOSORT;
 
+    MEMZERO(&globbuf, 1);
+
     while ((dir = argz_next(aug->modpathz, aug->nmodpath, dir)) != NULL) {
         char *globpat;
         r = asprintf(&globpat, "%s/*.aug", dir);




More information about the augeas-devel mailing list