RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/ CHANGES rpm/rpmio/ macro.c

From: Ralf S. Engelschall <rse@rpm5.org>
Date: Fri 25 Jan 2008 - 23:19:12 CET
Message-Id: <20080125221912.D95E9348464@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  rse@rpm5.org
  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) ||
  @@ .
Received on Fri Jan 25 23:19:12 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.