From 675aa21a3ba29322402d2a62871176283eb8ddac Mon Sep 17 00:00:00 2001 From: Isaac Brown Date: Fri, 30 Aug 2024 18:48:16 -0500 Subject: [PATCH 1/2] Added check for overlaps and added new words --- files/word_lists/adjectives.txt | 2 ++ files/word_lists/nouns.txt | 8 +++++ files/word_lists/overlaps.txt | 7 ++++ insults_files.c | 63 +++++++++++++++++++++++++++------ insults_files.h | 6 ++++ 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 files/word_lists/overlaps.txt diff --git a/files/word_lists/adjectives.txt b/files/word_lists/adjectives.txt index fad566a..e46d571 100644 --- a/files/word_lists/adjectives.txt +++ b/files/word_lists/adjectives.txt @@ -63,6 +63,7 @@ quivering quixotic rude-mouthed satanic +saucy scrawny shameful slack-jawed @@ -93,3 +94,4 @@ yeasty yellow-bellied yodeling zany +zealous diff --git a/files/word_lists/nouns.txt b/files/word_lists/nouns.txt index 0381bf0..2176763 100644 --- a/files/word_lists/nouns.txt +++ b/files/word_lists/nouns.txt @@ -1,13 +1,18 @@ abomination +ape beast boil blight +boor braggart cow +coward dung beetle dwarf +egg egotist farce +fool gallbladder garbage goblin @@ -25,6 +30,7 @@ liar lunatic monster nincompoop +nitwit oaf ogre peasant @@ -38,12 +44,14 @@ scallywag scum sot swine +thief toilet twit unibrow vassal wart witch +xenophobe yahoo yeast infection zamboni diff --git a/files/word_lists/overlaps.txt b/files/word_lists/overlaps.txt new file mode 100644 index 0000000..d50b5ec --- /dev/null +++ b/files/word_lists/overlaps.txt @@ -0,0 +1,7 @@ +egg-headed:egg +xenophobic:xenophobe +cowardly:coward +boorish:boor +ape-brained:ape +foolish:fool +thieving:thief diff --git a/insults_files.c b/insults_files.c index fdb1b3d..24ed978 100644 --- a/insults_files.c +++ b/insults_files.c @@ -26,6 +26,7 @@ InsultsFiles* insults_files_alloc(void) { insults_files->imperatives = file_lines_alloc(); insults_files->adjectives = file_lines_alloc(); insults_files->nouns = file_lines_alloc(); + insults_files->overlaps = file_lines_alloc(); insults_files_get_lines( insults_files, APP_ASSETS_PATH("word_lists/imperatives.txt"), insults_files->imperatives); @@ -33,6 +34,8 @@ InsultsFiles* insults_files_alloc(void) { insults_files, APP_ASSETS_PATH("word_lists/adjectives.txt"), insults_files->adjectives); insults_files_get_lines( insults_files, APP_ASSETS_PATH("word_lists/nouns.txt"), insults_files->nouns); + insults_files_get_lines( + insults_files, APP_ASSETS_PATH("word_lists/overlaps.txt"), insults_files->overlaps); return insults_files; } @@ -41,6 +44,7 @@ void insults_files_free(InsultsFiles* insults_files) { file_lines_free(insults_files->imperatives); file_lines_free(insults_files->adjectives); file_lines_free(insults_files->nouns); + file_lines_free(insults_files->overlaps); furi_record_close(RECORD_STORAGE); @@ -84,18 +88,55 @@ void insults_files_get_lines(InsultsFiles* insults_files, const char* path, File file_lines->num_lines = num_lines; } +bool insults_files_check_overlap( + InsultsFiles* insults_files, + const char* adjective, + const char* noun) { + for(unsigned int i = 0; i < insults_files->overlaps->num_lines; i++) { + const char* line = insults_files->overlaps->lines[i]; + + const char* adjective_temp = adjective; + const char* noun_temp = noun; + + while(*adjective_temp != '\0' && *line != '\0' && *adjective_temp == *line) { + adjective_temp++; + line++; + } + + if(*adjective_temp != '\0' || *line != ':') { + continue; + } + + line++; + + while(*noun_temp != '\0' && *line != '\0' && *noun_temp == *line) { + noun_temp++; + line++; + } + + if(*noun_temp == '\0' && *line == '\0') { + return true; + } + } + + return false; +} + char* insults_files_get_insult(InsultsFiles* insults_files) { - FuriString* insult_string = furi_string_alloc_set_str( - insults_files->imperatives->lines[rand() % insults_files->imperatives->num_lines]); - - furi_string_cat_str(insult_string, ", "); - furi_string_cat_str( - insult_string, - insults_files->adjectives->lines[rand() % insults_files->adjectives->num_lines]); - furi_string_cat_str(insult_string, " "); - furi_string_cat_str( - insult_string, insults_files->nouns->lines[rand() % insults_files->nouns->num_lines]); - furi_string_cat_str(insult_string, "!"); + const char* adjective; + const char* noun; + + do { + adjective = + insults_files->adjectives->lines[rand() % insults_files->adjectives->num_lines]; + noun = insults_files->nouns->lines[rand() % insults_files->nouns->num_lines]; + } while(insults_files_check_overlap(insults_files, adjective, noun)); + + FuriString* insult_string = furi_string_alloc_printf( + "%s, %s %s!", + insults_files->imperatives->lines[rand() % insults_files->imperatives->num_lines], + adjective, + noun); char* insult_cstr = strdup(furi_string_get_cstr(insult_string)); diff --git a/insults_files.h b/insults_files.h index 4bf5d07..31487a6 100644 --- a/insults_files.h +++ b/insults_files.h @@ -23,6 +23,7 @@ typedef struct InsultsFiles { FileLines* imperatives; FileLines* adjectives; FileLines* nouns; + FileLines* overlaps; } InsultsFiles; FileLines* file_lines_alloc(void); @@ -35,6 +36,11 @@ void insults_files_free(InsultsFiles* insults_files); void insults_files_get_lines(InsultsFiles* insults_files, const char* path, FileLines* file_lines); +bool insults_files_check_overlap( + InsultsFiles* insults_files, + const char* adjective, + const char* noun); + char* insults_files_get_insult(InsultsFiles* insults_files); void insults_files_save_insult(InsultsFiles* insults_files, const char* insult); From fdc1f4c6f8013d79a1c42840207ed60e2b979e7b Mon Sep 17 00:00:00 2001 From: Isaac Brown Date: Sat, 31 Aug 2024 16:53:59 -0500 Subject: [PATCH 2/2] Added some words --- files/word_lists/adjectives.txt | 2 ++ files/word_lists/nouns.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/files/word_lists/adjectives.txt b/files/word_lists/adjectives.txt index e46d571..81bd09a 100644 --- a/files/word_lists/adjectives.txt +++ b/files/word_lists/adjectives.txt @@ -29,6 +29,7 @@ half-witted hellish ill-tempered inappropriate +infertile joyless knock-kneed laggardly @@ -73,6 +74,7 @@ soulless stupid swindling tactless +tarnished thieving ululating uncouth diff --git a/files/word_lists/nouns.txt b/files/word_lists/nouns.txt index 2176763..8181f15 100644 --- a/files/word_lists/nouns.txt +++ b/files/word_lists/nouns.txt @@ -5,6 +5,7 @@ boil blight boor braggart +codpiece cow coward dung beetle @@ -29,6 +30,7 @@ leper liar lunatic monster +miscreant nincompoop nitwit oaf