Move variable printing from main.c to var.c
Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.233)
This commit is contained in:
parent
8b8eb9e2ab
commit
7594df85cf
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user