diff options
author | Frederic Culot <calcurse@culot.org> | 2007-07-28 13:11:42 +0000 |
---|---|---|
committer | Frederic Culot <calcurse@culot.org> | 2007-07-28 13:11:42 +0000 |
commit | 4b987f70ac463121f9791eb3493952a77aba495f (patch) | |
tree | 2754295b8dd40b6818ddd80d97a327329de854c0 /src | |
parent | fdc325acd8549acf0fb52c84b8074aef0c2c38c7 (diff) | |
download | calcurse-4b987f70ac463121f9791eb3493952a77aba495f.zip |
unuseful headers removed and some functions became static
Diffstat (limited to 'src')
-rwxr-xr-x | src/apoint.c | 6 | ||||
-rwxr-xr-x | src/apoint.h | 5 | ||||
-rwxr-xr-x | src/args.c | 412 | ||||
-rwxr-xr-x | src/args.h | 16 | ||||
-rwxr-xr-x | src/calcurse.c | 10 | ||||
-rwxr-xr-x | src/calendar.c | 5 | ||||
-rwxr-xr-x | src/calendar.h | 4 | ||||
-rwxr-xr-x | src/custom.c | 216 | ||||
-rwxr-xr-x | src/custom.h | 3 | ||||
-rwxr-xr-x | src/day.c | 399 | ||||
-rwxr-xr-x | src/day.h | 15 | ||||
-rwxr-xr-x | src/event.c | 4 | ||||
-rwxr-xr-x | src/event.h | 10 | ||||
-rwxr-xr-x | src/help.c | 37 | ||||
-rwxr-xr-x | src/help.h | 6 | ||||
-rwxr-xr-x | src/io.c | 23 | ||||
-rwxr-xr-x | src/io.h | 18 | ||||
-rwxr-xr-x | src/notify.c | 69 | ||||
-rwxr-xr-x | src/notify.h | 8 | ||||
-rwxr-xr-x | src/recur.c | 158 | ||||
-rwxr-xr-x | src/recur.h | 11 | ||||
-rwxr-xr-x | src/sigs.c | 6 | ||||
-rwxr-xr-x | src/todo.c | 84 | ||||
-rwxr-xr-x | src/todo.h | 5 | ||||
-rwxr-xr-x | src/utils.c | 145 | ||||
-rwxr-xr-x | src/utils.h | 10 | ||||
-rwxr-xr-x | src/vars.h | 3 | ||||
-rwxr-xr-x | src/wins.c | 54 |
28 files changed, 824 insertions, 918 deletions
diff --git a/src/apoint.c b/src/apoint.c index e7789fd..dd3cbac 100755 --- a/src/apoint.c +++ b/src/apoint.c @@ -1,4 +1,4 @@ -/* $calcurse: apoint.c,v 1.12 2007/07/21 19:35:14 culot Exp $ */ +/* $calcurse: apoint.c,v 1.13 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,7 +24,6 @@ * */ -#include <ncurses.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> @@ -403,7 +402,8 @@ void display_item_date(WINDOW *win, int incolor, apoint_llist_node_t *i, * the appointment panel. This is to help the appointment scroll function * to place beggining of the pad correctly. */ -int get_item_line(int item_nb, int nb_events_inday) +static int +get_item_line(int item_nb, int nb_events_inday) { int separator = 2; int line = 0; diff --git a/src/apoint.h b/src/apoint.h index 69ac520..bcf6483 100755 --- a/src/apoint.h +++ b/src/apoint.h @@ -1,4 +1,4 @@ -/* $calcurse: apoint.h,v 1.7 2007/07/21 19:35:14 culot Exp $ */ +/* $calcurse: apoint.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,8 +27,6 @@ #ifndef CALCURSE_APOINT_H #define CALCURSE_APOINT_H -#include <ncurses.h> - #include "notify.h" #include "recur.h" #include "vars.h" @@ -67,7 +65,6 @@ apoint_llist_node_t *apoint_scan(FILE *, struct tm, struct tm, char); void apoint_delete_bynum(long, unsigned); void display_item_date(WINDOW *, int, apoint_llist_node_t *, int, long, int, int); -int get_item_line(int, int); void scroll_pad_down(int, int, int); void scroll_pad_up(int, int); struct notify_app_s *apoint_check_next(struct notify_app_s *, long); @@ -1,4 +1,4 @@ -/* $calcurse: args.c,v 1.22 2007/07/21 19:34:42 culot Exp $ */ +/* $calcurse: args.c,v 1.23 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,12 +24,9 @@ * */ -#include <ncurses.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> -#include <stdbool.h> #include <sys/types.h> #include <getopt.h> #include <time.h> @@ -40,168 +37,36 @@ #include "args.h" #include "event.h" #include "apoint.h" -#include "recur.h" #include "day.h" #include "todo.h" #include "io.h" -#include "notify.h" /* - * Parse the command-line arguments and call the appropriate - * routines to handle those arguments. Also initialize the data paths. + * Print Calcurse usage and exit. */ -int -parse_args(int argc, char **argv, conf_t *conf) +static void +usage() { - int ch, add_line = 0; - int unknown_flag = 0, app_found = 0; - /* Command-line flags */ - int aflag = 0; /* -a: print appointments for current day */ - int cflag = 0; /* -c: specify the calendar file to use */ - int dflag = 0; /* -d: print appointments for a specified days */ - int hflag = 0; /* -h: print help text */ - int nflag = 0; /* -n: print next appointment */ - int tflag = 0; /* -t: print todo list */ - int vflag = 0; /* -v: print version number */ - int xflag = 0; /* -x: export data to iCalendar format */ - - int tnum = 0; - int non_interactive = 0, multiple_flag = 0, load_data = 0; - int no_file = 1; - char *ddate = "", *cfile = NULL; - - static char *optstr = "hvnaxt::d:c:"; - - struct option longopts[] = { - {"appointment", no_argument, NULL, 'a'}, - {"calendar", required_argument, NULL, 'c'}, - {"day", required_argument, NULL, 'd'}, - {"help", no_argument, NULL, 'h'}, - {"next", no_argument, NULL, 'n'}, - {"todo", optional_argument, NULL, 't'}, - {"version", no_argument, NULL, 'v'}, - {"export", no_argument, NULL, 'x'}, - {NULL, no_argument, NULL, 0} - }; + char *arg_usage = + _("Usage: calcurse [-h|-v] [-x] [-an] [-t[num]] [-d date|num] [-c file]\n"); + + fputs(arg_usage, stdout); +} - while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) { - switch (ch) { - case 'a': - aflag = 1; - multiple_flag++; - load_data++; - break; - case 'c': - cflag = 1; - multiple_flag++; - load_data++; - cfile = optarg; - break; - case 'd': - dflag = 1; - multiple_flag++; - load_data++; - ddate = optarg; - break; - case 'h': - hflag = 1; - break; - case 'n': - nflag = 1; - multiple_flag++; - load_data++; - break; - case 't': - tflag = 1; - multiple_flag++; - load_data++; - add_line = 1; - if (optarg != NULL) { - tnum = atoi(optarg); - if (tnum < 1 || tnum > 9) { - usage(); - usage_try(); - return EXIT_FAILURE; - } - } else - tnum = 0; - break; - case 'v': - vflag = 1; - break; - case 'x': - xflag = 1; - multiple_flag++; - load_data++; - break; - default: - usage(); - usage_try(); - unknown_flag = 1; - non_interactive = 1; - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; +static void +usage_try() +{ + char *arg_usage_try = + _("Try 'calcurse -h' for more information.\n"); - if (argc >= 1) { /* incorrect arguments */ - usage(); - usage_try(); - return EXIT_FAILURE; - } else { - if (unknown_flag) { - non_interactive = 1; - } else if (hflag) { - help_arg(); - non_interactive = 1; - } else if (vflag) { - version_arg(); - non_interactive = 1; - } else if (multiple_flag) { - if (load_data) { - io_init(cfile); - no_file = check_data_files(); - if (dflag || aflag || nflag || xflag) - load_app(); - } - if (xflag) { - notify_init_vars(); - custom_load_conf(conf, 0); - io_export_data(IO_EXPORT_NONINTERACTIVE, conf); - non_interactive = 1; - return (non_interactive); - } - if (tflag) { - todo_arg(tnum); - non_interactive = 1; - } - if (nflag) { - next_arg(); - non_interactive = 1; - } - if (dflag) { - date_arg(ddate, add_line); - non_interactive = 1; - } else if (aflag) { - date_t day; - day.dd = day.mm = day.yyyy = 0; - app_found = app_arg(add_line,day,0); - non_interactive = 1; - } - } else { - non_interactive = 0; - io_init(cfile); - no_file = check_data_files(); - } - return (non_interactive); - } + fputs(arg_usage_try, stdout); } /* * Print Calcurse version with a short copyright text and exit. */ -void version_arg() +static void +version_arg() { char vtitle[BUFSIZ]; char *vtext = @@ -209,7 +74,7 @@ void version_arg() "This is free software; see the source for copying conditions.\n"); snprintf(vtitle, BUFSIZ, - _("Calcurse %s - text-based organizer\n"), VERSION); + _("Calcurse %s - text-based organizer\n"), VERSION); fputs(vtitle, stdout); fputs(vtext, stdout); } @@ -217,7 +82,8 @@ void version_arg() /* * Print the command line options and exit. */ -void help_arg() +static void +help_arg() { char htitle[BUFSIZ]; char *htext = @@ -263,13 +129,14 @@ void help_arg() * Print todo list and exit. If a priority number is given (say not equal to * zero), then only todo items that have this priority will be displayed. */ -void todo_arg(int priority) +static void +todo_arg(int priority) { struct todo_s *i; int nb_tod, title = 1; char priority_str[BUFSIZ] = ""; - nb_tod = load_todo(); + nb_tod = io_load_todo(); for (i = todolist; i != 0; i = i->next) { if (priority == 0 || i->id == priority) { if (title) { @@ -285,7 +152,7 @@ void todo_arg(int priority) } /* Print the next appointment within the upcoming 24 hours. */ -void +static void next_arg(void) { struct notify_app_s *next_app; @@ -312,12 +179,31 @@ next_arg(void) free(next_app); } +/* + * Print the date on stdout. + */ +static void +arg_print_date(long date) +{ + char date_str[BUFSIZ]; + time_t t; + struct tm *lt; + + t = date; + lt = localtime(&t); + snprintf(date_str, BUFSIZ, "%02u/%02u/%04u", + lt->tm_mon+1, lt->tm_mday, 1900+lt->tm_year); + fputs(date_str,stdout); + fputs(":\n",stdout); +} + /* * Print appointments for given day and exit. * If no day is given, the given date is used. * If there is also no date given, current date is considered. */ -int app_arg(int add_line, date_t day, long date) +static int +app_arg(int add_line, date_t day, long date) { struct recur_event_s *re; struct event_s *j; @@ -428,7 +314,8 @@ int app_arg(int add_line, date_t day, long date) * Print appointment for the given date or for the given n upcoming * days. */ -void date_arg(char *ddate, int add_line) +static void +date_arg(char *ddate, int add_line) { int i; date_t day; @@ -486,75 +373,154 @@ void date_arg(char *ddate, int add_line) } } -/* - * Check if the entered date is of a valid format. - * First check the format by itself, and then check the - * numbers correctness. - */ -int -check_date(char *date) -{ - int ok = 0; - char month[3] = ""; - char day[3] = ""; - char year[5] = ""; - if ( - (strlen(date) == 10) & - (isdigit(date[0]) != 0) & - (isdigit(date[1]) != 0) & - (date[2] == '/') & - (isdigit(date[3]) != 0) & - (isdigit(date[4]) != 0) & - (date[5] == '/') & - (isdigit(date[6])!=0) & (isdigit(date[7])!=0) & - (isdigit(date[8])!=0) & (isdigit(date[9])!=0) - ) { - strncpy(month, date, 2); - strncpy(day, date + 3, 2); - strncpy(year, date + 6, 4); - if ( (atoi(month) <= 12) & - (atoi(month) >= 1) & - (atoi(day) <= 31) & - (atoi(day) >= 1) & - (atoi(year) <= 9999) & - (atoi(year) > 1)) - ok = 1; - } - return ok; -} - /* - * Print the date on stdout. + * Parse the command-line arguments and call the appropriate + * routines to handle those arguments. Also initialize the data paths. */ -void arg_print_date(long date) +int +parse_args(int argc, char **argv, conf_t *conf) { - char date_str[BUFSIZ]; - time_t t; - struct tm *lt; + int ch, add_line = 0; + int unknown_flag = 0, app_found = 0; + /* Command-line flags */ + int aflag = 0; /* -a: print appointments for current day */ + int cflag = 0; /* -c: specify the calendar file to use */ + int dflag = 0; /* -d: print appointments for a specified days */ + int hflag = 0; /* -h: print help text */ + int nflag = 0; /* -n: print next appointment */ + int tflag = 0; /* -t: print todo list */ + int vflag = 0; /* -v: print version number */ + int xflag = 0; /* -x: export data to iCalendar format */ + + int tnum = 0; + int non_interactive = 0, multiple_flag = 0, load_data = 0; + int no_file = 1; + char *ddate = "", *cfile = NULL; - t = date; - lt = localtime(&t); - snprintf(date_str, BUFSIZ, "%02u/%02u/%04u", - lt->tm_mon+1, lt->tm_mday, 1900+lt->tm_year); - fputs(date_str,stdout); - fputs(":\n",stdout); -} + static char *optstr = "hvnaxt::d:c:"; -/* - * Print Calcurse usage and exit. - */ -void usage() -{ - char *arg_usage = - _("Usage: calcurse [-h|-v] [-x] [-an] [-t[num]] [-d date|num] [-c file]\n"); - - fputs(arg_usage, stdout); -} + struct option longopts[] = { + {"appointment", no_argument, NULL, 'a'}, + {"calendar", required_argument, NULL, 'c'}, + {"day", required_argument, NULL, 'd'}, + {"help", no_argument, NULL, 'h'}, + {"next", no_argument, NULL, 'n'}, + {"todo", optional_argument, NULL, 't'}, + {"version", no_argument, NULL, 'v'}, + {"export", no_argument, NULL, 'x'}, + {NULL, no_argument, NULL, 0} + }; -void usage_try() -{ - char *arg_usage_try = - _("Try 'calcurse -h' for more information.\n"); + while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) { + switch (ch) { + case 'a': + aflag = 1; + multiple_flag++; + load_data++; + break; + case 'c': + cflag = 1; + multiple_flag++; + load_data++; + cfile = optarg; + break; + case 'd': + dflag = 1; + multiple_flag++; + load_data++; + ddate = optarg; + break; + case 'h': + hflag = 1; + break; + case 'n': + nflag = 1; + multiple_flag++; + load_data++; + break; + case 't': + tflag = 1; + multiple_flag++; + load_data++; + add_line = 1; + if (optarg != NULL) { + tnum = atoi(optarg); + if (tnum < 1 || tnum > 9) { + usage(); + usage_try(); + return EXIT_FAILURE; + } + } else + tnum = 0; + break; + case 'v': + vflag = 1; + break; + case 'x': + xflag = 1; + multiple_flag++; + load_data++; + break; + default: + usage(); + usage_try(); + unknown_flag = 1; + non_interactive = 1; + /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; - fputs(arg_usage_try, stdout); + if (argc >= 1) { /* incorrect arguments */ + usage(); + usage_try(); + return EXIT_FAILURE; + } else { + if (unknown_flag) { + non_interactive = 1; + } else if (hflag) { + help_arg(); + non_interactive = 1; + } else if (vflag) { + version_arg(); + non_interactive = 1; + } else if (multiple_flag) { + if (load_data) { + io_init(cfile); + no_file = io_check_data_files(); + if (dflag || aflag || nflag || xflag) + io_load_app(); + } + if (xflag) { + notify_init_vars(); + custom_load_conf(conf, 0); + io_export_data(IO_EXPORT_NONINTERACTIVE, conf); + non_interactive = 1; + return (non_interactive); + } + if (tflag) { + todo_arg(tnum); + non_interactive = 1; + } + if (nflag) { + next_arg(); + non_interactive = 1; + } + if (dflag) { + date_arg(ddate, add_line); + non_interactive = 1; + } else if (aflag) { + date_t day; + day.dd = day.mm = day.yyyy = 0; + app_found = app_arg(add_line,day,0); + non_interactive = 1; + } + } else { + non_interactive = 0; + io_init(cfile); + no_file = io_check_data_files(); + } + return (non_interactive); + } } @@ -1,4 +1,4 @@ -/* $calcurse: args.h,v 1.7 2007/07/01 17:56:08 culot Exp $ */ +/* $calcurse: args.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,18 +27,6 @@ #ifndef CALCURSE_ARGS_H #define CALCURSE_ARGS_H -#include "vars.h" - -void usage(); -void usage_try(); -int parse_args(int argc, char **argv, conf_t *conf); -void version_arg(); -void help_arg(); -void todo_arg(int priority); -void next_arg(void); -int app_arg(int add_line, date_t day, long date); -void date_arg(char *ddate, int add_line); -int check_date(char *date); -void arg_print_date(long date); +int parse_args(int, char **, conf_t *); #endif /* CALCURSE_ARGS_H */ diff --git a/src/calcurse.c b/src/calcurse.c index 6375395..2b55538 100755 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -1,4 +1,4 @@ -/* $calcurse: calcurse.c,v 1.50 2007/07/26 20:35:58 culot Exp $ */ +/* $calcurse: calcurse.c,v 1.51 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -160,11 +160,11 @@ main(int argc, char **argv) * configuration (the display is then updated), and then * the todo list, appointments and events. */ - no_data_file = check_data_files(); + no_data_file = io_check_data_files(); custom_load_conf(&conf, background); erase_status_bar(); - nb_tod = load_todo(); - load_app(); + nb_tod = io_load_todo(); + io_load_app(); if (notify_bar()) { notify_start_main_thread(); notify_check_next_app(); @@ -175,7 +175,7 @@ main(int argc, char **argv) &win[TODO], &win[CALENDAR], &win[NOTIFY]); wins_update(&conf, &win[STATUS], &win[APPOINTMENT], &win[TODO], hilt_app, hilt_tod, nb_tod, first_todo_onscreen, &saved_t_mesg); - startup_screen(conf.skip_system_dialogs, no_data_file); + io_startup_screen(conf.skip_system_dialogs, no_data_file); inday = *day_process_storage(0, day_changed, &inday); wins_slctd_set(CALENDAR); wins_update(&conf, &win[STATUS], &win[APPOINTMENT], &win[TODO], diff --git a/src/calendar.c b/src/calendar.c index 3869e68..15c511c 100755 --- a/src/calendar.c +++ b/src/calendar.c @@ -1,4 +1,4 @@ -/* $calcurse: calendar.c,v 1.8 2007/07/01 17:48:50 culot Exp $ */ +/* $calcurse: calendar.c,v 1.9 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,13 +24,10 @@ * */ -#include <ncurses.h> -#include <pthread.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> -#include <stdbool.h> #include <time.h> #include "i18n.h" diff --git a/src/calendar.h b/src/calendar.h index b43276a..1d60fe7 100755 --- a/src/calendar.h +++ b/src/calendar.h @@ -1,4 +1,4 @@ -/* $calcurse: calendar.h,v 1.4 2007/07/21 19:39:23 culot Exp $ */ +/* $calcurse: calendar.h,v 1.5 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,8 +27,8 @@ #ifndef CALCURSE_CALENDAR_H #define CALCURSE_CALENDAR_H -#include <stdbool.h> #include <ncurses.h> +#include <stdbool.h> #define CALHEIGHT 12 #define CALWIDTH 30 diff --git a/src/custom.c b/src/custom.c index 3894e41..b6cb812 100755 --- a/src/custom.c +++ b/src/custom.c @@ -1,4 +1,4 @@ -/* $calcurse: custom.c,v 1.14 2007/07/21 19:34:07 culot Exp $ */ +/* $calcurse: custom.c,v 1.15 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,16 +24,12 @@ * */ -#include <ncurses.h> #include <string.h> #include <stdlib.h> -#include <stdio.h> -#include "calendar.h" #include "custom.h" #include "i18n.h" #include "io.h" -#include "wins.h" #include "utils.h" #include "apoint.h" @@ -54,6 +50,111 @@ fill_config_var(char *string) } /* + * Load user color theme from file. + * Need to handle calcurse versions prior to 1.8, where colors where handled + * differently (number between 1 and 8). + */ +static void +custom_load_color(char *color, int background) +{ +#define AWAITED_COLORS 2 + + int i, len, color_num; + char c[AWAITED_COLORS][BUFSIZ]; + int colr[AWAITED_COLORS]; + const char *wrong_color_number = + _("FATAL ERROR in custom_load_color: wrong color number.\n"); + const char *wrong_color_name = + _("FATAL ERROR in custom_load_color: wrong color name.\n"); + const char *wrong_variable_format = + _("FATAL ERROR in custom_load_color: " + "wrong configuration variable format.\n"); + + len = strlen(color); + + if (len > 1) { + /* New version configuration */ + if (sscanf(color, "%s on %s", c[0], c[1]) != AWAITED_COLORS) { + fputs(_("FATAL ERROR in custom_load_color: " + "missing colors in config file.\n"), stderr); + exit(EXIT_FAILURE); + /* NOTREACHED */ + }; + + for (i = 0; i < AWAITED_COLORS; i++) { + if (!strncmp(c[i], "black", 5)) + colr[i] = COLOR_BLACK; + else if (!strncmp(c[i], "red", 3)) + colr[i] = COLOR_RED; + else if (!strncmp(c[i], "green", 5)) + colr[i] = COLOR_GREEN; + else if (!strncmp(c[i], "yellow", 6)) + colr[i] = COLOR_YELLOW; + else if (!strncmp(c[i], "blue", 4)) + colr[i] = COLOR_BLUE; + else if (!strncmp(c[i], "magenta", 7)) + colr[i] = COLOR_MAGENTA; + else if (!strncmp(c[i], "cyan", 4)) + colr[i] = COLOR_CYAN; + else if (!strncmp(c[i], "white", 5)) + colr[i] = COLOR_WHITE; + else if (!strncmp(c[i], "default", 7)) + colr[i] = background; + else { + fputs(wrong_color_name, stderr); + exit(EXIT_FAILURE); + /* NOTREACHED */ + } + } + + init_pair(COLR_CUSTOM, colr[0], colr[1]); + + } else if (len > 0 && len < 2) { + /* Old version configuration */ + color_num = atoi(color); + + switch (color_num) { + case 0: + colorize = false; + break; + case 1: + init_pair(COLR_CUSTOM, COLOR_RED, background); + break; + case 2: + init_pair(COLR_CUSTOM, COLOR_GREEN, background); + break; + case 3: + init_pair(COLR_CUSTOM, COLOR_BLUE, background); + break; + case 4: + init_pair(COLR_CUSTOM, COLOR_CYAN, background); + break; + case 5: + init_pair(COLR_CUSTOM, COLOR_YELLOW, background); + break; + case 6: + init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_GREEN); + break; + case 7: + init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW); + break; + case 8: + init_pair(COLR_CUSTOM, COLOR_RED, COLR_BLUE); + break; + default: + fputs(wrong_color_number, stderr); + exit(EXIT_FAILURE); + /* NOTREACHED */ + } + + } else { + fputs(wrong_variable_format, stderr); + exit(EXIT_FAILURE); + /* NOTREACHED */ + } +} + +/* * Define window attributes (for both color and non-color terminals): * ATTR_HIGHEST are for window titles * ATTR_HIGH are for month and days names @@ -489,111 +590,6 @@ custom_color_config(int notify_bar) } /* - * Load user color theme from file. - * Need to handle calcurse versions prior to 1.8, where colors where handled - * differently (number between 1 and 8). - */ -void -custom_load_color(char *color, int background) -{ -#define AWAITED_COLORS 2 - - int i, len, color_num; - char c[AWAITED_COLORS][BUFSIZ]; - int colr[AWAITED_COLORS]; - const char *wrong_color_number = - _("FATAL ERROR in custom_load_color: wrong color number.\n"); - const char *wrong_color_name = - _("FATAL ERROR in custom_load_color: wrong color name.\n"); - const char *wrong_variable_format = - _("FATAL ERROR in custom_load_color: " - "wrong configuration variable format.\n"); - - len = strlen(color); - - if (len > 1) { - /* New version configuration */ - if (sscanf(color, "%s on %s", c[0], c[1]) != AWAITED_COLORS) { - fputs(_("FATAL ERROR in custom_load_color: " - "missing colors in config file.\n"), stderr); - exit(EXIT_FAILURE); - /* NOTREACHED */ - }; - - for (i = 0; i < AWAITED_COLORS; i++) { - if (!strncmp(c[i], "black", 5)) - colr[i] = COLOR_BLACK; - else if (!strncmp(c[i], "red", 3)) - colr[i] = COLOR_RED; - else if (!strncmp(c[i], "green", 5)) - colr[i] = COLOR_GREEN; - else if (!strncmp(c[i], "yellow", 6)) - colr[i] = COLOR_YELLOW; - else if (!strncmp(c[i], "blue", 4)) - colr[i] = COLOR_BLUE; - else if (!strncmp(c[i], "magenta", 7)) - colr[i] = COLOR_MAGENTA; - else if (!strncmp(c[i], "cyan", 4)) - colr[i] = COLOR_CYAN; - else if (!strncmp(c[i], "white", 5)) - colr[i] = COLOR_WHITE; - else if (!strncmp(c[i], "default", 7)) - colr[i] = background; - else { - fputs(wrong_color_name, stderr); - exit(EXIT_FAILURE); - /* NOTREACHED */ - } - } - - init_pair(COLR_CUSTOM, colr[0], colr[1]); - - } else if (len > 0 && len < 2) { - /* Old version configuration */ - color_num = atoi(color); - - switch (color_num) { - case 0: - colorize = false; - break; - case 1: - init_pair(COLR_CUSTOM, COLOR_RED, background); - break; - case 2: - init_pair(COLR_CUSTOM, COLOR_GREEN, background); - break; - case 3: - init_pair(COLR_CUSTOM, COLOR_BLUE, background); - break; - case 4: - init_pair(COLR_CUSTOM, COLOR_CYAN, background); - break; - case 5: - init_pair(COLR_CUSTOM, COLOR_YELLOW, background); - break; - case 6: - init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_GREEN); - break; - case 7: - init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW); - break; - case 8: - init_pair(COLR_CUSTOM, COLOR_RED, COLR_BLUE); - break; - default: - fputs(wrong_color_number, stderr); - exit(EXIT_FAILURE); - /* NOTREACHED */ - } - - } else { - fputs(wrong_variable_format, stderr); - exit(EXIT_FAILURE); - /* NOTREACHED */ - } -} - -/* * Return a string defining the color theme in the form: * foreground color 'on' background color * in order to dump this data in the configuration file. diff --git a/src/custom.h b/src/custom.h index 07c071f..30e63d8 100755 --- a/src/custom.h +++ b/src/custom.h @@ -1,4 +1,4 @@ -/* $calcurse: custom.h,v 1.7 2007/07/21 19:34:07 culot Exp $ */ +/* $calcurse: custom.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -73,7 +73,6 @@ void custom_load_conf(conf_t *, int); void config_bar(void); int layout_config(int); void custom_color_config(int); -void custom_load_color(char *, int); void custom_color_theme_name(char *); void custom_general_config(conf_t *); @@ -1,4 +1,4 @@ -/* $calcurse: day.c,v 1.24 2007/07/20 19:05:19 culot Exp $ */ +/* $calcurse: day.c,v 1.25 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,105 +24,117 @@ * */ -#include <ncurses.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <ctype.h> -#include <stdbool.h> #include <time.h> #include "i18n.h" #include "utils.h" #include "apoint.h" #include "event.h" -#include "recur.h" #include "day.h" -#include "vars.h" -#include "args.h" -static struct day_item_s *day_items_ptr; -static struct day_saved_item_s *day_saved_item = NULL; +static struct day_item_s *day_items_ptr; +static struct day_saved_item_s *day_saved_item = NULL; - -/* - * Store the events and appointments for the selected day, and write - * those items in a pad. If selected day is null, then store items for current - * day. This is useful to speed up the appointment panel update. - */ -day_items_nb_t * -day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday) +/* Free the current day linked list containing the events and appointments. */ +static void +day_free_list(void) { - long date; - date_t day; - - if (slctd_date) - day = *slctd_date; - else - calendar_store_current_date(&day); - - date = date2sec(day, 0, 0); - - /* Inits */ - if (apad->length != 0) - delwin(apad->ptrwin); - - /* Store the events and appointments (recursive and normal items). */ - apad->length = day_store_items(date, - &inday->nb_events, &inday->nb_apoints); - - /* Create the new pad with its new length. */ - if (day_changed) - apad->first_onscreen = 0; - apad->ptrwin = newpad(apad->length, apad->width); + struct day_item_s *p, *q; - return (inday); + for (p = day_items_ptr; p != 0; p = q) { + q = p->next; + free(p->mesg); + free(p); + } + day_items_ptr = NULL; } -/* - * Store all of the items to be displayed for the selected day. - * Items are of four types: recursive events, normal events, - * recursive appointments and normal appointments. - * The items are stored in the linked list pointed by *day_items_ptr - * and the length of the new pad to write is returned. - * The number of events and appointments in the current day are also updated. - */ -int day_store_items(long date, int *pnb_events, int *pnb_apoints) +/* Add an event in the current day list */ +static struct day_item_s * +day_add_event(int type, char *mesg, long day, int id) { - int pad_length; - int nb_events, nb_recur_events; - int nb_apoints, nb_recur_apoints; - - pad_length = nb_events = nb_apoints = 0; - nb_recur_events = nb_recur_apoints = 0; + struct day_item_s *o, **i; + o = (struct day_item_s *) malloc(sizeof(struct day_item_s)); + o->mesg = (char *) malloc(strlen(mesg) + 1); + strncpy(o->mesg, mesg, strlen(mesg) + 1); + o->type = type; + o->appt_dur = 0; + o->appt_pos = 0; + o->start = day; + o->evnt_id = id; + i = &day_items_ptr; + for (;;) { + if (*i == 0) { + o->next = *i; + *i = o; + break; + } + i = &(*i)->next; + } + return o; +} - if (day_items_ptr != 0) - day_free_list(); - nb_recur_events = day_store_recur_events(date); - nb_events = day_store_events(date); - *pnb_events = nb_events; - nb_recur_apoints = day_store_recur_apoints(date); - nb_apoints = day_store_apoints(date); - *pnb_apoints = nb_apoints; - pad_length = nb_recur_events + nb_events + 1 + - 3*(nb_recur_apoints + nb_apoints); - *pnb_apoints += nb_recur_apoints; - *pnb_events += nb_recur_events; +/* Add an appointment in the current day list. */ +static struct day_item_s * +day_add_apoint(int type, char *mesg, long start, long dur, char state, + int real_pos) +{ + struct day_item_s *o, **i; + int insert_item = 0; - return pad_length; + o = (struct day_item_s *) malloc(sizeof(struct day_item_s)); + o->mesg = (char *) malloc(strlen(mesg) + 1); + strncpy(o->mesg, mesg, strlen(mesg) + 1); + o->start = start; + o->appt_dur = dur; + o->appt_pos = real_pos; + o->state = state; + o->type = type; + o->evnt_id = 0; + i = &day_items_ptr; + for (;;) { + if (*i == 0) { + insert_item = 1; + } else if ( ((*i)->start > start) && + ((*i)->type > EVNT) ) { + insert_item = 1; + } + if (insert_item) { + o->next = *i; + *i = o; + break; + } + i = &(*i)->next; + } + return o; } -/* Free the current day linked list containing the events and appointments. */ -void day_free_list(void) +/* + * Store the events for the selected day in structure pointed + * by day_items_ptr. This is done by copying the events + * from the general structure pointed by eventlist to the structure + * dedicated to the selected day. + * Returns the number of events for the selected day. + */ +static int +day_store_events(long date) { - struct day_item_s *p, *q; + struct event_s *j; + struct day_item_s *ptr; + int e_nb = 0; - for (p = day_items_ptr; p != 0; p = q) { - q = p->next; - free(p->mesg); - free(p); + for (j = eventlist; j != 0; j = j->next) { + if (event_inday(j, date)) { + e_nb++; + ptr = day_add_event(EVNT, j->mesg, j->day, j->id); + } } - day_items_ptr = NULL; + + return e_nb; } /* @@ -132,7 +144,8 @@ void day_free_list(void) * dedicated to the selected day. * Returns the number of recurrent events for the selected day. */ -int day_store_recur_events(long date) +static int +day_store_recur_events(long date) { struct recur_event_s *j; struct day_item_s *ptr; @@ -150,26 +163,30 @@ int day_store_recur_events(long date) } /* - * Store the events for the selected day in structure pointed - * by day_items_ptr. This is done by copying the events - * from the general structure pointed by eventlist to the structure - * dedicated to the selected day. - * Returns the number of events for the selected day. + * Store the apoints for the selected day in structure pointed + * by day_items_ptr. This is done by copying the appointments + * from the general structure pointed by alist_p->root to the + * structure dedicated to the selected day. + * Returns the number of appointments for the selected day. */ -int day_store_events(long date) +static int +day_store_apoints(long date) { - struct event_s *j; + apoint_llist_node_t *j; struct day_item_s *ptr; - int e_nb = 0; + int a_nb = 0; - for (j = eventlist; j != 0; j = j->next) { - if (event_inday(j, date)) { - e_nb++; - ptr = day_add_event(EVNT, j->mesg, j->day, j->id); + pthread_mutex_lock(&(alist_p->mutex)); + for (j = alist_p->root; j != 0; j = j->next) { + if (apoint_inday(j, date)) { + a_nb++; + ptr = day_add_apoint(APPT, j->mesg, j->start, j->dur, + j->state, 0); } } + pthread_mutex_unlock(&(alist_p->mutex)); - return e_nb; + return a_nb; } /* @@ -179,7 +196,8 @@ int day_store_events(long date) * structure dedicated to the selected day. * Returns the number of recurrent appointments for the selected day. */ -int day_store_recur_apoints(long date) +static int +day_store_recur_apoints(long date) { recur_apoint_llist_node_t *j; struct day_item_s *ptr; @@ -203,87 +221,89 @@ int day_store_recur_apoints(long date) } /* - * Store the apoints for the selected day in structure pointed - * by day_items_ptr. This is done by copying the appointments - * from the general structure pointed by alist_p->root to the - * structure dedicated to the selected day. - * Returns the number of appointments for the selected day. + * Store all of the items to be displayed for the selected day. + * Items are of four types: recursive events, normal events, + * recursive appointments and normal appointments. + * The items are stored in the linked list pointed by *day_items_ptr + * and the length of the new pad to write is returned. + * The number of events and appointments in the current day are also updated. */ -int day_store_apoints(long date) +static int +day_store_items(long date, int *pnb_events, int *pnb_apoints) { - apoint_llist_node_t *j; - struct day_item_s *ptr; - int a_nb = 0; + int pad_length; + int nb_events, nb_recur_events; + int nb_apoints, nb_recur_apoints; - pthread_mutex_lock(&(alist_p->mutex)); - for (j = alist_p->root; j != 0; j = j->next) { - if (apoint_inday(j, date)) { - a_nb++; - ptr = day_add_apoint(APPT, j->mesg, j->start, j->dur, - j->state, 0); - } - } - pthread_mutex_unlock(&(alist_p->mutex)); + pad_length = nb_events = nb_apoints = 0; + nb_recur_events = nb_recur_apoints = 0; - return a_nb; + if (day_items_ptr != 0) + day_free_list(); + nb_recur_events = day_store_recur_events(date); + nb_events = day_store_events(date); + *pnb_events = nb_events; + nb_recur_apoints = day_store_recur_apoints(date); + nb_apoints = day_store_apoints(date); + *pnb_apoints = nb_apoints; + pad_length = nb_recur_events + nb_events + 1 + + 3*(nb_recur_apoints + nb_apoints); + *pnb_apoints += nb_recur_apoints; + *pnb_events += nb_recur_events; + + return pad_length; } -/* Add an event in the current day list */ -struct day_item_s *day_add_event(int type, char *mesg, long day, int id) +/* + * Store the events and appointments for the selected day, and write + * those items in a pad. If selected day is null, then store items for current + * day. This is useful to speed up the appointment panel update. + */ +day_items_nb_t * +day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday) { - struct day_item_s *o, **i; - o = (struct day_item_s *) malloc(sizeof(struct day_item_s)); - o->mesg = (char *) malloc(strlen(mesg) + 1); - strncpy(o->mesg, mesg, strlen(mesg) + 1); - o->type = type; - o->appt_dur = 0; - o->appt_pos = 0; - o->start = day; - o->evnt_id = id; - i = &day_items_ptr; - for (;;) { - if (*i == 0) { - o->next = *i; - *i = o; - break; - } - i = &(*i)->next; - } - return o; + long date; + date_t day; + + if (slctd_date) + day = *slctd_date; + else + calendar_store_current_date(&day); + + date = date2sec(day, 0, 0); + + /* Inits */ + if (apad->length != 0) + delwin(apad->ptrwin); + + /* Store the events and appointments (recursive and normal items). */ + apad->length = day_store_items(date, + &inday->nb_events, &inday->nb_apoints); + + /* Create the new pad with its new length. */ + if (day_changed) + apad->first_onscreen = 0; + apad->ptrwin = newpad(apad->length, apad->width); + + return (inday); } -/* Add an appointment in the current day list. */ -struct day_item_s *day_add_apoint(int type, char *mesg, long start, long dur, - char state, int real_pos) +/* + * Returns a structure of type apoint_llist_node_t given a structure of type + * day_item_s + */ +static apoint_llist_node_t * +day_item_s2apoint_s(struct day_item_s *p) { - struct day_item_s *o, **i; - int insert_item = 0; + apoint_llist_node_t *a; - o = (struct day_item_s *) malloc(sizeof(struct day_item_s)); - o->mesg = (char *) malloc(strlen(mesg) + 1); - strncpy(o->mesg, mesg, strlen(mesg) + 1); - o->start = start; - o->appt_dur = dur; - o->appt_pos = real_pos; - o->state = state; - o->type = type; - o->evnt_id = 0; - i = &day_items_ptr; - for (;;) { - if (*i == 0) { - insert_item = 1; - } else if ( ((*i)->start > start) && - ((*i)->type > EVNT) ) { - insert_item = 1; - } - if (insert_item) { - o->next = *i; - *i = o; - break; - } - i = &(*i)->next; - } - return o; + a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t)); + a->mesg = (char *) malloc(strlen(p->mesg) + 1); + a->state = p->state; + a->start = p->start; + a->dur = p->appt_dur; + a->mesg = p->mesg; + return a; } /* @@ -355,23 +375,6 @@ day_write_pad(long date, int width, int length, int incolor) } } -/* - * Returns a structure of type apoint_llist_node_t given a structure of type - * day_item_s - */ -apoint_llist_node_t *day_item_s2apoint_s(struct day_item_s *p) -{ - apoint_llist_node_t *a; - - a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t)); - a->mesg = (char *) malloc(strlen(p->mesg) + 1); - a->state = p->state; - a->start = p->start; - a->dur = p->appt_dur; - a->mesg = p->mesg; - return a; -} - /* Display an item inside a popup window. */ void day_popup_item(void) { @@ -431,6 +434,27 @@ void day_popup_item(void) return 0; } +/* Request the user to enter a new time. */ +static char * +day_edit_time(long time) { + char *timestr; + char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : "); + char *enter_str = _("Press [Enter] to continue"); + char *fmt_msg = + _("You entered an invalid time, should be [h:mm] or [hh:mm]"); + + while (1) { + status_mesg(msg_time, ""); + timestr = date_sec2hour_str(time); + updatestring(swin, ×tr, 0, 1); + if (check_time(timestr) != 1 || strlen(timestr) == 0) { + status_mesg(fmt_msg, enter_str); + wgetch(swin); + } else + return timestr; + } +} + /* Edit an already existing item. */ void day_edit_item(int item_num) @@ -644,27 +668,6 @@ day_edit_item(int item_num) } } -/* Request the user to enter a new time. */ -char * -day_edit_time(long time) { - char *timestr; - char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : "); - char *enter_str = _("Press [Enter] to continue"); - char *fmt_msg = - _("You entered an invalid time, should be [h:mm] or [hh:mm]"); - - while (1) { - status_mesg(msg_time, ""); - timestr = date_sec2hour_str(time); - updatestring(swin, ×tr, 0, 1); - if (check_time(timestr) != 1 || strlen(timestr) == 0) { - status_mesg(fmt_msg, enter_str); - wgetch(swin); - } else - return timestr; - } -} - /* * In order to erase an item, we need to count first the number of * items for each type (in order: recurrent events, events, @@ -1,4 +1,4 @@ -/* $calcurse: day.h,v 1.13 2007/07/20 19:07:02 culot Exp $ */ +/* $calcurse: day.h,v 1.14 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,10 +27,7 @@ #ifndef CALCURSE_DAY_H #define CALCURSE_DAY_H -#include <stdio.h> - #include "calendar.h" -#include "apoint.h" #define MAX_TYPES 4 @@ -64,20 +61,10 @@ struct day_saved_item_s { }; day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *); -int day_store_items(long, int *, int *); -void day_free_list(void); -int day_store_recur_events(long); -int day_store_events(long); -int day_store_recur_apoints(long); -int day_store_apoints(long); -struct day_item_s *day_add_event(int, char *, long, int); -struct day_item_s *day_add_apoint(int, char *, long, long, char, int); void day_write_pad(long, int, int, int); -apoint_llist_node_t *day_item_s2apoint_s(struct day_item_s *); void day_popup_item(void); int day_check_if_item(date_t); void day_edit_item(int); -char *day_edit_time(long); int day_erase_item(long, int, int); struct day_item_s *day_get_item(int); int day_item_nb(long, int, int); diff --git a/src/event.c b/src/event.c index 95573ab..6aca296 100755 --- a/src/event.c +++ b/src/event.c @@ -1,4 +1,4 @@ -/* $calcurse: event.c,v 1.3 2007/04/04 19:37:14 culot Exp $ */ +/* $calcurse: event.c,v 1.4 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,7 +24,6 @@ * */ -#include <ncurses.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> @@ -33,7 +32,6 @@ #include "vars.h" #include "i18n.h" #include "event.h" -#include "utils.h" struct event_s *eventlist; diff --git a/src/event.h b/src/event.h index 6e06691..3b2e794 100755 --- a/src/event.h +++ b/src/event.h @@ -1,4 +1,4 @@ -/* $calcurse: event.h,v 1.1 2006/07/31 21:00:03 culot Exp $ */ +/* $calcurse: event.h,v 1.2 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -40,9 +40,9 @@ struct event_s { extern struct event_s *eventlist; struct event_s *event_new(char *, long, int); -unsigned event_inday(struct event_s *o, long start); -void event_write(struct event_s *o, FILE * f); -struct event_s *event_scan(FILE * f, struct tm start, int id); -void event_delete_bynum(long start, unsigned num); +unsigned event_inday(struct event_s *, long); +void event_write(struct event_s *, FILE *); +struct event_s *event_scan(FILE *, struct tm, int); +void event_delete_bynum(long, unsigned); #endif /* CALCURSE_EVENT_H */ @@ -1,4 +1,4 @@ -/* $calcurse: help.c,v 1.18 2007/07/23 19:29:34 culot Exp $ */ +/* $calcurse: help.c,v 1.19 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,28 +24,35 @@ * */ -#include <ncurses.h> #include <stdlib.h> -#include <stdio.h> #include <string.h> -#include <stdbool.h> #include <ctype.h> #include <sys/types.h> #include "i18n.h" #include "help.h" #include "custom.h" -#include "vars.h" #include "utils.h" -#include "apoint.h" #include "notify.h" -#include "wins.h" + +/* Returns the number of lines in an help text. */ +static int +get_help_lines(char *text) +{ + int i; + int nl = 0; + + for (i = 0; text[i]; i++) { + if (text[i] == '\n') nl++; + } + return nl + 1; +} /* * Write the desired help text inside the help pad, and return the number * of lines that were written. - * */ -int + */ +static int write_help_pad(WINDOW *win, char *title, char *text, int pad_width) { int nl_title = 0; @@ -61,18 +68,6 @@ write_help_pad(WINDOW *win, char *title, char *text, int pad_width) return nl_text + nl_title; } -int -get_help_lines(char *text) -{ - int i; - int nl = 0; - - for (i = 0; text[i]; i++) { - if (text[i] == '\n') nl++; - } - return nl + 1; -} - /* Draws the help screen */ void help_screen(void) @@ -1,4 +1,4 @@ -/* $calcurse: help.h,v 1.3 2007/07/23 19:29:34 culot Exp $ */ +/* $calcurse: help.h,v 1.4 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,15 +27,11 @@ #ifndef CALCURSE_HELP_H #define CALCURSE_HELP_H -#include <ncurses.h> - typedef struct { char *title; char *text; } help_page_t; -int write_help_pad(WINDOW *, char *, char *, int); -int get_help_lines(char *); void help_screen(void); #endif /* CALCURSE_HELP_H */ @@ -1,4 +1,4 @@ -/* $calcurse: io.c,v 1.17 2007/07/01 17:57:57 culot Exp $ */ +/* $calcurse: io.c,v 1.18 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,13 +24,8 @@ * */ -#include <ncurses.h> -#include <pthread.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdbool.h> -#include <sys/types.h> #include <sys/stat.h> #include <time.h> #include <math.h> @@ -42,9 +37,7 @@ #include "todo.h" #include "event.h" #include "apoint.h" -#include "recur.h" #include "io.h" -#include "calendar.h" typedef enum { PROGRESS_BAR_SAVE, @@ -548,7 +541,7 @@ io_save_cal(conf_t *conf) * recursive item (which can also be either an event or an appointment). */ void -load_app(void) +io_load_app(void) { FILE *data_file; int c, is_appointment, is_event, is_recursive; @@ -559,7 +552,7 @@ load_app(void) int freq; char type, state; char *error = - _("FATAL ERROR in load_app: wrong format in the appointment or event\n"); + _("FATAL ERROR in io_load_app: wrong format in the appointment or event\n"); t = time(NULL); lt = localtime(&t); @@ -578,7 +571,7 @@ load_app(void) */ if (fscanf(data_file, "%u / %u / %u ", &start.tm_mon, &start.tm_mday, &start.tm_year) != 3) { - fputs(_("FATAL ERROR in load_app: " + fputs(_("FATAL ERROR in io_load_app: " "syntax error in the item date\n"), stderr); exit(EXIT_FAILURE); } @@ -593,7 +586,7 @@ load_app(void) else if (c == '[') is_event = 1; else { - fputs(_("FATAL ERROR in load_app: " + fputs(_("FATAL ERROR in io_load_app: " "no event nor appointment found\n"), stderr); exit(EXIT_FAILURE); } @@ -689,7 +682,7 @@ load_app(void) /* Load the todo data */ int -load_todo(void) +io_load_todo(void) { FILE *data_file; char *mesg_line1 = _("Failed to open todo file"); @@ -729,7 +722,7 @@ load_todo(void) /* Checks if data files exist. If not, create them */ int -check_data_files(void) +io_check_data_files(void) { FILE *data_file; int no_data_file; @@ -775,7 +768,7 @@ check_data_files(void) /* Draw the startup screen */ void -startup_screen(bool skip_dialogs, int no_data_file) +io_startup_screen(bool skip_dialogs, int no_data_file) { char *welcome_mesg = _("Welcome to Calcurse. Missing data files were created."); @@ -1,4 +1,4 @@ -/* $calcurse: io.h,v 1.6 2007/05/06 13:32:42 culot Exp $ */ +/* $calcurse: io.h,v 1.7 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -35,13 +35,13 @@ typedef enum { IO_EXPORT_NBMODES } export_mode_t; -void io_init(char *cfile); -void io_extract_data(char *dst_data, const char *org, int len); -void io_save_cal(conf_t *conf); -void load_app(void); -int load_todo(void); -int check_data_files(void); -void startup_screen(bool skip_dialogs, int no_data_file); -void io_export_data(export_mode_t mode, conf_t *conf); +void io_init(char *); +void io_extract_data(char *, const char *, int); +void io_save_cal(conf_t *); +void io_load_app(void); +int io_load_todo(void); +int io_check_data_files(void); +void io_startup_screen(bool, int); +void io_export_data(export_mode_t, conf_t *); #endif /* CALCURSE_IO_H */ diff --git a/src/notify.c b/src/notify.c index 1d7fb42..e69317e 100755 --- a/src/notify.c +++ b/src/notify.c @@ -1,4 +1,4 @@ -/* $calcurse: notify.c,v 1.15 2007/07/21 19:36:45 culot Exp $ */ +/* $calcurse: notify.c,v 1.16 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,22 +24,15 @@ * */ -#include <ncurses.h> -#include <pthread.h> #include <time.h> #include <stdlib.h> -#include <stdio.h> #include <string.h> #include <unistd.h> #include "i18n.h" #include "utils.h" #include "custom.h" -#include "vars.h" -#include "apoint.h" #include "notify.h" -#include "recur.h" -#include "wins.h" static struct notify_vars_s *notify = NULL; static struct notify_app_s *notify_app = NULL; @@ -78,6 +71,14 @@ notify_init_vars(void) nbar->shell = "/bin/sh"; } +/* Extract the appointment file name from the complete file path. */ +static void +extract_aptsfile(void) +{ + notify->apts_file = strrchr(path_apts, '/'); + notify->apts_file++; +} + /* * Create the notification bar, by initializing all the variables and * creating the notification window (l is the number of lines, c the @@ -93,7 +94,7 @@ notify_init_bar(window_t *win) pthread_mutex_init(¬ify_app->mutex, NULL); notify_app->got_app = 0; notify->win = newwin(win->h, win->w, win->y, win->x); - notify_extract_aptsfile(); + extract_aptsfile(); } /* Stop the notify-bar main thread. */ @@ -115,6 +116,26 @@ notify_reinit_bar(int l, int c, int y, int x) notify->win = newwin(l, c, y, x); } +/* Launch user defined command as a notification. */ +static void +launch_cmd(char *cmd, char *shell) +{ + int pid; + + pid = fork(); + + if (pid < 0) { + fputs(_("FATAL ERROR in launch_cmd: could not fork\n"), + stderr); + exit(EXIT_FAILURE); + } else if (pid == 0) { /* Child: launch user defined command */ + if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0) + fputs(_("FATAL ERROR in launch_cmd: could not " + "launch user command\n"), stderr); + exit(EXIT_FAILURE); + } +} + /* * Update the notification bar. This is useful when changing color theme * for example. @@ -180,7 +201,7 @@ notify_update_bar(void) if (blinking && !(notify_app->state & APOINT_NOTIFIED)) { notify_app->state |= APOINT_NOTIFIED; - notify_launch_cmd(nbar->cmd, nbar->shell); + launch_cmd(nbar->cmd, nbar->shell); } pthread_mutex_unlock(&nbar->mutex); } else { @@ -200,14 +221,6 @@ notify_update_bar(void) pthread_mutex_unlock(¬ify->mutex); } -/* Extract the appointment file name from the complete file path. */ -void -notify_extract_aptsfile(void) -{ - notify->apts_file = strrchr(path_apts, '/'); - notify->apts_file++; -} - /* Update the notication bar content */ static void * notify_main_thread(void *arg) @@ -380,26 +393,6 @@ notify_same_recur_item(recur_apoint_llist_node_t *i) return same; } -/* Launch user defined command as a notification. */ -void -notify_launch_cmd(char *cmd, char *shell) -{ - int pid; - - pid = fork(); - - if (pid < 0) { - fputs(_("FATAL ERROR in notify_launch_cmd: could not fork\n"), - stderr); - exit(EXIT_FAILURE); - } else if (pid == 0) { /* Child: launch user defined command */ - if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0) - fputs(_("FATAL ERROR in notify_launch_cmd: could not " - "launch user command\n"), stderr); - exit(EXIT_FAILURE); - } -} - /* Launch the notify-bar main thread. */ void notify_start_main_thread(void) diff --git a/src/notify.h b/src/notify.h index c1fe957..85ae733 100755 --- a/src/notify.h +++ b/src/notify.h @@ -1,4 +1,4 @@ -/* $calcurse: notify.h,v 1.10 2007/07/23 19:30:04 culot Exp $ */ +/* $calcurse: notify.h,v 1.11 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,9 +27,6 @@ #ifndef CALCURSE_NOTIFY_H #define CALCURSE_NOTIFY_H -#include <ncurses.h> -#include <pthread.h> - #include "wins.h" #include "apoint.h" #include "recur.h" @@ -60,14 +57,11 @@ void notify_start_main_thread(void); void notify_stop_main_thread(void); void notify_reinit_bar(int, int, int, int); void notify_update_bar(void); -void notify_extract_aptsfile(void); void notify_check_next_app(void); void notify_check_added(char *, long, char); void notify_check_repeated(recur_apoint_llist_node_t *); int notify_same_item(long); int notify_same_recur_item(recur_apoint_llist_node_t *); -void notify_launch_cmd(char *, char *); -void notify_catch_children(void); void notify_config_bar(void); #endif /* CALCURSE_NOTIFY_H */ diff --git a/src/recur.c b/src/recur.c index d30d760..52bc44d 100755 --- a/src/recur.c +++ b/src/recur.c @@ -1,4 +1,4 @@ -/* $calcurse: recur.c,v 1.26 2007/07/01 17:53:42 culot Exp $ */ +/* $calcurse: recur.c,v 1.27 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,9 +24,7 @@ * */ -#include <ncurses.h> #include <stdlib.h> -#include <stdio.h> #include <string.h> #include <ctype.h> #include <sys/types.h> @@ -34,13 +32,9 @@ #include "i18n.h" #include "utils.h" -#include "apoint.h" -#include "event.h" -#include "recur.h" #include "notify.h" -#include "args.h" #include "day.h" -#include "vars.h" +#include "recur.h" recur_apoint_llist_t *recur_alist_p; struct recur_event_s *recur_elist; @@ -170,7 +164,8 @@ int recur_char2def(char type){ } /* Write days for which recurrent items should not be repeated. */ -void recur_write_exc(struct days_s *exc, FILE *f) { +static void +recur_write_exc(struct days_s *exc, FILE *f) { struct tm *lt; time_t t; int st_mon, st_day, st_year; @@ -186,78 +181,6 @@ void recur_write_exc(struct days_s *exc, FILE *f) { } } -/* Writting of a recursive appointment into file. */ -void -recur_apoint_write(recur_apoint_llist_node_t *o, FILE *f) -{ - struct tm *lt; - time_t t; - - t = o->start; - lt = localtime(&t); - fprintf(f, "%02u/%02u/%04u @ %02u:%02u", - lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, - lt->tm_hour, lt->tm_min); - - t = o->start + o->dur; - lt = localtime(&t); - fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u", - lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, - lt->tm_hour, lt->tm_min); - - t = o->rpt->until; - if (t == 0) { /* We have an endless recurrent appointment. */ - fprintf(f, " {%d%c", o->rpt->freq, - recur_def2char(o->rpt->type)); - } else { - lt = localtime(&t); - fprintf(f, " {%d%c -> %02u/%02u/%04u", - o->rpt->freq, recur_def2char(o->rpt->type), - lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year); - } - if (o->exc != 0) - recur_write_exc(o->exc, f); - if (o->state & APOINT_NOTIFY) - fprintf(f, "} !"); - else - fprintf(f, "} |"); - fprintf(f, "%s\n", o->mesg); -} - -/* Writting of a recursive event into file. */ -void recur_event_write(struct recur_event_s *o, FILE *f) -{ - struct tm *lt; - time_t t; - int st_mon, st_day, st_year; - int end_mon, end_day, end_year; - - t = o->day; - lt = localtime(&t); - st_mon = lt->tm_mon + 1; - st_day = lt->tm_mday; - st_year = lt->tm_year + 1900; - t = o->rpt->until; - if (t == 0) { /* We have an endless recurrent event. */ - fprintf(f, "%02u/%02u/%04u [%d] {%d%c", - st_mon, st_day, st_year, o->id, o->rpt->freq, - recur_def2char(o->rpt->type)); - if (o->exc != 0) recur_write_exc(o->exc, f); - fprintf(f,"} %s\n", o->mesg); - } else { - lt = localtime(&t); - end_mon = lt->tm_mon + 1; - end_day = lt->tm_mday; - end_year = lt->tm_year + 1900; - fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u", - st_mon, st_day, st_year, o->id, - o->rpt->freq, recur_def2char(o->rpt->type), - end_mon, end_day, end_year); - if (o->exc != 0) recur_write_exc(o->exc, f); - fprintf(f, "} %s\n", o->mesg); - } -} - /* Load the recursive appointment description */ recur_apoint_llist_node_t * recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type, @@ -348,6 +271,79 @@ struct recur_event_s *recur_event_scan(FILE * f, struct tm start, int id, freq, tuntil, exc); } +/* Writting of a recursive appointment into file. */ +static void +recur_apoint_write(recur_apoint_llist_node_t *o, FILE *f) +{ + struct tm *lt; + time_t t; + + t = o->start; + lt = localtime(&t); + fprintf(f, "%02u/%02u/%04u @ %02u:%02u", + lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, + lt->tm_hour, lt->tm_min); + + t = o->start + o->dur; + lt = localtime(&t); + fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u", + lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, + lt->tm_hour, lt->tm_min); + + t = o->rpt->until; + if (t == 0) { /* We have an endless recurrent appointment. */ + fprintf(f, " {%d%c", o->rpt->freq, + recur_def2char(o->rpt->type)); + } else { + lt = localtime(&t); + fprintf(f, " {%d%c -> %02u/%02u/%04u", + o->rpt->freq, recur_def2char(o->rpt->type), + lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year); + } + if (o->exc != 0) + recur_write_exc(o->exc, f); + if (o->state & APOINT_NOTIFY) + fprintf(f, "} !"); + else + fprintf(f, "} |"); + fprintf(f, "%s\n", o->mesg); +} + +/* Writting of a recursive event into file. */ +static void +recur_event_write(struct recur_event_s *o, FILE *f) +{ + struct tm *lt; + time_t t; + int st_mon, st_day, st_year; + int end_mon, end_day, end_year; + + t = o->day; + lt = localtime(&t); + st_mon = lt->tm_mon + 1; + st_day = lt->tm_mday; + st_year = lt->tm_year + 1900; + t = o->rpt->until; + if (t == 0) { /* We have an endless recurrent event. */ + fprintf(f, "%02u/%02u/%04u [%d] {%d%c", + st_mon, st_day, st_year, o->id, o->rpt->freq, + recur_def2char(o->rpt->type)); + if (o->exc != 0) recur_write_exc(o->exc, f); + fprintf(f,"} %s\n", o->mesg); + } else { + lt = localtime(&t); + end_mon = lt->tm_mon + 1; + end_day = lt->tm_mday; + end_year = lt->tm_year + 1900; + fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u", + st_mon, st_day, st_year, o->id, + o->rpt->freq, recur_def2char(o->rpt->type), + end_mon, end_day, end_year); + if (o->exc != 0) recur_write_exc(o->exc, f); + fprintf(f, "} %s\n", o->mesg); + } +} + /* Write recursive items to file. */ void recur_save_data(FILE *f) { diff --git a/src/recur.h b/src/recur.h index aca1b3d..a582ca5 100755 --- a/src/recur.h +++ b/src/recur.h @@ -1,4 +1,4 @@ -/* $calcurse: recur.h,v 1.12 2007/07/01 17:53:42 culot Exp $ */ +/* $calcurse: recur.h,v 1.13 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,10 +27,6 @@ #ifndef CALCURSE_RECUR_H #define CALCURSE_RECUR_H -#include "apoint.h" -#include "notify.h" -#include "vars.h" - typedef enum { RECUR_NO, RECUR_DAILY, RECUR_WEEKLY, @@ -84,11 +80,6 @@ struct recur_event_s *recur_event_new(char *, long, int, int, int, long, struct days_s *); char recur_def2char(int); int recur_char2def(char); -void recur_write_exc(struct days_s *, FILE *); -void recur_apoint_write(recur_apoint_llist_node_t *, - FILE *); -void recur_event_write(struct recur_event_s *, - FILE *); recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm, char, int, struct tm, struct days_s *, char); @@ -1,4 +1,4 @@ -/* $Id: sigs.c,v 1.1 2007/07/23 19:31:12 culot Exp $ */ +/* $Id: sigs.c,v 1.2 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -26,14 +26,10 @@ #include <sys/types.h> #include <sys/wait.h> -#include <ncurses.h> #include <stdlib.h> -#include <stdio.h> #include <signal.h> #include "i18n.h" -#include "utils.h" -#include "wins.h" #include "vars.h" /* @@ -1,4 +1,4 @@ -/* $calcurse: todo.c,v 1.12 2007/07/21 19:35:40 culot Exp $ */ +/* $calcurse: todo.c,v 1.13 2007/07/28 13:11:42 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,11 +24,9 @@ * */ -#include <stdio.h> #include <stdlib.h> #include <string.h> -#include "vars.h" #include "utils.h" #include "i18n.h" #include "todo.h" @@ -80,6 +78,30 @@ todo_add(char *mesg, int id) return o; } +/* Delete an item from the todo linked list. */ +static void +todo_delete_bynum(unsigned num) +{ + unsigned n; + struct todo_s *i, **iptr; + + n = 0; + iptr = &todolist; + for (i = todolist; i != 0; i = i->next) { + if (n == num) { + *iptr = i->next; + free(i->mesg); + free(i); + return; + } + iptr = &i->next; + n++; + } + /* NOTREACHED */ + fputs(_("FATAL ERROR in todo_delete_bynum: no such todo\n"), stderr); + exit(EXIT_FAILURE); +} + /* Delete an item from the ToDo list. */ void todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod) @@ -112,51 +134,11 @@ todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod) } } - - -/* Delete an item from the todo linked list. */ -void -todo_delete_bynum(unsigned num) -{ - unsigned n; - struct todo_s *i, **iptr; - - n = 0; - iptr = &todolist; - for (i = todolist; i != 0; i = i->next) { - if (n == num) { - *iptr = i->next; - free(i->mesg); - free(i); - return; - } - iptr = &i->next; - n++; - } - /* NOTREACHED */ - fputs(_("FATAL ERROR in todo_delete_bynum: no such todo\n"), stderr); - exit(EXIT_FAILURE); -} - -/* Returns a structure containing the selected item. */ -struct todo_s * -todo_get_item(int item_number) -{ - struct todo_s *o; - int i; - - o = todolist; - for (i = 1; i < item_number; i++) { - o = o->next; - } - return o; -} - /* * Returns the position into the linked list corresponding to the * given todo_s item. */ -int +static int todo_get_position(struct todo_s *i) { struct todo_s *o; @@ -178,6 +160,20 @@ todo_get_position(struct todo_s *i) } } +/* Returns a structure containing the selected item. */ +static struct todo_s * +todo_get_item(int item_number) +{ + struct todo_s *o; + int i; + + o = todolist; + for (i = 1; i < item_number; i++) { + o = o->next; + } + return o; +} + /* Change an item priority by pressing '+' or '-' inside TODO panel. */ int todo_chg_priority(int action, int item_num) @@ -1,4 +1,4 @@ -/* $calcurse: todo.h,v 1.7 2007/07/23 19:30:17 culot Exp $ */ +/* $calcurse: todo.h,v 1.8 2007/07/28 13:11:43 culot Exp $ */ /* * Calcurse - text-based organizer @@ -40,9 +40,6 @@ extern struct todo_s *todolist; int todo_new_item(int); struct todo_s *todo_add(char *, int); void todo_delete(conf_t *, int *, int *); -void todo_delete_bynum(unsigned); -struct todo_s *todo_get_item(int); -int todo_get_position(struct todo_s *); int todo_chg_priority(int, int); void todo_edit_item(int); void todo_update_panel(window_t *, int, int, int, int, char **); diff --git a/src/utils.c b/src/utils.c index ed620fd..07a6175 100755 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,4 @@ -/* $calcurse: utils.c,v 1.32 2007/07/23 19:26:38 culot Exp $ */ +/* $calcurse: utils.c,v 1.33 2007/07/28 13:11:43 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,21 +24,17 @@ * */ -#include <ncurses.h> #include <time.h> #include <string.h> #include <stdlib.h> -#include <stdio.h> #include <ctype.h> -#include <stdbool.h> #include <sys/types.h> #include <math.h> #include "i18n.h" -#include "utils.h" #include "wins.h" #include "custom.h" -#include "vars.h" +#include "utils.h" static unsigned status_page; @@ -135,34 +131,13 @@ print_in_middle(WINDOW * win, int starty, int startx, int width, char *string) custom_remove_attr(win, ATTR_HIGHEST); } -/* Delete a character at the given position in string. */ -void del_char(int pos, char *str) -{ - int len; - - str += pos; - len = strlen(str) + 1; - memmove(str, str + 1, len); -} - -/* Add a character at the given position in string. */ -char *add_char(int pos, int ch, char *str) -{ - int len; - - str += pos; - len = strlen(str) + 1; - memmove(str + 1, str, len); - *str = ch; - return (str += len); -} - /* * Draw the cursor at the correct position in string. * As echoing is not set, we need to know the string we are working on to * handle display correctly. */ -void showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset) +static void +showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset) { char *nc; @@ -172,7 +147,8 @@ void showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset) } /* Print the string at the desired position. */ -void showstring(WINDOW *win, int y, int x, char *str, int len, int pos) +static void +showstring(WINDOW *win, int y, int x, char *str, int len, int pos) { const int rec = 30, border = 3; const int max_col = col - border, max_len = max_col - rec; @@ -198,6 +174,30 @@ void showstring(WINDOW *win, int y, int x, char *str, int len, int pos) showcursor(win, y, pos, orig, len, offset); } +/* Delete a character at the given position in string. */ +static void +del_char(int pos, char *str) +{ + int len; + + str += pos; + len = strlen(str) + 1; + memmove(str, str + 1, len); +} + +/* Add a character at the given position in string. */ +static char * +add_char(int pos, int ch, char *str) +{ + int len; + + str += pos; + len = strlen(str) + 1; + memmove(str + 1, str, len); + *str = ch; + return (str += len); +} + /* * Getstring allows to get user input and to print it on a window, * even if noecho() is on. This function is also used to modify an existing @@ -338,54 +338,6 @@ int is_all_digit(char *string) return all_digit; } -/* draw panel border in color */ -void -border_color(WINDOW *window) -{ - int color_attr = A_BOLD; - int no_color_attr = A_BOLD; - - if (colorize) { - wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); - box(window, 0, 0); - } else { - wattron(window, no_color_attr); - box(window, 0, 0); - } - - if (colorize) { - wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); - } else { - wattroff(window, no_color_attr); - } - - wnoutrefresh(window); -} - -/* draw panel border without any color */ -void -border_nocolor(WINDOW *window) -{ - int color_attr = A_BOLD; - int no_color_attr = A_DIM; - - if (colorize) { - wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); - } else { - wattron(window, no_color_attr); - } - - box(window, 0, 0); - - if (colorize) { - wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); - } else { - wattroff(window, no_color_attr); - } - - wnoutrefresh(window); -} - /* * Draws the status bar. * To add a keybinding, insert a new binding_t item, add it in the *binding @@ -617,6 +569,43 @@ get_sec_date(date_t date) return long_date; } +/* + * Check if the entered date is of a valid format. + * First check the format by itself, and then check the + * numbers correctness. + */ +int +check_date(char *date) +{ + int ok = 0; + char month[3] = ""; + char day[3] = ""; + char year[5] = ""; + if ( + (strlen(date) == 10) & + (isdigit(date[0]) != 0) & + (isdigit(date[1]) != 0) & + (date[2] == '/') & + (isdigit(date[3]) != 0) & + (isdigit(date[4]) != 0) & + (date[5] == '/') & + (isdigit(date[6])!=0) & (isdigit(date[7])!=0) & + (isdigit(date[8])!=0) & (isdigit(date[9])!=0) + ) { + strncpy(month, date, 2); + strncpy(day, date + 3, 2); + strncpy(year, date + 6, 4); + if ( (atoi(month) <= 12) & + (atoi(month) >= 1) & + (atoi(day) <= 31) & + (atoi(day) >= 1) & + (atoi(year) <= 9999) & + (atoi(year) > 1)) + ok = 1; + } + return ok; +} + long min2sec(unsigned minutes) { diff --git a/src/utils.h b/src/utils.h index 6e7ff1a..ec06c1b 100755 --- a/src/utils.h +++ b/src/utils.h @@ -1,4 +1,4 @@ -/* $calcurse: utils.h,v 1.21 2007/07/23 19:26:38 culot Exp $ */ +/* $calcurse: utils.h,v 1.22 2007/07/28 13:11:43 culot Exp $ */ /* * Calcurse - text-based organizer @@ -28,7 +28,6 @@ #define CALCURSE_UTILS_H #include "calendar.h" -#include "vars.h" #define MAX(x,y) ((x)>(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y)) @@ -59,15 +58,9 @@ void erase_status_bar(void); void erase_window_part(WINDOW *, int, int, int, int); WINDOW *popup(int, int, int, int, char *); void print_in_middle(WINDOW *, int, int, int, char *); -void del_char(int, char *); -char *add_char(int, int, char *); -void showcursor(WINDOW *, int, int, char *, int, int); -void showstring(WINDOW *, int, int, char *, int, int); int getstring(WINDOW *, char *, int, int, int); int updatestring(WINDOW *, char **, int, int); int is_all_digit(char *); -void border_color(WINDOW *); -void border_nocolor(WINDOW *); void status_bar(void); long date2sec(date_t, unsigned, unsigned); char *date_sec2hour_str(long); @@ -76,6 +69,7 @@ void date_sec2ical_date(long, char *); void date_sec2ical_datetime(long, char *); long update_time_in_date(long, unsigned, unsigned); long get_sec_date(date_t); +int check_date(char *); long min2sec(unsigned); int check_time(char *); void draw_scrollbar(WINDOW *, int, int, int, int, int, bool); @@ -1,4 +1,4 @@ -/* $calcurse: vars.h,v 1.14 2007/07/23 19:27:28 culot Exp $ */ +/* $calcurse: vars.h,v 1.15 2007/07/28 13:11:43 culot Exp $ */ /* * Calcurse - text-based organizer @@ -30,7 +30,6 @@ #include <ncurses.h> #include <pthread.h> #include <stdbool.h> -#include <stdio.h> #define DIR_NAME ".calcurse" #define TODO_PATH ".calcurse/todo" @@ -1,4 +1,4 @@ -/* $Id: wins.c,v 1.2 2007/07/23 19:28:37 culot Exp $ */ +/* $Id: wins.c,v 1.3 2007/07/28 13:11:43 culot Exp $ */ /* * Calcurse - text-based organizer @@ -24,15 +24,13 @@ * */ -#include <ncurses.h> #include <stdlib.h> #include "i18n.h" -#include "vars.h" -#include "calendar.h" #include "notify.h" #include "utils.h" #include "todo.h" +#include "custom.h" #include "wins.h" static window_e slctd_win; @@ -245,6 +243,54 @@ wins_get_config(conf_t *conf, window_t *status, window_t *notify, } } +/* draw panel border in color */ +static void +border_color(WINDOW *window) +{ + int color_attr = A_BOLD; + int no_color_attr = A_BOLD; + + if (colorize) { + wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); + box(window, 0, 0); + } else { + wattron(window, no_color_attr); + box(window, 0, 0); + } + + if (colorize) { + wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); + } else { + wattroff(window, no_color_attr); + } + + wnoutrefresh(window); +} + +/* draw panel border without any color */ +static void +border_nocolor(WINDOW *window) +{ + int color_attr = A_BOLD; + int no_color_attr = A_DIM; + + if (colorize) { + wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); + } else { + wattron(window, no_color_attr); + } + + box(window, 0, 0); + + if (colorize) { + wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); + } else { + wattroff(window, no_color_attr); + } + + wnoutrefresh(window); +} + /* * Update all of the three windows and put a border around the * selected window. |