]> TLD Linux GIT Repositories - packages/rpm.git/blob - rpm-unglobal.patch
- package /usr/lib/rpm/macros.d dir
[packages/rpm.git] / rpm-unglobal.patch
1 --- rpm-4.5/rpmio/macro.c       2009-08-08 15:47:20.495455961 +0200
2 +++ rpm-4.5/rpmio/macro.c       2012-11-08 06:37:45.082618600 +0200
3 @@ -807,6 +807,42 @@
4      return se;
5  }
6  
7 +void delMacroAll(MacroContext mc, const char * n);
8 +/**
9 + * Parse (and execute) macro undefinition.
10 + * @param mc           macro context
11 + * @param se           macro name to undefine
12 + * @return             address to continue parsing
13 + */
14 +/*@dependent@*/ static const char *
15 +doUnglobal(MacroContext mc, /*@returned@*/ const char * se)
16 +       /*@globals rpmGlobalMacroContext @*/
17 +       /*@modifies mc, rpmGlobalMacroContext @*/
18 +{
19 +    const char *s = se;
20 +    char *buf = alloca(_macro_BUFSIZ);
21 +    char *n = buf, *ne = n;
22 +    int c;
23 +
24 +    COPYNAME(ne, s, c);
25 +
26 +    /* Move scan over body */
27 +    while (iseol(*s))
28 +       s++;
29 +    se = s;
30 +
31 +    /* Names must start with alphabetic or _ and be at least 3 chars */
32 +    if (!((c = *n) && (xisalpha(c) || c == '_') && (ne - n) > 2)) {
33 +       rpmError(RPMERR_BADSPEC,
34 +               _("Macro %%%s has illegal name (%%unglobal)\n"), n);
35 +       return se;
36 +    }
37 +
38 +    delMacroAll(mc, n);
39 +
40 +    return se;
41 +}
42 +
43  #ifdef DYING
44  static void
45  dumpME(const char * msg, MacroEntry me)
46 @@ -1430,6 +1466,10 @@
47                 s = doUndefine(mb->mc, se);
48                 continue;
49         }
50 +       if (STREQ("unglobal", f, fn)) {
51 +               s = doUnglobal(mb->mc, se);
52 +               continue;
53 +       }
54  
55         if (STREQ("echo", f, fn) ||
56             STREQ("warn", f, fn) ||
57 @@ -1984,6 +2024,18 @@
58      }
59  }
60  
61 +void
62 +delMacroAll(MacroContext mc, const char * n)
63 +{
64 +       MacroEntry * mep;
65 +
66 +       if (mc == NULL) mc = rpmGlobalMacroContext;
67 +       /* If name exists, pop entry */
68 +       while ((mep = findEntry(mc, n, 0)) != NULL) {
69 +               delMacro(mc, n);
70 +       }
71 +}
72 +
73  /*@-mustmod@*/ /* LCL: mc is modified through mb->mc, mb is abstract */
74  int
75  rpmDefineMacro(MacroContext mc, const char * macro, int level)