Compare commits

..

No commits in common. "691235d9b20c59ae63eb4bc74843ed9217478a01" and "34c5be0b413a483ac9e79df8d8c7327d00fb31b9" have entirely different histories.

160
main.c
View file

@ -7,9 +7,19 @@
#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");
} }
@ -23,32 +33,22 @@ void help() {
"usage: pride [name]\n\n" "usage: pride [name]\n\n"
"flag names:\n" "flag names:\n"
" aroace\n" INDENT AROACE "\n"
" bisexual\n" INDENT BISEXUAL "\n"
" gay\n" INDENT GAY "\n"
" lesbian\n" INDENT LESBIAN "\n"
" nonbinary\n" INDENT NONBINARY "\n"
" pansexual\n" INDENT PANSEXUAL "\n"
" rainbow\n" INDENT RAINBOW "\n"
" transgender\n" INDENT 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 = ""; } else { flag = RAINBOW; }
int color_mode = 0; int color_mode = 0;
char * term = getenv("TERM"); char * term = getenv("TERM");
@ -64,71 +64,67 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
unsigned long flag_hash = djb_hash(flag); if(strcmp(flag, RAINBOW) == 0) { // - RAINBOW -
if(color_mode)
char *output; rainbow_256();
switch(flag_hash) { else
// - RAINBOW - rainbow_8();
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;
} }