summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/args.c20
-rw-r--r--src/calcurse.h1
-rw-r--r--src/utils.c49
3 files changed, 52 insertions, 18 deletions
diff --git a/src/args.c b/src/args.c
index 3c5831a..d51478a 100644
--- a/src/args.c
+++ b/src/args.c
@@ -357,8 +357,6 @@ app_arg (int add_line, struct date *day, long date, int print_note,
long today;
unsigned print_date = 1;
int app_found = 0;
- char apoint_start_time[HRMIN_SIZE];
- char apoint_end_time[HRMIN_SIZE];
if (date == 0)
today = get_sec_date (*day);
@@ -468,14 +466,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
arg_print_date (today);
print_date = 0;
}
- apoint_sec2str (apt, today, apoint_start_time, apoint_end_time);
- fputs (" - ", stdout);
- fputs (apoint_start_time, stdout);
- fputs (" -> ", stdout);
- fputs (apoint_end_time, stdout);
- fputs ("\n\t", stdout);
- fputs (apt->mesg, stdout);
- fputs ("\n", stdout);
+ print_apoint (" - %S -> %E\n\t%m\n", today, apt);
if (print_note && apt->note)
print_notefile (stdout, apt->note, 2);
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday);
@@ -494,16 +485,9 @@ app_arg (int add_line, struct date *day, long date, int print_note,
print_date = 0;
}
apt = apoint_recur_s2apoint_s (ra);
- apoint_sec2str (apt, today, apoint_start_time, apoint_end_time);
+ print_apoint (" - %S -> %E\n\t%m\n", today, apt);
mem_free (apt->mesg);
mem_free (apt);
- fputs (" - ", stdout);
- fputs (apoint_start_time, stdout);
- fputs (" -> ", stdout);
- fputs (apoint_end_time, stdout);
- fputs ("\n\t", stdout);
- fputs (ra->mesg, stdout);
- fputs ("\n", stdout);
if (print_note && ra->note)
print_notefile (stdout, ra->note, 2);
apt = NULL;
diff --git a/src/calcurse.h b/src/calcurse.h
index 687c118..e4acab2 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -922,6 +922,7 @@ int fork_exec (int *, int *, const char *, char *const *);
int shell_exec (int *, int *, char *);
int child_wait (int *, int *, int);
void press_any_key (void);
+void print_apoint (const char *, long, struct apoint *);
/* vars.c */
extern int col, row;
diff --git a/src/utils.c b/src/utils.c
index 3c7f595..4628798 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -953,3 +953,52 @@ press_any_key (void)
fflush (stdin);
fputs ("\r\n", stdout);
}
+
+/* Print a formatted appointment to stdout. */
+void
+print_apoint (const char *format, long day, struct apoint *apt)
+{
+ const char *p;
+ char str_start[HRMIN_SIZE], str_end[HRMIN_SIZE];
+
+ apoint_sec2str (apt, day, str_start, str_end);
+
+ for (p = format; *p; p++)
+ {
+ if (*p == '%') {
+ p++;
+ switch (*p)
+ {
+ case 's':
+ printf ("%ld", apt->start);
+ break;
+ case 'S':
+ printf ("%s", str_start);
+ break;
+ case 'd':
+ printf ("%ld", apt->dur);
+ break;
+ case 'e':
+ printf ("%ld", apt->start + apt->dur);
+ break;
+ case 'E':
+ printf ("%s", str_end);
+ break;
+ case 'm':
+ printf ("%s", apt->mesg);
+ break;
+ case 'n':
+ printf ("%s", apt->note);
+ break;
+ case '\0':
+ return;
+ break;
+ default:
+ putchar ('?');
+ break;
+ }
+ }
+ else
+ putchar (*p);
+ }
+}