Compare commits

..

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

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