Merge branch 'hash-flag' into 256-color

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

160
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(); char *output;
else switch(flag_hash) {
rainbow_8(); // - RAINBOW -
case 229480993726103lu: // 'rainbow'
case 5381lu: // (empty)
if(color_mode) rainbow_256();
else rainbow_8();
break;
// - ARO/ACE -
case 6953324567312lu: // 'aroace'
case 22945708850429lu: // 'aro-ace'
if(color_mode) aroace_256();
else aroace_8();
break;
// - BISEXUAL -
case 7572201611094690lu: // 'bisexual'
case 5863248lu: // 'bi'
if(color_mode) bisexual_256();
else bisexual_8();
break;
// - GAY -
case 193492486lu: // 'gay'
case 193499371lu: // 'mlm'
if(color_mode) gay_256();
else gay_8();
break;
// - LESBIAN -
case 229473412894979lu: // 'lesbian'
case 193510271lu: // 'wlw'
if(color_mode) lesbian_256();
else lesbian_8();
break;
// - NONBINARY -
case 249899779187415445lu: // 'nonbinary'
case 5863637lu: // 'nb'
if(color_mode) nonbinary_256();
else nonbinary_8();
break;
// - PANSEXUAL -
case 249901996007388822lu: // 'pansexual'
case 193502276lu: // 'pan'
if(color_mode) pansexual_256();
else nonbinary_8();
break;
// - TRANSGENDER -
case 13895753452281080578lu: // 'transgender'
case 210729322765lu: // 'trans'
if(color_mode) transgender_256();
else transgender_8();
break;
default:
printf("pride-c: no flag '%s' found.", flag);
return 1;
} }
else if(strcmp(flag, AROACE) == 0) { // - ARO/ACE -
if(color_mode)
aroace_256();
else
aroace_8();
}
else if(strcmp(flag, BISEXUAL) == 0) { // - BISEXUAL -
if(color_mode)
bisexual_256();
else
bisexual_8();
}
else if(strcmp(flag, GAY) == 0) { // - GAY -
if(color_mode)
gay_256();
else
gay_8();
}
else if(strcmp(flag, LESBIAN) == 0) { // - LESBIAN -
if(color_mode)
lesbian_256();
else
lesbian_8();
}
else if(strcmp(flag, NONBINARY) == 0) { // - NONBINARY -
if(color_mode)
nonbinary_256();
else
nonbinary_8();
}
else if(strcmp(flag, PANSEXUAL) == 0) { // - PANSEXUAL -
if(color_mode)
pansexual_256();
else
pansexual_8();
}
else if(strcmp(flag, TRANSGENDER) == 0) { // - TRANSGENDER -
if(color_mode)
transgender_256();
else
transgender_8();
}
else {
printf("pride-c: no flag '%s' found.", flag);
return 1;
}
printf(RESET); printf(RESET);
return 0; return 0;
} }