From 633812d9610b8bc2d9cdca3f2e293ab8404a8a30 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Wed, 21 May 2025 23:43:40 -0400 Subject: [PATCH] Add "-c" option to "dump" to show constness when dumping variables. --- src/main.c | 2 +- src/protos.h | 2 +- src/var.c | 28 ++++++++++++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index b6ee81d5..b9e217f7 100644 --- a/src/main.c +++ b/src/main.c @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) DoReminders(); if (DebugFlag & DB_DUMP_VARS) { - DumpVarTable(); + DumpVarTable(0); DumpSysVarByName(NULL); } diff --git a/src/protos.h b/src/protos.h index 9530b266..7d86f5d4 100644 --- a/src/protos.h +++ b/src/protos.h @@ -156,7 +156,7 @@ int GetVarValue (char const *str, Value *val); int DoSet (Parser *p); int DoUnset (Parser *p); int DoDump (ParsePtr p); -void DumpVarTable (void); +void DumpVarTable (int dump_constness); void DestroyVars (int all); int PreserveVar (char const *name); int DoPreserve (Parser *p); diff --git a/src/var.c b/src/var.c index 46329083..d7ee663e 100644 --- a/src/var.c +++ b/src/var.c @@ -705,17 +705,25 @@ int DoDump(ParsePtr p) int r; Var *v; DynamicBuffer buf; + int dump_constness = 0; if (PurgeMode) return OK; DBufInit(&buf); r = ParseToken(p, &buf); if (r) return r; + if (!strcmp(DBufValue(&buf), "-c")) { + dump_constness = 1; + DBufFree(&buf); + DBufInit(&buf); + r = ParseToken(p, &buf); + if (r) return r; + } if (!*DBufValue(&buf) || *DBufValue(&buf) == '#' || *DBufValue(&buf) == ';') { DBufFree(&buf); - DumpVarTable(); + DumpVarTable(dump_constness); return OK; } fprintf(ErrFp, "%s %s\n\n", VARIABLE, VALUE); @@ -730,9 +738,11 @@ int DoDump(ParsePtr p) else { fprintf(ErrFp, "%s ", v->name); PrintValue(&(v->v), ErrFp); - /* if (!v->nonconstant) { - fprintf(ErrFp, " ."); - } */ + if (dump_constness) { + if (!v->nonconstant) { + fprintf(ErrFp, " "); + } + } fprintf(ErrFp, "\n"); } } @@ -754,7 +764,7 @@ int DoDump(ParsePtr p) /* Dump the variable table to ErrFp. */ /* */ /***************************************************************/ -void DumpVarTable(void) +void DumpVarTable(int dump_constness) { Var *v; @@ -763,9 +773,11 @@ void DumpVarTable(void) hash_table_for_each(v, &VHashTbl) { fprintf(ErrFp, "%s ", v->name); PrintValue(&(v->v), ErrFp); - /* if (!v->nonconstant) { - fprintf(ErrFp, " ."); - } */ + if (dump_constness) { + if (!v->nonconstant) { + fprintf(ErrFp, " "); + } + } fprintf(ErrFp, "\n"); } }