From 8a832592ce11ab5f5c94757893e5f7353808bee1 Mon Sep 17 00:00:00 2001 From: harti Date: Thu, 12 May 2005 14:31:42 +0000 Subject: Move variable printing from main.c to var.c Submitted by: Max Okumoto (7.233) --- usr.bin/make/main.c | 29 +---------------------------- usr.bin/make/var.c | 34 ++++++++++++++++++++++++++++++++++ usr.bin/make/var.h | 4 +++- 3 files changed, 38 insertions(+), 29 deletions(-) (limited to 'usr.bin/make') 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); -- cgit v1.1