Ignore:
Timestamp:
Nov 26, 2002, 10:24:54 PM (23 years ago)
Author:
bird
Message:

Import of RELENG_4_7_0_RELEASE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FREEBSD/src/kmk/var.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)var.c    8.3 (Berkeley) 3/19/94
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/var.c,v 1.35 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)var.c       8.3 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/var.c,v 1.16.2.3 2002/02/27 14:18:57 cjc Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    126130static Lst      allVars;      /* List of all variables */
    127131
    128 #define FIND_CMD        0x1   /* look in VAR_CMD when searching */
    129 #define FIND_GLOBAL     0x2   /* look in VAR_GLOBAL as well */
    130 #define FIND_ENV        0x4   /* look in the environment also */
     132#define FIND_CMD        0x1   /* look in VAR_CMD when searching */
     133#define FIND_GLOBAL     0x2   /* look in VAR_GLOBAL as well */
     134#define FIND_ENV        0x4   /* look in the environment also */
    131135
    132136typedef struct Var {
     
    134138    Buffer        val;          /* its value */
    135139    int           flags;        /* miscellaneous status flags */
    136 #define VAR_IN_USE      1           /* Variable's value currently being used.
     140#define VAR_IN_USE      1           /* Variable's value currently being used.
    137141                                     * Used to avoid recursion */
    138 #define VAR_FROM_ENV    2           /* Variable comes from the environment */
    139 #define VAR_JUNK        4           /* Variable is a junk variable that
     142#define VAR_FROM_ENV    2           /* Variable comes from the environment */
     143#define VAR_JUNK        4           /* Variable is a junk variable that
    140144                                     * should be destroyed when done with
    141145                                     * it. Used by Var_Parse for undefined,
     
    144148
    145149/* Var*Pattern flags */
    146 #define VAR_SUB_GLOBAL  0x01    /* Apply substitution globally */
    147 #define VAR_SUB_ONE     0x02    /* Apply substitution to one word */
    148 #define VAR_SUB_MATCHED 0x04    /* There was a match */
    149 #define VAR_MATCH_START 0x08    /* Match at start of word */
    150 #define VAR_MATCH_END   0x10    /* Match at end of word */
    151 #define VAR_NOSUBST     0x20    /* don't expand vars in VarGetPattern */
     150#define VAR_SUB_GLOBAL  0x01    /* Apply substitution globally */
     151#define VAR_SUB_ONE     0x02    /* Apply substitution to one word */
     152#define VAR_SUB_MATCHED 0x04    /* There was a match */
     153#define VAR_MATCH_START 0x08    /* Match at start of word */
     154#define VAR_MATCH_END   0x10    /* Match at end of word */
     155#define VAR_NOSUBST     0x20    /* don't expand vars in VarGetPattern */
    152156
    153157typedef struct {
     
    167171} VarREPattern;
    168172
    169 static int VarCmp(void *, void *);
    170 static void VarPossiblyExpand(char **, GNode *);
    171 static Var *VarFind(char *, GNode *, int);
    172 static void VarAdd(char *, char *, GNode *);
    173 static void VarDelete(void *);
    174 static Boolean VarHead(char *, Boolean, Buffer, void *);
    175 static Boolean VarTail(char *, Boolean, Buffer, void *);
    176 static Boolean VarSuffix(char *, Boolean, Buffer, void *);
    177 static Boolean VarRoot(char *, Boolean, Buffer, void *);
    178 static Boolean VarMatch(char *, Boolean, Buffer, void *);
     173static int VarCmp __P((ClientData, ClientData));
     174static Var *VarFind __P((char *, GNode *, int));
     175static void VarAdd __P((char *, char *, GNode *));
     176static void VarDelete __P((ClientData));
     177static Boolean VarHead __P((char *, Boolean, Buffer, ClientData));
     178static Boolean VarTail __P((char *, Boolean, Buffer, ClientData));
     179static Boolean VarSuffix __P((char *, Boolean, Buffer, ClientData));
     180static Boolean VarRoot __P((char *, Boolean, Buffer, ClientData));
     181static Boolean VarMatch __P((char *, Boolean, Buffer, ClientData));
    179182#ifdef SYSVVARSUB
    180 static Boolean VarSYSVMatch(char *, Boolean, Buffer, void *);
     183static Boolean VarSYSVMatch __P((char *, Boolean, Buffer, ClientData));
    181184#endif
    182 static Boolean VarNoMatch(char *, Boolean, Buffer, void *);
    183 static void VarREError(int, regex_t *, const char *);
    184 static Boolean VarRESubstitute(char *, Boolean, Buffer, void *);
    185 static Boolean VarSubstitute(char *, Boolean, Buffer, void *);
    186 static char *VarGetPattern(GNode *, int, char **, int, int *, int *,
    187                            VarPattern *);
    188 static char *VarQuote(char *);
    189 static char *VarModify(char *, Boolean (*)(char *, Boolean, Buffer, void *),
    190                        void *);
    191 static int VarPrintVar(void *, void *);
     185static Boolean VarNoMatch __P((char *, Boolean, Buffer, ClientData));
     186static void VarREError __P((int, regex_t *, const char *));
     187static Boolean VarRESubstitute __P((char *, Boolean, Buffer, ClientData));
     188static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData));
     189static char *VarGetPattern __P((GNode *, int, char **, int, int *, int *,
     190                                VarPattern *));
     191static char *VarQuote __P((char *));
     192static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer,
     193                                                ClientData),
     194                            ClientData));
     195static int VarPrintVar __P((ClientData, ClientData));
    192196
    193197/*-
     
    205209 */
    206210static int
    207 VarCmp (void *v, void *name)
     211VarCmp (v, name)
     212    ClientData     v;           /* VAR structure to compare */
     213    ClientData     name;        /* name to look for */
    208214{
    209215    return (strcmp ((char *) name, ((Var *) v)->name));
    210 }
    211 
    212 /*-
    213  *-----------------------------------------------------------------------
    214  * VarPossiblyExpand --
    215  *      Expand a variable name's embedded variables in the given context.
    216  *
    217  * Results:
    218  *      The contents of name, possibly expanded.
    219  *
    220  * Side Effects:
    221  *      The caller must free the new contents or old contents of name.
    222  *-----------------------------------------------------------------------
    223  */
    224 static void
    225 VarPossiblyExpand(char **name, GNode *ctxt)
    226 {
    227     if (strchr(*name, '$') != NULL)
    228         *name = Var_Subst(NULL, *name, ctxt, 0);
    229     else
    230         *name = estrdup(*name);
    231216}
    232217
     
    237222 *      indicated.
    238223 *
    239  *      Flags:
    240  *              FIND_GLOBAL     set means look in the VAR_GLOBAL context too
    241  *              FIND_CMD        set means to look in the VAR_CMD context too
    242  *              FIND_ENV        set means to look in the environment
    243  *
    244224 * Results:
    245225 *      A pointer to the structure describing the desired variable or
    246  *      NULL if the variable does not exist.
     226 *      NIL if the variable does not exist.
    247227 *
    248228 * Side Effects:
     
    251231 */
    252232static Var *
    253 VarFind (char *name, GNode *ctxt, int flags)
     233VarFind (name, ctxt, flags)
     234    char                *name;  /* name to find */
     235    GNode               *ctxt;  /* context in which to find it */
     236    int                 flags;  /* FIND_GLOBAL set means to look in the
     237                                 * VAR_GLOBAL context as well.
     238                                 * FIND_CMD set means to look in the VAR_CMD
     239                                 * context also.
     240                                 * FIND_ENV set means to look in the
     241                                 * environment */
    254242{
    255243    Boolean             localCheckEnvFirst;
     
    297285     * the -E flag to use environment-variable-override for.
    298286     */
    299     if (Lst_Find (envFirstVars, (void *)name,
    300                   (int (*)(void *, void *)) strcmp) != NULL)
     287    if (Lst_Find (envFirstVars, (ClientData)name,
     288                  (int (*)(ClientData, ClientData)) strcmp) != NILLNODE)
    301289    {
    302290        localCheckEnvFirst = TRUE;
     
    310298     * depending on the FIND_* flags in 'flags'
    311299     */
    312     var = Lst_Find (ctxt->context, (void *)name, VarCmp);
    313 
    314     if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
    315         var = Lst_Find (VAR_CMD->context, (void *)name, VarCmp);
    316     }
    317     if ((var == NULL) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL) &&
     300    var = Lst_Find (ctxt->context, (ClientData)name, VarCmp);
     301
     302    if ((var == NILLNODE) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
     303        var = Lst_Find (VAR_CMD->context, (ClientData)name, VarCmp);
     304    }
     305    if ((var == NILLNODE) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL) &&
    318306        !checkEnvFirst && !localCheckEnvFirst)
    319307    {
    320         var = Lst_Find (VAR_GLOBAL->context, (void *)name, VarCmp);
    321     }
    322     if ((var == NULL) && (flags & FIND_ENV)) {
     308        var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp);
     309    }
     310    if ((var == NILLNODE) && (flags & FIND_ENV)) {
    323311        char *env;
    324312
     
    339327                   (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL))
    340328        {
    341             var = Lst_Find (VAR_GLOBAL->context, (void *)name, VarCmp);
    342             if (var == NULL) {
    343                 return ((Var *) NULL);
     329            var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp);
     330            if (var == NILLNODE) {
     331                return ((Var *) NIL);
    344332            } else {
    345333                return ((Var *)Lst_Datum(var));
    346334            }
    347335        } else {
    348             return((Var *)NULL);
     336            return((Var *)NIL);
    349337        }
    350     } else if (var == NULL) {
    351         return ((Var *) NULL);
     338    } else if (var == NILLNODE) {
     339        return ((Var *) NIL);
    352340    } else {
    353341        return ((Var *) Lst_Datum (var));
     
    358346 *-----------------------------------------------------------------------
    359347 * VarAdd  --
    360  *      Add a new variable of name name and value val to the given context.
     348 *      Add a new variable of name name and value val to the given context
    361349 *
    362350 * Results:
     
    370358 */
    371359static void
    372 VarAdd (char *name, char *val, GNode *ctxt)
    373 {
    374     Var           *v;
     360VarAdd (name, val, ctxt)
     361    char           *name;       /* name of variable to add */
     362    char           *val;        /* value to set it to */
     363    GNode          *ctxt;       /* context in which to set it */
     364{
     365    register Var   *v;
    375366    int           len;
    376367
     
    385376    v->flags = 0;
    386377
    387     (void) Lst_AtFront (ctxt->context, (void *)v);
    388     (void) Lst_AtEnd (allVars, (void *) v);
    389     DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val));
     378    (void) Lst_AtFront (ctxt->context, (ClientData)v);
     379    (void) Lst_AtEnd (allVars, (ClientData) v);
     380    if (DEBUG(VAR)) {
     381        printf("%s:%s = %s\n", ctxt->name, name, val);
     382    }
    390383}
    391384
     
    404397 */
    405398static void
    406 VarDelete(void *vp)
     399VarDelete(vp)
     400    ClientData vp;
    407401{
    408402    Var *v = (Var *) vp;
    409403    free(v->name);
    410404    Buf_Destroy(v->val, TRUE);
    411     free(v);
     405    free((Address) v);
    412406}
    413407
     
    428422 */
    429423void
    430 Var_Delete(char *name, GNode *ctxt)
     424Var_Delete(name, ctxt)
     425    char          *name;
     426    GNode         *ctxt;
    431427{
    432428    LstNode       ln;
    433429
    434     DEBUGF(VAR, ("%s:delete %s\n", ctxt->name, name));
    435     ln = Lst_Find(ctxt->context, (void *)name, VarCmp);
    436     if (ln != NULL) {
    437         Var       *v;
     430    if (DEBUG(VAR)) {
     431        printf("%s:delete %s\n", ctxt->name, name);
     432    }
     433    ln = Lst_Find(ctxt->context, (ClientData)name, VarCmp);
     434    if (ln != NILLNODE) {
     435        register Var      *v;
    438436
    439437        v = (Var *)Lst_Datum(ln);
     
    441439        ln = Lst_Member(allVars, v);
    442440        Lst_Remove(allVars, ln);
    443         VarDelete((void *) v);
     441        VarDelete((ClientData) v);
    444442    }
    445443}
     
    467465 */
    468466void
    469 Var_Set (char *name, char *val, GNode *ctxt)
    470 {
    471     Var            *v;
     467Var_Set (name, val, ctxt)
     468    char           *name;       /* name of variable to set */
     469    char           *val;        /* value to give to the variable */
     470    GNode          *ctxt;       /* context in which to set it */
     471{
     472    register Var   *v;
    472473
    473474    /*
     
    476477     * point in searching them all just to save a bit of memory...
    477478     */
    478     VarPossiblyExpand(&name, ctxt);
    479479    v = VarFind (name, ctxt, 0);
    480     if (v == (Var *) NULL) {
     480    if (v == (Var *) NIL) {
    481481        VarAdd (name, val, ctxt);
    482482    } else {
     
    484484        Buf_AddBytes(v->val, strlen(val), (Byte *)val);
    485485
    486         DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val));
     486        if (DEBUG(VAR)) {
     487            printf("%s:%s = %s\n", ctxt->name, name, val);
     488        }
    487489    }
    488490    /*
     
    493495        setenv(name, val, 1);
    494496    }
    495     free(name);
    496497}
    497498
     
    519520 */
    520521void
    521 Var_Append (char *name, char *val, GNode *ctxt)
    522 {
    523     Var            *v;
    524 
    525     VarPossiblyExpand(&name, ctxt);
     522Var_Append (name, val, ctxt)
     523    char           *name;       /* Name of variable to modify */
     524    char           *val;        /* String to append to it */
     525    GNode          *ctxt;       /* Context in which this should occur */
     526{
     527    register Var   *v;
     528
    526529    v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0);
    527530
    528     if (v == (Var *) NULL) {
     531    if (v == (Var *) NIL) {
    529532        VarAdd (name, val, ctxt);
    530533    } else {
     
    532535        Buf_AddBytes(v->val, strlen(val), (Byte *)val);
    533536
    534         DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name,
    535                (char *) Buf_GetAll(v->val, (int *)NULL)));
     537        if (DEBUG(VAR)) {
     538            printf("%s:%s = %s\n", ctxt->name, name,
     539                   (char *) Buf_GetAll(v->val, (int *)NULL));
     540        }
    536541
    537542        if (v->flags & VAR_FROM_ENV) {
     
    543548             */
    544549            v->flags &= ~VAR_FROM_ENV;
    545             Lst_AtFront(ctxt->context, (void *)v);
     550            Lst_AtFront(ctxt->context, (ClientData)v);
    546551        }
    547552    }
    548     free(name);
    549553}
    550554
     
    563567 */
    564568Boolean
    565 Var_Exists(char *name, GNode *ctxt)
     569Var_Exists(name, ctxt)
     570    char          *name;        /* Variable to find */
     571    GNode         *ctxt;        /* Context in which to start search */
    566572{
    567573    Var           *v;
    568574
    569     VarPossiblyExpand(&name, ctxt);
    570575    v = VarFind(name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV);
    571     free(name);
    572 
    573     if (v == (Var *)NULL) {
     576
     577    if (v == (Var *)NIL) {
    574578        return(FALSE);
    575579    } else if (v->flags & VAR_FROM_ENV) {
     
    594598 */
    595599char *
    596 Var_Value (char *name, GNode *ctxt, char **frp)
     600Var_Value (name, ctxt, frp)
     601    char           *name;       /* name to find */
     602    GNode          *ctxt;       /* context in which to search for it */
     603    char           **frp;
    597604{
    598605    Var            *v;
    599606
    600     VarPossiblyExpand(&name, ctxt);
    601607    v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
    602     free(name);
    603608    *frp = NULL;
    604     if (v != (Var *) NULL) {
     609    if (v != (Var *) NIL) {
    605610        char *p = ((char *)Buf_GetAll(v->val, (int *)NULL));
    606611        if (v->flags & VAR_FROM_ENV) {
    607612            Buf_Destroy(v->val, FALSE);
    608             free(v);
     613            free((Address) v);
    609614            *frp = p;
    610615        }
     
    631636 */
    632637static Boolean
    633 VarHead (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    634 {
    635     char *slash;
     638VarHead (word, addSpace, buf, dummy)
     639    char          *word;        /* Word to trim */
     640    Boolean       addSpace;     /* True if need to add a space to the buffer
     641                                 * before sticking in the head */
     642    Buffer        buf;          /* Buffer in which to store it */
     643    ClientData    dummy;
     644{
     645    register char *slash;
    636646
    637647    slash = strrchr (word, '/');
     
    654664        }
    655665    }
    656     return (TRUE);
     666    return(dummy ? TRUE : TRUE);
    657667}
    658668
     
    673683 */
    674684static Boolean
    675 VarTail (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    676 {
    677     char *slash;
     685VarTail (word, addSpace, buf, dummy)
     686    char          *word;        /* Word to trim */
     687    Boolean       addSpace;     /* TRUE if need to stick a space in the
     688                                 * buffer before adding the tail */
     689    Buffer        buf;          /* Buffer in which to store it */
     690    ClientData    dummy;
     691{
     692    register char *slash;
    678693
    679694    if (addSpace) {
     
    689704        Buf_AddBytes (buf, strlen(word), (Byte *)word);
    690705    }
    691     return (TRUE);
     706    return (dummy ? TRUE : TRUE);
    692707}
    693708
     
    707722 */
    708723static Boolean
    709 VarSuffix (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    710 {
    711     char *dot;
     724VarSuffix (word, addSpace, buf, dummy)
     725    char          *word;        /* Word to trim */
     726    Boolean       addSpace;     /* TRUE if need to add a space before placing
     727                                 * the suffix in the buffer */
     728    Buffer        buf;          /* Buffer in which to store it */
     729    ClientData    dummy;
     730{
     731    register char *dot;
    712732
    713733    dot = strrchr (word, '.');
     
    721741        addSpace = TRUE;
    722742    }
    723     return (addSpace);
     743    return (dummy ? addSpace : addSpace);
    724744}
    725745
     
    740760 */
    741761static Boolean
    742 VarRoot (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    743 {
    744     char *dot;
     762VarRoot (word, addSpace, buf, dummy)
     763    char          *word;        /* Word to trim */
     764    Boolean       addSpace;     /* TRUE if need to add a space to the buffer
     765                                 * before placing the root in it */
     766    Buffer        buf;          /* Buffer in which to store it */
     767    ClientData    dummy;
     768{
     769    register char *dot;
    745770
    746771    if (addSpace) {
     
    756781        Buf_AddBytes (buf, strlen(word), (Byte *)word);
    757782    }
    758     return (TRUE);
     783    return (dummy ? TRUE : TRUE);
    759784}
    760785
     
    764789 *      Place the word in the buffer if it matches the given pattern.
    765790 *      Callback function for VarModify to implement the :M modifier.
    766  *      A space will be added if requested.  A pattern is supplied
    767  *      which the word must match.
    768791 *
    769792 * Results:
     
    777800 */
    778801static Boolean
    779 VarMatch (char *word, Boolean addSpace, Buffer buf, void *pattern)
     802VarMatch (word, addSpace, buf, pattern)
     803    char          *word;        /* Word to examine */
     804    Boolean       addSpace;     /* TRUE if need to add a space to the
     805                                 * buffer before adding the word, if it
     806                                 * matches */
     807    Buffer        buf;          /* Buffer in which to store it */
     808    ClientData    pattern;      /* Pattern the word must match */
    780809{
    781810    if (Str_Match(word, (char *) pattern)) {
     
    795824 *      Place the word in the buffer if it matches the given pattern.
    796825 *      Callback function for VarModify to implement the System V %
    797  *      modifiers.  A space is added if requested.
     826 *      modifiers.
    798827 *
    799828 * Results:
     
    807836 */
    808837static Boolean
    809 VarSYSVMatch (char *word, Boolean addSpace, Buffer buf, void *patp)
     838VarSYSVMatch (word, addSpace, buf, patp)
     839    char          *word;        /* Word to examine */
     840    Boolean       addSpace;     /* TRUE if need to add a space to the
     841                                 * buffer before adding the word, if it
     842                                 * matches */
     843    Buffer        buf;          /* Buffer in which to store it */
     844    ClientData    patp;         /* Pattern the word must match */
    810845{
    811846    int len;
     
    832867 * VarNoMatch --
    833868 *      Place the word in the buffer if it doesn't match the given pattern.
    834  *      Callback function for VarModify to implement the :N modifier.  A
    835  *      space is added if requested.
     869 *      Callback function for VarModify to implement the :N modifier.
    836870 *
    837871 * Results:
     
    845879 */
    846880static Boolean
    847 VarNoMatch (char *word, Boolean addSpace, Buffer buf, void *pattern)
     881VarNoMatch (word, addSpace, buf, pattern)
     882    char          *word;        /* Word to examine */
     883    Boolean       addSpace;     /* TRUE if need to add a space to the
     884                                 * buffer before adding the word, if it
     885                                 * matches */
     886    Buffer        buf;          /* Buffer in which to store it */
     887    ClientData    pattern;      /* Pattern the word must match */
    848888{
    849889    if (!Str_Match(word, (char *) pattern)) {
     
    862902 * VarSubstitute --
    863903 *      Perform a string-substitution on the given word, placing the
    864  *      result in the passed buffer.  A space is added if requested.
     904 *      result in the passed buffer.
    865905 *
    866906 * Results:
     
    873913 */
    874914static Boolean
    875 VarSubstitute (char *word, Boolean addSpace, Buffer buf, void *patternp)
    876 {
    877     int                 wordLen;    /* Length of word */
    878     char                *cp;        /* General pointer */
     915VarSubstitute (word, addSpace, buf, patternp)
     916    char                *word;      /* Word to modify */
     917    Boolean             addSpace;   /* True if space should be added before
     918                                     * other characters */
     919    Buffer              buf;        /* Buffer for result */
     920    ClientData          patternp;   /* Pattern for substitution */
     921{
     922    register int        wordLen;    /* Length of word */
     923    register char       *cp;        /* General pointer */
    879924    VarPattern  *pattern = (VarPattern *) patternp;
    880925
     
    9711016             * buffer.
    9721017             */
    973             Boolean done;
     1018            register Boolean done;
    9741019            int origSize;
    9751020
     
    10351080 */
    10361081static void
    1037 VarREError(int err, regex_t *pat, const char *str)
     1082VarREError(err, pat, str)
     1083    int err;
     1084    regex_t *pat;
     1085    const char *str;
    10381086{
    10391087    char *errbuf;
     
    10521100 * VarRESubstitute --
    10531101 *      Perform a regex substitution on the given word, placing the
    1054  *      result in the passed buffer.  A space is added if requested.
     1102 *      result in the passed buffer.
    10551103 *
    10561104 * Results:
     
    10631111 */
    10641112static Boolean
    1065 VarRESubstitute(char *word, Boolean addSpace, Buffer buf, void *patternp)
     1113VarRESubstitute(word, addSpace, buf, patternp)
     1114    char *word;
     1115    Boolean addSpace;
     1116    Buffer buf;
     1117    ClientData patternp;
    10661118{
    10671119    VarREPattern *pat;
     
    10721124    int flags = 0;
    10731125
    1074 #define MAYBE_ADD_SPACE()               \
     1126#define MAYBE_ADD_SPACE()               \
    10751127        if (addSpace && !added)         \
    10761128            Buf_AddByte(buf, ' ');      \
     
    11911243 */
    11921244static char *
    1193 VarModify (char *str, Boolean (*modProc)(char *, Boolean, Buffer, void *),
    1194     void *datum)
     1245VarModify (str, modProc, datum)
     1246    char          *str;             /* String whose words should be trimmed */
     1247                                    /* Function to use to modify them */
     1248    Boolean       (*modProc) __P((char *, Boolean, Buffer, ClientData));
     1249    ClientData    datum;            /* Datum to pass it */
    11951250{
    11961251    Buffer        buf;              /* Buffer for the new string */
     
    12381293 */
    12391294static char *
    1240 VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
    1241     int *length, VarPattern *pattern)
     1295VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
     1296    GNode *ctxt;
     1297    int err;
     1298    char **tstr;
     1299    int delim;
     1300    int *flags;
     1301    int *length;
     1302    VarPattern *pattern;
    12421303{
    12431304    char *cp;
     
    12471308        length = &junk;
    12481309
    1249 #define IS_A_MATCH(cp, delim) \
     1310#define IS_A_MATCH(cp, delim) \
    12501311    ((cp[0] == '\\') && ((cp[1] == delim) ||  \
    12511312     (cp[1] == '\\') || (cp[1] == '$') || (pattern && (cp[1] == '&'))))
     
    13521413 */
    13531414static char *
    1354 VarQuote(char *str)
     1415VarQuote(str)
     1416        char *str;
    13551417{
    13561418
     
    13921454 */
    13931455char *
    1394 Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr)
    1395 {
    1396     char            *tstr;      /* Pointer into str */
     1456Var_Parse (str, ctxt, err, lengthPtr, freePtr)
     1457    char          *str;         /* The string to parse */
     1458    GNode         *ctxt;        /* The context for the variable */
     1459    Boolean         err;        /* TRUE if undefined variables are an error */
     1460    int             *lengthPtr; /* OUT: The length of the specification */
     1461    Boolean         *freePtr;   /* OUT: TRUE if caller should free result */
     1462{
     1463    register char   *tstr;      /* Pointer into str */
    13971464    Var             *v;         /* Variable in invocation */
    13981465    char            *cp;        /* Secondary pointer into str (place marker
    13991466                                 * for tstr) */
    14001467    Boolean         haveModifier;/* TRUE if have modifiers for the variable */
    1401     char            endc;       /* Ending character when variable in parens
     1468    register char   endc;       /* Ending character when variable in parens
    14021469                                 * or braces */
    1403     char            startc=0;   /* Starting character when variable in parens
     1470    register char   startc=0;   /* Starting character when variable in parens
    14041471                                 * or braces */
    14051472    int             cnt;        /* Used to count brace pairs when variable in
     
    14301497
    14311498        v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
    1432         if (v == (Var *)NULL) {
     1499        if (v == (Var *)NIL) {
    14331500            *lengthPtr = 2;
    14341501
     
    14531520                    case '!':
    14541521                        return("$(.MEMBER)");
    1455                     default:
    1456                         break;
    14571522                }
    14581523            }
     
    15121577
    15131578        v = VarFind (str, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
    1514         if ((v == (Var *)NULL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) &&
     1579        if ((v == (Var *)NIL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) &&
    15151580            (vlen == 2) && (str[1] == 'F' || str[1] == 'D'))
    15161581        {
     
    15371602                    v = VarFind(vname, ctxt, 0);
    15381603
    1539                     if (v != (Var *)NULL && !haveModifier) {
     1604                    if (v != (Var *)NIL && !haveModifier) {
    15401605                        /*
    15411606                         * No need for nested expansion or anything, as we're
     
    15461611
    15471612                        if (str[1] == 'D') {
    1548                             val = VarModify(val, VarHead, (void *)0);
     1613                            val = VarModify(val, VarHead, (ClientData)0);
    15491614                        } else {
    1550                             val = VarModify(val, VarTail, (void *)0);
     1615                            val = VarModify(val, VarTail, (ClientData)0);
    15511616                        }
    15521617                        /*
     
    15611626                    }
    15621627                    break;
    1563                 default:
    1564                     break;
    15651628                }
    15661629            }
    15671630        }
    15681631
    1569         if (v == (Var *)NULL) {
     1632        if (v == (Var *)NIL) {
    15701633            if (((vlen == 1) ||
    15711634                 (((vlen == 2) && (str[1] == 'F' ||
     
    15881651                    case '!':
    15891652                        dynamic = TRUE;
    1590                         break;
    1591                     default:
    15921653                        break;
    15931654                }
     
    16931754            char        termc;      /* Character which terminated scan */
    16941755
    1695             DEBUGF(VAR, ("Applying :%c to \"%s\"\n", *tstr, str));
     1756            if (DEBUG(VAR)) {
     1757                printf("Applying :%c to \"%s\"\n", *tstr, str);
     1758            }
    16961759            switch (*tstr) {
    16971760                case 'U':
     
    17701833                    }
    17711834                    if (*tstr == 'M' || *tstr == 'm') {
    1772                         newStr = VarModify(str, VarMatch, (void *)pattern);
     1835                        newStr = VarModify(str, VarMatch, (ClientData)pattern);
    17731836                    } else {
    17741837                        newStr = VarModify(str, VarNoMatch,
    1775                                            (void *)pattern);
     1838                                           (ClientData)pattern);
    17761839                    }
    17771840                    if (copy) {
     
    17831846                {
    17841847                    VarPattern      pattern;
    1785                     char            del;
     1848                    register char   delim;
    17861849                    Buffer          buf;        /* Buffer for patterns */
    17871850
    17881851                    pattern.flags = 0;
    1789                     del = tstr[1];
     1852                    delim = tstr[1];
    17901853                    tstr += 2;
    17911854
     
    18081871                     * The result is left in the Buffer buf.
    18091872                     */
    1810                     for (cp = tstr; *cp != '\0' && *cp != del; cp++) {
     1873                    for (cp = tstr; *cp != '\0' && *cp != delim; cp++) {
    18111874                        if ((*cp == '\\') &&
    1812                             ((cp[1] == del) ||
     1875                            ((cp[1] == delim) ||
    18131876                             (cp[1] == '$') ||
    18141877                             (cp[1] == '\\')))
     
    18171880                            cp++;
    18181881                        } else if (*cp == '$') {
    1819                             if (cp[1] != del) {
     1882                            if (cp[1] != delim) {
    18201883                                /*
    18211884                                 * If unescaped dollar sign not before the
     
    18511914                     * return NULL
    18521915                     */
    1853                     if (*cp != del) {
     1916                    if (*cp != delim) {
    18541917                        *lengthPtr = cp - start + 1;
    18551918                        if (*freePtr) {
     
    18581921                        Buf_Destroy(buf, TRUE);
    18591922                        Error("Unclosed substitution for %s (%c missing)",
    1860                               v->name, del);
     1923                              v->name, delim);
    18611924                        return (var_Error);
    18621925                    }
     
    18831946
    18841947                    tstr = cp + 1;
    1885                     for (cp = tstr; *cp != '\0' && *cp != del; cp++) {
     1948                    for (cp = tstr; *cp != '\0' && *cp != delim; cp++) {
    18861949                        if ((*cp == '\\') &&
    1887                             ((cp[1] == del) ||
     1950                            ((cp[1] == delim) ||
    18881951                             (cp[1] == '&') ||
    18891952                             (cp[1] == '\\') ||
     
    18921955                            Buf_AddByte(buf, (Byte)cp[1]);
    18931956                            cp++;
    1894                         } else if ((*cp == '$') && (cp[1] != del)) {
     1957                        } else if ((*cp == '$') && (cp[1] != delim)) {
    18951958                            char    *cp2;
    18961959                            int     len;
     
    19161979                     * If didn't end in delimiter character, complain
    19171980                     */
    1918                     if (*cp != del) {
     1981                    if (*cp != delim) {
    19191982                        *lengthPtr = cp - start + 1;
    19201983                        if (*freePtr) {
     
    19231986                        Buf_Destroy(buf, TRUE);
    19241987                        Error("Unclosed substitution for %s (%c missing)",
    1925                               v->name, del);
     1988                              v->name, delim);
    19261989                        return (var_Error);
    19271990                    }
     
    19442007                    termc = *cp;
    19452008                    newStr = VarModify(str, VarSubstitute,
    1946                                        (void *)&pattern);
     2009                                       (ClientData)&pattern);
    19472010                    /*
    19482011                     * Free the two strings.
     
    19982061                            pattern.flags |= VAR_SUB_ONE;
    19992062                            continue;
    2000                         default:
    2001                             break;
    20022063                        }
    20032064                        break;
     
    20232084                                              sizeof(regmatch_t));
    20242085                    newStr = VarModify(str, VarRESubstitute,
    2025                                        (void *) &pattern);
     2086                                       (ClientData) &pattern);
    20262087                    regfree(&pattern.re);
    20272088                    free(pattern.replace);
     
    20392100                case 'T':
    20402101                    if (tstr[1] == endc || tstr[1] == ':') {
    2041                         newStr = VarModify (str, VarTail, (void *)0);
     2102                        newStr = VarModify (str, VarTail, (ClientData)0);
    20422103                        cp = tstr + 1;
    20432104                        termc = *cp;
     
    20472108                case 'H':
    20482109                    if (tstr[1] == endc || tstr[1] == ':') {
    2049                         newStr = VarModify (str, VarHead, (void *)0);
     2110                        newStr = VarModify (str, VarHead, (ClientData)0);
    20502111                        cp = tstr + 1;
    20512112                        termc = *cp;
     
    20552116                case 'E':
    20562117                    if (tstr[1] == endc || tstr[1] == ':') {
    2057                         newStr = VarModify (str, VarSuffix, (void *)0);
     2118                        newStr = VarModify (str, VarSuffix, (ClientData)0);
    20582119                        cp = tstr + 1;
    20592120                        termc = *cp;
     
    20632124                case 'R':
    20642125                    if (tstr[1] == endc || tstr[1] == ':') {
    2065                         newStr = VarModify (str, VarRoot, (void *)0);
     2126                        newStr = VarModify (str, VarRoot, (ClientData)0);
    20662127                        cp = tstr + 1;
    20672128                        termc = *cp;
     
    20722133                case 's':
    20732134                    if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
    2074                         char *error;
    2075                         newStr = Cmd_Exec (str, &error);
    2076                         if (error)
    2077                             Error (error, str);
     2135                        char *err;
     2136                        newStr = Cmd_Exec (str, &err);
     2137                        if (err)
     2138                            Error (err, str);
    20782139                        cp = tstr + 2;
    20792140                        termc = *cp;
     
    21432204                         */
    21442205                        newStr = VarModify(str, VarSYSVMatch,
    2145                                            (void *)&pattern);
     2206                                           (ClientData)&pattern);
    21462207
    21472208                        /*
     
    21642225                }
    21652226            }
    2166             DEBUGF(VAR, ("Result is \"%s\"\n", newStr));
     2227            if (DEBUG(VAR)) {
     2228                printf("Result is \"%s\"\n", newStr);
     2229            }
    21672230
    21682231            if (*freePtr) {
     
    22032266        }
    22042267        Buf_Destroy(v->val, destroy);
    2205         free(v);
     2268        free((Address)v);
    22062269    } else if (v->flags & VAR_JUNK) {
    22072270        /*
     
    22142277        *freePtr = FALSE;
    22152278        Buf_Destroy(v->val, TRUE);
    2216         free(v);
     2279        free((Address)v);
    22172280        if (dynamic) {
    22182281            str = emalloc(*lengthPtr + 1);
     
    22422305 */
    22432306char *
    2244 Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr)
     2307Var_Subst (var, str, ctxt, undefErr)
     2308    char          *var;             /* Named variable || NULL for all */
     2309    char          *str;             /* the string in which to substitute */
     2310    GNode         *ctxt;            /* the context wherein to find variables */
     2311    Boolean       undefErr;         /* TRUE if undefineds are an error */
    22452312{
    22462313    Buffer        buf;              /* Buffer for forming things */
     
    23772444                Buf_AddBytes (buf, strlen (val), (Byte *)val);
    23782445                if (doFree) {
    2379                     free (val);
     2446                    free ((Address)val);
    23802447                }
    23812448            }
     
    24042471 */
    24052472char *
    2406 Var_GetTail(char *file)
    2407 {
    2408     return(VarModify(file, VarTail, (void *)0));
     2473Var_GetTail(file)
     2474    char        *file;      /* Filename to modify */
     2475{
     2476    return(VarModify(file, VarTail, (ClientData)0));
    24092477}
    24102478
     
    24252493 */
    24262494char *
    2427 Var_GetHead(char *file)
    2428 {
    2429     return(VarModify(file, VarHead, (void *)0));
     2495Var_GetHead(file)
     2496    char        *file;      /* Filename to manipulate */
     2497{
     2498    return(VarModify(file, VarHead, (ClientData)0));
    24302499}
    24312500
     
    24432512 */
    24442513void
    2445 Var_Init (void)
     2514Var_Init ()
    24462515{
    24472516    VAR_GLOBAL = Targ_NewGN ("Global");
     
    24532522
    24542523void
    2455 Var_End (void)
     2524Var_End ()
    24562525{
    24572526    Lst_Destroy(allVars, VarDelete);
     
    24612530/****************** PRINT DEBUGGING INFO *****************/
    24622531static int
    2463 VarPrintVar (void *vp, void *dummy __unused)
     2532VarPrintVar (vp, dummy)
     2533    ClientData vp;
     2534    ClientData dummy;
    24642535{
    24652536    Var    *v = (Var *) vp;
    24662537    printf ("%-16s = %s\n", v->name, (char *) Buf_GetAll(v->val, (int *)NULL));
    2467     return (0);
     2538    return (dummy ? 0 : 0);
    24682539}
    24692540
     
    24752546 */
    24762547void
    2477 Var_Dump (GNode *ctxt)
    2478 {
    2479     Lst_ForEach (ctxt->context, VarPrintVar, (void *) 0);
    2480 }
     2548Var_Dump (ctxt)
     2549    GNode          *ctxt;
     2550{
     2551    Lst_ForEach (ctxt->context, VarPrintVar, (ClientData) 0);
     2552}
Note: See TracChangeset for help on using the changeset viewer.