Use a dynamic method to print events to stdout
Add a flexible helper function print_event() and use it whenever we print events to stdout. This reduces the number of copy-pasted code and eventually allows for specifying custom format strings. Following format specifiers are supported: * m: Print the description of the item * n: Print the name of the note file belonging to the item Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
31
src/utils.c
31
src/utils.c
@@ -1002,3 +1002,34 @@ print_apoint (const char *format, long day, struct apoint *apt)
|
||||
putchar (*p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Print a formatted event to stdout. */
|
||||
void
|
||||
print_event (const char *format, long day, struct event *ev)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
for (p = format; *p; p++)
|
||||
{
|
||||
if (*p == '%') {
|
||||
p++;
|
||||
switch (*p)
|
||||
{
|
||||
case 'm':
|
||||
printf ("%s", ev->mesg);
|
||||
break;
|
||||
case 'n':
|
||||
printf ("%s", ev->note);
|
||||
break;
|
||||
case '\0':
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
putchar ('?');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
putchar (*p);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user