commit e5d45343489768f394b2bf57ebd1fd2612df07e0
parent 9539a0a3cec60567b842c939a90e55a78bb00428
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 17 Nov 2024 19:44:33 +0100
clean hfile
Diffstat:
M | scal.c | | | 145 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
M | scal.h | | | 73 | ++++++++----------------------------------------------------------------- |
2 files changed, 108 insertions(+), 110 deletions(-)
diff --git a/scal.c b/scal.c
@@ -12,26 +12,73 @@
#include "scal.h"
+#define ctrl(x) ((x) & 0x1f)
+
+typedef enum {NO, YEARLY, MONTHLY, WEEKLY} Recurring;
+
+typedef struct
+{
+ Recurring recurring;
+ struct tm time;
+ 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 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_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_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 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 fatal(const char *fmt, ...);
+
static char *MonthName[] = {"January","February","March","April","May","June","July","August",
- "September","October","November","December"};
+ "September","October","November","December"};
static char *DayName[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
-
static struct tm curtm, highltm;
-
static WINDOW *wwin, *vwin;
static int maxy, maxx, wmaxy, wmaxx, vmaxy, vmaxx, highlight, note_count=0, curnote_count=0;
static Note **notes, **curnotes = NULL;
static char file[PATH_MAX];
-void
-curdate()
-{
- time_t t = time(NULL);
- curtm = *localtime(&t);
- highltm = curtm;
- highlight = highltm.tm_mday-1;
-}
-
int
main(int argc, char **argv)
{
@@ -56,7 +103,7 @@ main(int argc, char **argv)
clean();
}
-static void
+void
init_screen()
{
initscr();
@@ -81,7 +128,7 @@ init_screen()
resize();
}
-static void
+void
resize()
{
int startx;
@@ -102,7 +149,7 @@ resize()
refresh();
}
-static void
+void
print_words()
{
int y = 0;
@@ -125,7 +172,7 @@ print_words()
wrefresh(wwin);
}
-static void
+void
print_month(const int monthadd, int *y)
{
int wcount, today, wnote, sindex, x = 0;
@@ -175,7 +222,7 @@ print_month(const int monthadd, int *y)
}
}
-static void
+void
start()
{
int c;
@@ -226,7 +273,7 @@ start()
}
}
-static void
+void
combo_key(int keypress)
{
int c;
@@ -256,7 +303,7 @@ combo_key(int keypress)
clrtoeol();
}
-static void
+void
combo_go(int key)
{
char pathbuf[PATH_MAX];
@@ -270,7 +317,7 @@ combo_go(int key)
}
}
-static void
+void
combo_make(int key)
{
char pathbuf[PATH_MAX];
@@ -289,7 +336,7 @@ combo_make(int key)
}
}
-static char *
+char *
prompt_answer(char *buf, size_t size, const char *question, const char *mask, char *prefill)
{
int c, y, x, nr, phlen = mask == NULL ? 0 : strlen(mask);
@@ -386,7 +433,7 @@ prompt_answer(char *buf, size_t size, const char *question, const char *mask, ch
//mvprintw(maxy-2, 1, "%d: %s",len, buf);
}
-static void
+void
add_note(struct tm *tm) {
size_t len;
char answer[DESCLEN+20], buf[DESCLEN], rec[2], time[6], date[11], prefill[11];
@@ -421,7 +468,7 @@ add_note(struct tm *tm) {
clrtoeol();
}
-static void
+void
rm_note(struct tm *tm) {
int c, y, x;
@@ -466,7 +513,7 @@ rm_note(struct tm *tm) {
curs_set(0);
}
-static void
+void
write_notes()
{
FILE *fp = fopen(file, "w+");
@@ -488,7 +535,7 @@ write_notes()
fclose(fp);
}
-static Note **
+Note **
get_notes()
{
char *line_buf = NULL;
@@ -525,7 +572,7 @@ get_notes()
return notes;
}
-static Note *
+Note *
get_note(char *line_buf, ssize_t line_size)
{
char timestr[19];
@@ -559,7 +606,7 @@ get_note(char *line_buf, ssize_t line_size)
return note;
}
-static void
+void
print_view()
{
int y = -1, x = 0, color;
@@ -581,7 +628,7 @@ print_view()
wrefresh(vwin);
}
-static int
+int
get_curnotes()
{
if (curnote_count > 0) {
@@ -606,7 +653,7 @@ get_curnotes()
}
}
-static int
+int
get_note_view_col(Recurring recurring)
{
switch (recurring) {
@@ -621,7 +668,7 @@ get_note_view_col(Recurring recurring)
}
}
-static int
+int
has_note(struct tm *tm)
{
for (int i = 0; i < note_count; i++) {
@@ -631,7 +678,7 @@ has_note(struct tm *tm)
return 0;
}
-static int
+int
get_days(const struct tm *tm)
{
struct tm start = *tm, end = *tm;
@@ -643,7 +690,7 @@ get_days(const struct tm *tm)
return days_between(&start, &end);
}
-static int
+int
days_between(struct tm *tsa, struct tm *tsb)
{
time_t a = mktime(tsa);
@@ -652,7 +699,7 @@ days_between(struct tm *tsa, struct tm *tsb)
return (b - a)/(60*60*24);
}
-static int
+int
same_day(struct tm *a, struct tm *b, Recurring recurring)
{
if (a == NULL || b == NULL)
@@ -666,7 +713,7 @@ same_day(struct tm *a, struct tm *b, Recurring recurring)
&& (recurring >= YEARLY || a->tm_year == b->tm_year);
}
-static int
+int
compare_note(const void *a, const void *b)
{
int recurdif;
@@ -693,7 +740,7 @@ compare_note(const void *a, const void *b)
//return difftime(mktime(&ma->time), mktime(&mb->time));
}
-static void
+void
move_page_up()
{
highlight = 0;
@@ -702,7 +749,7 @@ move_page_up()
mktime(&highltm);
}
-static void
+void
move_page_down()
{
highlight = 0;
@@ -711,7 +758,7 @@ move_page_down()
mktime(&highltm);
}
-static void
+void
move_up()
{
if (highlight > 0) {
@@ -725,7 +772,7 @@ move_up()
}
}
-static void
+void
move_down()
{
int wcount = get_days(&highltm);
@@ -745,7 +792,7 @@ move_down()
}
}
-static void
+void
move_right()
{
int wcount = get_days(&highltm);
@@ -761,7 +808,7 @@ move_right()
}
}
-static void
+void
move_left()
{
if (highlight > 0) {
@@ -775,7 +822,7 @@ move_left()
}
}
-static char *
+char *
cpstr(char *dest, const char *src)
{
size_t cplen = strlen(src);
@@ -784,7 +831,7 @@ cpstr(char *dest, const char *src)
return dest;
}
-static char *
+char *
replace_digits(char *buf, const char *mask, int size) {
for (int i = 0; i < size; i++)
buf[i] = isdigit(mask[i]) ? '_' : mask[i] ;
@@ -792,7 +839,7 @@ replace_digits(char *buf, const char *mask, int size) {
return buf;
}
-static char *
+char *
replace_home(char *buf, const char *path, const char *userhome)
{
char *envv = "$HOME";
@@ -805,8 +852,16 @@ replace_home(char *buf, const char *path, const char *userhome)
return buf;
}
+void
+curdate()
+{
+ time_t t = time(NULL);
+ curtm = *localtime(&t);
+ highltm = curtm;
+ highlight = highltm.tm_mday-1;
+}
-static void
+void
clean()
{
clear();
@@ -827,7 +882,7 @@ clean()
free(curnotes);
}
-static void
+void
fatal(const char *fmt, ...)
{
va_list ap;
diff --git a/scal.h b/scal.h
@@ -25,70 +25,13 @@
#define KEY_COMBO_MAKE_ADD 'a'
#define KEY_COMBO_MAKE_RM 'd'
-#define HIGHLIGHT_COLOR COLOR_YELLOW
-#define MONTH_TITLE_COLOR COLOR_MAGENTA
-#define CURDAY_COLOR COLOR_GREEN
-#define NOTED_COLOR COLOR_RED
-#define WEEKLY_VIEW_COLOR COLOR_WHITE
-#define MONTHLY_VIEW_COLOR COLOR_YELLOW
-#define YEARLY_VIEW_COLOR COLOR_RED
-#define PROMPT_COLOR COLOR_RED
-
-#define ctrl(x) ((x) & 0x1f)
-
-typedef enum {NO, YEARLY, MONTHLY, WEEKLY} Recurring;
-
-typedef struct
-{
- Recurring recurring;
- struct tm time;
- 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 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_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_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 run_command(size_t size, const char *fmt, ...);
-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 fatal(const char *fmt, ...);
+#define HIGHLIGHT_COLOR COLOR_YELLOW
+#define MONTH_TITLE_COLOR COLOR_MAGENTA
+#define CURDAY_COLOR COLOR_GREEN
+#define NOTED_COLOR COLOR_RED
+#define WEEKLY_VIEW_COLOR COLOR_WHITE
+#define MONTHLY_VIEW_COLOR COLOR_YELLOW
+#define YEARLY_VIEW_COLOR COLOR_RED
+#define PROMPT_COLOR COLOR_RED
#endif