From fd9436a7f0962a479cdf2cd0f5d42ad3b4ab0d54 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 22 Jul 2018 20:47:25 +0200 Subject: auto-format c sources --- censor.c | 51 ++++++++++---------- lolcat.c | 164 ++++++++++++++++++++++++++++++++------------------------------- 2 files changed, 110 insertions(+), 105 deletions(-) diff --git a/censor.c b/censor.c index ab6c5ba..64e936b 100644 --- a/censor.c +++ b/censor.c @@ -13,63 +13,64 @@ * 0. You just DO WHAT THE FUCK YOU WANT TO. */ -#include -#include -#include #include #include #include +#include +#include +#include #include #include -#include -#include #include +#include +#include -int main(int argc, char **argv){ - char **inputs = argv+1; - char **inputs_end = argv+argc; - if(inputs == inputs_end){ - char *foo[] = {"-"}; +int main(int argc, char** argv) +{ + char** inputs = argv + 1; + char** inputs_end = argv + argc; + if (inputs == inputs_end) { + char* foo[] = { "-" }; inputs = foo; - inputs_end = inputs+1; + inputs_end = inputs + 1; } setlocale(LC_ALL, ""); int escape_state = 0; - for(char **filename=inputs; filename 0){ - if(!escape_state){ - if(c == '\e'){ + while ((c = fgetwc(f)) > 0) { + if (!escape_state) { + if (c == '\e') { printf("%lc", c); escape_state = 1; - }else if(strchr("acegmnopqrsuvwxyz", c)) + } else if (strchr("acegmnopqrsuvwxyz", c)) printf("▄"); - else if(strchr(".,:; \t\r\n", c)) + else if (strchr(".,:; \t\r\n", c)) printf("%lc", c); else printf("█"); - }else{ + } else { printf("%lc", c); - if(!strchr("[0123456789;", c)) + if (!strchr("[0123456789;", c)) escape_state = 0; } } fclose(f); - if(c != WEOF && c != 0){ + if (c != WEOF && c != 0) { fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno)); return 2; } diff --git a/lolcat.c b/lolcat.c index 6e6ffba..f1587dd 100644 --- a/lolcat.c +++ b/lolcat.c @@ -15,157 +15,161 @@ #define _XOPEN_SOURCE -#include -#include -#include #include #include #include +#include +#include +#include #include #include -#include -#include #include +#include +#include static char helpstr[] = "\n" -"Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n" -"\n" -"Concatenate FILE(s), or standard input, to standard output.\n" -"With no FILE, or when FILE is -, read standard input.\n" -"\n" -" -h : Horizontal rainbow frequency (default: 0.23)\n" -" -v : Vertical rainbow frequency (default: 0.1)\n" -" -f: Force color even when stdout is not a tty\n" -" --version: Print version and exit\n" -" --help: Show this message\n" -"\n" -"Examples:\n" -" lolcat f - g Output f's contents, then stdin, then g's contents.\n" -" lolcat Copy standard input to standard output.\n" -" fortune | lolcat Display a rainbow cookie.\n" -"\n" -"Report lolcat bugs to \n" -"lolcat home page: \n" -"Original idea: \n"; - -#define ARRAY_SIZE(foo) (sizeof(foo)/sizeof(foo[0])) -const char codes[] = {39,38,44,43,49,48,84,83,119,118,154,148,184,178,214,208,209,203,204,198,199,163,164,128,129,93,99,63,69,33}; - -void find_escape_sequences(int c, int *state){ - if(c == '\033'){ /* Escape sequence YAY */ + "Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n" + "\n" + "Concatenate FILE(s), or standard input, to standard output.\n" + "With no FILE, or when FILE is -, read standard input.\n" + "\n" + " -h : Horizontal rainbow frequency (default: 0.23)\n" + " -v : Vertical rainbow frequency (default: 0.1)\n" + " -f: Force color even when stdout is not a tty\n" + " --version: Print version and exit\n" + " --help: Show this message\n" + "\n" + "Examples:\n" + " lolcat f - g Output f's contents, then stdin, then g's contents.\n" + " lolcat Copy standard input to standard output.\n" + " fortune | lolcat Display a rainbow cookie.\n" + "\n" + "Report lolcat bugs to \n" + "lolcat home page: \n" + "Original idea: \n"; + +#define ARRAY_SIZE(foo) (sizeof(foo) / sizeof(foo[0])) +const char codes[] = { 39, 38, 44, 43, 49, 48, 84, 83, 119, 118, 154, 148, 184, 178, 214, 208, 209, 203, 204, 198, 199, 163, 164, 128, 129, 93, 99, 63, 69, 33 }; + +void find_escape_sequences(int c, int* state) +{ + if (c == '\033') { /* Escape sequence YAY */ *state = 1; - }else if(*state == 1){ - if(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) + } else if (*state == 1) { + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) *state = 2; - }else{ + } else { *state = 0; } } - -void usage(){ +void usage() +{ printf("Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n"); exit(1); } -void version(){ +void version() +{ printf("lolcat version 0.1, (c) 2014 jaseg\n"); exit(0); } -int main(int argc, char **argv){ - char *default_argv[] = {"-"}; - int cc=-1, i, l=0; +int main(int argc, char** argv) +{ + char* default_argv[] = { "-" }; + int cc = -1, i, l = 0; wint_t c; - int colors=1; + int colors = 1; double freq_h = 0.23, freq_v = 0.1; struct timeval tv; gettimeofday(&tv, NULL); - double offx = (tv.tv_sec%300)/300.0; + double offx = (tv.tv_sec % 300) / 300.0; - for(i=1;i