Add -l/--limit option
Adds the -l/--limit command line option. Limits the number of appointments and/or ToDo items displayed. Signed-off-by: William Pettersson <william.pettersson@gmail.com> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
906c2fa027
commit
fb61744f33
55
src/args.c
55
src/args.c
@ -133,6 +133,8 @@ static void help_arg(void)
|
|||||||
" print next appointment within upcoming 24 hours "
|
" print next appointment within upcoming 24 hours "
|
||||||
"and exit. Also given\n\tis the remaining time before this "
|
"and exit. Also given\n\tis the remaining time before this "
|
||||||
"next appointment.\n"
|
"next appointment.\n"
|
||||||
|
"\n -l <num>, --limit <num>\n"
|
||||||
|
" only print information regarding the next <num> items. \n"
|
||||||
"\n -r[num], --range[=num]\n"
|
"\n -r[num], --range[=num]\n"
|
||||||
" print events and appointments for the [num] number of days"
|
" print events and appointments for the [num] number of days"
|
||||||
"\n\tand exit. If no [num] is given, a range of 1 day is considered.\n"
|
"\n\tand exit. If no [num] is given, a range of 1 day is considered.\n"
|
||||||
@ -205,7 +207,8 @@ static void status_arg(void)
|
|||||||
* If priority == 0, only completed tasks will be displayed.
|
* If priority == 0, only completed tasks will be displayed.
|
||||||
* If regex is not null, only the matching todos are printed.
|
* If regex is not null, only the matching todos are printed.
|
||||||
*/
|
*/
|
||||||
static void todo_arg(int priority, const char *format, regex_t * regex)
|
static void todo_arg(int priority, const char *format, regex_t * regex,
|
||||||
|
int *limit)
|
||||||
{
|
{
|
||||||
llist_item_t *i;
|
llist_item_t *i;
|
||||||
int title = 1;
|
int title = 1;
|
||||||
@ -224,6 +227,8 @@ static void todo_arg(int priority, const char *format, regex_t * regex)
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
LLIST_FOREACH(&todolist, i) {
|
LLIST_FOREACH(&todolist, i) {
|
||||||
|
if (*limit == 0)
|
||||||
|
return;
|
||||||
struct todo *todo = LLIST_TS_GET_DATA(i);
|
struct todo *todo = LLIST_TS_GET_DATA(i);
|
||||||
if (regex && regexec(regex, todo->mesg, 0, 0, 0) != 0)
|
if (regex && regexec(regex, todo->mesg, 0, 0, 0) != 0)
|
||||||
continue;
|
continue;
|
||||||
@ -232,11 +237,13 @@ static void todo_arg(int priority, const char *format, regex_t * regex)
|
|||||||
if (priority == 0) {
|
if (priority == 0) {
|
||||||
DISPLAY_TITLE;
|
DISPLAY_TITLE;
|
||||||
print_todo(format, todo);
|
print_todo(format, todo);
|
||||||
|
(*limit)--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (priority < 0 || todo->id == priority) {
|
if (priority < 0 || todo->id == priority) {
|
||||||
DISPLAY_TITLE;
|
DISPLAY_TITLE;
|
||||||
print_todo(format, todo);
|
print_todo(format, todo);
|
||||||
|
(*limit)--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,8 +300,10 @@ static void arg_print_date(long date)
|
|||||||
static int
|
static int
|
||||||
app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
|
app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
|
||||||
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
|
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
|
||||||
regex_t * regex)
|
regex_t * regex, int *limit)
|
||||||
{
|
{
|
||||||
|
if (*limit == 0)
|
||||||
|
return 0;
|
||||||
if (date == 0)
|
if (date == 0)
|
||||||
date = get_sec_date(*day);
|
date = get_sec_date(*day);
|
||||||
|
|
||||||
@ -304,7 +313,8 @@ app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
|
|||||||
if (add_line)
|
if (add_line)
|
||||||
fputs("\n", stdout);
|
fputs("\n", stdout);
|
||||||
arg_print_date(date);
|
arg_print_date(date);
|
||||||
day_write_stdout(date, fmt_apt, fmt_rapt, fmt_ev, fmt_rev);
|
day_write_stdout(date, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
|
||||||
|
limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
@ -318,7 +328,7 @@ app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
|
|||||||
static void
|
static void
|
||||||
display_app(struct tm *t, int numdays, int add_line, const char *fmt_apt,
|
display_app(struct tm *t, int numdays, int add_line, const char *fmt_apt,
|
||||||
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
|
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
|
||||||
regex_t * regex)
|
regex_t * regex, int *limit)
|
||||||
{
|
{
|
||||||
int i, app_found;
|
int i, app_found;
|
||||||
struct date day;
|
struct date day;
|
||||||
@ -329,7 +339,7 @@ display_app(struct tm *t, int numdays, int add_line, const char *fmt_apt,
|
|||||||
day.yyyy = t->tm_year + 1900;
|
day.yyyy = t->tm_year + 1900;
|
||||||
app_found =
|
app_found =
|
||||||
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev,
|
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev,
|
||||||
fmt_rev, regex);
|
fmt_rev, regex, limit);
|
||||||
if (app_found)
|
if (app_found)
|
||||||
add_line = 1;
|
add_line = 1;
|
||||||
t->tm_mday++;
|
t->tm_mday++;
|
||||||
@ -344,7 +354,7 @@ display_app(struct tm *t, int numdays, int add_line, const char *fmt_apt,
|
|||||||
static void
|
static void
|
||||||
date_arg(const char *ddate, int add_line, const char *fmt_apt,
|
date_arg(const char *ddate, int add_line, const char *fmt_apt,
|
||||||
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
|
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
|
||||||
regex_t * regex)
|
regex_t * regex, int *limit)
|
||||||
{
|
{
|
||||||
struct date day;
|
struct date day;
|
||||||
static struct tm t;
|
static struct tm t;
|
||||||
@ -363,13 +373,13 @@ date_arg(const char *ddate, int add_line, const char *fmt_apt,
|
|||||||
timer = time(NULL);
|
timer = time(NULL);
|
||||||
localtime_r(&timer, &t);
|
localtime_r(&timer, &t);
|
||||||
display_app(&t, atoi(ddate), add_line, fmt_apt, fmt_rapt,
|
display_app(&t, atoi(ddate), add_line, fmt_apt, fmt_rapt,
|
||||||
fmt_ev, fmt_rev, regex);
|
fmt_ev, fmt_rev, regex, limit);
|
||||||
} else {
|
} else {
|
||||||
/* A date was entered. */
|
/* A date was entered. */
|
||||||
if (parse_date(ddate, conf.input_datefmt, (int *)&day.yyyy,
|
if (parse_date(ddate, conf.input_datefmt, (int *)&day.yyyy,
|
||||||
(int *)&day.mm, (int *)&day.dd, NULL)) {
|
(int *)&day.mm, (int *)&day.dd, NULL)) {
|
||||||
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt,
|
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt,
|
||||||
fmt_ev, fmt_rev, regex);
|
fmt_ev, fmt_rev, regex, limit);
|
||||||
} else {
|
} else {
|
||||||
fputs(_("Argument to the '-d' flag is not valid\n"),
|
fputs(_("Argument to the '-d' flag is not valid\n"),
|
||||||
stderr);
|
stderr);
|
||||||
@ -392,7 +402,8 @@ date_arg(const char *ddate, int add_line, const char *fmt_apt,
|
|||||||
static void
|
static void
|
||||||
date_arg_extended(const char *startday, const char *range, int add_line,
|
date_arg_extended(const char *startday, const char *range, int add_line,
|
||||||
const char *fmt_apt, const char *fmt_rapt,
|
const char *fmt_apt, const char *fmt_rapt,
|
||||||
const char *fmt_ev, const char *fmt_rev, regex_t * regex)
|
const char *fmt_ev, const char *fmt_rev, regex_t * regex,
|
||||||
|
int *limit)
|
||||||
{
|
{
|
||||||
int numdays = 1, error = 0;
|
int numdays = 1, error = 0;
|
||||||
static struct tm t;
|
static struct tm t;
|
||||||
@ -423,7 +434,7 @@ date_arg_extended(const char *startday, const char *range, int add_line,
|
|||||||
}
|
}
|
||||||
if (!error) {
|
if (!error) {
|
||||||
display_app(&t, numdays, add_line, fmt_apt, fmt_rapt,
|
display_app(&t, numdays, add_line, fmt_apt, fmt_rapt,
|
||||||
fmt_ev, fmt_rev, regex);
|
fmt_ev, fmt_rev, regex, limit);
|
||||||
} else {
|
} else {
|
||||||
fputs(_("Argument is not valid\n"), stderr);
|
fputs(_("Argument is not valid\n"), stderr);
|
||||||
fprintf(stdout,
|
fprintf(stdout,
|
||||||
@ -463,6 +474,7 @@ int parse_args(int argc, char **argv)
|
|||||||
const char *fmt_rev = " * %m\n";
|
const char *fmt_rev = " * %m\n";
|
||||||
const char *fmt_todo = "%p. %m\n";
|
const char *fmt_todo = "%p. %m\n";
|
||||||
|
|
||||||
|
int limit = INT_MAX; /* indicates no limit requested. */
|
||||||
int tnum = 0, xfmt = 0, non_interactive = 0, multiple_flag =
|
int tnum = 0, xfmt = 0, non_interactive = 0, multiple_flag =
|
||||||
0, load_data = 0;
|
0, load_data = 0;
|
||||||
const char *ddate = "", *cfile = NULL, *range = NULL, *startday =
|
const char *ddate = "", *cfile = NULL, *range = NULL, *startday =
|
||||||
@ -476,7 +488,7 @@ int parse_args(int argc, char **argv)
|
|||||||
STATUS_OPT = CHAR_MAX + 1
|
STATUS_OPT = CHAR_MAX + 1
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *optstr = "ghvnNax::t::d:c:r::s::S:D:i:";
|
static const char *optstr = "ghvnNax::t::d:c:r::s::S:D:i:l:";
|
||||||
|
|
||||||
struct option longopts[] = {
|
struct option longopts[] = {
|
||||||
{"appointment", no_argument, NULL, 'a'},
|
{"appointment", no_argument, NULL, 'a'},
|
||||||
@ -486,6 +498,7 @@ int parse_args(int argc, char **argv)
|
|||||||
{"gc", no_argument, NULL, 'g'},
|
{"gc", no_argument, NULL, 'g'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"import", required_argument, NULL, 'i'},
|
{"import", required_argument, NULL, 'i'},
|
||||||
|
{"limit", required_argument, NULL, 'l'},
|
||||||
{"next", no_argument, NULL, 'n'},
|
{"next", no_argument, NULL, 'n'},
|
||||||
{"note", no_argument, NULL, 'N'},
|
{"note", no_argument, NULL, 'N'},
|
||||||
{"range", optional_argument, NULL, 'r'},
|
{"range", optional_argument, NULL, 'r'},
|
||||||
@ -542,6 +555,9 @@ int parse_args(int argc, char **argv)
|
|||||||
load_data++;
|
load_data++;
|
||||||
ifile = optarg;
|
ifile = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
limit = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nflag = 1;
|
nflag = 1;
|
||||||
multiple_flag++;
|
multiple_flag++;
|
||||||
@ -646,6 +662,12 @@ int parse_args(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
usage_try();
|
usage_try();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
} else if ((limit != INT_MAX) && !(aflag || dflag || rflag || sflag || tflag)) {
|
||||||
|
fputs(_("Option '-l' must be used with either '-d', '-r', '-s', "
|
||||||
|
"'-a' or '-t'\n"), stderr);
|
||||||
|
usage();
|
||||||
|
usage_try();
|
||||||
|
return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
if (unknown_flag) {
|
if (unknown_flag) {
|
||||||
non_interactive = 1;
|
non_interactive = 1;
|
||||||
@ -699,7 +721,7 @@ int parse_args(int argc, char **argv)
|
|||||||
if (tflag) {
|
if (tflag) {
|
||||||
io_check_file(path_todo);
|
io_check_file(path_todo);
|
||||||
io_load_todo();
|
io_load_todo();
|
||||||
todo_arg(tnum, fmt_todo, preg);
|
todo_arg(tnum, fmt_todo, preg, &limit);
|
||||||
non_interactive = 1;
|
non_interactive = 1;
|
||||||
}
|
}
|
||||||
if (nflag) {
|
if (nflag) {
|
||||||
@ -716,13 +738,14 @@ int parse_args(int argc, char **argv)
|
|||||||
if (dflag)
|
if (dflag)
|
||||||
date_arg(ddate, add_line, fmt_apt,
|
date_arg(ddate, add_line, fmt_apt,
|
||||||
fmt_rapt, fmt_ev, fmt_rev,
|
fmt_rapt, fmt_ev, fmt_rev,
|
||||||
preg);
|
preg, &limit);
|
||||||
if (rflag || sflag)
|
if (rflag || sflag)
|
||||||
date_arg_extended(startday, range,
|
date_arg_extended(startday, range,
|
||||||
add_line,
|
add_line,
|
||||||
fmt_apt,
|
fmt_apt,
|
||||||
fmt_rapt, fmt_ev,
|
fmt_rapt, fmt_ev,
|
||||||
fmt_rev, preg);
|
fmt_rev, preg,
|
||||||
|
&limit);
|
||||||
non_interactive = 1;
|
non_interactive = 1;
|
||||||
} else if (aflag) {
|
} else if (aflag) {
|
||||||
struct date day;
|
struct date day;
|
||||||
@ -733,8 +756,8 @@ int parse_args(int argc, char **argv)
|
|||||||
config_load(); /* To get output date format. */
|
config_load(); /* To get output date format. */
|
||||||
io_load_app();
|
io_load_app();
|
||||||
day.dd = day.mm = day.yyyy = 0;
|
day.dd = day.mm = day.yyyy = 0;
|
||||||
app_arg(add_line, &day, 0, fmt_apt,
|
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt,
|
||||||
fmt_rapt, fmt_ev, fmt_rev, preg);
|
fmt_ev, fmt_rev, preg, &limit);
|
||||||
non_interactive = 1;
|
non_interactive = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -689,7 +689,7 @@ int day_store_items(long, unsigned *, unsigned *, regex_t *);
|
|||||||
struct day_items_nb day_process_storage(struct date *, unsigned);
|
struct day_items_nb day_process_storage(struct date *, unsigned);
|
||||||
void day_write_pad(long, int, int, int);
|
void day_write_pad(long, int, int, int);
|
||||||
void day_write_stdout(long, const char *, const char *, const char *,
|
void day_write_stdout(long, const char *, const char *, const char *,
|
||||||
const char *);
|
const char *, int *);
|
||||||
void day_popup_item(struct day_item *);
|
void day_popup_item(struct day_item *);
|
||||||
int day_check_if_item(struct date);
|
int day_check_if_item(struct date);
|
||||||
unsigned day_chk_busy_slices(struct date, int, int *);
|
unsigned day_chk_busy_slices(struct date, int, int *);
|
||||||
|
@ -507,11 +507,13 @@ void day_write_pad(long date, int width, int length, int incolor)
|
|||||||
|
|
||||||
/* Write the appointments and events for the selected day to stdout. */
|
/* Write the appointments and events for the selected day to stdout. */
|
||||||
void day_write_stdout(long date, const char *fmt_apt, const char *fmt_rapt,
|
void day_write_stdout(long date, const char *fmt_apt, const char *fmt_rapt,
|
||||||
const char *fmt_ev, const char *fmt_rev)
|
const char *fmt_ev, const char *fmt_rev, int *limit)
|
||||||
{
|
{
|
||||||
llist_item_t *i;
|
llist_item_t *i;
|
||||||
|
|
||||||
LLIST_FOREACH(&day_items, i) {
|
LLIST_FOREACH(&day_items, i) {
|
||||||
|
if (*limit == 0)
|
||||||
|
break;
|
||||||
struct day_item *day = LLIST_TS_GET_DATA(i);
|
struct day_item *day = LLIST_TS_GET_DATA(i);
|
||||||
|
|
||||||
switch (day->type) {
|
switch (day->type) {
|
||||||
@ -532,6 +534,7 @@ void day_write_stdout(long date, const char *fmt_apt, const char *fmt_rapt,
|
|||||||
EXIT(_("unknown item type"));
|
EXIT(_("unknown item type"));
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
(*limit)--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user