Merge branch 'hash-flag' into 256-color

This commit is contained in:
Valerie Wolfe 2024-03-23 00:31:12 -04:00
commit 691235d9b2

140
main.c
View file

@ -7,19 +7,9 @@
#include "full.h" #include "full.h"
#define VERSION "0.0.1" #define VERSION "0.0.1"
#define INDENT " "
#define RESET "\x1b[0m" #define RESET "\x1b[0m"
#define RAINBOW "rainbow"
#define AROACE "aroace"
#define BISEXUAL "bisexual"
#define GAY "gay"
#define LESBIAN "lesbian"
#define NONBINARY "nonbinary"
#define PANSEXUAL "pansexual"
#define TRANSGENDER "transgender"
void version() { void version() {
printf("pride-c v" VERSION "\n"); printf("pride-c v" VERSION "\n");
} }
@ -33,22 +23,32 @@ void help() {
"usage: pride [name]\n\n" "usage: pride [name]\n\n"
"flag names:\n" "flag names:\n"
INDENT AROACE "\n" " aroace\n"
INDENT BISEXUAL "\n" " bisexual\n"
INDENT GAY "\n" " gay\n"
INDENT LESBIAN "\n" " lesbian\n"
INDENT NONBINARY "\n" " nonbinary\n"
INDENT PANSEXUAL "\n" " pansexual\n"
INDENT RAINBOW "\n" " rainbow\n"
INDENT TRANSGENDER "\n" " transgender\n"
); );
} }
unsigned long djb_hash(unsigned char *string) {
unsigned long output = 5381;
int c;
while(c = *string++)
output = ((output << 5) + output) + c;
return output;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
// get argv[1] or fall back to RAINBOW // get argv[1] or fall back to RAINBOW
char *flag; char *flag;
if(argc > 1) { flag = argv[1]; } if(argc > 1) { flag = argv[1]; }
else { flag = RAINBOW; } else { flag = ""; }
int color_mode = 0; int color_mode = 0;
char * term = getenv("TERM"); char * term = getenv("TERM");
@ -64,67 +64,71 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
if(strcmp(flag, RAINBOW) == 0) { // - RAINBOW - unsigned long flag_hash = djb_hash(flag);
if(color_mode)
rainbow_256();
else
rainbow_8();
}
else if(strcmp(flag, AROACE) == 0) { // - ARO/ACE - char *output;
if(color_mode) switch(flag_hash) {
aroace_256(); // - RAINBOW -
else case 229480993726103lu: // 'rainbow'
aroace_8(); case 5381lu: // (empty)
} if(color_mode) rainbow_256();
else rainbow_8();
break;
else if(strcmp(flag, BISEXUAL) == 0) { // - BISEXUAL - // - ARO/ACE -
if(color_mode) case 6953324567312lu: // 'aroace'
bisexual_256(); case 22945708850429lu: // 'aro-ace'
else if(color_mode) aroace_256();
bisexual_8(); else aroace_8();
} break;
else if(strcmp(flag, GAY) == 0) { // - GAY - // - BISEXUAL -
if(color_mode) case 7572201611094690lu: // 'bisexual'
gay_256(); case 5863248lu: // 'bi'
else if(color_mode) bisexual_256();
gay_8(); else bisexual_8();
} break;
else if(strcmp(flag, LESBIAN) == 0) { // - LESBIAN - // - GAY -
if(color_mode) case 193492486lu: // 'gay'
lesbian_256(); case 193499371lu: // 'mlm'
else if(color_mode) gay_256();
lesbian_8(); else gay_8();
} break;
else if(strcmp(flag, NONBINARY) == 0) { // - NONBINARY - // - LESBIAN -
if(color_mode) case 229473412894979lu: // 'lesbian'
nonbinary_256(); case 193510271lu: // 'wlw'
else if(color_mode) lesbian_256();
nonbinary_8(); else lesbian_8();
} break;
else if(strcmp(flag, PANSEXUAL) == 0) { // - PANSEXUAL - // - NONBINARY -
if(color_mode) case 249899779187415445lu: // 'nonbinary'
pansexual_256(); case 5863637lu: // 'nb'
else if(color_mode) nonbinary_256();
pansexual_8(); else nonbinary_8();
} break;
else if(strcmp(flag, TRANSGENDER) == 0) { // - TRANSGENDER - // - PANSEXUAL -
if(color_mode) case 249901996007388822lu: // 'pansexual'
transgender_256(); case 193502276lu: // 'pan'
else if(color_mode) pansexual_256();
transgender_8(); else nonbinary_8();
} break;
// - TRANSGENDER -
case 13895753452281080578lu: // 'transgender'
case 210729322765lu: // 'trans'
if(color_mode) transgender_256();
else transgender_8();
break;
else { default:
printf("pride-c: no flag '%s' found.", flag); printf("pride-c: no flag '%s' found.", flag);
return 1; return 1;
} }
printf(RESET); printf(RESET);
return 0; return 0;
} }