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
+1 -1
View File
@@ -169,7 +169,7 @@ int main(int argc, char *argv[])
DoReminders(); DoReminders();
if (DebugFlag & DB_DUMP_VARS) { if (DebugFlag & DB_DUMP_VARS) {
DumpVarTable(); DumpVarTable(0);
DumpSysVarByName(NULL); DumpSysVarByName(NULL);
} }
+1 -1
View File
@@ -156,7 +156,7 @@ int GetVarValue (char const *str, Value *val);
int DoSet (Parser *p); int DoSet (Parser *p);
int DoUnset (Parser *p); int DoUnset (Parser *p);
int DoDump (ParsePtr p); int DoDump (ParsePtr p);
void DumpVarTable (void); void DumpVarTable (int dump_constness);
void DestroyVars (int all); void DestroyVars (int all);
int PreserveVar (char const *name); int PreserveVar (char const *name);
int DoPreserve (Parser *p); int DoPreserve (Parser *p);
+20 -8
View File
@@ -705,17 +705,25 @@ int DoDump(ParsePtr p)
int r; int r;
Var *v; Var *v;
DynamicBuffer buf; DynamicBuffer buf;
int dump_constness = 0;
if (PurgeMode) return OK; if (PurgeMode) return OK;
DBufInit(&buf); DBufInit(&buf);
r = ParseToken(p, &buf); r = ParseToken(p, &buf);
if (r) return r; 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) || if (!*DBufValue(&buf) ||
*DBufValue(&buf) == '#' || *DBufValue(&buf) == '#' ||
*DBufValue(&buf) == ';') { *DBufValue(&buf) == ';') {
DBufFree(&buf); DBufFree(&buf);
DumpVarTable(); DumpVarTable(dump_constness);
return OK; return OK;
} }
fprintf(ErrFp, "%s %s\n\n", VARIABLE, VALUE); fprintf(ErrFp, "%s %s\n\n", VARIABLE, VALUE);
@@ -730,9 +738,11 @@ int DoDump(ParsePtr p)
else { else {
fprintf(ErrFp, "%s ", v->name); fprintf(ErrFp, "%s ", v->name);
PrintValue(&(v->v), ErrFp); PrintValue(&(v->v), ErrFp);
/* if (!v->nonconstant) { if (dump_constness) {
fprintf(ErrFp, " ."); if (!v->nonconstant) {
} */ fprintf(ErrFp, " <const>");
}
}
fprintf(ErrFp, "\n"); fprintf(ErrFp, "\n");
} }
} }
@@ -754,7 +764,7 @@ int DoDump(ParsePtr p)
/* Dump the variable table to ErrFp. */ /* Dump the variable table to ErrFp. */
/* */ /* */
/***************************************************************/ /***************************************************************/
void DumpVarTable(void) void DumpVarTable(int dump_constness)
{ {
Var *v; Var *v;
@@ -763,9 +773,11 @@ void DumpVarTable(void)
hash_table_for_each(v, &VHashTbl) { hash_table_for_each(v, &VHashTbl) {
fprintf(ErrFp, "%s ", v->name); fprintf(ErrFp, "%s ", v->name);
PrintValue(&(v->v), ErrFp); PrintValue(&(v->v), ErrFp);
/* if (!v->nonconstant) { if (dump_constness) {
fprintf(ErrFp, " ."); if (!v->nonconstant) {
} */ fprintf(ErrFp, " <const>");
}
}
fprintf(ErrFp, "\n"); fprintf(ErrFp, "\n");
} }
} }