mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 23:08:40 +02:00
Start working on JSON-based alternate "remind -p" protocol.
This commit is contained in:
119
src/calendar.c
119
src/calendar.c
@@ -46,6 +46,8 @@ typedef struct cal_entry {
|
|||||||
int duration;
|
int duration;
|
||||||
char const *filename;
|
char const *filename;
|
||||||
int lineno;
|
int lineno;
|
||||||
|
Trigger trig;
|
||||||
|
TimeTrig tt;
|
||||||
} CalEntry;
|
} CalEntry;
|
||||||
|
|
||||||
/* Line-drawing sequences */
|
/* Line-drawing sequences */
|
||||||
@@ -375,7 +377,11 @@ static void DoCalendarOneMonth(void)
|
|||||||
|
|
||||||
if (PsCal) {
|
if (PsCal) {
|
||||||
FromJulian(JulianToday, &y, &m, &d);
|
FromJulian(JulianToday, &y, &m, &d);
|
||||||
printf("%s\n", PSBEGIN);
|
if (PsCal == PSCAL_LEVEL1) {
|
||||||
|
printf("%s\n", PSBEGIN);
|
||||||
|
} else {
|
||||||
|
printf("%s\n", PSBEGIN2);
|
||||||
|
}
|
||||||
printf("%s %d %d %d %d\n",
|
printf("%s %d %d %d %d\n",
|
||||||
MonthName[m], y, DaysInMonth(m, y), (JulianToday+1) % 7,
|
MonthName[m], y, DaysInMonth(m, y), (JulianToday+1) % 7,
|
||||||
MondayFirst);
|
MondayFirst);
|
||||||
@@ -396,7 +402,11 @@ static void DoCalendarOneMonth(void)
|
|||||||
}
|
}
|
||||||
while (WriteCalendarRow()) continue;
|
while (WriteCalendarRow()) continue;
|
||||||
|
|
||||||
if (PsCal) printf("%s\n", PSEND);
|
if (PsCal == PSCAL_LEVEL1) {
|
||||||
|
printf("%s\n", PSEND);
|
||||||
|
} else if (PsCal == PSCAL_LEVEL2) {
|
||||||
|
printf("%s\n", PSEND2);
|
||||||
|
}
|
||||||
if (!DoSimpleCalendar) WriteCalTrailer();
|
if (!DoSimpleCalendar) WriteCalTrailer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1161,6 +1171,8 @@ static int DoCalRem(ParsePtr p, int col)
|
|||||||
FreeTrig(&trig);
|
FreeTrig(&trig);
|
||||||
return E_NO_MEM;
|
return E_NO_MEM;
|
||||||
}
|
}
|
||||||
|
e->trig = trig;
|
||||||
|
e->tt = tim;
|
||||||
#ifdef REM_USE_WCHAR
|
#ifdef REM_USE_WCHAR
|
||||||
e->wc_pos = NULL;
|
e->wc_pos = NULL;
|
||||||
e->wc_text = NULL;
|
e->wc_text = NULL;
|
||||||
@@ -1213,23 +1225,8 @@ static int DoCalRem(ParsePtr p, int col)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
static void WriteSimpleEntryProtocol1(CalEntry *e)
|
||||||
/* */
|
|
||||||
/* WriteSimpleEntries */
|
|
||||||
/* */
|
|
||||||
/* Write entries in 'simple calendar' format. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
static void WriteSimpleEntries(int col, int jul)
|
|
||||||
{
|
{
|
||||||
CalEntry *e = CalColumn[col];
|
|
||||||
CalEntry *n;
|
|
||||||
int y, m, d;
|
|
||||||
|
|
||||||
FromJulian(jul, &y, &m, &d);
|
|
||||||
while(e) {
|
|
||||||
if (DoPrefixLineNo) printf("# fileinfo %d %s\n", e->lineno, e->filename);
|
|
||||||
printf("%04d/%02d/%02d", y, m+1, d);
|
|
||||||
if (e->passthru[0]) {
|
if (e->passthru[0]) {
|
||||||
printf(" %s", e->passthru);
|
printf(" %s", e->passthru);
|
||||||
} else {
|
} else {
|
||||||
@@ -1251,6 +1248,92 @@ static void WriteSimpleEntries(int col, int jul)
|
|||||||
printf("* ");
|
printf("* ");
|
||||||
}
|
}
|
||||||
printf("%s\n", e->text);
|
printf("%s\n", e->text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PrintJSONString(char const *s)
|
||||||
|
{
|
||||||
|
while (*s) {
|
||||||
|
switch(*s) {
|
||||||
|
case '\b': printf("\\b"); break;
|
||||||
|
case '\f': printf("\\f"); break;
|
||||||
|
case '\n': printf("\\n"); break;
|
||||||
|
case '\r': printf("\\r"); break;
|
||||||
|
case '\t': printf("\\t"); break;
|
||||||
|
case '"': printf("\\\""); break;
|
||||||
|
case '\\': printf("\\\\"); break;
|
||||||
|
default: printf("%c", *s);
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteSimpleEntryProtocol2(CalEntry *e)
|
||||||
|
{
|
||||||
|
if (e->passthru[0]) {
|
||||||
|
printf("\"passthru\":\"%s\", ", e->passthru);
|
||||||
|
}
|
||||||
|
if (*DBufValue(&(e->tags))) {
|
||||||
|
printf("\"tags\":\"");
|
||||||
|
PrintJSONString(DBufValue(&e->tags));
|
||||||
|
printf("\", ");
|
||||||
|
}
|
||||||
|
if (e->duration != NO_TIME) {
|
||||||
|
printf("\"duration\":%d, ", e->duration);
|
||||||
|
}
|
||||||
|
if (e->time != NO_TIME) {
|
||||||
|
printf("\"time\":%d, ", e->time);
|
||||||
|
}
|
||||||
|
if (e->trig.eventduration != NO_TIME) {
|
||||||
|
printf("\"eventduration\":%d, ", e->trig.eventduration);
|
||||||
|
}
|
||||||
|
if (e->trig.eventstart != NO_TIME) {
|
||||||
|
int y, m, d, h, i, k;
|
||||||
|
i = e->trig.eventstart / MINUTES_PER_DAY;
|
||||||
|
FromJulian(i, &y, &m, &d);
|
||||||
|
k = e->trig.eventstart % MINUTES_PER_DAY;
|
||||||
|
h = k / 60;
|
||||||
|
i = k % 60;
|
||||||
|
printf("\"eventstart\":\"%04d-%02d-%02dT%02d:%02d\", ", y, m+1, d, h, i);
|
||||||
|
}
|
||||||
|
if (DoPrefixLineNo) {
|
||||||
|
printf("\"filename\":\"");
|
||||||
|
PrintJSONString(e->filename);
|
||||||
|
printf("\", \"lineno\":%d, ", e->lineno);
|
||||||
|
}
|
||||||
|
printf("\"body\":\"");
|
||||||
|
PrintJSONString(e->text);
|
||||||
|
printf("\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* WriteSimpleEntries */
|
||||||
|
/* */
|
||||||
|
/* Write entries in 'simple calendar' format. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
static void WriteSimpleEntries(int col, int jul)
|
||||||
|
{
|
||||||
|
CalEntry *e = CalColumn[col];
|
||||||
|
CalEntry *n;
|
||||||
|
int y, m, d;
|
||||||
|
|
||||||
|
FromJulian(jul, &y, &m, &d);
|
||||||
|
while(e) {
|
||||||
|
if (DoPrefixLineNo) {
|
||||||
|
if (PsCal != PSCAL_LEVEL2) {
|
||||||
|
printf("# fileinfo %d %s\n", e->lineno, e->filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (PsCal == PSCAL_LEVEL2) {
|
||||||
|
printf("{\"date\":\"%04d-%02d-%02d\", ", y, m+1, d);
|
||||||
|
WriteSimpleEntryProtocol2(e);
|
||||||
|
printf("}\n");
|
||||||
|
} else {
|
||||||
|
printf("%04d/%02d/%02d", y, m+1, d);
|
||||||
|
WriteSimpleEntryProtocol1(e);
|
||||||
|
}
|
||||||
|
|
||||||
free((void *)e->text);
|
free((void *)e->text);
|
||||||
free((void *)e->filename);
|
free((void *)e->filename);
|
||||||
#ifdef REM_USE_WCHAR
|
#ifdef REM_USE_WCHAR
|
||||||
|
|||||||
Reference in New Issue
Block a user