mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Implement JSONTRANSLATE -zj command.
This commit is contained in:
@@ -114,6 +114,7 @@ int DoRun (ParsePtr p);
|
||||
int DoExpr (ParsePtr p);
|
||||
int DoTranslate (ParsePtr p);
|
||||
int InsertTranslation(char const *orig, char const *translated);
|
||||
void DumpTranslationTable(FILE *fp, int json);
|
||||
int DoErrMsg (ParsePtr p);
|
||||
int ClearGlobalOmits (void);
|
||||
int DoClear (ParsePtr p);
|
||||
|
||||
@@ -917,6 +917,15 @@ static void ServerWait(struct timeval *sleep_tv)
|
||||
printf("NOTE ENDJSONQUEUE\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
} else if (!strcmp(cmdLine, "JSONTRANSLATE\n")) {
|
||||
if (!DaemonJSON) {
|
||||
printf("NOTE JSONTRANSLATE\n");
|
||||
}
|
||||
DumpTranslationTable(stdout, 1);
|
||||
if (!DaemonJSON) {
|
||||
printf("NOTE ENDJSONTRANSLATE\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
} else if (!strcmp(cmdLine, "REREAD\n")) {
|
||||
if (DaemonJSON) {
|
||||
printf("{\"response\":\"reread\",\"command\":\"REREAD\"}\n");
|
||||
|
||||
37
src/trans.c
37
src/trans.c
@@ -131,21 +131,38 @@ print_escaped_string(FILE *fp, char const *s)
|
||||
/* DumpTranslationTable - Dump the table to a file descriptor */
|
||||
/* */
|
||||
/***************************************************************/
|
||||
static void
|
||||
DumpTranslationTable(FILE *fp)
|
||||
void
|
||||
DumpTranslationTable(FILE *fp, int json)
|
||||
{
|
||||
XlateItem *item;
|
||||
|
||||
fprintf(fp, "# Translation table\n");
|
||||
int done = 0;
|
||||
if (!json) {
|
||||
fprintf(fp, "# Translation table\n");
|
||||
} else {
|
||||
fprintf(fp, "{");
|
||||
}
|
||||
item = hash_table_next(&TranslationTable, NULL);
|
||||
while(item) {
|
||||
fprintf(fp, "TRANSLATE ");
|
||||
print_escaped_string(fp, item->orig);
|
||||
fprintf(fp, " ");
|
||||
print_escaped_string(fp, item->translated);
|
||||
fprintf(fp, "\n");
|
||||
if (!json) {
|
||||
fprintf(fp, "TRANSLATE ");
|
||||
print_escaped_string(fp, item->orig);
|
||||
fprintf(fp, " ");
|
||||
print_escaped_string(fp, item->translated);
|
||||
fprintf(fp, "\n");
|
||||
} else {
|
||||
if (done) {
|
||||
fprintf(fp, ",");
|
||||
}
|
||||
done=1;
|
||||
print_escaped_string(fp, item->orig);
|
||||
fprintf(fp, ":");
|
||||
print_escaped_string(fp, item->translated);
|
||||
}
|
||||
item = hash_table_next(&TranslationTable, item);
|
||||
}
|
||||
if (json) {
|
||||
fprintf(fp, "}\n");
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
@@ -241,7 +258,7 @@ DoTranslate(ParsePtr p)
|
||||
if (!StrCmpi(DBufValue(&orig), "dump")) {
|
||||
DBufFree(&orig);
|
||||
if (r) return r;
|
||||
DumpTranslationTable(stdout);
|
||||
DumpTranslationTable(stdout, 0);
|
||||
return OK;
|
||||
}
|
||||
if (!StrCmpi(DBufValue(&orig), "clear")) {
|
||||
|
||||
Reference in New Issue
Block a user