print_*(): Add format specifier to print notes
* Move print_notefile() from "src/args.c" to "src/utils.c". * Add a "%N" format specifier to print_*(). This invokes print_notefile() and prints the content of an item's note file. * src/args.c: Use the new format specifier instead of print_notefile() everywhere. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
349bd3f88b
commit
f77f4647d1
79
src/args.c
79
src/args.c
@ -182,58 +182,6 @@ status_arg (void)
|
|||||||
puts (_("calcurse is not running\n"));
|
puts (_("calcurse is not running\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Display note contents if one is asociated with the currently displayed item
|
|
||||||
* (to be used together with the '-a' or '-t' flag in non-interactive mode).
|
|
||||||
* Each line begins with nbtab tabs.
|
|
||||||
* Print "No note file found", if the notefile does not exists.
|
|
||||||
*
|
|
||||||
* (patch submitted by Erik Saule).
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
print_notefile (FILE *out, char *filename, int nbtab)
|
|
||||||
{
|
|
||||||
char path_to_notefile[BUFSIZ];
|
|
||||||
FILE *notefile;
|
|
||||||
char linestarter[BUFSIZ];
|
|
||||||
char buffer[BUFSIZ];
|
|
||||||
int i;
|
|
||||||
int printlinestarter = 1;
|
|
||||||
|
|
||||||
if (nbtab < BUFSIZ)
|
|
||||||
{
|
|
||||||
for (i = 0; i < nbtab; i++)
|
|
||||||
linestarter[i] = '\t';
|
|
||||||
linestarter[nbtab] = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
linestarter[0] = '\0';
|
|
||||||
|
|
||||||
snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
|
|
||||||
notefile = fopen (path_to_notefile, "r");
|
|
||||||
if (notefile)
|
|
||||||
{
|
|
||||||
while (fgets (buffer, BUFSIZ, notefile) != 0)
|
|
||||||
{
|
|
||||||
if (printlinestarter)
|
|
||||||
{
|
|
||||||
fputs (linestarter, out);
|
|
||||||
printlinestarter = 0;
|
|
||||||
}
|
|
||||||
fputs (buffer, out);
|
|
||||||
if (buffer[strlen (buffer) - 1] == '\n')
|
|
||||||
printlinestarter = 1;
|
|
||||||
}
|
|
||||||
fputs ("\n", out);
|
|
||||||
file_close (notefile, __FILE_POS__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fputs (linestarter, out);
|
|
||||||
fputs (_("No note file found\n"), out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print todo list and exit. If a priority number is given, then only todo
|
* Print todo list and exit. If a priority number is given, then only todo
|
||||||
* then only todo items that have this priority will be displayed.
|
* then only todo items that have this priority will be displayed.
|
||||||
@ -271,9 +219,7 @@ todo_arg (int priority, int print_note, regex_t *regex)
|
|||||||
if (priority == 0)
|
if (priority == 0)
|
||||||
{
|
{
|
||||||
DISPLAY_TITLE;
|
DISPLAY_TITLE;
|
||||||
print_todo ("%p. %m\n", todo);
|
print_todo (print_note ? "%p. %m\n%N" : "%p. %m\n", todo);
|
||||||
if (print_note && todo->note)
|
|
||||||
print_notefile (stdout, todo->note, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -281,9 +227,7 @@ todo_arg (int priority, int print_note, regex_t *regex)
|
|||||||
if (priority < 0 || todo->id == priority)
|
if (priority < 0 || todo->id == priority)
|
||||||
{
|
{
|
||||||
DISPLAY_TITLE;
|
DISPLAY_TITLE;
|
||||||
print_todo ("%p. %m\n", todo);
|
print_todo (print_note ? "%p. %m\n%N" : "%p. %m\n", todo);
|
||||||
if (print_note && todo->note)
|
|
||||||
print_notefile (stdout, todo->note, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,9 +323,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
arg_print_date (today);
|
arg_print_date (today);
|
||||||
print_date = 0;
|
print_date = 0;
|
||||||
}
|
}
|
||||||
print_recur_event (" * %m\n", today, re);
|
print_recur_event (print_note ? " * %m\n%N" : " * %m\n", today, re);
|
||||||
if (print_note && re->note)
|
|
||||||
print_notefile (stdout, re->note, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LLIST_FIND_FOREACH_CONT (&eventlist, today, event_inday, i)
|
LLIST_FIND_FOREACH_CONT (&eventlist, today, event_inday, i)
|
||||||
@ -401,9 +343,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
arg_print_date (today);
|
arg_print_date (today);
|
||||||
print_date = 0;
|
print_date = 0;
|
||||||
}
|
}
|
||||||
print_event (" * %m\n", today, ev);
|
print_event (print_note ? " * %m\n%N" : " * %m\n", today, ev);
|
||||||
if (print_note && ev->note)
|
|
||||||
print_notefile (stdout, ev->note, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Same process is performed but this time on the appointments. */
|
/* Same process is performed but this time on the appointments. */
|
||||||
@ -456,9 +396,8 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
arg_print_date (today);
|
arg_print_date (today);
|
||||||
print_date = 0;
|
print_date = 0;
|
||||||
}
|
}
|
||||||
print_apoint (" - %S -> %E\n\t%m\n", today, apt);
|
print_apoint (print_note ? " - %S -> %E\n\t%m\n%N" :
|
||||||
if (print_note && apt->note)
|
" - %S -> %E\n\t%m\n", today, apt);
|
||||||
print_notefile (stdout, apt->note, 2);
|
|
||||||
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday);
|
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday);
|
||||||
}
|
}
|
||||||
else if (ra)
|
else if (ra)
|
||||||
@ -475,9 +414,9 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
print_date = 0;
|
print_date = 0;
|
||||||
}
|
}
|
||||||
recur_apoint_find_occurrence (ra, today, &occurrence);
|
recur_apoint_find_occurrence (ra, today, &occurrence);
|
||||||
print_recur_apoint (" - %S -> %E\n\t%m\n", today, occurrence, ra);
|
print_recur_apoint (print_note ? " - %S -> %E\n\t%m\n%N" :
|
||||||
if (print_note && ra->note)
|
" - %S -> %E\n\t%m\n", today,
|
||||||
print_notefile (stdout, ra->note, 2);
|
occurrence, ra);
|
||||||
apt = NULL;
|
apt = NULL;
|
||||||
j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday);
|
j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday);
|
||||||
}
|
}
|
||||||
|
61
src/utils.c
61
src/utils.c
@ -954,6 +954,58 @@ press_any_key (void)
|
|||||||
fputs ("\r\n", stdout);
|
fputs ("\r\n", stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display note contents if one is asociated with the currently displayed item
|
||||||
|
* (to be used together with the '-a' or '-t' flag in non-interactive mode).
|
||||||
|
* Each line begins with nbtab tabs.
|
||||||
|
* Print "No note file found", if the notefile does not exists.
|
||||||
|
*
|
||||||
|
* (patch submitted by Erik Saule).
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
print_notefile (FILE *out, char *filename, int nbtab)
|
||||||
|
{
|
||||||
|
char path_to_notefile[BUFSIZ];
|
||||||
|
FILE *notefile;
|
||||||
|
char linestarter[BUFSIZ];
|
||||||
|
char buffer[BUFSIZ];
|
||||||
|
int i;
|
||||||
|
int printlinestarter = 1;
|
||||||
|
|
||||||
|
if (nbtab < BUFSIZ)
|
||||||
|
{
|
||||||
|
for (i = 0; i < nbtab; i++)
|
||||||
|
linestarter[i] = '\t';
|
||||||
|
linestarter[nbtab] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
linestarter[0] = '\0';
|
||||||
|
|
||||||
|
snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
|
||||||
|
notefile = fopen (path_to_notefile, "r");
|
||||||
|
if (notefile)
|
||||||
|
{
|
||||||
|
while (fgets (buffer, BUFSIZ, notefile) != 0)
|
||||||
|
{
|
||||||
|
if (printlinestarter)
|
||||||
|
{
|
||||||
|
fputs (linestarter, out);
|
||||||
|
printlinestarter = 0;
|
||||||
|
}
|
||||||
|
fputs (buffer, out);
|
||||||
|
if (buffer[strlen (buffer) - 1] == '\n')
|
||||||
|
printlinestarter = 1;
|
||||||
|
}
|
||||||
|
fputs ("\n", out);
|
||||||
|
file_close (notefile, __FILE_POS__);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fputs (linestarter, out);
|
||||||
|
fputs (_("No note file found\n"), out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Print a formatted appointment to stdout. */
|
/* Print a formatted appointment to stdout. */
|
||||||
void
|
void
|
||||||
print_apoint (const char *format, long day, struct apoint *apt)
|
print_apoint (const char *format, long day, struct apoint *apt)
|
||||||
@ -990,6 +1042,9 @@ print_apoint (const char *format, long day, struct apoint *apt)
|
|||||||
case 'n':
|
case 'n':
|
||||||
printf ("%s", apt->note);
|
printf ("%s", apt->note);
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
print_notefile (stdout, apt->note, 1);
|
||||||
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
@ -1021,6 +1076,9 @@ print_event (const char *format, long day, struct event *ev)
|
|||||||
case 'n':
|
case 'n':
|
||||||
printf ("%s", ev->note);
|
printf ("%s", ev->note);
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
print_notefile (stdout, ev->note, 1);
|
||||||
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
@ -1082,6 +1140,9 @@ print_todo (const char *format, struct todo *todo)
|
|||||||
case 'n':
|
case 'n':
|
||||||
printf ("%s", todo->note);
|
printf ("%s", todo->note);
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
print_notefile (stdout, todo->note, 1);
|
||||||
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user