diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 96c4ff4dfbb652c12a3a40bc08bd81d7efab5cc4
parent 891060ecc6dc3ed9db2700fd3a9cc66d6d728612
Author: Johnathan Jenkins <john@nixheads.co.uk>
Date:   Fri, 16 Dec 2016 01:00:41 -0800

Merge branch 'master' of https://github.com/in0rdr/diary

Diffstat:
Mdiary.c | 27+++++++++++++--------------
Mdiary.h | 11+++++------
2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/diary.c b/diary.c @@ -7,6 +7,13 @@ struct tm curs_date; struct tm cal_start; struct tm cal_end; +#define DATE_FMT "%Y-%m-%d" + +// normally leap is every 4 years, +// but is skipped every 100 years, +// unless it is divisible by 400 +#define is_leap(yr) ((yr % 400 == 0) || (yr % 4 == 0 && yr % 100 != 0)) + void setup_cal_timeframe() { raw_time = time(NULL); @@ -123,7 +130,7 @@ bool go_to(WINDOW* calendar, WINDOW* aside, time_t date, int* cur_pad_pos) } /* Update window 'win' with diary entry from date 'date' */ -void display_entry(char* dir, size_t dir_size, struct tm* date, WINDOW* win, int width) +void display_entry(const char* dir, size_t dir_size, const struct tm* date, WINDOW* win, int width) { char path[100]; char* ppath = path; @@ -152,7 +159,7 @@ void display_entry(char* dir, size_t dir_size, struct tm* date, WINDOW* win, int } /* Writes edit command for 'date' entry to 'rcmd'. '*rcmd' is NULL on error. */ -void edit_cmd(char* dir, size_t dir_size, struct tm* date, char** rcmd, size_t rcmd_size) +void edit_cmd(const char* dir, size_t dir_size, const struct tm* date, char** rcmd, size_t rcmd_size) { // get editor from environment char* editor = getenv("EDITOR"); @@ -190,7 +197,7 @@ void edit_cmd(char* dir, size_t dir_size, struct tm* date, char** rcmd, size_t r strcat(*rcmd, path); } -bool date_has_entry(char* dir, size_t dir_size, struct tm* i) +bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i) { char epath[100]; char* pepath = epath; @@ -206,21 +213,13 @@ bool date_has_entry(char* dir, size_t dir_size, struct tm* i) return (access(epath, F_OK) != -1); } -bool is_leap(int year) -{ - // normally leap is every 4 years, - // but is skipped every 100 years, - // unless it is divisible by 400 - return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); -} - -void get_date_str(struct tm* date, char* date_str, size_t date_str_size) +void get_date_str(const struct tm* date, char* date_str, size_t date_str_size) { - strftime(date_str, date_str_size, "%Y-%m-%d", date); + strftime(date_str, date_str_size, DATE_FMT, date); } /* Writes file path for 'date' entry to 'rpath'. '*rpath' is NULL on error. */ -void fpath(char* dir, size_t dir_size, struct tm* date, char** rpath, size_t rpath_size) +void fpath(const char* dir, size_t dir_size, const struct tm* date, char** rpath, size_t rpath_size) { // check size of result path if (dir_size + 1 > rpath_size) { diff --git a/diary.h b/diary.h @@ -23,12 +23,11 @@ void draw_calendar(WINDOW* number_pad, WINDOW* month_pad, char* diary_dir, size_ void update_date(WINDOW* header); bool go_to(WINDOW* calendar, WINDOW* aside, time_t date, int* cur_pad_pos); -void display_entry(char* dir, size_t dir_size, struct tm* date, WINDOW* win, int width); -void edit_cmd(char* dir, size_t dir_size, struct tm* date, char** rcmd, size_t rcmd_size); +void display_entry(const char* dir, size_t dir_size, const struct tm* date, WINDOW* win, int width); +void edit_cmd(const char* dir, size_t dir_size, const struct tm* date, char** rcmd, size_t rcmd_size); -bool date_has_entry(char* dir, size_t dir_size, struct tm* i); -bool is_leap(int year); -void get_date_str(struct tm* date, char* date_str, size_t date_str_size); -void fpath(char* dir, size_t dir_size, struct tm* date, char** rpath, size_t rpath_size); +bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i); +void get_date_str(const struct tm* date, char* date_str, size_t date_str_size); +void fpath(const char* dir, size_t dir_size, const struct tm* date, char** rpath, size_t rpath_size); #endif