scal

Simple Calendar
git clone git://git.wimdupont.com/scal.git
Log | Files | Refs | LICENSE

commit 95be084fb145784268c9a48adbd0396c3b3536a8
parent e5d45343489768f394b2bf57ebd1fd2612df07e0
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sun, 17 Nov 2024 20:01:43 +0100

cleanup

Diffstat:
Rscal.h -> config.h | 0
Mscal.c | 102+++++++++++++++++++++++++++++++++++--------------------------------------------
2 files changed, 45 insertions(+), 57 deletions(-)

diff --git a/scal.h b/config.h diff --git a/scal.c b/scal.c @@ -10,7 +10,7 @@ #include <time.h> #include <curses.h> -#include "scal.h" +#include "config.h" #define ctrl(x) ((x) & 0x1f) @@ -23,51 +23,39 @@ typedef struct char *description; } Note ; -static void init_screen(); -static void resize(); -static void start(); -static void set_startpr(); -static void print_words(); -static void retrieve_words(); -static void write_notes(); -static Note ** get_notes(); +static void init_screen(void); +static void resize(void); +static void start(void); +static void print_words(void); +static void write_notes(void); +static Note ** get_notes(void); static Note * get_note(char *line_buf, ssize_t line_size); static char * prompt_answer(char *buf, size_t size, const char *question, const char *mask, char *prefill); -static void open_view(); -static void print_view(); +static void print_view(void); static void print_month(const int monthadd, int *y); -static void clear_search(); -static void lookup_and_save(char *word); -static void search(); static void combo_key(int keypress); static void combo_go(int keypress); static void combo_make(int keypress); static void add_note(struct tm *tm); static void rm_note(struct tm *tm); -static int get_curnotes(); +static int get_curnotes(void); static int get_note_view_col(Recurring recurring); static int has_note(struct tm *tm); static int get_days(const struct tm *tm); static int days_between(struct tm *tsa, struct tm *tsb); static int same_day(struct tm *a, struct tm *b, Recurring recurring); static int compare_note(const void *a, const void *b); -static void move_top(); -static void move_bot(); -static void move_page_up(); -static void move_page_down(); -static void move_up(); -static void move_down(); -static void move_right(); -static void move_left(); -static void next_search(); -static void prev_search(); -static void free_words(); -static void curdate(); -static void run_command(size_t size, const char *fmt, ...); +static void move_page_up(void); +static void move_page_down(void); +static void move_up(void); +static void move_down(void); +static void move_right(void); +static void move_left(void); +static void curdate(void); static char * cpstr(char *dest, const char *src); static char * replace_digits(char *buf, const char *mask, int size); static char * replace_home(char *buf, const char *path, const char *userhome); -static void clean(); +static void clean(void); static void fatal(const char *fmt, ...); static char *MonthName[] = {"January","February","March","April","May","June","July","August", @@ -104,7 +92,7 @@ main(int argc, char **argv) } void -init_screen() +init_screen(void) { initscr(); noecho(); @@ -129,7 +117,7 @@ init_screen() } void -resize() +resize(void) { int startx; @@ -150,7 +138,7 @@ resize() } void -print_words() +print_words(void) { int y = 0; @@ -223,7 +211,7 @@ print_month(const int monthadd, int *y) } void -start() +start(void) { int c; @@ -439,10 +427,10 @@ add_note(struct tm *tm) { char answer[DESCLEN+20], buf[DESCLEN], rec[2], time[6], date[11], prefill[11]; if (tm != NULL) - snprintf(prefill, 11, "%04d-%02d-%02d\0", - tm->tm_year+1900, - tm->tm_mon+1, - tm->tm_mday); + snprintf(prefill, 11, "%04d-%02d-%02d\0", + tm->tm_year+1900, + tm->tm_mon+1, + tm->tm_mday); prompt_answer(rec, 1, "Recurring? (0=NO;1=YEARLY;2=MONTHLY;3=WEEKLY)", "3", NULL); prompt_answer(date, 10, "Date?", "2999-19-39", prefill); @@ -454,7 +442,7 @@ add_note(struct tm *tm) { if (len > 19) { notes = (Note**) realloc(notes, (sizeof(Note) * (note_count + 1))); - if (notes == NULL) + if (notes == NULL) fatal("Fatal: failed to reallocate bytes for notes.\n"); notes[note_count] = get_note(answer, len); @@ -514,7 +502,7 @@ rm_note(struct tm *tm) { } void -write_notes() +write_notes(void) { FILE *fp = fopen(file, "w+"); @@ -536,7 +524,7 @@ write_notes() } Note ** -get_notes() +get_notes(void) { char *line_buf = NULL; size_t line_buf_size = 0; @@ -544,18 +532,18 @@ get_notes() FILE *fp = fopen(file, "r"); - if (!fp) + if (!fp) fatal("Error opening file '%s'\n", file); line_size = getline(&line_buf, &line_buf_size, fp); notes = (Note**) malloc(sizeof(Note*)); - if (notes == NULL) + if (notes == NULL) fatal("Fatal: failed to allocate bytes for notes.\n"); while (line_size >= 0) { notes = (Note**) realloc(notes, (sizeof(Note*) * (note_count + 1))); - if (notes == NULL) + if (notes == NULL) fatal("Fatal: failed to reallocate bytes for notes.\n"); notes[note_count] = get_note(line_buf, line_size); @@ -573,7 +561,7 @@ get_notes() } Note * -get_note(char *line_buf, ssize_t line_size) +get_note(char *line_buf, ssize_t line_size) { char timestr[19]; Note *note = (Note*) calloc(1, sizeof(Note)); @@ -589,11 +577,11 @@ get_note(char *line_buf, ssize_t line_size) "%d|%[^|]|%[^\n]", &note->recurring, timestr, - note->description); + note->description); note->description[line_size-1] = '\0'; - if (sscanf(timestr, "%d-%d-%dT%d:%d", + if (sscanf(timestr, "%d-%d-%dT%d:%d", &(note->time.tm_year), &(note->time.tm_mon), &(note->time.tm_mday), @@ -607,7 +595,7 @@ get_note(char *line_buf, ssize_t line_size) } void -print_view() +print_view(void) { int y = -1, x = 0, color; @@ -629,7 +617,7 @@ print_view() } int -get_curnotes() +get_curnotes(void) { if (curnote_count > 0) { curnote_count = 0; @@ -645,7 +633,7 @@ get_curnotes() for (int i = 0; i < note_count; i++) { if (same_day(&(notes[i]->time), &highltm, notes[i]->recurring)) { curnotes = (Note**) realloc(curnotes, (sizeof(Note*) * (curnote_count + 1))); - if (curnotes == NULL) + if (curnotes == NULL) fatal("Fatal: failed to reallocate bytes for notes.\n"); curnotes[curnote_count] = notes[i]; curnote_count++; @@ -741,7 +729,7 @@ compare_note(const void *a, const void *b) } void -move_page_up() +move_page_up(void) { highlight = 0; highltm.tm_mday = highlight+1; @@ -750,7 +738,7 @@ move_page_up() } void -move_page_down() +move_page_down(void) { highlight = 0; highltm.tm_mday = highlight+1; @@ -759,7 +747,7 @@ move_page_down() } void -move_up() +move_up(void) { if (highlight > 0) { highlight = MAX(highlight-DAY_COLUMN_SIZE, 0); @@ -773,7 +761,7 @@ move_up() } void -move_down() +move_down(void) { int wcount = get_days(&highltm); if (highlight < wcount-DAY_COLUMN_SIZE) { @@ -793,7 +781,7 @@ move_down() } void -move_right() +move_right(void) { int wcount = get_days(&highltm); if (highlight < wcount-1) { @@ -809,7 +797,7 @@ move_right() } void -move_left() +move_left(void) { if (highlight > 0) { highlight--; @@ -853,7 +841,7 @@ replace_home(char *buf, const char *path, const char *userhome) } void -curdate() +curdate(void) { time_t t = time(NULL); curtm = *localtime(&t); @@ -862,7 +850,7 @@ curdate() } void -clean() +clean(void) { clear();