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>
This commit is contained in:
parent
5dc443fc3d
commit
a79a33e8f4
@ -779,6 +779,7 @@ void mem_stats (void);
|
|||||||
#endif /* CALCURSE_MEMORY_DEBUG */
|
#endif /* CALCURSE_MEMORY_DEBUG */
|
||||||
|
|
||||||
/* note.c */
|
/* note.c */
|
||||||
|
char *generate_note (const char *);
|
||||||
void edit_note (char **, char *);
|
void edit_note (char **, char *);
|
||||||
void view_note (char *, char *);
|
void view_note (char *, char *);
|
||||||
void erase_note (char **);
|
void erase_note (char **);
|
||||||
|
15
src/ical.c
15
src/ical.c
@ -37,7 +37,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "calcurse.h"
|
#include "calcurse.h"
|
||||||
#include "sha1.h"
|
|
||||||
|
|
||||||
#define ICALDATEFMT "%Y%m%d"
|
#define ICALDATEFMT "%Y%m%d"
|
||||||
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
|
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
|
||||||
@ -866,9 +865,7 @@ static char *
|
|||||||
ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type,
|
ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type,
|
||||||
const int itemline, FILE *log)
|
const int itemline, FILE *log)
|
||||||
{
|
{
|
||||||
char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1);
|
char *p, *notestr, *note;
|
||||||
char *p, *notestr, fullnotename[BUFSIZ];
|
|
||||||
FILE *fdo;
|
|
||||||
|
|
||||||
if ((p = strchr (line, ':')) != NULL)
|
if ((p = strchr (line, ':')) != NULL)
|
||||||
{
|
{
|
||||||
@ -888,15 +885,9 @@ ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sha1_digest (notestr, sha1);
|
note = generate_note (notestr);
|
||||||
snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, sha1);
|
|
||||||
fdo = fopen (fullnotename, "w");
|
|
||||||
EXIT_IF (fdo == NULL, _("Warning: could not open %s, Aborting..."),
|
|
||||||
fullnotename);
|
|
||||||
fprintf (fdo, "%s", notestr);
|
|
||||||
file_close (fdo, __FILE_POS__);
|
|
||||||
mem_free (notestr);
|
mem_free (notestr);
|
||||||
return sha1;
|
return note;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
19
src/note.c
19
src/note.c
@ -46,6 +46,25 @@ struct note_gc_hash {
|
|||||||
HTABLE_ENTRY (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. */
|
/* Edit a note with an external editor. */
|
||||||
void
|
void
|
||||||
edit_note (char **note, char *editor)
|
edit_note (char **note, char *editor)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user