diff options
author | harti <harti@FreeBSD.org> | 2005-05-12 14:31:42 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-05-12 14:31:42 +0000 |
commit | 8a832592ce11ab5f5c94757893e5f7353808bee1 (patch) | |
tree | 4063d4c37b93bccf895ea505b1cd72847fc1b684 /usr.bin/make | |
parent | e7ab78380c4d30d28dbf699ac0bffeb881f56c83 (diff) | |
download | FreeBSD-src-8a832592ce11ab5f5c94757893e5f7353808bee1.zip FreeBSD-src-8a832592ce11ab5f5c94757893e5f7353808bee1.tar.gz |
Move variable printing from main.c to var.c
Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.233)
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/main.c | 29 | ||||
-rw-r--r-- | usr.bin/make/var.c | 34 | ||||
-rw-r--r-- | usr.bin/make/var.h | 4 |
3 files changed, 38 insertions, 29 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 8e41fd8..ea4253b 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -988,34 +988,7 @@ main(int argc, char **argv) Lst_Destroy(&targs, NOFREE); } else { - /* - * Print the values of any variables requested by - * the user. - */ - LstNode *n; - const char *name; - char *v; - char *value; - - LST_FOREACH(n, &variables) { - name = Lst_Datum(n); - if (expandVars) { - v = emalloc(strlen(name) + 1 + 3); - sprintf(v, "${%s}", name); - - value = Buf_Peel(Var_Subst(v, - VAR_GLOBAL, FALSE)); - printf("%s\n", value); - - free(v); - free(value); - } else { - value = Var_Value(name, VAR_GLOBAL, &v); - printf("%s\n", value != NULL ? value : ""); - if (v != NULL) - free(v); - } - } + Var_Print(&variables, expandVars); } Lst_Destroy(&variables, free); diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index eb83c52..a70acae 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -96,6 +96,7 @@ __FBSDID("$FreeBSD$"); #include "globals.h" #include "GNode.h" #include "job.h" +#include "lst.h" #include "make.h" #include "parse.h" #include "str.h" @@ -2530,3 +2531,36 @@ Var_Dump(void) } } +/** + * Print the values of any variables requested by + * the user. + */ +void +Var_Print(Lst *vlist, Boolean expandVars) +{ + LstNode *n; + const char *name; + char *v; + char *value; + + LST_FOREACH(n, vlist) { + name = Lst_Datum(n); + if (expandVars) { + v = emalloc(strlen(name) + 1 + 3); + sprintf(v, "${%s}", name); + + value = Buf_Peel(Var_Subst(v, + VAR_GLOBAL, FALSE)); + printf("%s\n", value); + + free(v); + free(value); + } else { + value = Var_Value(name, VAR_GLOBAL, &v); + printf("%s\n", value != NULL ? value : ""); + if (v != NULL) + free(v); + } + } +} + diff --git a/usr.bin/make/var.h b/usr.bin/make/var.h index 51e8412..d4f1b4e 100644 --- a/usr.bin/make/var.h +++ b/usr.bin/make/var.h @@ -42,8 +42,9 @@ #ifndef var_h_9cccafce #define var_h_9cccafce -struct GNode; struct Buffer; +struct GNode; +struct List; /* Variables defined in a global context, e.g in the Makefile itself */ extern struct GNode *VAR_GLOBAL; @@ -73,6 +74,7 @@ Boolean Var_Exists(const char *, struct GNode *); void Var_Init(char **); size_t Var_Match(const char [], struct GNode *); char *Var_Parse(const char *, struct GNode *, Boolean, size_t *, Boolean *); +void Var_Print(struct Lst *, Boolean); void Var_Set(const char *, const char *, struct GNode *); void Var_SetEnv(const char *, struct GNode *); struct Buffer *Var_Subst(const char *, struct GNode *, Boolean); |