Always output well-formed JSON in --json mode.

This commit is contained in:
Dianne Skoll
2025-08-14 20:43:35 -04:00
parent eceb5e3f82
commit a62ed0e0c5
2 changed files with 17 additions and 0 deletions

View File

@@ -1576,6 +1576,15 @@ void DoExit(ParsePtr p)
if (PurgeMode) return;
if (JSONMode) {
if (JSONLinesEmitted) {
printf("}\n");
}
/* Close the reminder list */
printf("]\n");
}
fflush(stdout);
fflush(stderr);
r = EvaluateExpr(p, &v);
if (r || v.type != INT_TYPE) exit(99);
exit(v.v.val);

View File

@@ -16,6 +16,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <stddef.h>
#include <stdlib.h>
@@ -63,6 +64,9 @@ GenerateTranslationTemplate(void)
{
int i;
if (JSONMode) {
return;
}
printf("# Translation table template\n\n");
printf("TRANSLATE \"LANGID\" ");
@@ -233,6 +237,10 @@ DumpTranslationTable(FILE *fp, int json)
XlateItem *item;
int done = 0;
char const *t;
if (fileno(fp) == STDOUT_FILENO && JSONMode) {
return;
}
if (!json) {
fprintf(fp, "# Translation table\n");
/* Always to LANGID first */