From 4b987f70ac463121f9791eb3493952a77aba495f Mon Sep 17 00:00:00 2001 From: Frederic Culot Date: Sat, 28 Jul 2007 13:11:42 +0000 Subject: unuseful headers removed and some functions became static --- src/args.c | 412 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 189 insertions(+), 223 deletions(-) (limited to 'src/args.c') diff --git a/src/args.c b/src/args.c index 9692403..22535e7 100755 --- a/src/args.c +++ b/src/args.c @@ -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 -#include #include #include #include -#include #include #include #include @@ -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); + } } -- cgit v1.2.3-54-g00ecf