configure
configure~
configure.scan
+.lineno
Makefile
Makefile.in
stamp-h1
SUBDIRS = . test/unit
+format:
+ VERSION_CONTROL=none indent -linux -brf $(ev_SOURCES)
+
unit:
$(MAKE) -C test/unit check
#include<opt.h>
#include<usage.h>
-int add(int, char**);
-int add_to_file(struct event*);
+int add(int, char **);
+int add_to_file(struct event *);
#endif
SUB_COMMAND_VALIDATE
};
-enum sub_command args(int,char**);
+enum sub_command args(int, char **);
#endif
#include<event.h>
#include<file.h>
-int copy(FILE*,FILE*,time_t);
-int copy_next_event(FILE*,FILE*);
+int copy(FILE *, FILE *, time_t);
+int copy_next_event(FILE *, FILE *);
#endif
#include<event.h>
#include<file.h>
-int cut(struct event*, time_t, size_t);
+int cut(struct event *, time_t, size_t);
#endif
struct event_options {
unsigned int recur;
enum time_period recur_period;
-
+
struct tm until;
};
time_t end;
};
-void event_free(const struct event*);
-void event_init(struct event*);
-int event_name_set(struct event*, const char*);
-void event_options_init(struct event_options*);
+void event_free(const struct event *);
+void event_init(struct event *);
+int event_name_set(struct event *, const char *);
+void event_options_init(struct event_options *);
enum time_period event_options_period(char);
char event_options_period_char(enum time_period);
-int event_parse(char*, size_t, struct event*);
-int event_place_set(struct event*, const char*);
-int event_serialize(char*, size_t, const struct event*);
-int event_time_compare(const struct tm*,time_t);
-int event_time_date_only(const struct tm*);
-int event_time_set(struct tm*, const char*);
-int event_within(struct event*, struct event_filter*);
+int event_parse(char *, size_t, struct event *);
+int event_place_set(struct event *, const char *);
+int event_serialize(char *, size_t, const struct event *);
+int event_time_compare(const struct tm *, time_t);
+int event_time_date_only(const struct tm *);
+int event_time_set(struct tm *, const char *);
+int event_within(struct event *, struct event_filter *);
#endif
#include<opt.h>
-ssize_t file_line_next(char*, size_t, FILE*);
-int file_move(const char*);
+ssize_t file_line_next(char *, size_t, FILE *);
+int file_move(const char *);
FILE *file_open();
-int file_pipe(FILE*, FILE*);
-FILE *file_temp(char*);
+int file_pipe(FILE *, FILE *);
+FILE *file_temp(char *);
#endif
#include<rm.h>
#include<validate.h>
-int main(int,char**);
+int main(int, char **);
#endif
extern struct options global_options;
-int opt_event_filter_date_set(time_t*,const char*);
-int opt_event_filter_range_set(const char*, const char*);
-int opt_event_filter_set(const char*);
-int opt_file_set(const char*);
+int opt_event_filter_date_set(time_t *, const char *);
+int opt_event_filter_range_set(const char *, const char *);
+int opt_event_filter_set(const char *);
+int opt_file_set(const char *);
void opt_global_init();
int opt_load_from_env();
-int opt_recur_set(const char*);
-int opt_until_set(const char*);
+int opt_recur_set(const char *);
+int opt_until_set(const char *);
#endif
#include<event.h>
#include<usage.h>
-int postpone(int, char**);
+int postpone(int, char **);
#endif
#include<event.h>
-int recur(struct event*);
+int recur(struct event *);
#endif
#define RM_FLAG_DISMISS 1
-int rm(int,char**,int);
+int rm(int, char **, int);
#endif
#include<event.h>
#include<file.h>
-int seek(FILE*,time_t);
+int seek(FILE *, time_t);
#endif
#include<add.h>
-static int add_name_set(struct event*,const char*);
-static int add_place_set(struct event*,const char*);
-static int add_time_set(struct event*,const char*);
-static int handle_args(int,char**,struct event*);
-static int handle_options(struct event*);
+static int add_name_set(struct event *, const char *);
+static int add_place_set(struct event *, const char *);
+static int add_time_set(struct event *, const char *);
+static int handle_args(int, char **, struct event *);
+static int handle_options(struct event *);
int add(int argc, char **argv) {
struct event ev;
event_init(&ev);
- if(handle_options(&ev)<0) { return EXIT_FAILURE; }
- if(handle_args(argc,argv,&ev)<0) { return EXIT_FAILURE; }
-
- strftime(timebuf,40,"%a, %d %b %Y %T %z",&(ev.datetime));
-
- if(ev.place!=NULL) {
- if(snprintf(
- buf,
- EVENT_SERIALIZE_MAX_LENGTH,
- "Added event '%s' at '%s' on %s\n",
- ev.name,
- ev.place,
- timebuf
- )<0) { goto too_long; }
+ if (handle_options(&ev) < 0) {
+ return EXIT_FAILURE;
+ }
+ if (handle_args(argc, argv, &ev) < 0) {
+ return EXIT_FAILURE;
+ }
+
+ strftime(timebuf, 40, "%a, %d %b %Y %T %z", &(ev.datetime));
+
+ if (ev.place != NULL) {
+ if (snprintf(buf,
+ EVENT_SERIALIZE_MAX_LENGTH,
+ "Added event '%s' at '%s' on %s\n",
+ ev.name, ev.place, timebuf) < 0) {
+ goto too_long;
+ }
} else {
- if(snprintf(
- buf,
- EVENT_SERIALIZE_MAX_LENGTH,
- "Added event '%s' on %s\n",
- ev.name,
- timebuf
- )<0) { goto too_long; }
+ if (snprintf(buf,
+ EVENT_SERIALIZE_MAX_LENGTH,
+ "Added event '%s' on %s\n",
+ ev.name, timebuf) < 0) {
+ goto too_long;
+ }
+ }
+
+ if (add_to_file(&ev) < 0) {
+ return EXIT_FAILURE;
}
-
- if(add_to_file(&ev)<0) { return EXIT_FAILURE; }
- fprintf(stdout,buf);
+ fprintf(stdout, buf);
return EXIT_SUCCESS;
-too_long:
- fprintf(stderr,"event too long\n");
+ too_long:
+ fprintf(stderr, "event too long\n");
return EXIT_FAILURE;
}
static int add_name_set(struct event *ev, const char *p) {
- assert(ev!=NULL);
+ assert(ev != NULL);
- if(NULL==p) { return -1; }
+ if (NULL == p) {
+ return -1;
+ }
ev->name = strdup(p);
- if(NULL==ev->name) { return -1; }
+ if (NULL == ev->name) {
+ return -1;
+ }
return 1;
}
static int add_place_set(struct event *ev, const char *p) {
- assert(ev!=NULL);
+ assert(ev != NULL);
- if(NULL==p) { return -1; }
+ if (NULL == p) {
+ return -1;
+ }
ev->place = strdup(p);
- if(NULL==ev->place) { return -1; }
+ if (NULL == ev->place) {
+ return -1;
+ }
return 1;
}
static int add_time_set(struct event *ev, const char *str) {
- assert(ev!=NULL);
+ assert(ev != NULL);
- if(NULL==str) { return -1; }
+ if (NULL == str) {
+ return -1;
+ }
- if(event_time_set(&(ev->datetime),str)<0) {
- fprintf(stderr,"invalid date format provided\n");
+ if (event_time_set(&(ev->datetime), str) < 0) {
+ fprintf(stderr, "invalid date format provided\n");
usage();
- return -1;
+ return -1;
}
return 1;
FILE *src, *to;
ssize_t i;
- assert(to_add!=NULL);
+ assert(to_add != NULL);
- if(NULL==to_add->name) { return -1; }
+ if (NULL == to_add->name) {
+ return -1;
+ }
char tempfile[] = "/tmp/XXXXXX";
to = file_temp(tempfile);
- if(NULL==to) { return -1; }
+ if (NULL == to) {
+ return -1;
+ }
src = file_open();
- if(NULL==src) { return -1; }
+ if (NULL == src) {
+ return -1;
+ }
- memcpy(&tm,&(to_add->datetime),sizeof(struct tm));
+ memcpy(&tm, &(to_add->datetime), sizeof(struct tm));
to_add_time = mktime(&tm);
- if(copy(to,src,to_add_time)<0) { return -1; }
+ if (copy(to, src, to_add_time) < 0) {
+ return -1;
+ }
- if(event_serialize(buf,EVENT_SERIALIZE_MAX_LENGTH,to_add)<0) { return -1; }
+ if (event_serialize(buf, EVENT_SERIALIZE_MAX_LENGTH, to_add) < 0) {
+ return -1;
+ }
i = strlen(buf);
- if(fwrite(buf,1,i,to)!=i) { return -1; }
+ if (fwrite(buf, 1, i, to) != i) {
+ return -1;
+ }
- if(file_pipe(to,src)<0) { return -1; }
+ if (file_pipe(to, src) < 0) {
+ return -1;
+ }
- if(fclose(src)!=0) { return -1; }
- if(fclose(to)!=0) { return -1; }
+ if (fclose(src) != 0) {
+ return -1;
+ }
+ if (fclose(to) != 0) {
+ return -1;
+ }
- if(file_move(tempfile)<0) { return -1; }
+ if (file_move(tempfile) < 0) {
+ return -1;
+ }
return 1;
}
int handle_args(int argc, char **argv, struct event *ev) {
- assert(ev!=NULL);
-
- switch(argc-optind) {
- case 4:
- if(add_place_set(ev,argv[optind+2])<0) { return -1; }
- case 3:
- if(add_name_set(ev,argv[optind+1])<0) { return -1; }
- if(add_time_set(ev,argv[argc-1])<0) { return -1; }
- break;
- default:
- fprintf(stderr,"invalid number of arguments\n");
- usage();
+ assert(ev != NULL);
+
+ switch (argc - optind) {
+ case 4:
+ if (add_place_set(ev, argv[optind + 2]) < 0) {
return -1;
+ }
+ case 3:
+ if (add_name_set(ev, argv[optind + 1]) < 0) {
+ return -1;
+ }
+ if (add_time_set(ev, argv[argc - 1]) < 0) {
+ return -1;
+ }
+ break;
+ default:
+ fprintf(stderr, "invalid number of arguments\n");
+ usage();
+ return -1;
}
return 1;
int handle_options(struct event *ev) {
struct tm *time;
- if(global_options.event_options.recur>0) {
+ if (global_options.event_options.recur > 0) {
ev->options.recur = global_options.event_options.recur;
- ev->options.recur_period = global_options.event_options.recur_period;
-
- if(global_options.event_filter.end>0) {
+ ev->options.recur_period =
+ global_options.event_options.recur_period;
+
+ if (global_options.event_filter.end > 0) {
time = localtime(&(global_options.event_filter.end));
- if(NULL==time) { return -1; }
+ if (NULL == time) {
+ return -1;
+ }
- memcpy(&(ev->options.until),time,sizeof(struct tm));
+ memcpy(&(ev->options.until), time, sizeof(struct tm));
}
}
{"recurring", required_argument, 0, 'r'},
{"start-date", required_argument, 0, 's'},
{"upcoming", optional_argument, 0, 'u'},
- {0,0,0,0}
+ {0, 0, 0, 0}
};
enum sub_command args(int argc, char **argv) {
char c;
- while(1) {
+ while (1) {
int option_index = 0;
- if((c = getopt_long(argc,argv,"ae:f:hor:s:t:u::",long_options,&option_index))==-1) { break; }
+ if ((c =
+ getopt_long(argc, argv, "ae:f:hor:s:t:u::", long_options,
+ &option_index)) == -1) {
+ break;
+ }
- switch(c) {
- case 'a':
- if(opt_event_filter_set("all")<0) { goto fail; }
- break;
- case 'e':
- if(opt_event_filter_date_set(
- &(global_options.event_filter.end),
- /* time_t *to_set */
- optarg /* const char *date_string */
- )<0) { goto fail; }
- break;
- case 'f':
- if(opt_file_set(optarg)<0) { goto fail; }
- break;
- case 'o':
- if(opt_event_filter_set("overdue")<0) { goto fail; }
- break;
- case 'r':
- if(opt_recur_set(optarg)<0) { goto fail; }
- break;
- case 's':
- if(opt_event_filter_date_set(
- &(global_options.event_filter.start),
- /* time_t *to_set */
- optarg /* const char *date_string */
- )<0) { goto fail; }
- break;
- case 'u':
- if((NULL==optarg)&&(argv[optind]!=NULL)&&(argv[optind][0]!='-')) {
- if(opt_event_filter_range_set("upcoming",argv[optind])<0) { goto fail; }
- optind++;
- } else {
- if(opt_event_filter_range_set("upcoming",optarg)<0) { goto fail; }
- }
- break;
- case 'h':
- case '?':
- default:
+ switch (c) {
+ case 'a':
+ if (opt_event_filter_set("all") < 0) {
+ goto fail;
+ }
+ break;
+ case 'e':
+ if (opt_event_filter_date_set
+ (&(global_options.event_filter.end),
+ /* time_t *to_set */
+ optarg /* const char *date_string */
+ ) < 0) {
+ goto fail;
+ }
+ break;
+ case 'f':
+ if (opt_file_set(optarg) < 0) {
+ goto fail;
+ }
+ break;
+ case 'o':
+ if (opt_event_filter_set("overdue") < 0) {
goto fail;
+ }
+ break;
+ case 'r':
+ if (opt_recur_set(optarg) < 0) {
+ goto fail;
+ }
+ break;
+ case 's':
+ if (opt_event_filter_date_set
+ (&(global_options.event_filter.start),
+ /* time_t *to_set */
+ optarg /* const char *date_string */
+ ) < 0) {
+ goto fail;
+ }
+ break;
+ case 'u':
+ if ((NULL == optarg) && (argv[optind] != NULL)
+ && (argv[optind][0] != '-')) {
+ if (opt_event_filter_range_set
+ ("upcoming", argv[optind]) < 0) {
+ goto fail;
+ }
+ optind++;
+ } else {
+ if (opt_event_filter_range_set
+ ("upcoming", optarg) < 0) {
+ goto fail;
+ }
+ }
+ break;
+ case 'h':
+ case '?':
+ default:
+ goto fail;
}
}
- if(optind>=argc) { return SUB_COMMAND_LS; }
+ if (optind >= argc) {
+ return SUB_COMMAND_LS;
+ }
- if(strcmp(argv[optind],"add")==0) { return SUB_COMMAND_ADD; }
- if(strcmp(argv[optind],"dismiss")==0) { return SUB_COMMAND_DISMISS; }
- if(strcmp(argv[optind],"ls")==0) { return SUB_COMMAND_LS; }
- if(strcmp(argv[optind],"postpone")==0) { return SUB_COMMAND_POSTPONE; }
- if(strcmp(argv[optind],"prune")==0) { return SUB_COMMAND_PRUNE; }
- if(strcmp(argv[optind],"rm")==0) { return SUB_COMMAND_RM; }
- if(strcmp(argv[optind],"validate")==0) { return SUB_COMMAND_VALIDATE; }
+ if (strcmp(argv[optind], "add") == 0) {
+ return SUB_COMMAND_ADD;
+ }
+ if (strcmp(argv[optind], "dismiss") == 0) {
+ return SUB_COMMAND_DISMISS;
+ }
+ if (strcmp(argv[optind], "ls") == 0) {
+ return SUB_COMMAND_LS;
+ }
+ if (strcmp(argv[optind], "postpone") == 0) {
+ return SUB_COMMAND_POSTPONE;
+ }
+ if (strcmp(argv[optind], "prune") == 0) {
+ return SUB_COMMAND_PRUNE;
+ }
+ if (strcmp(argv[optind], "rm") == 0) {
+ return SUB_COMMAND_RM;
+ }
+ if (strcmp(argv[optind], "validate") == 0) {
+ return SUB_COMMAND_VALIDATE;
+ }
goto fail;
-fail:
+ fail:
usage();
return SUB_COMMAND_INVALID_ARGS;
}
struct event ev;
ssize_t i;
- if(NULL==to) { return -1; }
- if(NULL==src) { return -1; }
+ if (NULL == to) {
+ return -1;
+ }
+ if (NULL == src) {
+ return -1;
+ }
+
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ while ((i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, src)) > 0) {
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- while((i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,src))>0) {
+ if (event_parse(buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ return -1;
+ }
- if(event_parse(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) { return -1; }
-
- if(event_time_compare(&(ev.datetime),until)>0) {
+ if (event_time_compare(&(ev.datetime), until) > 0) {
event_free(&ev);
- if(fseek(src,-i,SEEK_CUR)!=0) { return -1; }
+ if (fseek(src, -i, SEEK_CUR) != 0) {
+ return -1;
+ }
break;
}
- if(event_serialize(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) { return -1; }
+ if (event_serialize(buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ return -1;
+ }
- if(fwrite(buf,1,i,to)!=i) { return -1; }
+ if (fwrite(buf, 1, i, to) != i) {
+ return -1;
+ }
}
- if(i<0) {
- if(ferror(src)!=0) {
- fprintf(stderr,"failed to get line\n");
+ if (i < 0) {
+ if (ferror(src) != 0) {
+ fprintf(stderr, "failed to get line\n");
return -1;
}
}
char buf[EVENT_SERIALIZE_MAX_LENGTH];
ssize_t i;
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,src);
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, src);
- if(i<0) {
- if(ferror(src)!=0) {
- fprintf(stderr,"failed to get line");
+ if (i < 0) {
+ if (ferror(src) != 0) {
+ fprintf(stderr, "failed to get line");
return -1;
}
}
-
- if(i>0) {
- if(fwrite(buf,1,i,to)!=i) { return -1; }
+
+ if (i > 0) {
+ if (fwrite(buf, 1, i, to) != i) {
+ return -1;
+ }
}
return 1;
#include<cut.h>
-static int extract(FILE*, struct event*);
+static int extract(FILE *, struct event *);
int cut(struct event *ev, time_t start, size_t offset) {
FILE *src, *to;
- assert(ev!=NULL);
+ assert(ev != NULL);
char tempfile[] = "/tmp/XXXXXX";
to = file_temp(tempfile);
- if(NULL==to) { return -1; }
+ if (NULL == to) {
+ return -1;
+ }
src = file_open();
- if(NULL==src) { return -1; }
+ if (NULL == src) {
+ return -1;
+ }
- if(copy(to,src,start)<0) { return -1; }
+ if (copy(to, src, start) < 0) {
+ return -1;
+ }
- while(offset>0) {
- if(copy_next_event(to,src)<0) { return -1; }
+ while (offset > 0) {
+ if (copy_next_event(to, src) < 0) {
+ return -1;
+ }
offset--;
}
- if(extract(src,ev)<0) { return -1; }
+ if (extract(src, ev) < 0) {
+ return -1;
+ }
- if(file_pipe(to,src)<0) { return -1; }
-
- if(fclose(src)!=0) { return -1; }
- if(fclose(to)!=0) { return -1; }
-
- if(file_move(tempfile)<0) { return -1; }
+ if (file_pipe(to, src) < 0) {
+ return -1;
+ }
+
+ if (fclose(src) != 0) {
+ return -1;
+ }
+ if (fclose(to) != 0) {
+ return -1;
+ }
+
+ if (file_move(tempfile) < 0) {
+ return -1;
+ }
return 1;
}
char buf[EVENT_SERIALIZE_MAX_LENGTH];
ssize_t i;
- assert(ev!=NULL);
+ assert(ev != NULL);
- if(NULL==src) { return -1; }
+ if (NULL == src) {
+ return -1;
+ }
+
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
-
- i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,src);
- if(i<0) {
- if(ferror(src)!=0) {
- fprintf(stderr,"failed to get line");
+ i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, src);
+ if (i < 0) {
+ if (ferror(src) != 0) {
+ fprintf(stderr, "failed to get line");
return -1;
}
}
- if(event_parse(buf,EVENT_SERIALIZE_MAX_LENGTH,ev)<0) { return -1; }
+ if (event_parse(buf, EVENT_SERIALIZE_MAX_LENGTH, ev) < 0) {
+ return -1;
+ }
return 1;
}
int defaults() {
opt_global_init();
- if(opt_file_set(default_file)<0) { return -1; }
+ if (opt_file_set(default_file) < 0) {
+ return -1;
+ }
global_options.event_filter.start = 0;
global_options.event_filter.end = midnight();
#include<event.h>
void event_free(const struct event *p) {
- if(p->name!=NULL) { free(p->name); }
- if(p->place!=NULL) { free(p->place); }
+ if (p->name != NULL) {
+ free(p->name);
+ }
+ if (p->place != NULL) {
+ free(p->place);
+ }
}
#include<event.h>
void event_init(struct event *p) {
- assert(p!=NULL);
+ assert(p != NULL);
event_options_init(&(p->options));
p->name = NULL;
p->place = NULL;
-
- memset(&(p->datetime),0,sizeof(struct tm));
+
+ memset(&(p->datetime), 0, sizeof(struct tm));
}
void event_options_init(struct event_options *p) {
- assert(p!=NULL);
+ assert(p != NULL);
p->recur = 0;
p->recur_period = TIME_PERIOD_NONE;
-
- memset(&(p->until),0,sizeof(struct tm));
-}
+ memset(&(p->until), 0, sizeof(struct tm));
+}
int event_name_set(struct event *ev, const char *name) {
size_t len;
- if(ev->name!=NULL) { free(ev->name); }
+ if (ev->name != NULL) {
+ free(ev->name);
+ }
ev->name = strdup(name);
- if(ev->name==NULL) { return -1; }
+ if (ev->name == NULL) {
+ return -1;
+ }
len = strlen(ev->name);
len--;
- if(ev->name[len]=='\n') {
+ if (ev->name[len] == '\n') {
ev->name[len] = '\0';
}
#include<event.h>
-static int event_parse_name(char*, size_t, struct event*);
-static int event_parse_options(char*, size_t, struct event*);
-static int event_parse_place(char*, size_t, struct event*);
-static int event_parse_time(char*, size_t, struct event*);
+static int event_parse_name(char *, size_t, struct event *);
+static int event_parse_options(char *, size_t, struct event *);
+static int event_parse_place(char *, size_t, struct event *);
+static int event_parse_time(char *, size_t, struct event *);
int event_parse(char *buf, size_t buf_size, struct event *ev) {
event_init(ev);
- if(event_parse_options(buf,buf_size,ev)<0) { return -1; }
- if(event_parse_time(buf,buf_size,ev)<0) { return -1; }
- if(event_parse_name(buf,buf_size,ev)<0) { return -1; }
- if(event_parse_place(buf,buf_size,ev)<0) { return -1; }
+ if (event_parse_options(buf, buf_size, ev) < 0) {
+ return -1;
+ }
+ if (event_parse_time(buf, buf_size, ev) < 0) {
+ return -1;
+ }
+ if (event_parse_name(buf, buf_size, ev) < 0) {
+ return -1;
+ }
+ if (event_parse_place(buf, buf_size, ev) < 0) {
+ return -1;
+ }
return 1;
}
const char *token;
char *p;
- if(buf[0]=='"') {
+ if (buf[0] == '"') {
token = escaped;
} else {
token = normal;
}
- if(strlen(buf)<1) { return -1; }
+ if (strlen(buf) < 1) {
+ return -1;
+ }
- p = strtok(buf,token);
- if(p!=NULL) {
- if(event_name_set(ev,p)<0) { return -1; }
+ p = strtok(buf, token);
+ if (p != NULL) {
+ if (event_name_set(ev, p) < 0) {
+ return -1;
+ }
}
- p = strtok(NULL,token);
+ p = strtok(NULL, token);
/*
* fix string for if place is also escaped
*/
- if(token[0]!=':') {
- if(p[1]=='\0') {
+ if (token[0] != ':') {
+ if (p[1] == '\0') {
p[1] = '"';
}
p++;
}
- if(p!=NULL) {
- memmove(buf,p,(buf_size - (p - buf)));
+ if (p != NULL) {
+ memmove(buf, p, (buf_size - (p - buf)));
} else {
buf[0] = '\0';
}
char *options, *p;
size_t diff;
- if(buf[0]!='[') { return 0; }
+ if (buf[0] != '[') {
+ return 0;
+ }
- options = strtok(buf,"]");
+ options = strtok(buf, "]");
- diff = strlen(options)+1;
+ diff = strlen(options) + 1;
- p = strtok(&(options[1]),",");
- while(p!=NULL) {
- if(memcmp(p,"until:",6)==0) {
- if(event_time_set(&(ev->options.until),&(p[6]))<0) { return -1; }
- } else if(memcmp(p,"recur",5)==0) {
- if(sscanf(
- p,
- "recur:%u%c",
- &(ev->options.recur),
- &period
- )!=2) {
- if(errno!=0) {
+ p = strtok(&(options[1]), ",");
+ while (p != NULL) {
+ if (memcmp(p, "until:", 6) == 0) {
+ if (event_time_set(&(ev->options.until), &(p[6])) < 0) {
+ return -1;
+ }
+ } else if (memcmp(p, "recur", 5) == 0) {
+ if (sscanf(p,
+ "recur:%u%c",
+ &(ev->options.recur), &period) != 2) {
+ if (errno != 0) {
perror("sccanf");
return -1;
}
}
ev->options.recur_period = event_options_period(period);
- } else { return -1; }
+ } else {
+ return -1;
+ }
- p = strtok(NULL,",");
+ p = strtok(NULL, ",");
}
- memmove(buf,&(buf[diff]),(buf_size - diff));
+ memmove(buf, &(buf[diff]), (buf_size - diff));
return 1;
}
const char *token;
char *p;
- if(buf[0]=='"') {
+ if (buf[0] == '"') {
token = escaped;
} else {
token = normal;
}
- p = strtok(buf,token);
- if(p!=NULL) {
- if(event_place_set(ev,p)<0) { return -1; }
+ p = strtok(buf, token);
+ if (p != NULL) {
+ if (event_place_set(ev, p) < 0) {
+ return -1;
+ }
}
return 1;
static int event_parse_time(char *buf, size_t buf_size, struct event *ev) {
char *p;
- if(buf[10]!=' ') {
+ if (buf[10] != ' ') {
buf[10] = '\0';
p = &(buf[11]);
- } else if(buf[19]!=' ') {
+ } else if (buf[19] != ' ') {
buf[19] = '\0';
p = &(buf[20]);
} else {
p = &(buf[26]);
}
- if(event_time_set(&(ev->datetime),buf)<0) { return -1; }
+ if (event_time_set(&(ev->datetime), buf) < 0) {
+ return -1;
+ }
- if((buf_size - (p - buf))>0) {
- memmove(buf,p,(buf_size - (p - buf)));
+ if ((buf_size - (p - buf)) > 0) {
+ memmove(buf, p, (buf_size - (p - buf)));
} else {
buf[0] = '\0';
}
#include<event.h>
enum time_period event_options_period(char period) {
- switch(period) {
- case 'Y':
- return TIME_PERIOD_YEAR;
- case 'M':
- return TIME_PERIOD_MONTH;
- case 'W':
- return TIME_PERIOD_WEEK;
- case 'D':
- return TIME_PERIOD_DAY;
- case 'h':
- return TIME_PERIOD_HOUR;
- case 'm':
- return TIME_PERIOD_MINUTE;
- case 's':
- return TIME_PERIOD_SECOND;
- default:
- return TIME_PERIOD_NONE;
+ switch (period) {
+ case 'Y':
+ return TIME_PERIOD_YEAR;
+ case 'M':
+ return TIME_PERIOD_MONTH;
+ case 'W':
+ return TIME_PERIOD_WEEK;
+ case 'D':
+ return TIME_PERIOD_DAY;
+ case 'h':
+ return TIME_PERIOD_HOUR;
+ case 'm':
+ return TIME_PERIOD_MINUTE;
+ case 's':
+ return TIME_PERIOD_SECOND;
+ default:
+ return TIME_PERIOD_NONE;
}
}
char event_options_period_char(enum time_period period) {
- switch(period) {
- case TIME_PERIOD_SECOND:
- return 's';
- case TIME_PERIOD_MINUTE:
- return 'm';
- case TIME_PERIOD_HOUR:
- return 'h';
- case TIME_PERIOD_DAY:
- return 'D';
- case TIME_PERIOD_WEEK:
- return 'W';
- case TIME_PERIOD_MONTH:
- return 'M';
- case TIME_PERIOD_YEAR:
- return 'Y';
- default:
- return '\0';
+ switch (period) {
+ case TIME_PERIOD_SECOND:
+ return 's';
+ case TIME_PERIOD_MINUTE:
+ return 'm';
+ case TIME_PERIOD_HOUR:
+ return 'h';
+ case TIME_PERIOD_DAY:
+ return 'D';
+ case TIME_PERIOD_WEEK:
+ return 'W';
+ case TIME_PERIOD_MONTH:
+ return 'M';
+ case TIME_PERIOD_YEAR:
+ return 'Y';
+ default:
+ return '\0';
}
}
int event_place_set(struct event *ev, const char *place) {
size_t len;
- if(ev->place!=NULL) { free(ev->place); }
+ if (ev->place != NULL) {
+ free(ev->place);
+ }
ev->place = strdup(place);
- if(ev->place==NULL) { return -1; }
+ if (ev->place == NULL) {
+ return -1;
+ }
len = strlen(ev->place);
len--;
- if(ev->place[len]=='\n') {
+ if (ev->place[len] == '\n') {
ev->place[len] = '\0';
}
#include<event.h>
-static int event_serialize_name(char*, size_t, const struct event*);
-static int event_serialize_options(char*, size_t, const struct event*);
-static int event_serialize_place(char*, size_t, const struct event*);
-static int event_serialize_time(char*, size_t, const struct tm*);
+static int event_serialize_name(char *, size_t, const struct event *);
+static int event_serialize_options(char *, size_t, const struct event *);
+static int event_serialize_place(char *, size_t, const struct event *);
+static int event_serialize_time(char *, size_t, const struct tm *);
int event_serialize(char *buf, size_t buf_size, const struct event *ev) {
- assert(buf!=NULL);
+ assert(buf != NULL);
- memset(buf,0,buf_size);
+ memset(buf, 0, buf_size);
- if(event_serialize_options(buf,buf_size,ev)<0) { return -1; }
- if(event_serialize_time(buf,buf_size,&(ev->datetime))<0) { return -1; }
- if(event_serialize_name(buf,buf_size,ev)<0) { return -1; }
- if(event_serialize_place(buf,buf_size,ev)<0) { return -1; }
+ if (event_serialize_options(buf, buf_size, ev) < 0) {
+ return -1;
+ }
+ if (event_serialize_time(buf, buf_size, &(ev->datetime)) < 0) {
+ return -1;
+ }
+ if (event_serialize_name(buf, buf_size, ev) < 0) {
+ return -1;
+ }
+ if (event_serialize_place(buf, buf_size, ev) < 0) {
+ return -1;
+ }
event_free(ev);
- strcat(buf,"\n");
+ strcat(buf, "\n");
return 1;
}
-static int event_serialize_name(char *buf, size_t buf_size, const struct event *ev) {
+static int event_serialize_name(char *buf, size_t buf_size,
+ const struct event *ev) {
char *p;
- if(NULL==ev->name) { return -1; }
+ if (NULL == ev->name) {
+ return -1;
+ }
+
+ if (strlen(buf) + strlen(ev->name) + 2 > buf_size) {
+ return -1;
+ }
- if(strlen(buf)+strlen(ev->name)+2>buf_size) { return -1; }
+ strcat(buf, ":");
- strcat(buf,":");
+ p = strchr(ev->name, ':');
+ if (p != NULL) {
+ strcat(buf, "\"");
+ }
- p = strchr(ev->name,':');
- if(p!=NULL) { strcat(buf,"\""); }
+ strcat(buf, ev->name);
- strcat(buf,ev->name);
-
- if(p!=NULL) { strcat(buf,"\""); }
+ if (p != NULL) {
+ strcat(buf, "\"");
+ }
return 1;
}
-static int event_serialize_options(char *buf, size_t buf_size, const struct event *ev) {
+static int event_serialize_options(char *buf, size_t buf_size,
+ const struct event *ev) {
size_t pos;
- if(!(ev->options.recur>0)) { return 0; }
+ if (!(ev->options.recur > 0)) {
+ return 0;
+ }
- strcpy(buf,"[");
+ strcpy(buf, "[");
pos = 1;
- if(ev->options.recur>0) {
- if(sprintf(
- &(buf[pos]),
- "recur:%u%c",
- ev->options.recur,
- event_options_period_char(ev->options.recur_period)
- )<0) { return -1; }
-
- if(event_time_compare(&(ev->options.until),0)>0) {
- strcat(buf,",until:");
-
- if(event_serialize_time(
- &(buf[pos]),
- buf_size,
- &(ev->options.until)
- )<0) { return -1; }
+ if (ev->options.recur > 0) {
+ if (sprintf(&(buf[pos]),
+ "recur:%u%c",
+ ev->options.recur,
+ event_options_period_char(ev->options.recur_period)
+ ) < 0) {
+ return -1;
+ }
+
+ if (event_time_compare(&(ev->options.until), 0) > 0) {
+ strcat(buf, ",until:");
+
+ if (event_serialize_time(&(buf[pos]),
+ buf_size, &(ev->options.until)
+ ) < 0) {
+ return -1;
+ }
pos = strlen(buf);
}
}
- strcat(buf,"]");
+ strcat(buf, "]");
return 1;
}
-static int event_serialize_place(char *buf, size_t buf_size, const struct event *ev) {
+static int event_serialize_place(char *buf, size_t buf_size,
+ const struct event *ev) {
char *p;
- assert(buf!=NULL);
+ assert(buf != NULL);
+
+ if (NULL == ev->place) {
+ return 0;
+ }
- if(NULL==ev->place) { return 0; }
-
- if(strlen(buf)+strlen(ev->place)+2>buf_size) { return -1; }
+ if (strlen(buf) + strlen(ev->place) + 2 > buf_size) {
+ return -1;
+ }
- strcat(buf,":");
-
- p = strchr(ev->name,':');
- if(p!=NULL) { strcat(buf,"\""); }
+ strcat(buf, ":");
- strcat(buf,ev->place);
+ p = strchr(ev->name, ':');
+ if (p != NULL) {
+ strcat(buf, "\"");
+ }
- if(p!=NULL) { strcat(buf,"\""); }
+ strcat(buf, ev->place);
+
+ if (p != NULL) {
+ strcat(buf, "\"");
+ }
return 1;
}
-static int event_serialize_time(char *buf, size_t buf_size, const struct tm *datetime) {
+static int event_serialize_time(char *buf, size_t buf_size,
+ const struct tm *datetime) {
size_t len, i;
- assert(buf!=NULL);
+ assert(buf != NULL);
len = strlen(buf);
-
- if(event_time_date_only(datetime)>0) {
- if(0==strftime(
- &(buf[len]), /* char *s */
- buf_size - len, /* size_t max */
- "%Y-%m-%d", /* const char *format */
- datetime /* const struct tm *tm */
- )) { return -1; }
+
+ if (event_time_date_only(datetime) > 0) {
+ if (0 == strftime(&(buf[len]), /* char *s */
+ buf_size - len, /* size_t max */
+ "%Y-%m-%d", /* const char *format */
+ datetime /* const struct tm *tm */
+ )) {
+ return -1;
+ }
} else {
long offset = datetime->__tm_gmtoff;
- i = strftime(
- &(buf[len]), /* char *s */
- buf_size - len, /* size_t max */
- "%Y-%m-%d %H:%M:%S ", /* const char *format */
- datetime /* const struct tm *tm */
- );
- if(i==0) { return -1; }
+ i = strftime(&(buf[len]), /* char *s */
+ buf_size - len, /* size_t max */
+ "%Y-%m-%d %H:%M:%S ", /* const char *format */
+ datetime /* const struct tm *tm */
+ );
+ if (i == 0) {
+ return -1;
+ }
len += i;
- if(snprintf(&(buf[len]),buf_size - len,"%+.2li%.2li", offset/3600, offset%60)<0) { return -1; }
+ if (snprintf
+ (&(buf[len]), buf_size - len, "%+.2li%.2li", offset / 3600,
+ offset % 60) < 0) {
+ return -1;
+ }
}
return 1;
struct tm tm;
time_t event_time;
- assert(datetime!=NULL);
+ assert(datetime != NULL);
- memcpy(&tm,datetime,sizeof(struct tm));
+ memcpy(&tm, datetime, sizeof(struct tm));
event_time = mktime(&tm);
- if(event_time>time) { return 1; }
- if(event_time<time) { return -1; }
+ if (event_time > time) {
+ return 1;
+ }
+ if (event_time < time) {
+ return -1;
+ }
return 0;
}
int event_time_date_only(const struct tm *date) {
- if((*date).tm_sec != 0) { return -1; }
- if((*date).tm_min != 0) { return -1; }
- if((*date).tm_hour != 0) { return -1; }
+ if ((*date).tm_sec != 0) {
+ return -1;
+ }
+ if ((*date).tm_min != 0) {
+ return -1;
+ }
+ if ((*date).tm_hour != 0) {
+ return -1;
+ }
return 1;
}
int event_time_set(struct tm *datetime, const char *str) {
const char *p;
-
+
/* this call is necessary here to guarantee
* that extern int daylight is set correctly.
* see man tzset.
datetime->tm_isdst = -1;
/* minimum expected date format */
- p = strptime(str,"%Y-%m-%d %H:%M:%S %z",datetime);
- if(p!=NULL) { return 1; }
+ p = strptime(str, "%Y-%m-%d %H:%M:%S %z", datetime);
+ if (p != NULL) {
+ return 1;
+ }
- p = strptime(str,"%Y-%m-%d %H:%M:%S",datetime);
- if(p!=NULL) {
- if(mktime(datetime)<0) { return -1; }
+ p = strptime(str, "%Y-%m-%d %H:%M:%S", datetime);
+ if (p != NULL) {
+ if (mktime(datetime) < 0) {
+ return -1;
+ }
return 1;
}
- p = strptime(str,"%Y-%m-%d",datetime);
- if(NULL==p) { return -1; }
-
+ p = strptime(str, "%Y-%m-%d", datetime);
+ if (NULL == p) {
+ return -1;
+ }
+
return 1;
}
struct tm tm;
time_t event_time;
- memcpy(&tm,&(ev->datetime),sizeof(struct tm));
+ memcpy(&tm, &(ev->datetime), sizeof(struct tm));
event_time = mktime(&tm);
- if(filter->start>event_time) { return -1; }
- if(filter->end<event_time) { return -1; }
+ if (filter->start > event_time) {
+ return -1;
+ }
+ if (filter->end < event_time) {
+ return -1;
+ }
return 1;
}
#include<file.h>
ssize_t file_line_next(char *buf, size_t n, FILE *stream) {
- return getline(&buf,&n,stream);
+ return getline(&buf, &n, stream);
}
FILE *src, *to;
src = fopen(tempname, "r");
- if(NULL==src) {
+ if (NULL == src) {
perror("fopen");
return -1;
}
to = fopen(global_options.file, "w");
- if(NULL==to) {
+ if (NULL == to) {
perror("fopen");
return -1;
}
- if(file_pipe(to, src)<0) { return -1; }
+ if (file_pipe(to, src) < 0) {
+ return -1;
+ }
- if(fclose(src)!=0) { return -1; }
- if(fclose(to)!=0) { return -1; }
+ if (fclose(src) != 0) {
+ return -1;
+ }
+ if (fclose(to) != 0) {
+ return -1;
+ }
- if(remove(tempname)!=0) { return -1; }
+ if (remove(tempname) != 0) {
+ return -1;
+ }
return 1;
}
static FILE *file_create_prompt();
static FILE *file_create_prompt() {
- fprintf(stderr,"%s doesn't exist... create? [Y/n] ",global_options.file);
- if(fgetc(stdin)!='Y') { return NULL; }
- return fopen(global_options.file,"w+");
+ fprintf(stderr, "%s doesn't exist... create? [Y/n] ",
+ global_options.file);
+ if (fgetc(stdin) != 'Y') {
+ return NULL;
+ }
+ return fopen(global_options.file, "w+");
}
FILE *file_open() {
FILE *fp;
- fp = fopen(global_options.file,"r");
- if(NULL==fp) {
- if(errno!=ENOENT) {
+ fp = fopen(global_options.file, "r");
+ if (NULL == fp) {
+ if (errno != ENOENT) {
perror("fopen");
return NULL;
} else {
char buf[100];
size_t i;
- while((i = fread(buf, 1, 100, from))>0) {
- if(fwrite(buf,1,i,to)!=i) { return -1; }
+ while ((i = fread(buf, 1, 100, from)) > 0) {
+ if (fwrite(buf, 1, i, to) != i) {
+ return -1;
+ }
}
- if(feof(from)==0) { return -1; }
+ if (feof(from) == 0) {
+ return -1;
+ }
return 1;
}
FILE *file_temp(char *template) {
int fd = mkstemp(template);
- if(fd<0) {
+ if (fd < 0) {
perror("mkstemp");
return NULL;
}
- return fdopen(fd,"w");
+ return fdopen(fd, "w");
}
#include<ls.h>
-static int event_print(struct event*);
+static int event_print(struct event *);
int ls() {
char buf[EVENT_SERIALIZE_MAX_LENGTH];
FILE *fp;
fp = file_open();
- if(fp==NULL) { return EXIT_FAILURE; }
+ if (fp == NULL) {
+ return EXIT_FAILURE;
+ }
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- while((i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,fp))>0) {
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ while ((i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, fp)) > 0) {
+
+ if (event_parse(buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ goto close;
+ }
- if(event_parse(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) { goto close; }
-
- if(event_within(&ev,&(global_options.event_filter))>0) {
- if(event_print(&ev)<0) { goto close; }
+ if (event_within(&ev, &(global_options.event_filter)) > 0) {
+ if (event_print(&ev) < 0) {
+ goto close;
+ }
}
-
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
+
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
}
- if(fclose(fp)!=0) {
+ if (fclose(fp) != 0) {
perror("fclose");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
-close:
+ close:
fclose(fp);
return EXIT_FAILURE;
}
struct tm *local;
long offset;
- assert(ev!=NULL);
+ assert(ev != NULL);
- if(NULL==ev->name) { return -1; }
+ if (NULL == ev->name) {
+ return -1;
+ }
- if(event_time_date_only(&(ev->datetime))>0) {
- if(strftime(datebuf,20,"%Y-%m-%d",&(ev->datetime))!=10) { return -1; }
+ if (event_time_date_only(&(ev->datetime)) > 0) {
+ if (strftime(datebuf, 20, "%Y-%m-%d", &(ev->datetime)) != 10) {
+ return -1;
+ }
} else {
offset = ev->datetime.tm_gmtoff;
timestamp = timegm(&(ev->datetime)) - offset;
- if(timestamp<0) { return -1; }
+ if (timestamp < 0) {
+ return -1;
+ }
local = localtime(×tamp);
- if(NULL==local) { return -1; }
+ if (NULL == local) {
+ return -1;
+ }
- if(strftime(datebuf,20,"%Y-%m-%d %H:%M:%S",local)!=19) { return -1; }
+ if (strftime(datebuf, 20, "%Y-%m-%d %H:%M:%S", local) != 19) {
+ return -1;
+ }
}
- if(fprintf(stdout,"%-20s\t",datebuf)<0) { return -1; }
- if(fprintf(stdout,"%s",ev->name)<0) { return -1; }
+ if (fprintf(stdout, "%-20s\t", datebuf) < 0) {
+ return -1;
+ }
+ if (fprintf(stdout, "%s", ev->name) < 0) {
+ return -1;
+ }
- if(ev->place!=NULL) {
- if(fprintf(stdout," @ %s",ev->place)<0) { return -1; }
+ if (ev->place != NULL) {
+ if (fprintf(stdout, " @ %s", ev->place) < 0) {
+ return -1;
+ }
}
- if(event_time_compare(&(ev->datetime),time(NULL))<1) {
- if(fprintf(stdout," \x1B[31m[OVERDUE]\x1B[0m")<0) { return -1; }
+ if (event_time_compare(&(ev->datetime), time(NULL)) < 1) {
+ if (fprintf(stdout, " \x1B[31m[OVERDUE]\x1B[0m") < 0) {
+ return -1;
+ }
}
- if(fprintf(stdout,"\n")<0) { return -1; }
+ if (fprintf(stdout, "\n") < 0) {
+ return -1;
+ }
return 1;
}
int main(int argc, char **argv) {
enum sub_command cmd;
- if(defaults()<0) { return EXIT_FAILURE; }
- if(opt_load_from_env()<0) { return EXIT_FAILURE; }
+ if (defaults() < 0) {
+ return EXIT_FAILURE;
+ }
+ if (opt_load_from_env() < 0) {
+ return EXIT_FAILURE;
+ }
- cmd = args(argc,argv);
- if(SUB_COMMAND_INVALID_ARGS==cmd) { return EXIT_FAILURE; }
+ cmd = args(argc, argv);
+ if (SUB_COMMAND_INVALID_ARGS == cmd) {
+ return EXIT_FAILURE;
+ }
- switch(cmd) {
- case SUB_COMMAND_ADD:
- return add(argc,argv);
- case SUB_COMMAND_DISMISS:
- return rm(argc,argv,RM_FLAG_DISMISS);
- case SUB_COMMAND_LS:
- return ls();
- case SUB_COMMAND_POSTPONE:
- return postpone(argc,argv);
- case SUB_COMMAND_PRUNE:
- return prune();
- case SUB_COMMAND_RM:
- return rm(argc,argv,0);
- case SUB_COMMAND_VALIDATE:
- return validate();
- default:
- return EXIT_FAILURE;
+ switch (cmd) {
+ case SUB_COMMAND_ADD:
+ return add(argc, argv);
+ case SUB_COMMAND_DISMISS:
+ return rm(argc, argv, RM_FLAG_DISMISS);
+ case SUB_COMMAND_LS:
+ return ls();
+ case SUB_COMMAND_POSTPONE:
+ return postpone(argc, argv);
+ case SUB_COMMAND_PRUNE:
+ return prune();
+ case SUB_COMMAND_RM:
+ return rm(argc, argv, 0);
+ case SUB_COMMAND_VALIDATE:
+ return validate();
+ default:
+ return EXIT_FAILURE;
}
}
int opt_load_from_env() {
char *p;
- CHECK_ENV("EVENT_FILTER",opt_event_filter_set);
- CHECK_ENV("FILE",opt_file_set);
- CHECK_ENV("RECUR",opt_recur_set);
- CHECK_ENV("UNTIL",opt_until_set);
+ CHECK_ENV("EVENT_FILTER", opt_event_filter_set);
+ CHECK_ENV("FILE", opt_file_set);
+ CHECK_ENV("RECUR", opt_recur_set);
+ CHECK_ENV("UNTIL", opt_until_set);
return 1;
}
#include<opt.h>
int opt_file_set(const char *p) {
- if(global_options.file!=NULL) { free(global_options.file); }
+ if (global_options.file != NULL) {
+ free(global_options.file);
+ }
global_options.file = strdup(p);
- if(NULL==global_options.file) { return -1; }
+ if (NULL == global_options.file) {
+ return -1;
+ }
return 1;
}
#include<opt.h>
-static int opt_event_filter_range_set_upcoming(const char*);
+static int opt_event_filter_range_set_upcoming(const char *);
int opt_event_filter_date_set(time_t *to_set, const char *date_string) {
struct event ev;
- assert(to_set!=NULL);
+ assert(to_set != NULL);
/*
* This function uses the event_time_set(struct tm *datetime, const char *str)
* method for consistencies' sake.
*/
- if(event_time_set(&(ev.datetime),date_string)<0) {
- fprintf(stderr,"invalid date given: %s\n",date_string);
+ if (event_time_set(&(ev.datetime), date_string) < 0) {
+ fprintf(stderr, "invalid date given: %s\n", date_string);
return -1;
}
}
int opt_event_filter_range_set(const char *type, const char *arg) {
- if(strcmp(type,"upcoming")==0) {
- if(opt_event_filter_range_set_upcoming((NULL==arg)?"1W":arg)<0) {
+ if (strcmp(type, "upcoming") == 0) {
+ if (opt_event_filter_range_set_upcoming
+ ((NULL == arg) ? "1W" : arg) < 0) {
fprintf(stderr,
- "invalid time period given as argument to --upcoming option\n"
- );
+ "invalid time period given as argument to --upcoming option\n");
return -1;
}
return 1;
}
- fprintf(stderr,"should never get to here\n");
+ fprintf(stderr, "should never get to here\n");
return -1;
}
now_timet = time(NULL);
now = localtime(&now_timet);
- if(sscanf(arg,"%u%c",&offset,&period)!=2) {
- if(errno!=0) { perror("sscanf"); }
+ if (sscanf(arg, "%u%c", &offset, &period) != 2) {
+ if (errno != 0) {
+ perror("sscanf");
+ }
return -1;
}
- switch(event_options_period(period)) {
- case TIME_PERIOD_YEAR:
- now->tm_year += offset;
- break;
- case TIME_PERIOD_MONTH:
- now->tm_mon += offset;
- break;
- case TIME_PERIOD_WEEK:
- now->tm_mday += 7*offset;
- break;
- case TIME_PERIOD_DAY:
- now->tm_mday += offset;
- break;
- case TIME_PERIOD_HOUR:
- now->tm_hour += offset;
- break;
- case TIME_PERIOD_MINUTE:
- now->tm_min += offset;
- break;
- case TIME_PERIOD_SECOND:
- now->tm_sec += offset;
- break;
- default:
- return -1;
+ switch (event_options_period(period)) {
+ case TIME_PERIOD_YEAR:
+ now->tm_year += offset;
+ break;
+ case TIME_PERIOD_MONTH:
+ now->tm_mon += offset;
+ break;
+ case TIME_PERIOD_WEEK:
+ now->tm_mday += 7 * offset;
+ break;
+ case TIME_PERIOD_DAY:
+ now->tm_mday += offset;
+ break;
+ case TIME_PERIOD_HOUR:
+ now->tm_hour += offset;
+ break;
+ case TIME_PERIOD_MINUTE:
+ now->tm_min += offset;
+ break;
+ case TIME_PERIOD_SECOND:
+ now->tm_sec += offset;
+ break;
+ default:
+ return -1;
}
global_options.event_filter.start = time(NULL);
}
int opt_event_filter_set(const char *p) {
- if(strcmp(p,"all")==0) {
+ if (strcmp(p, "all") == 0) {
global_options.event_filter.start = 0;
global_options.event_filter.end = INT_MAX;
return 1;
}
- if(strcmp(p,"overdue")==0) {
+ if (strcmp(p, "overdue") == 0) {
global_options.event_filter.start = 0;
global_options.event_filter.end = time(NULL);
return 1;
char c;
enum time_period period;
- if(NULL==p) { return -1; }
+ if (NULL == p) {
+ return -1;
+ }
- if(sscanf(p,"%u%c",&recur,&c)!=2) {
- fprintf(stderr,"invalid recur option value: %s\n",p);
+ if (sscanf(p, "%u%c", &recur, &c) != 2) {
+ fprintf(stderr, "invalid recur option value: %s\n", p);
return -1;
}
period = event_options_period(c);
- if(TIME_PERIOD_NONE==period) {
- fprintf(stderr,"invalid recur option value: %s\n",p);
+ if (TIME_PERIOD_NONE == period) {
+ fprintf(stderr, "invalid recur option value: %s\n", p);
return -1;
}
int opt_until_set(const char *p) {
struct event ev;
-
- if(NULL==p) { return -1; }
+
+ if (NULL == p) {
+ return -1;
+ }
event_init(&ev);
- if(event_time_set(&(ev.datetime),p)<0) {
- fprintf(stderr,"invalid until option value: %s\n",p);
+ if (event_time_set(&(ev.datetime), p) < 0) {
+ fprintf(stderr, "invalid until option value: %s\n", p);
return -1;
}
static char *postpone_offset_string = NULL;
-static int handle_args(int,char**,unsigned long int*,time_t*);
-static int postpone_event(struct event*);
+static int handle_args(int, char **, unsigned long int *, time_t *);
+static int postpone_event(struct event *);
-static int handle_args(int argc, char **argv, unsigned long int *offset, time_t *start_time) {
+static int handle_args(int argc, char **argv, unsigned long int *offset,
+ time_t *start_time) {
unsigned long int i;
-
- assert(offset!=NULL);
- assert(start_time!=NULL);
-
- switch(argc-optind) {
- case 4: /* date index period */
- if(opt_event_filter_date_set(start_time,argv[optind+1])<0) {
- goto invalid;
- }
-
- i = strtoul(argv[optind+2],NULL,0);
- if(i>UINT_MAX) { goto invalid; }
- (*offset) = i;
-
- postpone_offset_string = strdup(argv[argc-1]);
- if(NULL==postpone_offset_string) { goto invalid; }
- break;
- case 3: /* date index */
- if(opt_event_filter_date_set(start_time,argv[optind+1])<0) {
- goto invalid;
- }
-
- i = strtoul(argv[argc-1],NULL,0);
- if(i>UINT_MAX) { goto invalid; }
- (*offset) = i;
- break;
- case 2: /* index */
- (*start_time) = 0;
-
- i = strtoul(argv[argc-1],NULL,0);
- if(i>UINT_MAX) { goto invalid; }
- (*offset) = i;
- break;
- default:
+
+ assert(offset != NULL);
+ assert(start_time != NULL);
+
+ switch (argc - optind) {
+ case 4: /* date index period */
+ if (opt_event_filter_date_set(start_time, argv[optind + 1]) < 0) {
+ goto invalid;
+ }
+
+ i = strtoul(argv[optind + 2], NULL, 0);
+ if (i > UINT_MAX) {
+ goto invalid;
+ }
+ (*offset) = i;
+
+ postpone_offset_string = strdup(argv[argc - 1]);
+ if (NULL == postpone_offset_string) {
+ goto invalid;
+ }
+ break;
+ case 3: /* date index */
+ if (opt_event_filter_date_set(start_time, argv[optind + 1]) < 0) {
+ goto invalid;
+ }
+
+ i = strtoul(argv[argc - 1], NULL, 0);
+ if (i > UINT_MAX) {
goto invalid;
+ }
+ (*offset) = i;
+ break;
+ case 2: /* index */
+ (*start_time) = 0;
+
+ i = strtoul(argv[argc - 1], NULL, 0);
+ if (i > UINT_MAX) {
+ goto invalid;
+ }
+ (*offset) = i;
+ break;
+ default:
+ goto invalid;
}
return 1;
-invalid:
- fprintf(stderr,"invalid number of arguments\n");
+ invalid:
+ fprintf(stderr, "invalid number of arguments\n");
usage();
return -1;
}
size_t offset;
struct event ev;
- if(handle_args(argc,argv,&offset,&start_time)<0) { goto fail; }
+ if (handle_args(argc, argv, &offset, &start_time) < 0) {
+ goto fail;
+ }
+
+ if (cut(&ev, start_time, offset) < 0) {
+ goto fail;
+ }
- if(cut(&ev,start_time,offset)<0) { goto fail; }
+ if (postpone_event(&ev) < 0) {
+ goto fail;
+ }
- if(postpone_event(&ev)<0) { goto fail; }
-
- strftime(timebuf,40,"%a, %d %b %Y %T %z",&(ev.datetime));
+ strftime(timebuf, 40, "%a, %d %b %Y %T %z", &(ev.datetime));
- if(snprintf(
- buf,
- EVENT_SERIALIZE_MAX_LENGTH,
- "postponed event '%s' until '%s'\n",
- ev.name,
- timebuf
- )<0) { goto fail; }
+ if (snprintf(buf,
+ EVENT_SERIALIZE_MAX_LENGTH,
+ "postponed event '%s' until '%s'\n",
+ ev.name, timebuf) < 0) {
+ goto fail;
+ }
- if(add_to_file(&ev)<0) { goto fail; }
+ if (add_to_file(&ev) < 0) {
+ goto fail;
+ }
- fprintf(stdout,buf);
+ fprintf(stdout, buf);
return EXIT_SUCCESS;
-fail:
- if(postpone_offset_string!=NULL) { free(postpone_offset_string); }
+ fail:
+ if (postpone_offset_string != NULL) {
+ free(postpone_offset_string);
+ }
return EXIT_FAILURE;
}
unsigned int offset;
char period;
- assert(ev!=NULL);
+ assert(ev != NULL);
- if(NULL==postpone_offset_string) {
+ if (NULL == postpone_offset_string) {
ev->datetime.tm_mday += 1;
return 1;
}
- if(sscanf(postpone_offset_string,"%u%c",&offset,&period)!=2) {
- if(errno!=0) {
+ if (sscanf(postpone_offset_string, "%u%c", &offset, &period) != 2) {
+ if (errno != 0) {
perror("sscanf");
return -1;
}
}
- switch(event_options_period(period)) {
- case TIME_PERIOD_YEAR:
- ev->datetime.tm_year += offset;
- break;
- case TIME_PERIOD_MONTH:
- ev->datetime.tm_mon += offset;
- break;
- case TIME_PERIOD_WEEK:
- ev->datetime.tm_mday += 7*offset;
- break;
- case TIME_PERIOD_DAY:
- ev->datetime.tm_mday += offset;
- break;
- case TIME_PERIOD_HOUR:
- ev->datetime.tm_hour += offset;
- break;
- case TIME_PERIOD_MINUTE:
- ev->datetime.tm_min += offset;
- break;
- case TIME_PERIOD_SECOND:
- ev->datetime.tm_sec += offset;
- break;
- default:
- return -1;
+ switch (event_options_period(period)) {
+ case TIME_PERIOD_YEAR:
+ ev->datetime.tm_year += offset;
+ break;
+ case TIME_PERIOD_MONTH:
+ ev->datetime.tm_mon += offset;
+ break;
+ case TIME_PERIOD_WEEK:
+ ev->datetime.tm_mday += 7 * offset;
+ break;
+ case TIME_PERIOD_DAY:
+ ev->datetime.tm_mday += offset;
+ break;
+ case TIME_PERIOD_HOUR:
+ ev->datetime.tm_hour += offset;
+ break;
+ case TIME_PERIOD_MINUTE:
+ ev->datetime.tm_min += offset;
+ break;
+ case TIME_PERIOD_SECOND:
+ ev->datetime.tm_sec += offset;
+ break;
+ default:
+ return -1;
}
free(postpone_offset_string);
#include<prune.h>
-static int copy_recur_events(FILE*,FILE*);
+static int copy_recur_events(FILE *, FILE *);
static int copy_recur_events(FILE *src, FILE *to) {
char buf[EVENT_SERIALIZE_MAX_LENGTH];
now = time(NULL);
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- while((i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,src))>0) {
- if(event_parse(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) { return -1; }
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ while ((i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, src)) > 0) {
+ if (event_parse(buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ return -1;
+ }
- if(event_time_compare(&(ev.datetime),now)>0) {
+ if (event_time_compare(&(ev.datetime), now) > 0) {
event_free(&ev);
- if(fseek(src,-i,SEEK_CUR)!=0) { return -1; }
+ if (fseek(src, -i, SEEK_CUR) != 0) {
+ return -1;
+ }
break;
}
- switch(recur(&ev)) {
- case -1:
- event_free(&ev);
+ switch (recur(&ev)) {
+ case -1:
+ event_free(&ev);
+ return -1;
+ case 1:
+ if (event_serialize
+ (buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ return -1;
+ }
+ if (fwrite(buf, 1, i, to) != i) {
return -1;
- case 1:
- if(event_serialize(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) { return -1; }
- if(fwrite(buf,1,i,to)!=i) { return -1; }
- break;
- default:
- event_free(&ev);
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- break;
+ }
+ break;
+ default:
+ event_free(&ev);
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ break;
}
}
char tempfile[] = "/tmp/XXXXXX";
to = file_temp(tempfile);
- if(NULL==to) { return EXIT_FAILURE; }
+ if (NULL == to) {
+ return EXIT_FAILURE;
+ }
src = file_open();
- if(NULL==src) { return EXIT_FAILURE; }
+ if (NULL == src) {
+ return EXIT_FAILURE;
+ }
+
+ if (copy_recur_events(src, to) < 0) {
+ return EXIT_FAILURE;
+ }
+
+ if (file_pipe(to, src) < 0) {
+ return EXIT_FAILURE;
+ }
- if(copy_recur_events(src,to)<0) { return EXIT_FAILURE; }
-
- if(file_pipe(to,src)<0) { return EXIT_FAILURE; }
+ if (fclose(src) != 0) {
+ return EXIT_FAILURE;
+ }
+ if (fclose(to) != 0) {
+ return EXIT_FAILURE;
+ }
- if(fclose(src)!=0) { return EXIT_FAILURE; }
- if(fclose(to)!=0) { return EXIT_FAILURE; }
-
- if(file_move(tempfile)<0) { return EXIT_FAILURE; }
+ if (file_move(tempfile) < 0) {
+ return EXIT_FAILURE;
+ }
return EXIT_SUCCESS;
}
time_t compare;
struct tm tm;
- if(ev->options.recur==0) { return 0; }
-
- memcpy(&tm,&(ev->datetime),sizeof(struct tm));
-
- switch(ev->options.recur_period) {
- case TIME_PERIOD_YEAR:
- tm.tm_year += ev->options.recur;
- break;
- case TIME_PERIOD_MONTH:
- tm.tm_mon += ev->options.recur;
- break;
- case TIME_PERIOD_WEEK:
- tm.tm_mday += 7*(ev->options.recur);
- break;
- case TIME_PERIOD_DAY:
- tm.tm_mday += ev->options.recur;
- break;
- case TIME_PERIOD_HOUR:
- tm.tm_hour += ev->options.recur;
- break;
- case TIME_PERIOD_MINUTE:
- tm.tm_min += ev->options.recur;
- break;
- case TIME_PERIOD_SECOND:
- tm.tm_sec += ev->options.recur;
- break;
- default:
- return -1;
+ if (ev->options.recur == 0) {
+ return 0;
+ }
+
+ memcpy(&tm, &(ev->datetime), sizeof(struct tm));
+
+ switch (ev->options.recur_period) {
+ case TIME_PERIOD_YEAR:
+ tm.tm_year += ev->options.recur;
+ break;
+ case TIME_PERIOD_MONTH:
+ tm.tm_mon += ev->options.recur;
+ break;
+ case TIME_PERIOD_WEEK:
+ tm.tm_mday += 7 * (ev->options.recur);
+ break;
+ case TIME_PERIOD_DAY:
+ tm.tm_mday += ev->options.recur;
+ break;
+ case TIME_PERIOD_HOUR:
+ tm.tm_hour += ev->options.recur;
+ break;
+ case TIME_PERIOD_MINUTE:
+ tm.tm_min += ev->options.recur;
+ break;
+ case TIME_PERIOD_SECOND:
+ tm.tm_sec += ev->options.recur;
+ break;
+ default:
+ return -1;
}
tm.tm_isdst = -1;
compare = mktime(&tm);
- if(compare<0) { return -1; }
+ if (compare < 0) {
+ return -1;
+ }
ev->datetime.tm_year = tm.tm_year;
ev->datetime.tm_mon = tm.tm_mon;
ev->datetime.tm_sec = tm.tm_sec;
ev->datetime.tm_wday = tm.tm_wday;
- if(event_time_compare(&(ev->options.until),0)>0) {
- if(event_time_compare(&(ev->options.until),compare)<0) { return 0; }
+ if (event_time_compare(&(ev->options.until), 0) > 0) {
+ if (event_time_compare(&(ev->options.until), compare) < 0) {
+ return 0;
+ }
}
return 1;
#include<rm.h>
-static int check_need_readd(struct event*);
-static int handle_args(int,char**,unsigned long int*, time_t *);
+static int check_need_readd(struct event *);
+static int handle_args(int, char **, unsigned long int *, time_t *);
static int check_need_readd(struct event *ev) {
char buf[EVENT_SERIALIZE_MAX_LENGTH];
char timebuf[40];
- assert(ev!=NULL);
+ assert(ev != NULL);
- switch(recur(ev)) {
- case -1:
- return -1;
- case 0:
- return 1;
- default:
- break;
+ switch (recur(ev)) {
+ case -1:
+ return -1;
+ case 0:
+ return 1;
+ default:
+ break;
}
- strftime(timebuf,40,"%a, %d %b %Y %T %z",&(ev->datetime));
+ strftime(timebuf, 40, "%a, %d %b %Y %T %z", &(ev->datetime));
- if(snprintf(
- buf,
- EVENT_SERIALIZE_MAX_LENGTH,
- "re-added event '%s' on %s\n",
- ev->name,
- timebuf
- )<0) { return -1; }
+ if (snprintf(buf,
+ EVENT_SERIALIZE_MAX_LENGTH,
+ "re-added event '%s' on %s\n", ev->name, timebuf) < 0) {
+ return -1;
+ }
- if(add_to_file(ev)<0) { return -1; }
+ if (add_to_file(ev) < 0) {
+ return -1;
+ }
- fprintf(stdout,buf);
+ fprintf(stdout, buf);
return 1;
}
-static int handle_args(int argc, char **argv, unsigned long int *offset, time_t *start_time) {
+static int handle_args(int argc, char **argv, unsigned long int *offset,
+ time_t *start_time) {
unsigned long i;
- assert(offset!=NULL);
- assert(start_time!=NULL);
+ assert(offset != NULL);
+ assert(start_time != NULL);
(*start_time) = 0;
- switch(argc-optind) {
- case 3:
- if(opt_event_filter_date_set(start_time,argv[optind+1])<0) {
- goto invalid;
- }
- case 2:
- i = strtoul(argv[argc-1],NULL,0);
- if(i>UINT_MAX) { goto invalid; }
- (*offset) = i;
- break;
- default:
+ switch (argc - optind) {
+ case 3:
+ if (opt_event_filter_date_set(start_time, argv[optind + 1]) < 0) {
+ goto invalid;
+ }
+ case 2:
+ i = strtoul(argv[argc - 1], NULL, 0);
+ if (i > UINT_MAX) {
goto invalid;
+ }
+ (*offset) = i;
+ break;
+ default:
+ goto invalid;
}
return 1;
-invalid:
- fprintf(stderr,"invalid arguments\n");
+ invalid:
+ fprintf(stderr, "invalid arguments\n");
usage();
return -1;
}
size_t offset;
struct event ev;
- if(handle_args(argc,argv,&offset,&start_time)<0) { return EXIT_FAILURE; }
+ if (handle_args(argc, argv, &offset, &start_time) < 0) {
+ return EXIT_FAILURE;
+ }
- if(cut(&ev,start_time,offset)<0) { return EXIT_FAILURE; }
+ if (cut(&ev, start_time, offset) < 0) {
+ return EXIT_FAILURE;
+ }
- strftime(timebuf,40,"%a, %d %b %Y %T %z",&(ev.datetime));
+ strftime(timebuf, 40, "%a, %d %b %Y %T %z", &(ev.datetime));
- fprintf(stderr,"removed event %s on %s\n",ev.name,timebuf);
+ fprintf(stderr, "removed event %s on %s\n", ev.name, timebuf);
- if(RM_FLAG_DISMISS==flags) {
- if(check_need_readd(&ev)<0) { return EXIT_FAILURE; }
+ if (RM_FLAG_DISMISS == flags) {
+ if (check_need_readd(&ev) < 0) {
+ return EXIT_FAILURE;
+ }
} else {
event_free(&ev);
}
struct event ev;
ssize_t i;
- if(NULL==fp) { return -1; }
+ if (NULL == fp) {
+ return -1;
+ }
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- while((i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,fp))>0) {
- if(event_parse(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) { return -1; }
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ while ((i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, fp)) > 0) {
+ if (event_parse(buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ return -1;
+ }
- if(event_time_compare(&(ev.datetime),time)>=0) {
+ if (event_time_compare(&(ev.datetime), time) >= 0) {
event_free(&ev);
- if(fseek(fp,-i,SEEK_CUR)!=0) { return -1; }
+ if (fseek(fp, -i, SEEK_CUR) != 0) {
+ return -1;
+ }
break;
}
-
+
event_free(&ev);
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
}
- if(i<0) {
- if(ferror(fp)!=0) {
- fprintf(stderr,"failed to get line");
+ if (i < 0) {
+ if (ferror(fp) != 0) {
+ fprintf(stderr, "failed to get line");
return -1;
}
}
};
static struct option_description options[] = {
- {"all",'a',"show all"},
- {"end-date",'e',"ending date"},
- {"file",'f',"events file location"},
- {"help",'h',"show this help"},
- {"overdue",'o',"show only overdue events"},
- {"recurring",'r',"denote event as recurring"},
- {"start-date",'s',"starting date"},
- {"upcoming",'u',"show only upcoming events"},
- {NULL,0,NULL}
+ {"all", 'a', "show all"},
+ {"end-date", 'e', "ending date"},
+ {"file", 'f', "events file location"},
+ {"help", 'h', "show this help"},
+ {"overdue", 'o', "show only overdue events"},
+ {"recurring", 'r', "denote event as recurring"},
+ {"start-date", 's', "starting date"},
+ {"upcoming", 'u', "show only upcoming events"},
+ {NULL, 0, NULL}
};
static void usage_print_options();
void usage() {
- fprintf(stderr,"Usage:\n");
- fprintf(stderr,"\tev [options] [command = 'ls'] [arg1, arg2, ..., argn]\n");
- fprintf(stderr,"\n");
- fprintf(stderr,"Commands:\n");
- fprintf(stderr,"\tadd\n");
- fprintf(stderr,"\tdismiss\n");
- fprintf(stderr,"\tls\n");
- fprintf(stderr,"\tpostpone\n");
- fprintf(stderr,"\tprune\n");
- fprintf(stderr,"\trm\n");
- fprintf(stderr,"\n");
-
- fprintf(stderr,"Options:\n");
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr,
+ "\tev [options] [command = 'ls'] [arg1, arg2, ..., argn]\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Commands:\n");
+ fprintf(stderr, "\tadd\n");
+ fprintf(stderr, "\tdismiss\n");
+ fprintf(stderr, "\tls\n");
+ fprintf(stderr, "\tpostpone\n");
+ fprintf(stderr, "\tprune\n");
+ fprintf(stderr, "\trm\n");
+ fprintf(stderr, "\n");
+
+ fprintf(stderr, "Options:\n");
usage_print_options();
- fprintf(stderr,"\n");
- fprintf(stderr,"See `man ev` for more information.\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "See `man ev` for more information.\n");
return;
}
// NOTE: long options defined in src/args.c
i = 0;
- while(
- !((NULL==options[i].long_opt) &&
- (0==options[i].short_opt) &&
- (NULL==options[i].description))) {
+ while (!((NULL == options[i].long_opt) &&
+ (0 == options[i].short_opt) &&
+ (NULL == options[i].description))) {
- fprintf(stderr,"\t--%s, -%c\t\t%s\n",options[i].long_opt,options[i].short_opt,options[i].description);
+ fprintf(stderr, "\t--%s, -%c\t\t%s\n", options[i].long_opt,
+ options[i].short_opt, options[i].description);
i++;
}
}
size_t line;
src = file_open();
- if(NULL==src) { return EXIT_FAILURE; }
-
+ if (NULL == src) {
+ return EXIT_FAILURE;
+ }
+
line = 1;
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
- while((i = file_line_next(buf,EVENT_SERIALIZE_MAX_LENGTH,src))>0) {
- if(event_parse(buf,EVENT_SERIALIZE_MAX_LENGTH,&ev)<0) {
- fprintf(stderr,"invalid event: event on line %lu failed to parse\n",line);
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
+ while ((i = file_line_next(buf, EVENT_SERIALIZE_MAX_LENGTH, src)) > 0) {
+ if (event_parse(buf, EVENT_SERIALIZE_MAX_LENGTH, &ev) < 0) {
+ fprintf(stderr,
+ "invalid event: event on line %lu failed to parse\n",
+ line);
return EXIT_FAILURE;
}
event_free(&ev);
- memset(buf,0,EVENT_SERIALIZE_MAX_LENGTH);
+ memset(buf, 0, EVENT_SERIALIZE_MAX_LENGTH);
line++;
}
-
- if(i<0) {
- if(ferror(src)!=0) {
- fprintf(stderr,"failed to get line");
+
+ if (i < 0) {
+ if (ferror(src) != 0) {
+ fprintf(stderr, "failed to get line");
return EXIT_FAILURE;
}
}
- fprintf(stdout,"%s: \x1B[32mVALID\x1B[0m\n",global_options.file);
+ fprintf(stdout, "%s: \x1B[32mVALID\x1B[0m\n", global_options.file);
return EXIT_SUCCESS;
}