default to printing 5 events and added option -a
This commit is contained in:
parent
0773d4f561
commit
e8ed8b0319
@ -6,13 +6,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
|
printf ("-a\t\t\tshow all upcoming events (default is 5 events)\n");
|
||||||
printf ("-f [FILE PATH]\t\tspecify ics file path\n");
|
printf ("-f [FILE PATH]\t\tspecify ics file path\n");
|
||||||
printf ("-h\t\t\tprint this help\n");
|
printf ("-h\t\t\tprint this help\n");
|
||||||
printf ("-i\t\t\tinsert an event\n");
|
printf ("-i\t\t\tinsert an event\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_cli_args(int argc, char **argv, char **file_name) {
|
void get_cli_args(int argc, char **argv, char **file_name, int *show_all_events) {
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
|
|
||||||
memset(file_name, '\0', strlen(*file_name));
|
memset(file_name, '\0', strlen(*file_name));
|
||||||
@ -27,17 +28,20 @@ void get_cli_args(int argc, char **argv, char **file_name) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "f:hi")) != -1) {
|
while ((opt = getopt(argc, argv, "f:ahi")) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'f':
|
case 'a':
|
||||||
*file_name = optarg;
|
*show_all_events = 1;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'f':
|
||||||
usage();
|
*file_name = optarg;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'h':
|
||||||
insert_event(*file_name);
|
usage();
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
insert_event(*file_name);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
void usage();
|
void usage();
|
||||||
|
|
||||||
void get_cli_args(int argc, char **argv, char **file_name);
|
void get_cli_args(int argc, char **argv, char **file_name, int *show_all_events);
|
||||||
|
@ -46,12 +46,20 @@ void free_list(struct event *head)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_upcoming(struct event *head, char current_start_date[]) {
|
void print_upcoming(struct event *head, char current_start_date[], int show_all_events) {
|
||||||
|
int i = 0;
|
||||||
while (head != NULL) {
|
while (head != NULL) {
|
||||||
if (strcmp(head->start_date, current_start_date) >= 0) {
|
if (strcmp(head->start_date, current_start_date) >= 0) {
|
||||||
pretty_print_date_time(head->start_date);
|
pretty_print_date_time(head->start_date);
|
||||||
print_end_date(head->end_date, head->start_date);
|
print_end_date(head->end_date, head->start_date);
|
||||||
printf("\n%s\n", head->summary);
|
printf("\n%s\n", head->summary);
|
||||||
|
|
||||||
|
if (!show_all_events) {
|
||||||
|
i++;
|
||||||
|
if (i > 4)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (head->next != NULL)
|
if (head->next != NULL)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
@ -10,4 +10,4 @@ struct event {
|
|||||||
void print_list(struct event *head);
|
void print_list(struct event *head);
|
||||||
void sorted_insert(struct event **head, char start_date[], char end_date[], char summary[]);
|
void sorted_insert(struct event **head, char start_date[], char end_date[], char summary[]);
|
||||||
void free_list(struct event *head);
|
void free_list(struct event *head);
|
||||||
void print_upcoming(struct event *head, char current_date[]);
|
void print_upcoming(struct event *head, char current_date[], int show_all_events);
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char *ics_path = "";
|
char *ics_path = "";
|
||||||
get_cli_args(argc, argv, &ics_path);
|
int show_all_events = 0;
|
||||||
|
|
||||||
|
get_cli_args(argc, argv, &ics_path, &show_all_events);
|
||||||
|
|
||||||
char my_event[8192] = "";
|
char my_event[8192] = "";
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ int main(int argc, char **argv) {
|
|||||||
memset(my_event, '\0', sizeof(my_event));
|
memset(my_event, '\0', sizeof(my_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
print_upcoming(head, current_date);
|
print_upcoming(head, current_date, show_all_events);
|
||||||
|
|
||||||
free_list(head);
|
free_list(head);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user