utils.h (2352B)
1 #ifndef DIARY_UTILS_H 2 #define DIARY_UTILS_H 3 4 #include <regex.h> 5 #include <stdio.h> 6 #include <unistd.h> 7 #include <stdlib.h> 8 #include <time.h> 9 #include <string.h> 10 #include <pthread.h> 11 #include <wordexp.h> 12 #include <stdbool.h> 13 #include <ncurses.h> 14 #include <libxml/parser.h> 15 #include <libxml/xpath.h> 16 #include <libxml/tree.h> 17 18 #define CAL_WIDTH 21 19 #define ASIDE_WIDTH 4 20 #define MAX_MONTH_HEIGHT 6 21 22 /* Create simple debug messsages to stderr 23 * https://stackoverflow.com/questions/1644868/define-macro-for-debug-printing-in-c 24 */ 25 #define debug(fmt, ...) \ 26 fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \ 27 __LINE__, __func__, __VA_ARGS__); \ 28 fprintf(stderr, "\n"); 29 30 void update_date(WINDOW* header, struct tm* curs_date); 31 bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i); 32 char* fold(const char* str); 33 char* unfold(const char* str); 34 char* extract_ical_field(const char* ical, char* key, long* start_pos, bool multline); 35 char* extract_xml_content(const char* xml, const char* xpathExpression, WINDOW* w, pthread_t* p); 36 char* expand_path(const char* str); 37 char* strrstr(char *haystack, char *needle); 38 void fpath(const char* dir, size_t dir_size, const struct tm* date, char** rpath, size_t rpath_size); 39 bool go_to(WINDOW* calendar, WINDOW* aside, time_t date, int* cur_pad_pos, struct tm* curs_date, struct tm* cal_start, struct tm* cal_end); 40 void* show_progress(void* vargp); 41 void show_info(WINDOW* w, char* msg, pthread_t* p); 42 43 typedef struct 44 { 45 // Path that holds the journal text files 46 char* dir; 47 // Number of years to show before/after todays date 48 int range; 49 // 7 = Sunday, 1 = Monday, ..., 6 = Saturday 50 int weekday; 51 // 2020-12-31 52 char* fmt; 53 // Text formatting command/utility fmt, 54 // default width 75 chars (-w75), do not refill lines (-s) 55 char* fmt_cmd; 56 // Don't use pty, use ncurses for preview 57 bool no_pty; 58 // Don't listen for mouse events 59 bool no_mouse; 60 // Editor to open journal files with 61 char* editor; 62 // CalDAV calendar to synchronize 63 char* caldav_calendar; 64 // CalDAV server URI 65 char* caldav_server; 66 // CalDAV username 67 char* caldav_username; 68 // CalDAV password 69 char* caldav_password; 70 // OAuth command to fetch access token 71 char* oauth_eval_cmd; 72 } config; 73 74 extern config CONFIG; 75 76 #endif