Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ERSUCC committed Sep 11, 2024
2 parents 151ebc2 + fdc1f4c commit f054662
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
4 changes: 4 additions & 0 deletions files/word_lists/adjectives.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ half-witted
hellish
ill-tempered
inappropriate
infertile
joyless
knock-kneed
laggardly
Expand Down Expand Up @@ -63,6 +64,7 @@ quivering
quixotic
rude-mouthed
satanic
saucy
scrawny
shameful
slack-jawed
Expand All @@ -72,6 +74,7 @@ soulless
stupid
swindling
tactless
tarnished
thieving
ululating
uncouth
Expand All @@ -93,3 +96,4 @@ yeasty
yellow-bellied
yodeling
zany
zealous
10 changes: 10 additions & 0 deletions files/word_lists/nouns.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
abomination
ape
beast
boil
blight
boor
braggart
codpiece
cow
coward
dung beetle
dwarf
egg
egotist
farce
fool
gallbladder
garbage
goblin
Expand All @@ -24,7 +30,9 @@ leper
liar
lunatic
monster
miscreant
nincompoop
nitwit
oaf
ogre
peasant
Expand All @@ -38,12 +46,14 @@ scallywag
scum
sot
swine
thief
toilet
twit
unibrow
vassal
wart
witch
xenophobe
yahoo
yeast infection
zamboni
7 changes: 7 additions & 0 deletions files/word_lists/overlaps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
egg-headed:egg
xenophobic:xenophobe
cowardly:coward
boorish:boor
ape-brained:ape
foolish:fool
thieving:thief
63 changes: 52 additions & 11 deletions insults_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ 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);
insults_files_get_lines(
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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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));

Expand Down
6 changes: 6 additions & 0 deletions insults_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct InsultsFiles {
FileLines* imperatives;
FileLines* adjectives;
FileLines* nouns;
FileLines* overlaps;
} InsultsFiles;

FileLines* file_lines_alloc(void);
Expand All @@ -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);
Expand Down

0 comments on commit f054662

Please sign in to comment.