summaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-11-09 18:48:09 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2011-11-14 11:08:14 +0100
commita9b820abbe46764f23687eac1d1f62b145cd0962 (patch)
treed14b1428a75428d3ae1286f777e50bb68d6ffd10 /src/utils.c
parent330ca4d3cbd702f4f0e7689a1da4f77945f768e0 (diff)
downloadcalcurse-a9b820abbe46764f23687eac1d1f62b145cd0962.tar.gz
calcurse-a9b820abbe46764f23687eac1d1f62b145cd0962.zip
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>
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 4628798..6b4fa1d 100644
--- a/src/utils.c
+++ b/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);
+ }
+}