Add "-c" option to "dump" to show constness when dumping variables.

This commit is contained in:
Dianne Skoll
2025-05-21 23:43:40 -04:00
parent ec8cae6d4b
commit 633812d961
3 changed files with 22 additions and 10 deletions

View File

@@ -169,7 +169,7 @@ int main(int argc, char *argv[])
DoReminders();
if (DebugFlag & DB_DUMP_VARS) {
DumpVarTable();
DumpVarTable(0);
DumpSysVarByName(NULL);
}

View File

@@ -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);

View File

@@ -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, " <const>");
}
}
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, " <const>");
}
}
fprintf(ErrFp, "\n");
}
}