=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/varmodifiers.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/make/varmodifiers.c 2001/05/07 22:59:33 1.8 --- src/usr.bin/make/varmodifiers.c 2001/05/23 12:34:52 1.9 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: varmodifiers.c,v 1.8 2001/05/07 22:59:33 espie Exp $ */ /* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: varmodifiers.c,v 1.9 2001/05/23 12:34:52 espie Exp $ */ /* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */ /* *************** *** 70,84 **** * is also called directly by Var_SubstVar. */ ! #include #ifndef MAKE_BOOTSTRAP ! #include ! #include #endif ! #include "make.h" #include "buf.h" #include "varmodifiers.h" /* Var*Pattern flags */ #define VAR_SUB_GLOBAL 0x01 /* Apply substitution globally */ #define VAR_SUB_ONE 0x02 /* Apply substitution to one word */ --- 70,98 ---- * is also called directly by Var_SubstVar. */ ! #include ! #include #ifndef MAKE_BOOTSTRAP ! #include #endif ! #include ! #include ! #include ! #include ! #include "config.h" ! #include "defines.h" #include "buf.h" + #include "var.h" #include "varmodifiers.h" + #include "varname.h" + #include "targ.h" + #include "error.h" + #include "str.h" + #include "cmd_exec.h" + #include "memory.h" + #include "gnode.h" + /* Var*Pattern flags */ #define VAR_SUB_GLOBAL 0x01 /* Apply substitution globally */ #define VAR_SUB_ONE 0x02 /* Apply substitution to one word */ *************** *** 105,127 **** char *var; char *expand; SymTable *ctxt; ! Boolean err; }; ! static Boolean VarHead(struct Name *, Boolean, Buffer, void *); ! static Boolean VarTail(struct Name *, Boolean, Buffer, void *); ! static Boolean VarSuffix(struct Name *, Boolean, Buffer, void *); ! static Boolean VarRoot(struct Name *, Boolean, Buffer, void *); ! static Boolean VarMatch(struct Name *, Boolean, Buffer, void *); ! static Boolean VarSYSVMatch(struct Name *, Boolean, Buffer, void *); ! static Boolean VarNoMatch(struct Name *, Boolean, Buffer, void *); ! static Boolean VarUniq(struct Name *, Boolean, Buffer, void *); ! static Boolean VarLoop(struct Name *, Boolean, Buffer, void *); #ifndef MAKE_BOOTSTRAP static void VarREError(int, regex_t *, const char *); ! static Boolean VarRESubstitute(struct Name *, Boolean, Buffer, void *); static char *do_regex(const char *, const struct Name *, void *); typedef struct { --- 119,141 ---- char *var; char *expand; SymTable *ctxt; ! bool err; }; ! static bool VarHead(struct Name *, bool, Buffer, void *); ! static bool VarTail(struct Name *, bool, Buffer, void *); ! static bool VarSuffix(struct Name *, bool, Buffer, void *); ! static bool VarRoot(struct Name *, bool, Buffer, void *); ! static bool VarMatch(struct Name *, bool, Buffer, void *); ! static bool VarSYSVMatch(struct Name *, bool, Buffer, void *); ! static bool VarNoMatch(struct Name *, bool, Buffer, void *); ! static bool VarUniq(struct Name *, bool, Buffer, void *); ! static bool VarLoop(struct Name *, bool, Buffer, void *); #ifndef MAKE_BOOTSTRAP static void VarREError(int, regex_t *, const char *); ! static bool VarRESubstitute(struct Name *, bool, Buffer, void *); static char *do_regex(const char *, const struct Name *, void *); typedef struct { *************** *** 133,148 **** } VarREPattern; #endif ! static Boolean VarSubstitute(struct Name *, Boolean, Buffer, void *); static char *VarGetPattern(SymTable *, int, const char **, int, int, size_t *, VarPattern *); static char *VarQuote(const char *, const struct Name *, void *); ! static char *VarModify(char *, Boolean (*)(struct Name *, Boolean, Buffer, void *), void *); ! static void *check_empty(const char **, SymTable *, Boolean, int); static char *do_upper(const char *, const struct Name *, void *); static char *do_lower(const char *, const struct Name *, void *); ! static void *check_shcmd(const char **, SymTable *, Boolean, int); static char *do_shcmd(const char *, const struct Name *, void *); static char *do_sort(const char *, const struct Name *, void *); static char *finish_loop(const char *, const struct Name *, void *); --- 147,162 ---- } VarREPattern; #endif ! static bool VarSubstitute(struct Name *, bool, Buffer, void *); static char *VarGetPattern(SymTable *, int, const char **, int, int, size_t *, VarPattern *); static char *VarQuote(const char *, const struct Name *, void *); ! static char *VarModify(char *, bool (*)(struct Name *, bool, Buffer, void *), void *); ! static void *check_empty(const char **, SymTable *, bool, int); static char *do_upper(const char *, const struct Name *, void *); static char *do_lower(const char *, const struct Name *, void *); ! static void *check_shcmd(const char **, SymTable *, bool, int); static char *do_shcmd(const char *, const struct Name *, void *); static char *do_sort(const char *, const struct Name *, void *); static char *finish_loop(const char *, const struct Name *, void *); *************** *** 154,206 **** static char *do_assign(const char *, const struct Name *, void *); static char *do_exec(const char *, const struct Name *, void *); ! static void *assign_get_value(const char **, SymTable *, Boolean, int); ! static void *get_cmd(const char **, SymTable *, Boolean, int); ! static void *get_value(const char **, SymTable *, Boolean, int); ! static void *get_stringarg(const char **, SymTable *, Boolean, int); static void free_stringarg(void *); ! static void *get_patternarg(const char **, SymTable *, Boolean, int); ! static void *get_spatternarg(const char **, SymTable *, Boolean, int); static void free_patternarg(void *); static void free_looparg(void *); ! static void *get_sysvpattern(const char **, SymTable *, Boolean, int); ! static void *get_loop(const char **, SymTable *, Boolean, int); static char *LoopGrab(const char **); static struct Name dummy; static struct Name *dummy_arg = &dummy; static struct modifier { ! Boolean atstart; ! void * (*getarg)(const char **, SymTable *, Boolean, int); char * (*apply)(const char *, const struct Name *, void *); ! Boolean (*word_apply)(struct Name *, Boolean, Buffer, void *); void (*freearg)(void *); } *choose_mod[256], ! match_mod = {FALSE, get_stringarg, NULL, VarMatch, free_stringarg}, ! nomatch_mod = {FALSE, get_stringarg, NULL, VarNoMatch, free_stringarg}, ! subst_mod = {FALSE, get_spatternarg, NULL, VarSubstitute, free_patternarg}, #ifndef MAKE_BOOTSTRAP ! resubst_mod = {FALSE, get_patternarg, do_regex, NULL, free_patternarg}, #endif ! quote_mod = {FALSE, check_empty, VarQuote, NULL , NULL}, ! tail_mod = {FALSE, check_empty, NULL, VarTail, NULL}, ! head_mod = {FALSE, check_empty, NULL, VarHead, NULL}, ! suffix_mod = {FALSE, check_empty, NULL, VarSuffix, NULL}, ! root_mod = {FALSE, check_empty, NULL, VarRoot, NULL}, ! upper_mod = {FALSE, check_empty, do_upper, NULL, NULL}, ! lower_mod = {FALSE, check_empty, do_lower, NULL, NULL}, ! shcmd_mod = {FALSE, check_shcmd, do_shcmd, NULL, NULL}, ! sysv_mod = {FALSE, get_sysvpattern, NULL, VarSYSVMatch, free_patternarg}, ! uniq_mod = {FALSE, check_empty, NULL, VarUniq, NULL}, ! sort_mod = {FALSE, check_empty, do_sort, NULL, NULL}, ! loop_mod = {FALSE, get_loop, finish_loop, VarLoop, free_looparg}, ! undef_mod = {TRUE, get_value, do_undef, NULL, NULL}, ! def_mod = {TRUE, get_value, do_def, NULL, NULL}, ! label_mod = {TRUE, check_empty, do_label, NULL, NULL}, ! path_mod = {TRUE, check_empty, do_path, NULL, NULL}, ! assign_mod = {TRUE, assign_get_value, do_assign, NULL, free_patternarg}, ! exec_mod = {TRUE, get_cmd, do_exec, NULL, free_patternarg} ; void --- 168,220 ---- static char *do_assign(const char *, const struct Name *, void *); static char *do_exec(const char *, const struct Name *, void *); ! static void *assign_get_value(const char **, SymTable *, bool, int); ! static void *get_cmd(const char **, SymTable *, bool, int); ! static void *get_value(const char **, SymTable *, bool, int); ! static void *get_stringarg(const char **, SymTable *, bool, int); static void free_stringarg(void *); ! static void *get_patternarg(const char **, SymTable *, bool, int); ! static void *get_spatternarg(const char **, SymTable *, bool, int); static void free_patternarg(void *); static void free_looparg(void *); ! static void *get_sysvpattern(const char **, SymTable *, bool, int); ! static void *get_loop(const char **, SymTable *, bool, int); static char *LoopGrab(const char **); static struct Name dummy; static struct Name *dummy_arg = &dummy; static struct modifier { ! bool atstart; ! void * (*getarg)(const char **, SymTable *, bool, int); char * (*apply)(const char *, const struct Name *, void *); ! bool (*word_apply)(struct Name *, bool, Buffer, void *); void (*freearg)(void *); } *choose_mod[256], ! match_mod = {false, get_stringarg, NULL, VarMatch, free_stringarg}, ! nomatch_mod = {false, get_stringarg, NULL, VarNoMatch, free_stringarg}, ! subst_mod = {false, get_spatternarg, NULL, VarSubstitute, free_patternarg}, #ifndef MAKE_BOOTSTRAP ! resubst_mod = {false, get_patternarg, do_regex, NULL, free_patternarg}, #endif ! quote_mod = {false, check_empty, VarQuote, NULL , NULL}, ! tail_mod = {false, check_empty, NULL, VarTail, NULL}, ! head_mod = {false, check_empty, NULL, VarHead, NULL}, ! suffix_mod = {false, check_empty, NULL, VarSuffix, NULL}, ! root_mod = {false, check_empty, NULL, VarRoot, NULL}, ! upper_mod = {false, check_empty, do_upper, NULL, NULL}, ! lower_mod = {false, check_empty, do_lower, NULL, NULL}, ! shcmd_mod = {false, check_shcmd, do_shcmd, NULL, NULL}, ! sysv_mod = {false, get_sysvpattern, NULL, VarSYSVMatch, free_patternarg}, ! uniq_mod = {false, check_empty, NULL, VarUniq, NULL}, ! sort_mod = {false, check_empty, do_sort, NULL, NULL}, ! loop_mod = {false, get_loop, finish_loop, VarLoop, free_looparg}, ! undef_mod = {true, get_value, do_undef, NULL, NULL}, ! def_mod = {true, get_value, do_def, NULL, NULL}, ! label_mod = {true, check_empty, do_label, NULL, NULL}, ! path_mod = {true, check_empty, do_path, NULL, NULL}, ! assign_mod = {true, assign_get_value, do_assign, NULL, free_patternarg}, ! exec_mod = {true, get_cmd, do_exec, NULL, free_patternarg} ; void *************** *** 251,270 **** * buffer. *----------------------------------------------------------------------- */ ! static Boolean VarHead(word, addSpace, buf, dummy) struct Name *word; ! Boolean addSpace; Buffer buf; void *dummy UNUSED; { const char *slash; ! slash = lastchar(word->s, word->e, '/'); if (slash != NULL) { if (addSpace) Buf_AddSpace(buf); ! Buf_AddInterval(buf, word->s, slash); } else { /* If no directory part, give . (q.v. the POSIX standard). */ if (addSpace) --- 265,284 ---- * buffer. *----------------------------------------------------------------------- */ ! static bool VarHead(word, addSpace, buf, dummy) struct Name *word; ! bool addSpace; Buffer buf; void *dummy UNUSED; { const char *slash; ! slash = Str_rchri(word->s, word->e, '/'); if (slash != NULL) { if (addSpace) Buf_AddSpace(buf); ! Buf_Addi(buf, word->s, slash); } else { /* If no directory part, give . (q.v. the POSIX standard). */ if (addSpace) *************** *** 272,278 **** else Buf_AddChar(buf, '.'); } ! return TRUE; } /*- --- 286,292 ---- else Buf_AddChar(buf, '.'); } ! return true; } /*- *************** *** 282,291 **** * buffer. *----------------------------------------------------------------------- */ ! static Boolean VarTail(word, addSpace, buf, dummy) struct Name *word; ! Boolean addSpace; Buffer buf; void *dummy UNUSED; { --- 296,305 ---- * buffer. *----------------------------------------------------------------------- */ ! static bool VarTail(word, addSpace, buf, dummy) struct Name *word; ! bool addSpace; Buffer buf; void *dummy UNUSED; { *************** *** 293,304 **** if (addSpace) Buf_AddSpace(buf); ! slash = lastchar(word->s, word->e, '/'); if (slash != NULL) ! Buf_AddInterval(buf, slash+1, word->e); else ! Buf_AddInterval(buf, word->s, word->e); ! return TRUE; } /*- --- 307,318 ---- if (addSpace) Buf_AddSpace(buf); ! slash = Str_rchri(word->s, word->e, '/'); if (slash != NULL) ! Buf_Addi(buf, slash+1, word->e); else ! Buf_Addi(buf, word->s, word->e); ! return true; } /*- *************** *** 307,327 **** * Add the suffix of the given word to the given buffer. *----------------------------------------------------------------------- */ ! static Boolean VarSuffix(word, addSpace, buf, dummy) struct Name *word; ! Boolean addSpace; Buffer buf; void *dummy UNUSED; { const char *dot; ! dot = lastchar(word->s, word->e, '.'); if (dot != NULL) { if (addSpace) Buf_AddSpace(buf); ! Buf_AddInterval(buf, dot+1, word->e); ! addSpace = TRUE; } return addSpace; } --- 321,341 ---- * Add the suffix of the given word to the given buffer. *----------------------------------------------------------------------- */ ! static bool VarSuffix(word, addSpace, buf, dummy) struct Name *word; ! bool addSpace; Buffer buf; void *dummy UNUSED; { const char *dot; ! dot = Str_rchri(word->s, word->e, '.'); if (dot != NULL) { if (addSpace) Buf_AddSpace(buf); ! Buf_Addi(buf, dot+1, word->e); ! addSpace = true; } return addSpace; } *************** *** 333,342 **** * buffer. *----------------------------------------------------------------------- */ ! static Boolean VarRoot(word, addSpace, buf, dummy) struct Name *word; ! Boolean addSpace; Buffer buf; void *dummy UNUSED; { --- 347,356 ---- * buffer. *----------------------------------------------------------------------- */ ! static bool VarRoot(word, addSpace, buf, dummy) struct Name *word; ! bool addSpace; Buffer buf; void *dummy UNUSED; { *************** *** 344,355 **** if (addSpace) Buf_AddSpace(buf); ! dot = lastchar(word->s, word->e, '.'); if (dot != NULL) ! Buf_AddInterval(buf, word->s, dot); else ! Buf_AddInterval(buf, word->s, word->e); ! return TRUE; } /*- --- 358,369 ---- if (addSpace) Buf_AddSpace(buf); ! dot = Str_rchri(word->s, word->e, '.'); if (dot != NULL) ! Buf_Addi(buf, word->s, dot); else ! Buf_Addi(buf, word->s, word->e); ! return true; } /*- *************** *** 358,375 **** * Add the word to the buffer if it matches the given pattern. *----------------------------------------------------------------------- */ ! static Boolean VarMatch(word, addSpace, buf, pattern) struct Name *word; ! Boolean addSpace; Buffer buf; void *pattern; /* Pattern the word must match */ { ! if (Str_Match(word->s, (const char *)pattern)) { if (addSpace) Buf_AddSpace(buf); ! Buf_AddInterval(buf, word->s, word->e); ! return TRUE; } else return addSpace; } --- 372,391 ---- * Add the word to the buffer if it matches the given pattern. *----------------------------------------------------------------------- */ ! static bool VarMatch(word, addSpace, buf, pattern) struct Name *word; ! bool addSpace; Buffer buf; void *pattern; /* Pattern the word must match */ { ! const char *pat = (const char *)pattern; ! ! if (Str_Matchi(word->s, word->e, pat, strchr(pat, '\0'))) { if (addSpace) Buf_AddSpace(buf); ! Buf_Addi(buf, word->s, word->e); ! return true; } else return addSpace; } *************** *** 380,405 **** * Add the word to the buffer if it doesn't match the given pattern. *----------------------------------------------------------------------- */ ! static Boolean VarNoMatch(word, addSpace, buf, pattern) struct Name *word; ! Boolean addSpace; Buffer buf; void *pattern; /* Pattern the word must not match */ { ! if (!Str_Match(word->s, (const char *)pattern)) { if (addSpace) Buf_AddSpace(buf); ! Buf_AddInterval(buf, word->s, word->e); ! return TRUE; } else return addSpace; } ! static Boolean VarUniq(word, addSpace, buf, lastp) struct Name *word; ! Boolean addSpace; Buffer buf; void *lastp; { --- 396,423 ---- * Add the word to the buffer if it doesn't match the given pattern. *----------------------------------------------------------------------- */ ! static bool VarNoMatch(word, addSpace, buf, pattern) struct Name *word; ! bool addSpace; Buffer buf; void *pattern; /* Pattern the word must not match */ { ! const char *pat = (const char *)pattern; ! ! if (!Str_Matchi(word->s, word->e, pat, strchr(pat, '\0'))) { if (addSpace) Buf_AddSpace(buf); ! Buf_Addi(buf, word->s, word->e); ! return true; } else return addSpace; } ! static bool VarUniq(word, addSpace, buf, lastp) struct Name *word; ! bool addSpace; Buffer buf; void *lastp; { *************** *** 410,427 **** strncmp(word->s, last->s, word->e - word->s) != 0) { if (addSpace) Buf_AddSpace(buf); ! Buf_AddInterval(buf, word->s, word->e); ! addSpace = TRUE; } last->s = word->s; last->e = word->e; return addSpace; } ! static Boolean VarLoop(word, addSpace, buf, vp) struct Name *word; ! Boolean addSpace; Buffer buf; void *vp; { --- 428,445 ---- strncmp(word->s, last->s, word->e - word->s) != 0) { if (addSpace) Buf_AddSpace(buf); ! Buf_Addi(buf, word->s, word->e); ! addSpace = true; } last->s = word->s; last->e = word->e; return addSpace; } ! static bool VarLoop(word, addSpace, buf, vp) struct Name *word; ! bool addSpace; Buffer buf; void *vp; { *************** *** 430,436 **** if (addSpace) Buf_AddSpace(buf); Var_SubstVar(buf, v->expand, v->var, word->s); ! return TRUE; } static char * --- 448,454 ---- if (addSpace) Buf_AddSpace(buf); Var_SubstVar(buf, v->expand, v->var, word->s); ! return true; } static char * *************** *** 504,513 **** Buf_Init(&buf, end - s); qsort(t, i, sizeof(struct Name), NameCompare); ! Buf_AddInterval(&buf, t[0].s, t[0].e); for (j = 1; j < i; j++) { Buf_AddSpace(&buf); ! Buf_AddInterval(&buf, t[j].s, t[j].e); } free(t); return Buf_Retrieve(&buf); --- 522,531 ---- Buf_Init(&buf, end - s); qsort(t, i, sizeof(struct Name), NameCompare); ! Buf_Addi(&buf, t[0].s, t[0].e); for (j = 1; j < i; j++) { Buf_AddSpace(&buf); ! Buf_Addi(&buf, t[j].s, t[j].e); } free(t); return Buf_Retrieve(&buf); *************** *** 523,529 **** const struct Name *n; void *arg UNUSED; { ! return interval_dup(n->s, n->e); } static char * --- 541,547 ---- const struct Name *n; void *arg UNUSED; { ! return Str_dupi(n->s, n->e); } static char * *************** *** 534,542 **** { GNode *gn; ! gn = Targ_FindNode(n->s, n->e, TARG_NOCREATE); if (gn == NULL) ! return interval_dup(n->s, n->e); else return strdup(gn->path); } --- 552,560 ---- { GNode *gn; ! gn = Targ_FindNodei(n->s, n->e, TARG_NOCREATE); if (gn == NULL) ! return Str_dupi(n->s, n->e); else return strdup(gn->path); } *************** *** 581,602 **** switch (v->flags) { case VAR_EQUAL: ! Var_Set_interval(n->s, n->e, v->lbuffer, VAR_GLOBAL); break; case VAR_MAY_EQUAL: if (s == NULL) ! Var_Set_interval(n->s, n->e, v->lbuffer, VAR_GLOBAL); break; case VAR_ADD_EQUAL: if (s == NULL) ! Var_Set_interval(n->s, n->e, v->lbuffer, VAR_GLOBAL); else ! Var_Append_interval(n->s, n->e, v->lbuffer, VAR_GLOBAL); break; case VAR_BANG_EQUAL: result = Cmd_Exec(v->lbuffer, &msg); if (result != NULL) { ! Var_Set_interval(n->s, n->e, result, VAR_GLOBAL); free(result); } else Error(msg, v->lbuffer); --- 599,620 ---- switch (v->flags) { case VAR_EQUAL: ! Var_Seti(n->s, n->e, v->lbuffer, VAR_GLOBAL); break; case VAR_MAY_EQUAL: if (s == NULL) ! Var_Seti(n->s, n->e, v->lbuffer, VAR_GLOBAL); break; case VAR_ADD_EQUAL: if (s == NULL) ! Var_Seti(n->s, n->e, v->lbuffer, VAR_GLOBAL); else ! Var_Appendi(n->s, n->e, v->lbuffer, VAR_GLOBAL); break; case VAR_BANG_EQUAL: result = Cmd_Exec(v->lbuffer, &msg); if (result != NULL) { ! Var_Seti(n->s, n->e, result, VAR_GLOBAL); free(result); } else Error(msg, v->lbuffer); *************** *** 629,638 **** * Used to implement the System V % modifiers. *----------------------------------------------------------------------- */ ! static Boolean VarSYSVMatch(word, addSpace, buf, patp) struct Name *word; ! Boolean addSpace; Buffer buf; void *patp; /* Pattern the word must match */ { --- 647,656 ---- * Used to implement the System V % modifiers. *----------------------------------------------------------------------- */ ! static bool VarSYSVMatch(word, addSpace, buf, patp) struct Name *word; ! bool addSpace; Buffer buf; void *patp; /* Pattern the word must match */ { *************** *** 646,653 **** if ((ptr = Str_SYSVMatch(word->s, pat->lhs, &len)) != NULL) Str_SYSVSubst(buf, pat->rhs, ptr, len); else ! Buf_AddInterval(buf, word->s, word->e); ! return TRUE; } else return addSpace; } --- 664,671 ---- if ((ptr = Str_SYSVMatch(word->s, pat->lhs, &len)) != NULL) Str_SYSVSubst(buf, pat->rhs, ptr, len); else ! Buf_Addi(buf, word->s, word->e); ! return true; } else return addSpace; } *************** *** 656,662 **** get_sysvpattern(p, ctxt, err, endc) const char **p; SymTable *ctxt UNUSED; ! Boolean err UNUSED; int endc; { VarPattern *pattern; --- 674,680 ---- get_sysvpattern(p, ctxt, err, endc) const char **p; SymTable *ctxt UNUSED; ! bool err UNUSED; int endc; { VarPattern *pattern; *************** *** 690,698 **** } pattern = (VarPattern *)emalloc(sizeof(VarPattern)); ! pattern->lbuffer = pattern->lhs = interval_dup(*p, cp); pattern->leftLen = cp - *p; ! pattern->rhs = interval_dup(cp+1, cp2); pattern->rightLen = cp2 - (cp+1); pattern->flags = 0; *p = cp2; --- 708,716 ---- } pattern = (VarPattern *)emalloc(sizeof(VarPattern)); ! pattern->lbuffer = pattern->lhs = Str_dupi(*p, cp); pattern->leftLen = cp - *p; ! pattern->rhs = Str_dupi(cp+1, cp2); pattern->rightLen = cp2 - (cp+1); pattern->flags = 0; *p = cp2; *************** *** 707,716 **** * result to the given buffer. *----------------------------------------------------------------------- */ ! static Boolean VarSubstitute(word, addSpace, buf, patternp) struct Name *word; ! Boolean addSpace; Buffer buf; void *patternp; /* Pattern for substitution */ { --- 725,734 ---- * result to the given buffer. *----------------------------------------------------------------------- */ ! static bool VarSubstitute(word, addSpace, buf, patternp) struct Name *word; ! bool addSpace; Buffer buf; void *patternp; /* Pattern for substitution */ { *************** *** 734,740 **** if (pattern->rightLen != 0) { if (addSpace) Buf_AddSpace(buf); ! addSpace = TRUE; Buf_AddChars(buf, pattern->rightLen, pattern->rhs); } --- 752,758 ---- if (pattern->rightLen != 0) { if (addSpace) Buf_AddSpace(buf); ! addSpace = true; Buf_AddChars(buf, pattern->rightLen, pattern->rhs); } *************** *** 748,754 **** if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){ if (addSpace) Buf_AddSpace(buf); ! addSpace = TRUE; } Buf_AddChars(buf, pattern->rightLen, pattern->rhs); Buf_AddChars(buf, wordLen - pattern->leftLen, --- 766,772 ---- if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){ if (addSpace) Buf_AddSpace(buf); ! addSpace = true; } Buf_AddChars(buf, pattern->rightLen, pattern->rhs); Buf_AddChars(buf, wordLen - pattern->leftLen, *************** *** 773,781 **** if (((cp - word->s) + pattern->rightLen) != 0) { if (addSpace) Buf_AddSpace(buf); ! addSpace = TRUE; } ! Buf_AddInterval(buf, word->s, cp); Buf_AddChars(buf, pattern->rightLen, pattern->rhs); pattern->flags |= VAR_SUB_MATCHED; } else { --- 791,799 ---- if (((cp - word->s) + pattern->rightLen) != 0) { if (addSpace) Buf_AddSpace(buf); ! addSpace = true; } ! Buf_Addi(buf, word->s, cp); Buf_AddChars(buf, pattern->rightLen, pattern->rhs); pattern->flags |= VAR_SUB_MATCHED; } else { *************** *** 790,818 **** * remaining part of the word (word and wordLen are adjusted * accordingly through the loop) is copied straight into the * buffer. ! * addSpace is set to FALSE as soon as a space is added to the * buffer. */ ! Boolean done; size_t origSize; ! done = FALSE; origSize = Buf_Size(buf); while (!done) { cp = strstr(word->s, pattern->lhs); if (cp != NULL) { if (addSpace && (cp - word->s) + pattern->rightLen != 0){ Buf_AddSpace(buf); ! addSpace = FALSE; } ! Buf_AddInterval(buf, word->s, cp); Buf_AddChars(buf, pattern->rightLen, pattern->rhs); wordLen -= (cp - word->s) + pattern->leftLen; word->s = cp + pattern->leftLen; if (wordLen == 0 || (pattern->flags & VAR_SUB_GLOBAL) == 0) ! done = TRUE; pattern->flags |= VAR_SUB_MATCHED; } else ! done = TRUE; } if (wordLen != 0) { if (addSpace) --- 808,836 ---- * remaining part of the word (word and wordLen are adjusted * accordingly through the loop) is copied straight into the * buffer. ! * addSpace is set to false as soon as a space is added to the * buffer. */ ! bool done; size_t origSize; ! done = false; origSize = Buf_Size(buf); while (!done) { cp = strstr(word->s, pattern->lhs); if (cp != NULL) { if (addSpace && (cp - word->s) + pattern->rightLen != 0){ Buf_AddSpace(buf); ! addSpace = false; } ! Buf_Addi(buf, word->s, cp); Buf_AddChars(buf, pattern->rightLen, pattern->rhs); wordLen -= (cp - word->s) + pattern->leftLen; word->s = cp + pattern->leftLen; if (wordLen == 0 || (pattern->flags & VAR_SUB_GLOBAL) == 0) ! done = true; pattern->flags |= VAR_SUB_MATCHED; } else ! done = true; } if (wordLen != 0) { if (addSpace) *************** *** 830,836 **** if (addSpace) Buf_AddSpace(buf); Buf_AddChars(buf, wordLen, word->s); ! return TRUE; } #ifndef MAKE_BOOTSTRAP --- 848,854 ---- if (addSpace) Buf_AddSpace(buf); Buf_AddChars(buf, wordLen, word->s); ! return true; } #ifndef MAKE_BOOTSTRAP *************** *** 863,872 **** * result in the passed buffer. *----------------------------------------------------------------------- */ ! static Boolean VarRESubstitute(word, addSpace, buf, patternp) struct Name *word; ! Boolean addSpace; Buffer buf; void *patternp; { --- 881,890 ---- * result in the passed buffer. *----------------------------------------------------------------------- */ ! static bool VarRESubstitute(word, addSpace, buf, patternp) struct Name *word; ! bool addSpace; Buffer buf; void *patternp; { *************** *** 984,1000 **** VarModify(str, modProc, datum) char *str; /* String whose words should be trimmed */ /* Function to use to modify them */ ! Boolean (*modProc)(struct Name *, Boolean, Buffer, void *); void *datum; /* Datum to pass it */ { BUFFER buf; /* Buffer for the new string */ ! Boolean addSpace; /* TRUE if need to add a space to the * buffer before adding the trimmed * word */ struct Name word; Buf_Init(&buf, 0); ! addSpace = FALSE; word.e = str; --- 1002,1018 ---- VarModify(str, modProc, datum) char *str; /* String whose words should be trimmed */ /* Function to use to modify them */ ! bool (*modProc)(struct Name *, bool, Buffer, void *); void *datum; /* Datum to pass it */ { BUFFER buf; /* Buffer for the new string */ ! bool addSpace; /* true if need to add a space to the * buffer before adding the trimmed * word */ struct Name word; Buf_Init(&buf, 0); ! addSpace = false; word.e = str; *************** *** 1124,1130 **** check_empty(p, ctxt, b, endc) const char **p; SymTable *ctxt UNUSED; ! Boolean b UNUSED; int endc; { dummy_arg->s = NULL; --- 1142,1148 ---- check_empty(p, ctxt, b, endc) const char **p; SymTable *ctxt UNUSED; ! bool b UNUSED; int endc; { dummy_arg->s = NULL; *************** *** 1139,1145 **** check_shcmd(p, ctxt, b, endc) const char **p; SymTable *ctxt UNUSED; ! Boolean b UNUSED; int endc; { if ((*p)[1] == 'h' && ((*p)[2] == endc || (*p)[2] == ':')) { --- 1157,1163 ---- check_shcmd(p, ctxt, b, endc) const char **p; SymTable *ctxt UNUSED; ! bool b UNUSED; int endc; { if ((*p)[1] == 'h' && ((*p)[2] == endc || (*p)[2] == ':')) { *************** *** 1169,1175 **** get_stringarg(p, ctxt, b, endc) const char **p; SymTable *ctxt UNUSED; ! Boolean b UNUSED; int endc; { const char *cp; --- 1187,1193 ---- get_stringarg(p, ctxt, b, endc) const char **p; SymTable *ctxt UNUSED; ! bool b UNUSED; int endc; { const char *cp; *************** *** 1182,1188 **** } else if (*cp == '\0') return NULL; } ! s = escape_dup(*p+1, cp, ":)}"); *p = cp; return s; } --- 1200,1206 ---- } else if (*cp == '\0') return NULL; } ! s = escape_dupi(*p+1, cp, ":)}"); *p = cp; return s; } *************** *** 1233,1239 **** get_spatternarg(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! Boolean err; int endc; { VarPattern *pattern; --- 1251,1257 ---- get_spatternarg(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! bool err; int endc; { VarPattern *pattern; *************** *** 1277,1290 **** return NULL; } *s = p+1; ! return escape_dup(start, p, "@\\"); } static void * get_loop(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! Boolean err; int endc; { static struct LoopStuff loop; --- 1295,1308 ---- return NULL; } *s = p+1; ! return escape_dupi(start, p, "@\\"); } static void * get_loop(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! bool err; int endc; { static struct LoopStuff loop; *************** *** 1312,1318 **** get_patternarg(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! Boolean err; int endc; { VarPattern *pattern; --- 1330,1336 ---- get_patternarg(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! bool err; int endc; { VarPattern *pattern; *************** *** 1364,1370 **** assign_get_value(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! Boolean err; int endc; { const char *s; --- 1382,1388 ---- assign_get_value(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! bool err; int endc; { const char *s; *************** *** 1395,1401 **** get_value(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! Boolean err; int endc; { VarPattern *pattern; --- 1413,1419 ---- get_value(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! bool err; int endc; { VarPattern *pattern; *************** *** 1418,1424 **** get_cmd(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! Boolean err; int endc UNUSED; { VarPattern *pattern; --- 1436,1442 ---- get_cmd(p, ctxt, err, endc) const char **p; SymTable *ctxt; ! bool err; int endc UNUSED; { VarPattern *pattern; *************** *** 1485,1498 **** char *str; const struct Name *name; SymTable *ctxt; ! Boolean err; ! Boolean *freePtr; const char *start; int endc; size_t *lengthPtr; { const char *tstr; ! Boolean atstart; /* Some ODE modifiers only make sense at start */ tstr = start; /* --- 1503,1516 ---- char *str; const struct Name *name; SymTable *ctxt; ! bool err; ! bool *freePtr; const char *start; int endc; size_t *lengthPtr; { const char *tstr; ! bool atstart; /* Some ODE modifiers only make sense at start */ tstr = start; /* *************** *** 1515,1521 **** * the invocation. */ ! atstart = TRUE; while (*tstr != endc && *tstr != '\0') { struct modifier *mod; void *arg; --- 1533,1539 ---- * the invocation. */ ! atstart = true; while (*tstr != endc && *tstr != '\0') { struct modifier *mod; void *arg; *************** *** 1534,1540 **** mod = &sysv_mod; arg = mod->getarg(&tstr, ctxt, err, endc); } ! atstart = FALSE; if (arg != NULL) { if (str != NULL || (mod->atstart && name != NULL)) { if (mod->word_apply != NULL) { --- 1552,1558 ---- mod = &sysv_mod; arg = mod->getarg(&tstr, ctxt, err, endc); } ! atstart = false; if (arg != NULL) { if (str != NULL || (mod->atstart && name != NULL)) { if (mod->word_apply != NULL) { *************** *** 1552,1560 **** free(str); str = newStr; if (str != var_Error) ! *freePtr = TRUE; else ! *freePtr = FALSE; } if (mod->freearg != NULL) mod->freearg(arg); --- 1570,1578 ---- free(str); str = newStr; if (str != var_Error) ! *freePtr = true; else ! *freePtr = false; } if (mod->freearg != NULL) mod->freearg(arg); *************** *** 1566,1572 **** if (str != NULL && *freePtr) free(str); str = var_Error; ! freePtr = FALSE; break; } if (DEBUG(VAR)) --- 1584,1590 ---- if (str != NULL && *freePtr) free(str); str = var_Error; ! freePtr = false; break; } if (DEBUG(VAR)) *************** *** 1579,1592 **** return str; } - /*- - *----------------------------------------------------------------------- - * Var_GetHead -- - * Find the leading components of a (list of) filename(s). - * XXX: VarHead does not replace foo by ., as (sun) System V make - * does. - *----------------------------------------------------------------------- - */ char * Var_GetHead(s) char *s; --- 1597,1602 ---- *************** *** 1594,1606 **** return VarModify(s, VarHead, NULL); } - /*- - *----------------------------------------------------------------------- - * Var_GetTail -- - * Return the tail from each of a list of words. Used to set the - * System V local variables. - *----------------------------------------------------------------------- - */ char * Var_GetTail(s) char *s; --- 1604,1609 ----