logo

utils

~/.local/bin tools and git-hooks
commit: d4ec9e7f32451b1ede06ffc5435dfb1bd67b8811
parent: 7404e27dd318b734b3e85f3a8352e5080d902e46
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 29 Sep 2018 20:32:18 +0200

src/*.c: Coding style changes

Diffstat:

Msrc/argc.c6++++--
Msrc/date.c22++++++++++++++--------
Msrc/range.c35++++++++++++++++++++++-------------
3 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/src/argc.c b/src/argc.c @@ -3,10 +3,12 @@ // printf() #include <stdio.h> -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ printf("argc: %i\n", argc); - for(int i = 0; i<argc; i++) { + for(int i = 0; i < argc; i++) + { printf("argv[%d]: \"%s\"\n", i, argv[i]); } diff --git a/src/date.c b/src/date.c @@ -4,31 +4,37 @@ #include <stdlib.h> /* exit() */ #include <time.h> /* time, localtime, tm, strftime */ -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ char outstr[BUFSIZ]; - time_t now = time(NULL); + time_t now = time(NULL); struct tm *tm = localtime(&now); - char *format = "%c"; + char *format = "%c"; setlocale(LC_ALL, ""); - for(int i = (argc-1);i>0;i--) { - if ((argv[i][0] == '-') && (argv[i][1] == 'u')) { + for(int i = (argc - 1); i > 0; i--) + { + if((argv[i][0] == '-') && (argv[i][1] == 'u')) + { tm = gmtime(&now); } - if (argv[i][0] == '+') { + if(argv[i][0] == '+') + { /* format = argv[1][1,]; */ format = &argv[i][1]; } } - if (tm == NULL) { + if(tm == NULL) + { perror("localtime"); exit(EXIT_FAILURE); } - if (strftime(outstr, sizeof(outstr), format, tm) == 0) { + if(strftime(outstr, sizeof(outstr), format, tm) == 0) + { perror("strftime returned 0"); exit(EXIT_FAILURE); } diff --git a/src/range.c b/src/range.c @@ -6,31 +6,40 @@ char *IFS; int a, b; -void usage(char *a0) { - printf("usage: %s [ini <max>]\n", a0); -} +void usage(char *a0) { printf("usage: %s [ini <max>]\n", a0); } -void range(int initial, int maximum) { +void range(int initial, int maximum) +{ printf("%i", initial); - if(initial<maximum) { - for(initial++; initial<=maximum; initial++) + if(initial < maximum) + { + for(initial++; initial <= maximum; initial++) printf("%s%i", IFS, initial); - } else if(initial>maximum) { - for(initial--; initial>=maximum; initial--) + } + else if(initial > maximum) + { + for(initial--; initial >= maximum; initial--) printf("%s%i", IFS, initial); } } -int main(int argc, char *argv[]){ - if(!(IFS = getenv("IFS"))) { +int main(int argc, char *argv[]) +{ + if(!(IFS = getenv("IFS"))) + { IFS = " "; } - if (argc == 2) { + if(argc == 2) + { range(0, atoi(argv[1])); - } else if(argc == 3) { + } + else if(argc == 3) + { range(atoi(argv[1]), atoi(argv[2])); - } else { + } + else + { usage(argv[0]); } }