aboutsummaryrefslogtreecommitdiffstats
path: root/src/note.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-01-17 00:41:19 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2012-01-17 00:52:39 +0100
commita79a33e8f4da016e4ae42b061db8400337d5a580 (patch)
treec025cc9c231dd7d0953950d586f214a458fe7765 /src/note.c
parent5dc443fc3d236fc2520df58495e62f197a98a64f (diff)
downloadcalcurse-a79a33e8f4da016e4ae42b061db8400337d5a580.tar.gz
calcurse-a79a33e8f4da016e4ae42b061db8400337d5a580.zip
Split note file generation into separate function
We currently use this in one place only but might reuse this a couple of times later (when migrating to libical). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/note.c')
-rw-r--r--src/note.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/note.c b/src/note.c
index e5595fc..2686dd7 100644
--- a/src/note.c
+++ b/src/note.c
@@ -46,6 +46,25 @@ struct note_gc_hash {
HTABLE_ENTRY (note_gc_hash);
};
+/* Create note file from a string and return a newly allocated string that
+ * contains its name. */
+char *
+generate_note (const char *str)
+{
+ char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1);
+ char notepath[BUFSIZ];
+ FILE *fp;
+
+ sha1_digest (str, sha1);
+ snprintf (notepath, BUFSIZ, "%s%s", path_notes, sha1);
+ fp = fopen (notepath, "w");
+ EXIT_IF (fp == NULL, _("Warning: could not open %s, Aborting..."), notepath);
+ fputs (str, fp);
+ file_close (fp, __FILE_POS__);
+
+ return sha1;
+}
+
/* Edit a note with an external editor. */
void
edit_note (char **note, char *editor)