Deleted Added
sdiff udiff text old ( 105895 ) new ( 106106 )
full compact
1/*
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)var.c 8.3 (Berkeley) 3/19/94
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/usr.bin/make/var.c 106106 2002-10-28 23:33:57Z jmallett $");
43
44/*-
45 * var.c --
46 * Variable-handling functions
47 *
48 * Interface:
49 * Var_Set Set the value of a variable in the given
50 * context. The variable is created if it doesn't

--- 33 unchanged lines hidden (view full) ---

84 */
85
86#include <ctype.h>
87#include <sys/types.h>
88#include <regex.h>
89#include <stdlib.h>
90#include "make.h"
91#include "buf.h"
92#include "var.h"
93
94/*
95 * This is a harmless return value for Var_Parse that can be used by Var_Subst
96 * to determine if there was an error in parsing -- easier than returning
97 * a flag, as things outside this module don't give a hoot.
98 */
99char var_Error[] = "";
100

--- 24 unchanged lines hidden (view full) ---

125GNode *VAR_CMD; /* variables defined on the command-line */
126
127static Lst allVars; /* List of all variables */
128
129#define FIND_CMD 0x1 /* look in VAR_CMD when searching */
130#define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */
131#define FIND_ENV 0x4 /* look in the environment also */
132
133static int VarCmp(void *, void *);
134static void VarPossiblyExpand(char **, GNode *);
135static Var *VarFind(char *, GNode *, int);
136static void VarAdd(char *, char *, GNode *);
137static void VarDelete(void *);
138static char *VarGetPattern(GNode *, int, char **, int, int *, int *,
139 VarPattern *);
140static char *VarQuote(const char *);
141static char *VarModify(char *,
142 Boolean (*)(const char *, Boolean, Buffer, void *),
143 void *);
144static int VarPrintVar(void *, void *);
145
146/*-
147 *-----------------------------------------------------------------------
148 * VarCmp --
149 * See if the given variable matches the named one. Called from
150 * Lst_Find when searching for a variable of a given name.

--- 413 unchanged lines hidden (view full) ---

564 return p;
565 } else {
566 return ((char *) NULL);
567 }
568}
569
570/*-
571 *-----------------------------------------------------------------------
572 * VarModify --
573 * Modify each of the words of the passed string using the given
574 * function. Used to implement all modifiers.
575 *
576 * Results:
577 * A string of all the words modified appropriately.
578 *
579 * Side Effects:
580 * None.
581 *
582 *-----------------------------------------------------------------------
583 */
584static char *
585VarModify (char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *),
586 void *datum)
587{
588 Buffer buf; /* Buffer for the new string */
589 Boolean addSpace; /* TRUE if need to add a space to the
590 * buffer before adding the trimmed
591 * word */
592 char **av; /* word list [first word does not count] */
593 int ac, i;

--- 144 unchanged lines hidden (view full) ---

738 * The quoted string
739 *
740 * Side Effects:
741 * None.
742 *
743 *-----------------------------------------------------------------------
744 */
745static char *
746VarQuote(const char *str)
747{
748
749 Buffer buf;
750 /* This should cover most shells :-( */
751 static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
752 char *ret;
753
754 buf = Buf_Init (MAKE_BSIZE);
755 for (; *str; str++) {
756 if (strchr(meta, *str) != NULL)
757 Buf_AddByte(buf, (Byte)'\\');
758 Buf_AddByte(buf, (Byte)*str);
759 }
760 Buf_AddByte(buf, (Byte) '\0');
761 ret = Buf_GetAll (buf, NULL);
762 Buf_Destroy (buf, FALSE);
763 return ret;
764}
765
766/*-
767 *-----------------------------------------------------------------------
768 * VarREError --
769 * Print the error caused by a regcomp or regexec call.
770 *
771 * Results:
772 * None.
773 *
774 * Side Effects:
775 * An error gets printed.
776 *
777 *-----------------------------------------------------------------------
778 */
779void
780VarREError(int err, regex_t *pat, const char *str)
781{
782 char *errbuf;
783 int errlen;
784
785 errlen = regerror(err, pat, 0, 0);
786 errbuf = emalloc(errlen);
787 regerror(err, pat, errbuf, errlen);
788 Error("%s: %s", str, errbuf);
789 free(errbuf);
790}
791
792
793/*-
794 *-----------------------------------------------------------------------
795 * Var_Parse --
796 * Given the start of a variable invocation, extract the variable
797 * name and find its value, then modify it according to the
798 * specification.
799 *
800 * Results:
801 * The (possibly-modified) value of the variable or var_Error if the
802 * specification is invalid. The length of the specification is

--- 1100 unchanged lines hidden ---