From efc77d6286fc50819ac2ca6dbfad3ab9726522cc Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Fri, 21 Sep 2018 10:33:25 +0930 Subject: added -m option by default the program now uses the 12 hour format. updated the readme accordingly --- binstatus.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'binstatus.c') diff --git a/binstatus.c b/binstatus.c index a5b1d33..860529c 100644 --- a/binstatus.c +++ b/binstatus.c @@ -22,6 +22,7 @@ #define MAXLENGTH 256 int binary = 1; /* 0 = decimal display, 1 = binary display */ +int miltime = 0; /* 0=12 hour time, 1 = 24 hour time */ int dectobin(int dec) @@ -55,17 +56,45 @@ formatstring(char *status, int *time) } } +int +converthour(int hour) +{ + // is there a better way? + switch (hour) + { + case 0:return 12; + case 13: return 1; + case 14: return 2; + case 15: return 3; + case 16: return 5; + case 17: return 6; + case 18: return 7; + case 19: return 8; + case 20: return 9; + case 21: return 10; + case 22: return 11; + case 23: return 12; + default: return 0; + } +} + int main(int argc, char *argv[]) { - if (argc >= 2) + for (int c = 1; c < argc; c++) { - if (strcmp(argv[1], "-d") == 0) - binary = 0; - else + if (argc >= 2) { - printf("usage: %s [-d]\n", argv[0]); - exit(EXIT_SUCCESS); + if (strcmp(argv[c], "-d") == 0) + binary = 0; + else if (strcmp(argv[c], "-m") == 0) + miltime = 1; + else + { + printf("usage: %s [-d] [-m]\n-d: decimal output\n" + "-m: 24-hour format\n", argv[0]); + exit(EXIT_SUCCESS); + } } } int exitflag = EXIT_SUCCESS; @@ -80,6 +109,8 @@ main(int argc, char *argv[]) while (1) { gettime(time); + if (!miltime) + time[0] = converthour(time[0]); formatstring(status, time); XStoreName(dsp, DefaultRootWindow(dsp), status); XFlush(dsp); -- cgit v1.2.3