]> infiniteadaptability.org Git - events/commitdiff
chore: format
authoralex <[email protected]>
Sun, 14 Dec 2025 07:59:01 +0000 (23:59 -0800)
committeralex <[email protected]>
Sun, 14 Dec 2025 07:59:01 +0000 (23:59 -0800)
46 files changed:
.gitignore
Makefile.am
inc/add.h
inc/args.h
inc/copy.h
inc/cut.h
inc/event.h
inc/file.h
inc/main.h
inc/opt.h
inc/postpone.h
inc/recur.h
inc/rm.h
inc/seek.h
src/add.c
src/args.c
src/copy.c
src/cut.c
src/defaults.c
src/event/free.c
src/event/init.c
src/event/name.c
src/event/parse.c
src/event/period.c
src/event/place.c
src/event/serial.c
src/event/time.c
src/file/line.c
src/file/mv.c
src/file/open.c
src/file/pipe.c
src/file/tmp.c
src/ls.c
src/main.c
src/opt/env.c
src/opt/file.c
src/opt/filter.c
src/opt/recur.c
src/opt/until.c
src/postpone.c
src/prune.c
src/recur.c
src/rm.c
src/seek.c
src/usage.c
src/validate.c

index 737de469925f1993b39371a12ba7b876a3b6107b..d566f7923588f79130fc3ea6fbe129905f8822e4 100644 (file)
@@ -24,6 +24,7 @@ config.status
 configure
 configure~
 configure.scan
+.lineno
 Makefile
 Makefile.in
 stamp-h1
index 7fafde0a67efe22c933b988868af62feebb87b73..cf9ad8ff11d363a9be96f3cd9aef5fa024bfd096 100644 (file)
@@ -71,5 +71,8 @@ dist_bashcompletion_SCRIPTS = completions/ev
 
 SUBDIRS = . test/unit
 
+format:
+       VERSION_CONTROL=none indent -linux -brf $(ev_SOURCES)
+
 unit:
        $(MAKE) -C test/unit check
index afe6f6b88751e5989452a843a92749e44bf16804..d111d6c109058104289fbe625dab9b4e46369829 100644 (file)
--- a/inc/add.h
+++ b/inc/add.h
@@ -13,7 +13,7 @@
 #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
index 21f5a2dc15bb9bba76e390bf1db35512b7a25dee..c1016b3fe778d78f9922ff0b7596f7af9d4c5f8e 100644 (file)
@@ -17,6 +17,6 @@ enum sub_command {
        SUB_COMMAND_VALIDATE
 };
 
-enum sub_command args(int,char**);
+enum sub_command args(int, char **);
 
 #endif
index ef9a9dff2bb79b858e20b0db664c8db16c4a2d26..916a8e6936da2c01e05bc092cff5545a363d5ce9 100644 (file)
@@ -6,7 +6,7 @@
 #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
index 371dac4c79bd81044e8e8fc5b83349b6b598207a..8a597cd2cc373ae7926925ec8a61faef24689e3c 100644 (file)
--- a/inc/cut.h
+++ b/inc/cut.h
@@ -5,6 +5,6 @@
 #include<event.h>
 #include<file.h>
 
-int cut(struct event*, time_t, size_t);
+int cut(struct event *, time_t, size_t);
 
 #endif
index 390253fda3ae61de76b1267dbf0854553b88196f..e08550fa155a811e6bf43089d7152dabd6c9e247 100644 (file)
@@ -30,7 +30,7 @@ enum time_period {
 struct event_options {
        unsigned int recur;
        enum time_period recur_period;
-       
+
        struct tm until;
 };
 
@@ -48,18 +48,18 @@ struct event_filter {
        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
index b2bc20d249b99d2a4ceceea49e30076df8ee25a8..b9ae70bd903c092e63bd88fbf015e24a381a479c 100644 (file)
@@ -6,10 +6,10 @@
 
 #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
index 35304aea191ac9f083d626ed4ac95b040f78c91b..67b558479ddcb6640e5e43bb4d45e4860f597db6 100644 (file)
@@ -13,6 +13,6 @@
 #include<rm.h>
 #include<validate.h>
 
-int main(int,char**);
+int main(int, char **);
 
 #endif
index 28018e030fa6a5b46d7bfe98a86e9e00f83ee5d1..55a4673f9e4abdc2ee07eea8cb82c15177bbf1d0 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -17,13 +17,13 @@ struct options {
 
 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
index f6d80c2ded4b6da63dea65a83b02222f69680e07..41edffba5c50339c7769f1f4c369be9c6d3fa9e4 100644 (file)
@@ -9,6 +9,6 @@
 #include<event.h>
 #include<usage.h>
 
-int postpone(int, char**);
+int postpone(int, char **);
 
 #endif
index 9c7710ae354262e0cdec6a0a5e2842b293ca62d9..e56bd393071921f1aed027dc8dd835cbd8b715f2 100644 (file)
@@ -3,6 +3,6 @@
 
 #include<event.h>
 
-int recur(struct event*);
+int recur(struct event *);
 
 #endif
index bf5e4e58145713701c23453c60ab07e4f8226fbe..17ebbda644f94400264f3c4703fc01dccb751cad 100644 (file)
--- a/inc/rm.h
+++ b/inc/rm.h
@@ -13,6 +13,6 @@
 
 #define RM_FLAG_DISMISS 1
 
-int rm(int,char**,int);
+int rm(int, char **, int);
 
 #endif
index cca97870e6a0c454c6064b629860dbc46442c9a4..8dc8b8e121eea37bdf6dbf25da883e6a18660a56 100644 (file)
@@ -4,6 +4,6 @@
 #include<event.h>
 #include<file.h>
 
-int seek(FILE*,time_t);
+int seek(FILE *, time_t);
 
 #endif
index 20a4228a56d4a0bf54414b92a7946aa9a75b7a66..e1d2e1bf4e217e29b0622fb35acd63872cb4d263 100644 (file)
--- a/src/add.c
+++ b/src/add.c
@@ -1,10 +1,10 @@
 #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;
@@ -13,71 +13,84 @@ int add(int argc, char **argv) {
 
        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;
@@ -90,51 +103,77 @@ int add_to_file(struct event *to_add) {
        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;
@@ -143,15 +182,18 @@ int handle_args(int argc, char **argv, struct event *ev) {
 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));
                }
        }
 
index 0efdb5fe527621b2c75963c6de29727c10db4466..f04bd9e5c7e85036536df6552a475918db8df06e 100644 (file)
@@ -9,71 +9,110 @@ struct option long_options[] = {
        {"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;
 }
index 1e2f80ebde4bc478e356e5cc73f9c364265d7cc3..d337dd0b6e72b1d7b6fae7948d487a6d8b561f3a 100644 (file)
@@ -5,28 +5,40 @@ int copy(FILE *to, FILE *src, time_t until) {
        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;
                }
        }
@@ -38,18 +50,20 @@ int copy_next_event(FILE *to, FILE *src) {
        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;
index f6239ff164d93f9b48a043a598f78f55f8f3823d..3627922f3b61b366a49d35c7deae1eb2577100c9 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -1,34 +1,52 @@
 #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;
 }
@@ -37,21 +55,25 @@ static int extract(FILE *src, struct event *ev) {
        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;
 }
index cd3d8f675d0bd504b7a4c854b95ce2fcb87b0639..ff853b3479bec56a9dbf0908115becb8524f0127 100644 (file)
@@ -9,7 +9,9 @@ static time_t midnight();
 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();
index 72ab2e7e05102c77f89f1168411893532bf42903..d5f970caa66d69ef95ba1be3471bedc02eb08ac9 100644 (file)
@@ -1,6 +1,10 @@
 #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);
+       }
 }
index 1872152a8da6a7aa0bedd102792b0a535e231b28..613f5f8d3daaa2daf76d5e787e58ad84e0605d45 100644 (file)
@@ -1,22 +1,21 @@
 #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));
+}
index ae20e91d043bc05194f7e6c7049a8b7ae0c5c6b4..d04148d22b8cba646cf4486240fa461fd0ea8d4b 100644 (file)
@@ -3,14 +3,18 @@
 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';
        }
 
index 58d6a07e09e8f2ca0b5dcc664ff1af134ce56abf..c3074080a7e8032796c836e35406ba4b0ea62dd5 100644 (file)
@@ -1,17 +1,25 @@
 #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;
 }
@@ -22,33 +30,37 @@ static int event_parse_name(char *buf, size_t buf_size, struct event *ev) {
        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';
        }
@@ -61,35 +73,38 @@ static int event_parse_options(char *buf, size_t buf_size, struct event *ev) {
        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;
 }
 
@@ -99,15 +114,17 @@ static int event_parse_place(char *buf, size_t buf_size, struct event *ev) {
        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;
@@ -116,10 +133,10 @@ static int event_parse_place(char *buf, size_t buf_size, struct event *ev) {
 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 {
@@ -127,10 +144,12 @@ static int event_parse_time(char *buf, size_t buf_size, struct event *ev) {
                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';
        }
index 9a7b5dc1173f2efededf5af116f4bbfaca4e5e54..9856e3d796659f42afdd573fc5272ea182970eb7 100644 (file)
@@ -1,43 +1,43 @@
 #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';
        }
 }
index 01f293cadeaf05fbd8c66f48f04dbd2335e369e5..122b8793a455d55e0e7ac0e479e9039b10ade1b7 100644 (file)
@@ -3,14 +3,18 @@
 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';
        }
 
index 64381c748285b48ff17dbc395776cc8f629b8ae0..96577097bd19b8f7fc2d34b75155ff605a3daae1 100644 (file)
 #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;
index 0245b440d2776c2d965c9a214914bb95ec3cab5c..bdb6860a6948b532f20ba6d9a73dd3fb16e6b1d6 100644 (file)
@@ -4,26 +4,36 @@ int event_time_compare(const struct tm *datetime, time_t time) {
        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.
@@ -34,18 +44,24 @@ int event_time_set(struct tm *datetime, const char *str) {
        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;
 }
 
@@ -53,12 +69,16 @@ int event_within(struct event *ev, struct event_filter *filter) {
        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;
 }
index b84252673508fe3c6d45cebad6669f2f507fd9d0..7fa3c005e1692d1b071283c149d3e6a834a306b5 100644 (file)
@@ -1,5 +1,5 @@
 #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);
 }
index 22506b75f6ed0f5c44e817632d9be2d57d154737..6d9c6b26dc697ab99d6d9a6fe51a1f3f9259df10 100644 (file)
@@ -4,23 +4,31 @@ int file_move(const char *tempname) {
        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;
 }
index ecbf85ed3fb28da3e72b3c75a14a54d533a4bd5a..a6b50170d35be406adb19e84dcbb1e4906a9adcf 100644 (file)
@@ -3,17 +3,20 @@
 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 {
index 1f6c439652bf8ad4eaef302ea2e33a10217e08a6..3662b3d2c6ece259457ea9d3153b488b2bc01091 100644 (file)
@@ -4,11 +4,15 @@ int file_pipe(FILE *to, FILE *from) {
        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;
 }
index ca4050e72b2045fd219a11eb292b8ba0cc328c91..a112a057874327299c36ee12728309dabd7dc4d8 100644 (file)
@@ -2,10 +2,10 @@
 
 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");
 }
index 480dc7360f6b2a3b6ee9712032da977f57e2f351..8919b4bc81fd5e766fc5f48de52c2bfba9c0fc71 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1,6 +1,6 @@
 #include<ls.h>
 
-static int event_print(struct event*);
+static int event_print(struct event *);
 
 int ls() {
        char buf[EVENT_SERIALIZE_MAX_LENGTH];
@@ -9,27 +9,33 @@ int ls() {
        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;
 }
@@ -40,35 +46,55 @@ static int event_print(struct event *ev) {
        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(&timestamp);
-               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;
 }
index bd3f4e5280c95d26d503f04f3a8a2c53cd87a4dd..a3baf8caf5524c47e4dfd97aeb32edeb40c52fab 100644 (file)
@@ -3,28 +3,34 @@
 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;
        }
 }
index 041564100198bd332dccf8e5a083eb56b7b35f2e..fcc8641c81a64d5ffd2110201b27f879067ffc5e 100644 (file)
 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;
 }
index 2e539db4dd798f4c3cd63d240a2f2bdb48be7629..10decc2a2c7e3855c4437fd84c96a0fc37c51340 100644 (file)
@@ -1,10 +1,14 @@
 #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;
 }
index b0e6e372d736908605845c93a1814f4144243807..29921d530b96d84862fc551454ae8387ec8b1796 100644 (file)
@@ -1,19 +1,19 @@
 #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;
        }
 
@@ -23,17 +23,17 @@ int opt_event_filter_date_set(time_t *to_set, const char *date_string) {
 }
 
 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;
 }
 
@@ -46,35 +46,37 @@ static int opt_event_filter_range_set_upcoming(const char *arg) {
        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);
@@ -84,13 +86,13 @@ static int opt_event_filter_range_set_upcoming(const char *arg) {
 }
 
 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;
index d7a49387e4257d09ac36db67381b8ebc2c4e320a..4a7421c3dc5683bb49ab535d301c25866783fa90 100644 (file)
@@ -5,16 +5,18 @@ int opt_recur_set(const char *p) {
        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;
        }
 
index 49d15220948d7b514d83b98a0904c64bb625568b..0ba5d0c432b8f972d85e7594fa2487b5fb35cfa7 100644 (file)
@@ -2,13 +2,15 @@
 
 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;
        }
 
index 263971b3f08f43873840006ed20230cfdbd88baa..62fc7bb9268c16ef2973257e49ee4d2a06ccee94 100644 (file)
@@ -2,51 +2,60 @@
 
 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;
 }
@@ -58,29 +67,38 @@ int postpone(int argc, char **argv) {
        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;
 }
 
@@ -88,44 +106,44 @@ int postpone_event(struct event *ev) {
        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);
index 422f5f8c585c9f2138a17c5fcc48f8cb79704000..9f885b992e460e73c1d444f6e97cf623acdeccfc 100644 (file)
@@ -1,6 +1,6 @@
 #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];
@@ -10,28 +10,37 @@ static int copy_recur_events(FILE *src, FILE *to) {
 
        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;
                }
        }
 
@@ -43,19 +52,33 @@ int prune() {
 
        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;
 }
index 8aec40271c0d9cfc823ae38b62a6c10a482dc23f..ec462b0cabde0626547c2bd49fdee3d060dbb8d5 100644 (file)
@@ -4,39 +4,43 @@ int recur(struct event *ev) {
        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;
@@ -46,8 +50,10 @@ int recur(struct event *ev) {
        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;
index 29adea4a30559ae3d7135b830aa165c2c52dbb8f..36b54b44b512b82db03d3e89fb4762d899b7e493 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -1,65 +1,68 @@
 #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;
 }
@@ -70,16 +73,22 @@ int rm(int argc, char **argv, int flags) {
        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);
        }
index 0166ef3f13f952d8880c9e24094ee1e1b38c8319..116312e39ae26d21f03cd7436ac4fe9b31a459a0 100644 (file)
@@ -5,25 +5,31 @@ int seek(FILE *fp, time_t time) {
        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;
                }
        }
index 1b73693d6ad7ffffe3790f3a815c56d323a5d382..6dfcccf7fd2fc7fa96f7f236f54dcbc1913b52de 100644 (file)
@@ -7,38 +7,39 @@ struct option_description {
 };
 
 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;
 }
@@ -49,12 +50,12 @@ static void usage_print_options() {
        // 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++;
        }
 }
index e0025e957e78715db5267c35a1286ca4f80d9fb6..c6fe8a1658aa9973f040a6abf98fdead4c6bd837 100644 (file)
@@ -8,30 +8,34 @@ int validate() {
        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;
 }