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