diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-11-11 10:16:50 +0100 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-11-14 11:08:15 +0100 |
commit | f77f4647d12bcf06e501ab00c892f44c78e9ace5 (patch) | |
tree | b44fcea351ca889be52f52bf5bfe3dd8dffd7d0a /src/utils.c | |
parent | 349bd3f88b094d3e17a84308f9ae4cf0a16d6727 (diff) | |
download | calcurse-f77f4647d12bcf06e501ab00c892f44c78e9ace5.zip |
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>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index f2f6305..21190f0 100644 --- a/src/utils.c +++ b/src/utils.c @@ -954,6 +954,58 @@ press_any_key (void) 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. */ void 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': printf ("%s", apt->note); break; + case 'N': + print_notefile (stdout, apt->note, 1); + break; case '\0': return; break; @@ -1021,6 +1076,9 @@ print_event (const char *format, long day, struct event *ev) case 'n': printf ("%s", ev->note); break; + case 'N': + print_notefile (stdout, ev->note, 1); + break; case '\0': return; break; @@ -1082,6 +1140,9 @@ print_todo (const char *format, struct todo *todo) case 'n': printf ("%s", todo->note); break; + case 'N': + print_notefile (stdout, todo->note, 1); + break; case '\0': return; break; |