aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/args.c20
-rw-r--r--src/calcurse.h1
-rw-r--r--src/utils.c34
3 files changed, 42 insertions, 13 deletions
diff --git a/src/args.c b/src/args.c
index a944513..9ace459 100644
--- a/src/args.c
+++ b/src/args.c
@@ -246,7 +246,7 @@ todo_arg (int priority, int print_note, regex_t *regex)
{
llist_item_t *i;
int title = 1;
- char *titlestr, priority_str[BUFSIZ] = "";
+ char *titlestr;
char *all_todos_title = _("to do:\n");
char *completed_title = _("completed tasks:\n");
@@ -260,15 +260,6 @@ todo_arg (int priority, int print_note, regex_t *regex)
} \
} while (0)
-#define DISPLAY_TODO do { \
- (void)snprintf (priority_str, BUFSIZ, "%d. ", abs (todo->id)); \
- fputs (priority_str, stdout); \
- fputs (todo->mesg, stdout); \
- fputs ("\n", stdout); \
- if (print_note && todo->note) \
- print_notefile (stdout, todo->note, 1); \
- } while (0)
-
LLIST_FOREACH (&todolist, i)
{
struct todo *todo = LLIST_TS_GET_DATA (i);
@@ -280,7 +271,9 @@ todo_arg (int priority, int print_note, regex_t *regex)
if (priority == 0)
{
DISPLAY_TITLE;
- DISPLAY_TODO;
+ print_todo ("%p. %m\n", todo);
+ if (print_note && todo->note)
+ print_notefile (stdout, todo->note, 1);
}
}
else
@@ -288,13 +281,14 @@ todo_arg (int priority, int print_note, regex_t *regex)
if (priority < 0 || todo->id == priority)
{
DISPLAY_TITLE;
- DISPLAY_TODO;
+ print_todo ("%p. %m\n", todo);
+ if (print_note && todo->note)
+ print_notefile (stdout, todo->note, 1);
}
}
}
#undef DISPLAY_TITLE
-#undef DISPLAY_TODO
}
/* Print the next appointment within the upcoming 24 hours. */
diff --git a/src/calcurse.h b/src/calcurse.h
index 9cfc2e5..d79a604 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -926,6 +926,7 @@ void print_event (const char *, long, struct event *);
void print_recur_apoint (const char *, long, unsigned,
struct recur_apoint *);
void print_recur_event (const char *, long, struct recur_event *);
+void print_todo (const char *, struct todo *);
/* vars.c */
extern int col, row;
diff --git a/src/utils.c b/src/utils.c
index e94c7fa..f2f6305 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1060,3 +1060,37 @@ print_recur_event (const char *format, long day, struct recur_event *rev)
print_event (format, day, &ev);
}
+
+/* Print a formatted todo item to stdout. */
+void
+print_todo (const char *format, struct todo *todo)
+{
+ const char *p;
+
+ for (p = format; *p; p++)
+ {
+ if (*p == '%') {
+ p++;
+ switch (*p)
+ {
+ case 'p':
+ printf ("%d", abs (todo->id));
+ break;
+ case 'm':
+ printf ("%s", todo->mesg);
+ break;
+ case 'n':
+ printf ("%s", todo->note);
+ break;
+ case '\0':
+ return;
+ break;
+ default:
+ putchar ('?');
+ break;
+ }
+ }
+ else
+ putchar (*p);
+ }
+}