summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2016-04-27 20:16:49 +0200
committerjaseg <code@jaseg.net>2016-04-27 20:33:31 +0200
commitdd685e3d8b35973be28a03cfa0c20cd2b35b5cbd (patch)
tree6e196efdc9bc458318d4f2fc6556d74ebda66308
parentb53d2e82b40ada1212d424c367c776744d5fd9da (diff)
downloadlolcat-dd685e3d8b35973be28a03cfa0c20cd2b35b5cbd.tar.gz
lolcat-dd685e3d8b35973be28a03cfa0c20cd2b35b5cbd.tar.bz2
lolcat-dd685e3d8b35973be28a03cfa0c20cd2b35b5cbd.zip
Formatting fixes
-rwxr-xr-xcensorbin26088 -> 26088 bytes
-rw-r--r--censor.c54
-rwxr-xr-xlolcatbin40904 -> 40840 bytes
-rw-r--r--lolcat.c210
4 files changed, 130 insertions, 134 deletions
diff --git a/censor b/censor
index 7b9606e..94b83f7 100755
--- a/censor
+++ b/censor
Binary files differ
diff --git a/censor.c b/censor.c
index 80eabc8..7efe81e 100644
--- a/censor.c
+++ b/censor.c
@@ -27,47 +27,43 @@
#include <unistd.h>
#include <sys/time.h>
-
-#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};
-
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;
- }
+ char **inputs = argv+1;
+ char **inputs_end = argv+argc;
+ if(inputs == inputs_end){
+ char *foo[] = {"-"};
+ inputs = foo;
+ inputs_end = inputs+1;
+ }
- setlocale(LC_ALL, "");
+ setlocale(LC_ALL, "");
- for(char **filename=inputs; filename<inputs_end; filename++){
- FILE *f = stdin;
+ for(char **filename=inputs; filename<inputs_end; filename++){
+ FILE *f = stdin;
- if(strcmp(*filename, "-"))
- f = fopen(*filename, "r");
-
- if(!f){
- fprintf(stderr, "Cannot open input file \"%s\": %s\n", *filename, strerror(errno));
- return 2;
- }
+ if(strcmp(*filename, "-"))
+ f = fopen(*filename, "r");
+
+ if(!f){
+ fprintf(stderr, "Cannot open input file \"%s\": %s\n", *filename, strerror(errno));
+ return 2;
+ }
int c;
- while((c = fgetwc(f)) > 0){
+ while((c = fgetwc(f)) > 0){
if(strchr("acegmnopqrsuvwxyz", c))
printf("▄");
else if(strchr(".,:; \t\r\n", c))
printf("%lc", c);
else
printf("█");
- }
+ }
- fclose(f);
+ fclose(f);
- if(c != WEOF && c != 0){
- fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno));
- return 2;
- }
- }
+ if(c != WEOF && c != 0){
+ fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno));
+ return 2;
+ }
+ }
}
diff --git a/lolcat b/lolcat
index 682cf60..83fdf9a 100755
--- a/lolcat
+++ b/lolcat
Binary files differ
diff --git a/lolcat.c b/lolcat.c
index 324de5b..9e9cdc5 100644
--- a/lolcat.c
+++ b/lolcat.c
@@ -53,119 +53,119 @@ static char helpstr[] = "\n"
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'))
- *state = 2;
- }else{
- *state = 0;
- }
+ if(c == '\033'){ /* Escape sequence YAY */
+ *state = 1;
+ }else if(*state == 1){
+ if(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
+ *state = 2;
+ }else{
+ *state = 0;
+ }
}
void usage(){
- printf("Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n");
- exit(1);
+ printf("Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n");
+ exit(1);
}
void version(){
- printf("lolcat version 0.1, (c) 2014 jaseg\n");
- exit(0);
+ printf("lolcat version 0.1, (c) 2014 jaseg\n");
+ exit(0);
}
int main(int argc, char **argv){
- int c, cc=-1, i, l=0;
- int colors=(isatty(1) == 1);
- double freq_h = 0.23, freq_v = 0.1;
-
- struct timeval tv;
- gettimeofday(&tv, NULL);
- double offx = (tv.tv_sec%300)/300.0;
-
- for(i=1;i<argc;i++){
- char *endptr;
- if(!strcmp(argv[i], "-h")){
- if((++i)<argc){
- freq_h = strtod(argv[i], &endptr);
- if(*endptr)
- usage();
- }else{
- usage();
- }
- }else if(!strcmp(argv[i], "-v")){
- if((++i)<argc){
- freq_v = strtod(argv[i], &endptr);
- if(*endptr)
- usage();
- }else{
- usage();
- }
- }else if(!strcmp(argv[i], "-f")){
- colors = 1;
- }else if(!strcmp(argv[i], "--version")){
- version();
- }else{
- if(!strcmp(argv[i], "--"))
- i++;
- break;
- }
- }
-
- char **inputs = argv+i;
- char **inputs_end = argv+argc;
- if(inputs == inputs_end){
- char *foo[] = {"-"};
- inputs = foo;
- inputs_end = inputs+1;
- }
-
- setlocale(LC_ALL, "");
-
- i=0;
- for(char **filename=inputs; filename<inputs_end; filename++){
- FILE *f = stdin;
- int escape_state = 0;
-
- if(!strcmp(*filename, "--help"))
- f = fmemopen(helpstr, strlen(helpstr), "r");
- else if(strcmp(*filename, "-"))
- f = fopen(*filename, "r");
-
- if(!f){
- fprintf(stderr, "Cannot open input file \"%s\": %s\n", *filename, strerror(errno));
- return 2;
- }
-
- while((c = fgetwc(f)) > 0){
- if(colors){
- find_escape_sequences(c, &escape_state);
-
- if(!escape_state){
- if(c == '\n'){
- l++;
- i = 0;
- }else{
- int ncc = offx*ARRAY_SIZE(codes) + (int)((i+=wcwidth(c))*freq_h + l*freq_v);
- if(cc != ncc)
- printf("\033[38;5;%hhum", codes[(cc = ncc) % ARRAY_SIZE(codes)]);
- }
- }
- }
-
- printf("%lc", c);
-
- if(escape_state == 2)
- printf("\033[38;5;%hhum", codes[cc % ARRAY_SIZE(codes)]);
- }
- printf("\n\033[0m");
- cc = -1;
-
- fclose(f);
-
- if(c != WEOF && c != 0){
- fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno));
- return 2;
- }
- }
+ int c, cc=-1, i, l=0;
+ 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;
+
+ for(i=1;i<argc;i++){
+ char *endptr;
+ if(!strcmp(argv[i], "-h")){
+ if((++i)<argc){
+ freq_h = strtod(argv[i], &endptr);
+ if(*endptr)
+ usage();
+ }else{
+ usage();
+ }
+ }else if(!strcmp(argv[i], "-v")){
+ if((++i)<argc){
+ freq_v = strtod(argv[i], &endptr);
+ if(*endptr)
+ usage();
+ }else{
+ usage();
+ }
+ }else if(!strcmp(argv[i], "-f")){
+ colors = 1;
+ }else if(!strcmp(argv[i], "--version")){
+ version();
+ }else{
+ if(!strcmp(argv[i], "--"))
+ i++;
+ break;
+ }
+ }
+
+ char **inputs = argv+i;
+ char **inputs_end = argv+argc;
+ if(inputs == inputs_end){
+ char *foo[] = {"-"};
+ inputs = foo;
+ inputs_end = inputs+1;
+ }
+
+ setlocale(LC_ALL, "");
+
+ i=0;
+ for(char **filename=inputs; filename<inputs_end; filename++){
+ FILE *f = stdin;
+ int escape_state = 0;
+
+ if(!strcmp(*filename, "--help"))
+ f = fmemopen(helpstr, strlen(helpstr), "r");
+ else if(strcmp(*filename, "-"))
+ f = fopen(*filename, "r");
+
+ if(!f){
+ fprintf(stderr, "Cannot open input file \"%s\": %s\n", *filename, strerror(errno));
+ return 2;
+ }
+
+ while((c = fgetwc(f)) > 0){
+ if(colors){
+ find_escape_sequences(c, &escape_state);
+
+ if(!escape_state){
+ if(c == '\n'){
+ l++;
+ i = 0;
+ }else{
+ int ncc = offx*ARRAY_SIZE(codes) + (int)((i+=wcwidth(c))*freq_h + l*freq_v);
+ if(cc != ncc)
+ printf("\033[38;5;%hhum", codes[(cc = ncc) % ARRAY_SIZE(codes)]);
+ }
+ }
+ }
+
+ printf("%lc", c);
+
+ if(escape_state == 2)
+ printf("\033[38;5;%hhum", codes[cc % ARRAY_SIZE(codes)]);
+ }
+ printf("\n\033[0m");
+ cc = -1;
+
+ fclose(f);
+
+ if(c != WEOF && c != 0){
+ fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno));
+ return 2;
+ }
+ }
}