aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-04-13 18:44:32 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-04-17 11:10:11 +0200
commitb73ce859dbbd694f5096626a6db224127a16c8a7 (patch)
tree15e1f7c6684b0c4dd3391f5aa912dac30f4f3409 /src
parentcd4f8bb68fbdd0983a2375202134c560878de3ac (diff)
downloadcalcurse-b73ce859dbbd694f5096626a6db224127a16c8a7.tar.gz
calcurse-b73ce859dbbd694f5096626a6db224127a16c8a7.zip
Add support for long format specifiers
Adds following long format specifiers for each short format specifier: * s: (start) * S: (startstr) * d: (duration) * e: (end) * E: (endstr) * m: (message) * n: (noteid) * N: (note) * p: (priority) Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/utils.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c
index aa52977..c5e2ce6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -49,6 +49,8 @@
#define ISLEAP(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
+#define FS_EXT_MAXLEN 64
+
enum format_specifier {
FS_STARTDATE,
FS_STARTDATESTR,
@@ -1080,9 +1082,12 @@ print_escape (const char *s)
/* Parse a format specifier. */
static enum format_specifier
-parse_fs (const char *s)
+parse_fs (const char **s)
{
- switch (*s)
+ char buf[FS_EXT_MAXLEN];
+ int i;
+
+ switch (**s)
{
case 's':
return FS_STARTDATE;
@@ -1102,6 +1107,39 @@ parse_fs (const char *s)
return FS_NOTEFILE;
case 'p':
return FS_PRIORITY;
+ case '(':
+ /* Long format specifier. */
+ for ((*s)++, i = 0; **s != ')'; (*s)++, i++)
+ {
+ if (**s == '\0')
+ return FS_EOF;
+
+ if (i < FS_EXT_MAXLEN)
+ buf[i] = **s;
+ }
+
+ buf[(i < FS_EXT_MAXLEN) ? i : FS_EXT_MAXLEN - 1] = '\0';
+
+ if (!strcmp (buf, "start"))
+ return FS_STARTDATE;
+ else if (!strcmp (buf, "startstr"))
+ return FS_STARTDATESTR;
+ else if (!strcmp (buf, "duration"))
+ return FS_DURATION;
+ else if (!strcmp (buf, "end"))
+ return FS_ENDDATE;
+ else if (!strcmp (buf, "endstr"))
+ return FS_ENDDATESTR;
+ else if (!strcmp (buf, "message"))
+ return FS_MESSAGE;
+ else if (!strcmp (buf, "noteid"))
+ return FS_NOTE;
+ else if (!strcmp (buf, "note"))
+ return FS_NOTEFILE;
+ else if (!strcmp (buf, "priority"))
+ return FS_PRIORITY;
+ else
+ return FS_UNKNOWN;
case '%':
return FS_PSIGN;
case '\0':
@@ -1124,7 +1162,7 @@ print_apoint (const char *format, long day, struct apoint *apt)
{
if (*p == '%') {
p++;
- switch (parse_fs (p))
+ switch (parse_fs (&p))
{
case FS_STARTDATE:
printf ("%ld", apt->start);
@@ -1178,7 +1216,7 @@ print_event (const char *format, long day, struct event *ev)
{
if (*p == '%') {
p++;
- switch (parse_fs (p))
+ switch (parse_fs (&p))
{
case FS_MESSAGE:
printf ("%s", ev->mesg);
@@ -1244,7 +1282,7 @@ print_todo (const char *format, struct todo *todo)
{
if (*p == '%') {
p++;
- switch (parse_fs (p))
+ switch (parse_fs (&p))
{
case FS_PRIORITY:
printf ("%d", abs (todo->id));