diff options
Diffstat (limited to 'src/calcurse.h')
-rw-r--r-- | src/calcurse.h | 305 |
1 files changed, 187 insertions, 118 deletions
diff --git a/src/calcurse.h b/src/calcurse.h index 091d16a..ee6612f 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -103,99 +103,111 @@ #define DEFAULT_EDITOR "vi" #define DEFAULT_PAGER "less" -#define ATTR_FALSE 0 -#define ATTR_TRUE 1 -#define ATTR_LOWEST 2 -#define ATTR_LOW 3 -#define ATTR_MIDDLE 4 -#define ATTR_HIGH 5 -#define ATTR_HIGHEST 6 - -#define STATUSHEIGHT 2 -#define NOTESIZ 6 +#define ATTR_FALSE 0 +#define ATTR_TRUE 1 +#define ATTR_LOWEST 2 +#define ATTR_LOW 3 +#define ATTR_MIDDLE 4 +#define ATTR_HIGH 5 +#define ATTR_HIGHEST 6 + +#define STATUSHEIGHT 2 +#define MAX_NOTESIZ 40 +#define TMPEXTSIZ 6 /* Format for appointment hours is: HH:MM */ #define HRMIN_SIZE 6 /* Maximum number of colors available. */ -#define NBUSERCOLORS 6 +#define NBUSERCOLORS 6 /* Side bar width acceptable boundaries. */ #define SBARMINWIDTH 32 #define SBARMAXWIDTHPERC 50 /* Related to date manipulation. */ -#define DAYINSEC 86400 -#define HOURINSEC 3600 -#define MININSEC 60 -#define YEARINDAYS 365 #define YEARINMONTHS 12 -#define WEEKINDAYS 7 +#define YEARINDAYS 365 #define TM_YEAR_BASE 1900 +#define WEEKINDAYS 7 +#define DAYINHOURS 24 +#define HOURINMIN 60 +#define MININSEC 60 + +#define WEEKINHOURS (WEEKINDAYS * DAYINHOURS) +#define WEEKINMIN (WEEKINHOURS * HOURINMIN) +#define WEEKINSEC (WEEKINMIN * MININSEC) +#define DAYINMIN (DAYINHOURS * HOURINMIN) +#define DAYINSEC (DAYINMIN * MININSEC) +#define HOURINSEC (HOURINMIN * MININSEC) + /* Calendar window. */ -#define CALHEIGHT 12 +#define CALHEIGHT 12 /* Key definitions. */ #define CTRLVAL 0x1F #define CTRL(x) ((x) & CTRLVAL) -#define ESCAPE 27 -#define TAB 9 +#define ESCAPE 27 +#define TAB 9 #define SPACE 32 -#define KEYS_KEYLEN 3 /* length of each keybinding */ -#define KEYS_LABELEN 8 /* length of command description */ -#define KEYS_CMDS_PER_LINE 6 /* max number of commands per line */ - -#define ERROR_MSG(...) do { \ - char msg[BUFSIZ]; \ - int len; \ - \ - len = snprintf (msg, BUFSIZ, "%s: %d: ", __FILE__, __LINE__); \ - (void)snprintf (msg + len, BUFSIZ - len, __VA_ARGS__); \ - if (ui_mode == UI_CURSES) \ - fatalbox (msg); \ - else \ - (void)fprintf (stderr, "%s\n", msg); \ +#define KEYS_KEYLEN 3 /* length of each keybinding */ +#define KEYS_LABELEN 8 /* length of command description */ +#define KEYS_CMDS_PER_LINE 6 /* max number of commands per line */ + +/* Size of the hash table the note garbage collector uses. */ +#define NOTE_GC_HSIZE 1024 + +#define ERROR_MSG(...) do { \ + char msg[BUFSIZ]; \ + int len; \ + \ + len = snprintf (msg, BUFSIZ, "%s: %d: ", __FILE__, __LINE__); \ + snprintf (msg + len, BUFSIZ - len, __VA_ARGS__); \ + if (ui_mode == UI_CURSES) \ + fatalbox (msg); \ + else \ + fprintf (stderr, "%s\n", msg); \ } while (0) -#define WARN_MSG(...) do { \ - char msg[BUFSIZ]; \ - \ - (void)snprintf (msg, BUFSIZ, __VA_ARGS__); \ - if (ui_mode == UI_CURSES) \ - warnbox (msg); \ - else \ - (void)fprintf (stderr, "%s\n", msg); \ +#define WARN_MSG(...) do { \ + char msg[BUFSIZ]; \ + \ + snprintf (msg, BUFSIZ, __VA_ARGS__); \ + if (ui_mode == UI_CURSES) \ + warnbox (msg); \ + else \ + fprintf (stderr, "%s\n", msg); \ } while (0) -#define EXIT(...) do { \ - ERROR_MSG(__VA_ARGS__); \ - if (ui_mode == UI_CURSES) \ - exit_calcurse (EXIT_FAILURE); \ - else \ - exit (EXIT_FAILURE); \ +#define EXIT(...) do { \ + ERROR_MSG(__VA_ARGS__); \ + if (ui_mode == UI_CURSES) \ + exit_calcurse (EXIT_FAILURE); \ + else \ + exit (EXIT_FAILURE); \ } while (0) -#define EXIT_IF(cond, ...) do { \ - if ((cond)) \ - EXIT(__VA_ARGS__); \ +#define EXIT_IF(cond, ...) do { \ + if ((cond)) \ + EXIT(__VA_ARGS__); \ } while (0) -#define RETURN_IF(cond, ...) do { \ - if ((cond)) \ - { \ - ERROR_MSG(__VA_ARGS__); \ - return; \ - } \ +#define RETURN_IF(cond, ...) do { \ + if ((cond)) \ + { \ + ERROR_MSG(__VA_ARGS__); \ + return; \ + } \ } while (0) -#define RETVAL_IF(cond, val, ...) do { \ - if ((cond)) \ - { \ - ERROR_MSG(__VA_ARGS__); \ - return (val); \ - } \ +#define RETVAL_IF(cond, val, ...) do { \ + if ((cond)) \ + { \ + ERROR_MSG(__VA_ARGS__); \ + return (val); \ + } \ } while (0) #define STRING_BUILD(str) {str, sizeof (str) - 1} @@ -203,12 +215,22 @@ #define TOSTRING(x) STRINGIFY(x) #define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__) +#define UTF8_MAXLEN 6 +#define UTF8_LENGTH(ch) ((unsigned char)ch >= 0xFC ? 6 : \ + ((unsigned char)ch >= 0xF8 ? 5 : \ + ((unsigned char)ch >= 0xF0 ? 4 : \ + ((unsigned char)ch >= 0xE0 ? 3 : \ + ((unsigned char)ch >= 0xC0 ? 2 : 1))))) +#define UTF8_ISCONT(ch) ((unsigned char)ch >= 0x80 && \ + (unsigned char)ch <= 0xBF) + #define MAX(x,y) ((x)>(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y)) /* General configuration variables. */ struct conf { unsigned auto_save; + unsigned auto_gc; unsigned periodic_save; unsigned confirm_quit; unsigned confirm_delete; @@ -217,7 +239,7 @@ struct conf { char *editor; char *pager; char output_datefmt[BUFSIZ]; /* format for displaying date */ - int input_datefmt; /* format for reading date */ + int input_datefmt; /* format for reading date */ }; /* Daemon-related configuration. */ @@ -239,16 +261,13 @@ enum datefmt { DATE_FORMATS }; -#define DATEFMT(datefmt) (datefmt == DATEFMT_MMDDYYYY ? "%m/%d/%Y" : \ - (datefmt == DATEFMT_DDMMYYYY ? "%d/%m/%Y" : \ - (datefmt == DATEFMT_YYYYMMDD ? "%Y/%m/%d" : "%Y-%m-%d"))) +#define DATEFMT(datefmt) (datefmt == DATEFMT_MMDDYYYY ? "%m/%d/%Y" : \ + (datefmt == DATEFMT_DDMMYYYY ? "%d/%m/%Y" : \ + (datefmt == DATEFMT_YYYYMMDD ? "%Y/%m/%d" : "%Y-%m-%d"))) -#define DATEFMT_DESC(datefmt) (datefmt == DATEFMT_MMDDYYYY ? \ - _("mm/dd/yyyy") : \ - (datefmt == DATEFMT_DDMMYYYY ? \ - _("dd/mm/yyyy") : \ - (datefmt == DATEFMT_YYYYMMDD ? \ - _("yyyy/mm/dd") : _("yyyy-mm-dd")))) +#define DATEFMT_DESC(datefmt) (datefmt == DATEFMT_MMDDYYYY ? \ + _("mm/dd/yyyy") : (datefmt == DATEFMT_DDMMYYYY ? _("dd/mm/yyyy") : \ + (datefmt == DATEFMT_YYYYMMDD ? _("yyyy/mm/dd") : _("yyyy-mm-dd")))) struct date { unsigned dd; @@ -263,8 +282,8 @@ struct apoint long dur; /* duration of the appointment in seconds */ #define APOINT_NULL 0x0 -#define APOINT_NOTIFY 0x1 /* Item needs to be notified */ -#define APOINT_NOTIFIED 0x2 /* Item was already notified */ +#define APOINT_NOTIFY 0x1 /* Item needs to be notified */ +#define APOINT_NOTIFIED 0x2 /* Item was already notified */ int state; char *mesg; @@ -395,6 +414,7 @@ enum key { KEY_DEL_ITEM, KEY_EDIT_ITEM, KEY_VIEW_ITEM, + KEY_PIPE_ITEM, KEY_FLAG_ITEM, KEY_REPEAT_ITEM, KEY_EDIT_NOTE, @@ -421,6 +441,13 @@ enum win { NBWINS }; +#define FLAG_CAL (1 << CAL) +#define FLAG_APP (1 << APP) +#define FLAG_TOD (1 << TOD) +#define FLAG_NOT (1 << NOT) +#define FLAG_STA (1 << STA) +#define FLAG_ALL ((1 << NBWINS) - 1) + enum ui_mode { UI_CURSES, UI_CMDLINE, @@ -455,13 +482,14 @@ struct pad { /* Notification bar definition. */ struct nbar { - int show; /* display or hide the notify-bar */ - int cntdwn; /* warn when time left before next app - becomes lesser than cntdwn */ + unsigned show; /* display or hide the notify-bar */ + int cntdwn; /* warn when time left before next app + becomes lesser than cntdwn */ char datefmt[BUFSIZ]; /* format for displaying date */ char timefmt[BUFSIZ]; /* format for displaying time */ - char cmd[BUFSIZ]; /* notification command */ - char *shell; /* user shell to launch notif. cmd */ + char cmd[BUFSIZ]; /* notification command */ + char *shell; /* user shell to launch notif. cmd */ + unsigned notify_all; /* notify all appointments */ pthread_mutex_t mutex; }; @@ -478,7 +506,6 @@ enum item_type { enum eraseflg { ERASE_DONT_FORCE, ERASE_FORCE, - ERASE_FORCE_KEEP_NOTE, ERASE_FORCE_ONLY_NOTE, ERASE_CUT }; @@ -548,20 +575,20 @@ enum save_display { /* apoint.c */ extern llist_ts_t alist_p; -void apoint_free_bkp (enum eraseflg); +void apoint_free_bkp (void); void apoint_llist_init (void); void apoint_llist_free (void); void apoint_hilt_set (int); -void apoint_hilt_decrease (void); -void apoint_hilt_increase (void); +void apoint_hilt_decrease (int); +void apoint_hilt_increase (int); int apoint_hilt (void); struct apoint *apoint_new (char *, char *, long, long, char); void apoint_add (void); -void apoint_delete (struct conf *, unsigned *, unsigned *); +void apoint_delete (unsigned *, unsigned *); int apoint_cut (unsigned *, unsigned *); void apoint_paste (unsigned *, unsigned *, int); unsigned apoint_inday (struct apoint *, long); -void apoint_sec2str (struct apoint *, int, long, char *, char *); +void apoint_sec2str (struct apoint *, long, char *, char *); void apoint_write (struct apoint *, FILE *); struct apoint *apoint_scan (FILE *, struct tm, struct tm, char, char *); struct apoint *apoint_get (long, int); @@ -569,13 +596,12 @@ void apoint_delete_bynum (long, unsigned, enum eraseflg); void apoint_scroll_pad_down (int, int); void apoint_scroll_pad_up (int); struct notify_app *apoint_check_next (struct notify_app *, long); -struct apoint *apoint_recur_s2apoint_s (struct recur_apoint *); void apoint_switch_notify (void); void apoint_update_panel (int); void apoint_paste_item (void); /* args.c */ -int parse_args (int, char **, struct conf *); +int parse_args (int, char **); /* calendar.c */ void calendar_view_next (void); @@ -595,16 +621,20 @@ long calendar_get_slctd_day_sec (void); void calendar_update_panel (struct window *); void calendar_goto_today (void); void calendar_change_day (int); -void calendar_move (enum move); +void calendar_move (enum move, int); long calendar_start_of_year (void); long calendar_end_of_year (void); char *calendar_get_pom (time_t); +/* config.c */ + +void config_load (void); +unsigned config_save (void); + /* custom.c */ void custom_init_attr (void); void custom_apply_attr (WINDOW *, int); void custom_remove_attr (WINDOW *, int); -void custom_load_conf (struct conf *, int); void custom_config_bar (void); void custom_layout_config (void); void custom_sidebar_config (void); @@ -612,7 +642,7 @@ void custom_color_config (void); void custom_color_theme_name (char *); void custom_confwin_init (struct window *, char *); void custom_set_swsiz (struct scrollwin *); -void custom_general_config (struct conf *); +void custom_general_config (void); void custom_keys_config (void); /* day.c */ @@ -623,7 +653,7 @@ void day_write_pad (long, int, int, int); void day_popup_item (void); int day_check_if_item (struct date); unsigned day_chk_busy_slices (struct date, int, int *); -void day_edit_item (struct conf *); +void day_edit_item (void); int day_erase_item (long, int, enum eraseflg); int day_cut_item (long, int); int day_paste_item (long, int); @@ -631,6 +661,7 @@ struct day_item *day_get_item (int); int day_item_nb (long, int, int); void day_edit_note (char *); void day_view_note (char *); +void day_pipe_item (void); /* dmon.c */ void dmon_start (int); @@ -638,7 +669,7 @@ void dmon_stop (void); /* event.c */ extern llist_t eventlist; -void event_free_bkp (enum eraseflg); +void event_free_bkp (void); void event_llist_init (void); void event_llist_free (void); struct event *event_new (char *, char *, long, int); @@ -653,15 +684,18 @@ void event_paste_item (void); void help_wins_init (struct scrollwin *, int, int, int, int); void help_screen (void); +/* getstring.c */ +enum getstr getstring (WINDOW *, char *, int, int, int); +int updatestring (WINDOW *, char **, int, int); + /* io.c */ unsigned io_fprintln (const char *, const char *, ...); void io_init (char *, char *); void io_extract_data (char *, const char *, int); -unsigned io_save_conf (struct conf *); unsigned io_save_apts (void); unsigned io_save_todo (void); unsigned io_save_keys (void); -void io_save_cal (struct conf *, enum save_display); +void io_save_cal (enum save_display); void io_load_app (void); void io_load_todo (void); void io_load_keys (char *); @@ -670,19 +704,20 @@ unsigned io_file_exist (char *); void io_check_file (char *, int *); int io_check_data_files (void); void io_startup_screen (unsigned, int); -void io_export_data (enum export_type, struct conf *); +void io_export_data (enum export_type); void io_export_bar (void); -void io_import_data (enum import_type, struct conf *, char *); +void io_import_data (enum import_type, char *); struct io_file *io_log_init (void); void io_log_print (struct io_file *, int, char *); void io_log_display (struct io_file *, char *, char *); void io_log_free (struct io_file *); -void io_start_psave_thread (struct conf *); +void io_start_psave_thread (void); void io_stop_psave_thread (void); void io_set_lock (void); unsigned io_dump_pid (char *); unsigned io_get_pid (char *); int io_file_is_empty (char *); +int io_file_cp (const char *, const char *); /* keys.c */ void keys_init (void); @@ -690,7 +725,7 @@ void keys_free (void); void keys_dump_defaults (char *); char *keys_get_label (enum key); enum key keys_get_action (int); -enum key keys_getch (WINDOW *win); +enum key keys_getch (WINDOW *win, int *); int keys_assign_binding (int, enum key); void keys_remove_binding (int, enum key); int keys_str2int (char *); @@ -738,6 +773,13 @@ void mem_stats (void); #endif /* CALCURSE_MEMORY_DEBUG */ +/* note.c */ +void edit_note (char **, char *); +void view_note (char *, char *); +void erase_note (char **); +void note_read (char *, FILE *); +void note_gc (void); + /* notify.c */ int notify_time_left (void); unsigned notify_needs_reminder (void); @@ -764,8 +806,8 @@ void notify_config_bar (void); /* recur.c */ extern llist_ts_t recur_alist_p; extern llist_t recur_elist; -void recur_event_free_bkp (enum eraseflg); -void recur_apoint_free_bkp (enum eraseflg); +void recur_event_free_bkp (void); +void recur_apoint_free_bkp (void); void recur_apoint_llist_init (void); void recur_apoint_llist_free (void); void recur_event_llist_free (void); @@ -781,15 +823,24 @@ struct recur_apoint *recur_apoint_scan (FILE *, struct tm, struct tm, struct recur_event *recur_event_scan (FILE *, struct tm, int, char, int, struct tm, char *, llist_t *); +void recur_apoint_write (struct recur_apoint *, FILE *); +void recur_event_write (struct recur_event *, FILE *); void recur_save_data (FILE *); -unsigned recur_item_inday (long, llist_t *, int, int, long, long); +unsigned recur_item_find_occurrence (long, long, llist_t *, int, + int, long, long, unsigned *); +unsigned recur_apoint_find_occurrence (struct recur_apoint *, + long, unsigned *); +unsigned recur_event_find_occurrence (struct recur_event *, long, + unsigned *); +unsigned recur_item_inday (long, long, llist_t *, int, int, long, + long); unsigned recur_apoint_inday(struct recur_apoint *, long); unsigned recur_event_inday(struct recur_event *, long); void recur_event_erase (long, unsigned, unsigned, enum eraseflg); void recur_apoint_erase (long, unsigned, unsigned, enum eraseflg); -void recur_repeat_item (struct conf *); +void recur_repeat_item (void); void recur_exc_scan (llist_t *, FILE *); struct notify_app *recur_apoint_check_next (struct notify_app *, long, long); struct recur_apoint *recur_get_apoint (long, int); @@ -805,28 +856,34 @@ unsigned sigs_set_hdlr (int, void (*)(int)); /* todo.c */ extern llist_t todolist; void todo_hilt_set (int); -void todo_hilt_decrease (void); -void todo_hilt_increase (void); +void todo_hilt_decrease (int); +void todo_hilt_increase (int); int todo_hilt (void); int todo_nb (void); void todo_set_nb (int); void todo_set_first (int); -void todo_first_increase (void); -void todo_first_decrease (void); +void todo_first_increase (int); +void todo_first_decrease (int); int todo_hilt_pos (void); char *todo_saved_mesg (void); void todo_new_item (void); struct todo *todo_add (char *, int, char *); +void todo_write (struct todo *, FILE *); void todo_flag (void); -void todo_delete (struct conf *); +void todo_delete (void); void todo_chg_priority (int); void todo_edit_item (void); void todo_update_panel (int); void todo_edit_note (char *); void todo_view_note (char *); +void todo_pipe_item (void); void todo_init_list (void); void todo_free_list (void); +/* utf8.c */ +int utf8_width (char *); +int utf8_strwidth (char *); + /* utils.c */ void exit_calcurse (int) __attribute__((__noreturn__)); void free_user_data (void); @@ -836,9 +893,7 @@ void status_mesg (char *, char *); void erase_window_part (WINDOW *, int, int, int, int); WINDOW *popup (int, int, int, int, char *, char *, int); void print_in_middle (WINDOW *, int, int, int, char *); -enum getstr getstring (WINDOW *, char *, int, int, int); -int updatestring (WINDOW *, char **, int, int); -int is_all_digit (char *); +int is_all_digit (const char *); long get_item_time (long); int get_item_hour (long); int get_item_min (long); @@ -849,7 +904,6 @@ long date_sec_change (long, int, int); long update_time_in_date (long, unsigned, unsigned); long get_sec_date (struct date); long min2sec (unsigned); -int check_time (char *); void draw_scrollbar (WINDOW *, int, int, int, int, int, unsigned); void item_in_popup (char *, char *, char *, char *); long get_today (void); @@ -859,17 +913,29 @@ long mystrtol (const char *); void print_bool_option_incolor (WINDOW *, unsigned, int, int); const char *get_tempdir (void); char *new_tempfile (const char *, int); -void erase_note (char **, enum eraseflg); -int parse_date (char *, enum datefmt, int *, int *, int *, +int parse_date (const char *, enum datefmt, int *, int *, int *, struct date *); +int parse_time (const char *, unsigned *, unsigned *); +int parse_duration (const char *, unsigned *); void str_toupper (char *); void file_close (FILE *, const char *); void psleep (unsigned); +int fork_exec (int *, int *, const char *, char *const *); +int shell_exec (int *, int *, char *); +int child_wait (int *, int *, int); +void press_any_key (void); +void print_apoint (const char *, long, struct apoint *); +void print_event (const char *, long, struct event *); +void print_recur_apoint (const char *, long, unsigned, + struct recur_apoint *); +void print_recur_event (const char *, long, struct recur_event *); +void print_todo (const char *, struct todo *); /* vars.c */ extern int col, row; extern int resize; extern unsigned colorize; +extern int foreground, background; extern enum ui_mode ui_mode; extern int days[12]; extern char *monthnames[12]; @@ -883,10 +949,11 @@ extern char path_notes[BUFSIZ]; extern char path_cpid[BUFSIZ]; extern char path_dpid[BUFSIZ]; extern char path_dmon_log[BUFSIZ]; +extern struct conf conf; extern struct pad apad; extern struct nbar nbar; extern struct dmon_conf dmon; -void vars_init (struct conf *); +void vars_init (void); /* wins.c */ extern struct window win[NBWINS]; @@ -914,11 +981,13 @@ void wins_reinit (void); void wins_reinit_panels (void); void wins_show (WINDOW *, char *); void wins_get_config (void); -void wins_update_border (void); -void wins_update_panels (void); -void wins_update (void); +void wins_update_border (int); +void wins_update_panels (int); +void wins_update (int); void wins_reset (void); -void wins_launch_external (const char *, const char *); +void wins_prepare_external (void); +void wins_unprepare_external (void); +void wins_launch_external (char *, char *); void wins_status_bar (void); void wins_erase_status_bar (void); void wins_other_status_page (int); |