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

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
  Module: rpm                              Date:   25-Jan-2008 23:19:12
  Branch: HEAD                             Handle: 2008012522191200

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               macro.c

  Log:
    Provide a convenient %{shrink:<body>} macro to shrink the body by
    removing all leading and trailing whitespaces and reducing intermediate
    whitespaces to a single space character.
    
    Sidenode: this is for instance especially very handy if one plays macro
    tricks where mixed multi-level native+Lua expansions are performed and
    one wants to avoid trouble when generating intermediate Lua strings
    "..." on the fly (which cannot spawn multiple lines). Well, perhaps
    better not ask me for more details... ;-)

  Summary:
    Revision    Changes     Path
    1.2097      +1  -0      rpm/CHANGES
    2.180       +21 -0      rpm/rpmio/macro.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2096 -r1.2097 CHANGES
  --- rpm/CHANGES       25 Jan 2008 21:39:43 -0000      1.2096
  +++ rpm/CHANGES       25 Jan 2008 22:19:12 -0000      1.2097
  @@ -1,4 +1,5 @@
   5.0.0 -> 5.1a1:
  +    - rse: provide %{shrink:<body>} macro for removing leading+trailing and 
removing intermediate whitespaces
       - rse: allow sub-shell and Lua independent speedy lookup of environment 
variables via %{getenv:<name>} in macros
       - jbj: QNX needs defines for fts.c.
       - rse: upgrade from Lua 5.1.2 to Lua 5.1.3 (external and internal)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/macro.c
  ============================================================================
  $ cvs diff -u -r2.179 -r2.180 macro.c
  --- rpm/rpmio/macro.c 25 Jan 2008 21:39:43 -0000      2.179
  +++ rpm/rpmio/macro.c 25 Jan 2008 22:19:12 -0000      2.180
  @@ -1211,6 +1211,26 @@
           char *cp;
           if ((cp = getenv(buf)) != NULL)
               b = cp;
  +    } else if (STREQ("shrink", f, fn)) {
  +        /* shrink body by removing all leading and trailing whitespaces and
  +           reducing intermediate whitespaces to a single space character */
  +        int i, j, k, was_space = 0;
  +        for (i = 0, j = 0, k = strlen(buf); i < k; ) {
  +            if (xisspace((int)(buf[i]))) {
  +                was_space = 1;
  +                i++;
  +                continue;
  +            }
  +            else if (was_space) {
  +                was_space = 0;
  +                if (j > 0) /* remove leading blanks at all */
  +                    buf[j++] = ' ';
  +                /* fallthrough */
  +            }
  +            buf[j++] = buf[i++];
  +        }
  +        buf[j] = '\0';
  +        b = buf;
       } else if (STREQ("suffix", f, fn)) {
        if ((b = strrchr(buf, '.')) != NULL)
            b++;
  @@ -1606,6 +1626,7 @@
            STREQ("dirname", f, fn) ||
            STREQ("realpath", f, fn) ||
            STREQ("getenv", f, fn) ||
  +         STREQ("shrink", f, fn) ||
            STREQ("suffix", f, fn) ||
            STREQ("expand", f, fn) ||
            STREQ("verbose", f, fn) ||
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to