getopt function in parse_args() replaced by getopt_long
This commit is contained in:
parent
b60c2c7249
commit
dc2d5ef2a2
54
src/args.c
54
src/args.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: args.c,v 1.8 2006/10/16 15:48:30 culot Exp $ */
|
||||
/* $calcurse: args.c,v 1.9 2006/10/17 14:38:21 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -31,7 +31,7 @@
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "i18n.h"
|
||||
@ -54,13 +54,34 @@ int parse_args(int argc, char **argv, int colr)
|
||||
{
|
||||
int ch, add_line = 0;
|
||||
int unknown_flag = 0, app_found = 0;
|
||||
int aflag = 0, cflag = 0, dflag = 0, vflag = 0;
|
||||
int hflag = 0, tflag = 0, nflag = 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 tnum = 0;
|
||||
int non_interactive = 0, multiple_flag = 0, load_data = 0;
|
||||
int no_file = 1;
|
||||
char *ddate = "", *cfile = NULL, *tnum = NULL;
|
||||
char *ddate = "", *cfile = NULL;
|
||||
|
||||
while ((ch = getopt(argc, argv, "hvnat:d:c:")) != -1) {
|
||||
static char *optstr = "hvnat::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'},
|
||||
{NULL, no_argument, NULL, 0}
|
||||
};
|
||||
|
||||
while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
@ -92,12 +113,20 @@ int parse_args(int argc, char **argv, int colr)
|
||||
multiple_flag++;
|
||||
load_data++;
|
||||
add_line = 1;
|
||||
tnum = optarg;
|
||||
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;
|
||||
default:
|
||||
default: /* NOTREACHED */
|
||||
usage();
|
||||
usage_try();
|
||||
unknown_flag = 1;
|
||||
@ -106,6 +135,7 @@ int parse_args(int argc, char **argv, int colr)
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc >= 1) { /* incorrect arguments */
|
||||
usage();
|
||||
usage_try();
|
||||
@ -127,7 +157,7 @@ int parse_args(int argc, char **argv, int colr)
|
||||
load_app(colr);
|
||||
}
|
||||
if (tflag) {
|
||||
todo_arg(atoi(tnum), colr);
|
||||
todo_arg(tnum, colr);
|
||||
non_interactive = 1;
|
||||
}
|
||||
if (nflag) {
|
||||
@ -210,11 +240,6 @@ int todo_arg(int priority, int colr)
|
||||
int nb_tod, title = 1;
|
||||
char priority_str[MAX_LENGTH] = "";
|
||||
|
||||
if (priority >= 9 || priority <= 0) {
|
||||
usage();
|
||||
usage_try();
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
nb_tod = load_todo(colr);
|
||||
for (i = todolist; i != 0; i = i->next) {
|
||||
if (priority == 0 || i->id == priority) {
|
||||
@ -229,7 +254,6 @@ int todo_arg(int priority, int colr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Print the next appointment within the upcoming 24 hours. */
|
||||
void next_arg(void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user