diff --git a/ttyclock.c b/ttyclock.c index f0bddd5..544e566 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -158,7 +158,7 @@ update_hour(void) /* Set date string */ strftime(ttyclock->date.datestr, sizeof(ttyclock->date.datestr), - "%d/%m/%Y", + ttyclock->option.format, ttyclock->tm); /* Set seconds */ @@ -403,13 +403,18 @@ main(int argc, char **argv) {"twelve", 0, NULL, 't'}, {"rebound", 0, NULL, 'r'}, {"center", 0, NULL, 'c'}, + {"format", 1, NULL, 'f'}, {NULL, 0, NULL, 0} }; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); - while ((c = getopt_long(argc,argv,"tvsrcih", + /* Date format */ + ttyclock->option.format = malloc(sizeof(char)*100); + strncpy(ttyclock->option.format, "%d/%m/%Y", 100); + + while ((c = getopt_long(argc,argv,"tvsrcihf:", long_options, NULL)) != -1) { switch(c) @@ -442,6 +447,9 @@ main(int argc, char **argv) case 'r': ttyclock->option.rebound = True; break; + case 'f': + strncpy(ttyclock->option.format, optarg, 100); + break; } } diff --git a/ttyclock.h b/ttyclock.h index 1486ac7..e7dc623 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -55,6 +55,7 @@ -c, --center Set the clock at the center of the terminal \n\ -t, --twelve Set the hour in 12h format \n\ -r, --rebound Do rebound the clock \n\ + -f, --format Set the date format \n\ -v, --version Show tty-clock version \n\ -i, --info Show some info about tty-clock \n\ -h, --help Show this page " @@ -74,6 +75,7 @@ typedef struct Bool twelve; Bool center; Bool rebound; + char *format; } option; /* Clock geometry */