RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   15-Jun-2009 22:42:03
  Branch: HEAD                             Handle: 2009061520420201

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               librpmio.vers rpmaug.c rpmaug.h rpmsquirrel.h
    rpm/tools               augtool.c

  Log:
    - augtool: capture stdout in aug->iob, return through rpmaugRun().

  Summary:
    Revision    Changes     Path
    1.3027      +1  -0      rpm/CHANGES
    2.124       +1  -0      rpm/rpmio/librpmio.vers
    1.5         +30 -1      rpm/rpmio/rpmaug.c
    1.5         +10 -1      rpm/rpmio/rpmaug.h
    2.3         +5  -2      rpm/rpmio/rpmsquirrel.h
    2.8         +63 -63     rpm/tools/augtool.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3026 -r1.3027 CHANGES
  --- rpm/CHANGES       15 Jun 2009 14:16:20 -0000      1.3026
  +++ rpm/CHANGES       15 Jun 2009 20:42:02 -0000      1.3027
  @@ -1,5 +1,6 @@
   
   5.2b1 -> 5.3a1
  +    - jbj: augtool: capture stdout in aut->iob, return through rpmaugRun().
       - jbj: debugedit: handle DWARF-3 changes (#505774).
       - jbj: augtool: use rpmaug globals where useful.
       - jbj: rpmaug: add rpmaugPoptTable and global parameters.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/librpmio.vers
  ============================================================================
  $ cvs diff -u -r2.123 -r2.124 librpmio.vers
  --- rpm/rpmio/librpmio.vers   14 Jun 2009 23:41:25 -0000      2.123
  +++ rpm/rpmio/librpmio.vers   15 Jun 2009 20:42:03 -0000      2.124
  @@ -261,6 +261,7 @@
       rpmaugDefnode;
       rpmaugDefvar;
       _rpmaugFlags;
  +    rpmaugFprintf;
       rpmaugGet;
       rpmaugInsert;
       rpmaugLoad;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmaug.c
  ============================================================================
  $ cvs diff -u -r1.4 -r1.5 rpmaug.c
  --- rpm/rpmio/rpmaug.c        14 Jun 2009 23:41:25 -0000      1.4
  +++ rpm/rpmio/rpmaug.c        15 Jun 2009 20:42:03 -0000      1.5
  @@ -31,8 +31,10 @@
   
   #if defined(WITH_AUGEAS)
       (void) aug_close(aug->I);
  -    aug->I = NULL;
   #endif
  +    aug->I = NULL;
  +    (void)rpmiobFree(aug->iob);
  +    aug->iob = NULL;
       aug->root = _free(aug->root);
       aug->loadpath = _free(aug->loadpath);
   }
  @@ -128,6 +130,7 @@
       aug->I = (void *) aug_init(aug->root, aug->loadpath, aug->flags);
   assert(aug->I != NULL);
   #endif
  +    aug->iob = rpmiobNew(0);
   
       return rpmaugLink(aug);
   }
  @@ -253,3 +256,29 @@
   #endif
       return rc;
   }
  +
  +void rpmaugFprintf(rpmaug aug, const char *fmt, ...)
  +{
  +#if defined(WITH_AUGEAS)
  +    size_t nb = 1024;
  +    char * b = xmalloc(nb);
  +    va_list va;
  +
  +    va_start(va, fmt);
  +    while(1) {
  +     int nw = vsnprintf(b, nb, fmt, va);
  +     if (nw > -1 && (size_t)nw < nb)
  +         break;
  +     if (nb > -1)            /* glibc 2.1 (and later) */
  +         nb = nw+1;
  +     else                    /* glibc 2.0 */
  +         nb *= 2;
  +     b = xrealloc(b, nb);
  +    }
  +    va_end(va);
  +
  +    if (aug == NULL) aug = rpmaugI();
  +    (void) rpmiobAppend(aug->iob, b, 0);
  +    b = _free(b);
  +#endif
  +}
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmaug.h
  ============================================================================
  $ cvs diff -u -r1.4 -r1.5 rpmaug.h
  --- rpm/rpmio/rpmaug.h        14 Jun 2009 23:41:25 -0000      1.4
  +++ rpm/rpmio/rpmaug.h        15 Jun 2009 20:42:03 -0000      1.5
  @@ -37,7 +37,8 @@
       const char * loadpath;
       unsigned int flags;
   /*...@relnull@*/
  -    void * I;
  +    void * I;                        /* XXX struct augeas * */
  +    rpmiob iob;
   #if defined(__LCLINT__)
   /*...@refs@*/
       int nrefs;                       /*!< (unused) keep splint happy */
  @@ -213,6 +214,14 @@
   int rpmaugPrint(/*...@null@*/ rpmaug aug, /*...@null@*/ FILE * out, const 
char * path)
        /*...@modifies aug, *out @*/;
   
  +/**
  + * Append output to an iob.
  + * @param aug                augeas wrapper (NULL uses global interpreter)
  + * @param fmt                format to use
  + */
  +void rpmaugFprintf(rpmaug aug, const char *fmt, ...)
  +     /*...@modifies aug @*/;
  +
   #ifdef __cplusplus
   }
   #endif
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmsquirrel.h
  ============================================================================
  $ cvs diff -u -r2.2 -r2.3 rpmsquirrel.h
  --- rpm/rpmio/rpmsquirrel.h   3 Jun 2009 02:05:45 -0000       2.2
  +++ rpm/rpmio/rpmsquirrel.h   15 Jun 2009 20:42:03 -0000      2.3
  @@ -8,7 +8,7 @@
   #include <rpmiotypes.h>
   #include <rpmio.h>
   
  -typedef /*...@abstract@*/ struct rpmsquirrel_s * rpmsquirrel;
  +typedef /*...@refcounted@*/ struct rpmsquirrel_s * rpmsquirrel;
   
   /*...@unchecked@*/
   extern int _rpmsquirrel_debug;
  @@ -21,7 +21,10 @@
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
       void * I;                        /* HSQUIRRELVM */
       rpmiob iob;
  -
  +#if defined(__LCLINT__)
  +/*...@refs@*/
  +    int nrefs;                       /*!< (unused) keep splint happy */
  +#endif
   };
   #endif /* _RPMSQUIRREL_INTERNAL */
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/augtool.c
  ============================================================================
  $ cvs diff -u -r2.7 -r2.8 augtool.c
  --- rpm/tools/augtool.c       15 Jun 2009 18:16:06 -0000      2.7
  +++ rpm/tools/augtool.c       15 Jun 2009 20:42:03 -0000      2.8
  @@ -195,7 +195,7 @@
           basnam = (basnam == NULL) ? paths[i] : basnam + 1;
           if (val == NULL)
               val = "(none)";
  -        printf("%s%s= %s\n", basnam, dir ? "/ " : " ", val);
  +        rpmaugFprintf(NULL, "%s%s= %s\n", basnam, dir ? "/ " : " ", val);
       }
       (void) argvFree((const char **)paths);
       path = _free(path);
  @@ -213,12 +213,12 @@
   
       cnt = rpmaugMatch(NULL, pattern, &matches);
       if (cnt < 0) {
  -        printf("  (error matching %s)\n", pattern);
  +        rpmaugFprintf(NULL, "  (error matching %s)\n", pattern);
           result = -1;
           goto done;
       }
       if (cnt == 0) {
  -        printf("  (no matches)\n");
  +        rpmaugFprintf(NULL, "  (no matches)\n");
           goto done;
       }
   
  @@ -229,9 +229,9 @@
               val = "(none)";
           if (filter) {
               if (!strcmp(av[1], val))
  -                printf("%s\n", matches[i]);
  +                rpmaugFprintf(NULL, "%s\n", matches[i]);
           } else {
  -            printf("%s = %s\n", matches[i], val);
  +            rpmaugFprintf(NULL, "%s = %s\n", matches[i], val);
           }
       }
    done:
  @@ -244,9 +244,9 @@
       const char *path = cleanpath(av[0]);
       int cnt;
   
  -    printf("rm : %s", path);
  +    rpmaugFprintf(NULL, "rm : %s", path);
       cnt = rpmaugRm(NULL, path);
  -    printf(" %d\n", cnt);
  +    rpmaugFprintf(NULL, " %d\n", cnt);
       return 0;
   }
   
  @@ -307,13 +307,13 @@
       const char *path = cleanpath(av[0]);
       const char *val;
   
  -    printf("%s", path);
  +    rpmaugFprintf(NULL, "%s", path);
       if (rpmaugGet(NULL, path, &val) != 1)
  -        printf(" (o)\n");
  +        rpmaugFprintf(NULL, " (o)\n");
       else if (val == NULL)
  -        printf(" (none)\n");
  +        rpmaugFprintf(NULL, " (none)\n");
       else
  -        printf(" = %s\n", val);
  +        rpmaugFprintf(NULL, " = %s\n", val);
       return 0;
   }
   
  @@ -329,9 +329,9 @@
       if (r != -1) {
           r = rpmaugMatch(NULL, "/augeas/events/saved", NULL);
           if (r > 0)
  -            printf("Saved %d file(s)\n", r);
  +            rpmaugFprintf(NULL, "Saved %d file(s)\n", r);
           else if (r < 0)
  -            printf("Error during match: %d\n", r);
  +            rpmaugFprintf(NULL, "Error during match: %d\n", r);
       }
       return r;
   }
  @@ -342,9 +342,9 @@
       if (r != -1) {
           r = rpmaugMatch(NULL, "/augeas/events/saved", NULL);
           if (r > 0)
  -            printf("Saved %d file(s)\n", r);
  +            rpmaugFprintf(NULL, "Saved %d file(s)\n", r);
           else if (r < 0)
  -            printf("Error during match: %d\n", r);
  +            rpmaugFprintf(NULL, "Error during match: %d\n", r);
       }
       return r;
   }
  @@ -362,7 +362,7 @@
       else if (!strcmp(where, "before"))
           before = 1;
       else {
  -        printf("The <WHERE> argument must be either 'before' or 'after'.");
  +        rpmaugFprintf(NULL, "The <WHERE> argument must be either 'before' or 
'after'.");
        goto exit;
       }
   
  @@ -376,13 +376,13 @@
   {
       const struct command *c;
   
  -    printf("Commands:\n\n");
  +    rpmaugFprintf(NULL, "Commands:\n\n");
       for (c=commands; c->name != NULL; c++) {
  -        printf("    %s\n        %s\n\n", c->synopsis, c->help);
  +        rpmaugFprintf(NULL, "    %s\n        %s\n\n", c->synopsis, c->help);
       }
  -    printf("\nEnvironment:\n\n");
  -    printf("    AUGEAS_ROOT\n        the file system root, defaults to 
'/'\n\n");
  -    printf("    AUGEAS_LENS_LIB\n        colon separated list of directories 
with lenses,\n\
  +    rpmaugFprintf(NULL, "\nEnvironment:\n\n");
  +    rpmaugFprintf(NULL, "    AUGEAS_ROOT\n        the file system root, 
defaults to '/'\n\n");
  +    rpmaugFprintf(NULL, "    AUGEAS_LENS_LIB\n        colon separated list 
of directories with lenses,\n\
           defaults to " AUGEAS_LENS_DIR "\n\n");
       return 0;
   }
  @@ -457,40 +457,6 @@
       { NULL, -1, -1, NULL, NULL, NULL }
   };
   
  -static int run_command(int ac, char *av[])
  -{
  -    const struct command *c;
  -    int r = -1;              /* assume failure */
  -
  -    for (c = commands; c->name; c++) {
  -        if (!strcmp(av[0], c->name))
  -            break;
  -    }
  -    if (c->name == NULL) {
  -        fprintf(stderr, "Unknown command '%s'\n", av[0]);
  -     goto exit;
  -    }
  -    if ((ac - 1) < c->minargs) {
  -     fprintf(stderr, "Not enough arguments for %s\n", c->name);
  -     goto exit;
  -    }
  -    if ((ac - 1) > c->maxargs) {
  -     fprintf(stderr, "Too many arguments for %s\n", c->name);
  -     goto exit;
  -    }
  -
  -    r = (*c->handler)(ac-1, av+1);
  -
  -    if (r == -1) {
  -     const char * cmd = argvJoin((const char **)av, ' ');
  -        printf ("Failed(%d): %s\n", r, cmd);
  -     cmd = _free(cmd);
  -    }
  -
  -exit:
  -    return r;
  -}
  -
   static rpmRC rpmaugRun(rpmaug aug, const char * str, const char ** resultp)
   {
       static char whitespace[] = " \t\n\r";
  @@ -502,6 +468,7 @@
       rpmRC rc = RPMRC_OK;     /* assume success */
       int xx;
   
  +    if (aug == NULL) aug = _rpmaugI;
       if (resultp)
        *resultp = NULL;
       if (buf && *buf)
  @@ -517,13 +484,38 @@
   assert(xx == 0);
   
        if (av[0] != NULL && strlen(av[0]) > 0) {
  -         if (run_command(ac, (char **)av) < 0)
  +         const struct command *c;
  +
  +         for (c = commands; c->name; c++) {
  +             if (!strcmp(av[0], c->name))
  +                 break;
  +         }
  +         if (c->name == NULL) {
  +             rpmaugFprintf(NULL, "Unknown command '%s'\n", av[0]);
  +             rc = RPMRC_FAIL;
  +         } else
  +         if ((ac - 1) < c->minargs) {
  +             rpmaugFprintf(NULL, "Not enough arguments for %s\n", c->name);
  +             rc = RPMRC_FAIL;
  +         } else
  +         if ((ac - 1) > c->maxargs) {
  +             rpmaugFprintf(NULL, "Too many arguments for %s\n", c->name);
                rc = RPMRC_FAIL;
  +         } else
  +         if ((xx = (*c->handler)(ac-1, (char **)av+1)) < 0) {
  +             rpmaugFprintf(NULL, "Failed(%d): %s\n", xx, b);
  +             rc = RPMRC_FAIL;
  +         }
        }
        av = _free(av);         /* XXX popt allocates contiguous argv */
        if (rc != RPMRC_OK)
            break;
       }
  +    {        rpmiob iob = aug->iob;
  +     if (resultp)
  +         *resultp = rpmiobStr(iob);
  +     iob->blen = 0;
  +    }
       buf = _free(buf);
       return rc;
   }
  @@ -630,6 +622,8 @@
       int ret = 0;     /* assume success */
   
       while (1) {
  +     const char *buf;
  +
           if (isatty(fileno(stdin))) {
               line = readline("augtool> ");
           } else if (getline(&line, &len, stdin) == -1) {
  @@ -643,12 +637,13 @@
           if (line[0] == '#')
               continue;
   
  -     /* XXX fill in 1st/3rd args */
  -     if (rpmaugRun(NULL, line, NULL) == RPMRC_OK) {
  +     buf = NULL;
  +     if (rpmaugRun(NULL, line, &buf) == RPMRC_OK) {
            if (isatty(fileno(stdin)))
                add_history(line);
  -     } else
  -         ret = -1;
  +     }
  +     if (buf && *buf)
  +         fprintf(stdout, "%s", buf);
       }
       line = _free(line);
       return ret;
  @@ -695,9 +690,14 @@
   
       av = poptGetArgs(optCon);
       ac = argvCount(av);
  -    if (ac > 0) {
  -        // Accept one command from the command line
  -        r = run_command(ac, (char **)av);
  +    if (ac > 0) {    // Accept one command from the command line
  +     const char * cmd = argvJoin((const char **)av, ' ');
  +     const char *buf;
  +
  +        r = rpmaugRun(NULL, cmd, &buf);
  +     cmd = _free(cmd);
  +     if (buf && *buf)
  +         fprintf(stdout, "%s", buf);
       } else {
           r = main_loop();
       }
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to