aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dictionary.c42
-rw-r--r--jdtalk.h3
-rw-r--r--main.c2
-rw-r--r--talk.c18
4 files changed, 37 insertions, 28 deletions
diff --git a/dictionary.c b/dictionary.c
index 3766525..3b3b687 100644
--- a/dictionary.c
+++ b/dictionary.c
@@ -238,33 +238,39 @@ char *dictionary_word_formats(struct Dictionary *dict, const char *s) {
* @param type type of word (WT_NOUN, WT_VERB, WT_ADVERB, WT_ADJECTIVE) || (WT_ANY, WT_ICASE)
* @return 0=not found, !0=found
*/
-int dictionary_contains(struct Dictionary *dict, const char *s, unsigned type) {
- int result;
+unsigned dictionary_contains(struct Dictionary *dict[], const char *s, unsigned type) {
+ unsigned result;
+ int found;
unsigned icase;
icase = type & WT_ICASE; // Determine case-sensitivity of the search function
type &= 0x7f; // Strip case-insensitive flag from type
result = 0;
- for (size_t i = 0; i < dict->nelem_inuse; i++) {
- if (*s != *dict->words[i]->word) {
- // Didn't start with first character in s
- continue;
- }
+ for (size_t x = 0; dict[x] != NULL; x++) {
+ found = 0;
+ struct Dictionary *rec = dict[x];
+ for (size_t i = 0; i < rec->nelem_inuse; i++) {
+ if (*s != *rec->words[i]->word) {
+ // Didn't start with first character in s
+ continue;
+ }
- if (type != WT_ANY && dict->words[i]->type != type) {
- // Incorrect type of word
- continue;
- }
+ if (type != WT_ANY && rec->words[i]->type != type) {
+ // Incorrect type of word
+ continue;
+ }
- if (icase) {
- result = strcasecmp(dict->words[i]->word, s) == 0;
- } else {
- result = strcmp(dict->words[i]->word, s) == 0;
- }
+ if (icase) {
+ found = strcasecmp(rec->words[i]->word, s) == 0;
+ } else {
+ found = strcmp(rec->words[i]->word, s) == 0;
+ }
- if (result) {
- break;
+ if (found) {
+ result |= (unsigned) rec->words[i]->type;
+ break;
+ }
}
}
return result;
diff --git a/jdtalk.h b/jdtalk.h
index e8237cd..8256041 100644
--- a/jdtalk.h
+++ b/jdtalk.h
@@ -40,7 +40,7 @@ struct Dictionary *dictionary_new();
void dictionary_append(struct Dictionary **dict, char *s, unsigned type);
int dictionary_read(FILE *fp, struct Dictionary **dict, unsigned type);
struct Dictionary *dictionary_populate();
-int dictionary_contains(struct Dictionary *dict, const char *s, unsigned type);
+unsigned dictionary_contains(struct Dictionary *dict[], const char *s, unsigned type);
char *dictionary_word(struct Dictionary *dict, unsigned type);
char *dictionary_word_formats(struct Dictionary *dict, const char *s);
struct Dictionary *dictionary_of(struct Dictionary **src, unsigned type);
@@ -52,7 +52,6 @@ char *str_leet(char *s);
char *str_title_case(char *s);
char *str_randomize_words(char *s);
char *str_reverse(char *s);
-char *str_album(char *s, char **parts);
char *talkf(struct Dictionary *dict[], char *fmt, char **parts, size_t parts_max);
char *talk_salad(struct Dictionary *dict[], size_t limit, char **parts, size_t parts_max);
diff --git a/main.c b/main.c
index 1de43c7..3cf4142 100644
--- a/main.c
+++ b/main.c
@@ -216,7 +216,7 @@ int main(int argc, char *argv[]) {
NULL,
};
- if (do_pattern && !dictionary_contains(dict, pattern, WT_ANY)) {
+ if (do_pattern && !dictionary_contains(&dicts[1], pattern, WT_ANY)) {
fprintf(stderr, "Word not found in dictionary: %s\n", pattern);
exit(1);
}
diff --git a/talk.c b/talk.c
index 9ed5824..094edaf 100644
--- a/talk.c
+++ b/talk.c
@@ -82,20 +82,20 @@ char *talk_salad(struct Dictionary *dict[], size_t limit, char **parts, size_t p
char *talk_acronym(struct Dictionary *dict[], char *fmt, char *s, char **parts, size_t parts_max) {
size_t s_len;
- size_t format_len;
- char format[INPUT_SIZE_MAX];
static char buf[OUTPUT_SIZE_MAX];
static char *local_parts[OUTPUT_PART_MAX];
buf[0] = '\0';
+ s_len = strlen(s);
+ /*
+ size_t format_len;
+ char format[INPUT_SIZE_MAX];
format[0] = '\0';
-
if (fmt) {
strcpy(format, fmt);
} else {
strcpy(format, "x");
}
- s_len = strlen(s);
format_len = strlen(fmt);
if (format_len > s_len) {
*(format + s_len) = '\0';
@@ -103,13 +103,15 @@ char *talk_acronym(struct Dictionary *dict[], char *fmt, char *s, char **parts,
size_t x;
x = 0;
+ */
for (size_t i = 0; i < s_len; i++) {
char word[OUTPUT_SIZE_MAX];
word[0] = '\0';
while(1) {
- char elem[2] = {0, 0};
- elem[0] = format[x];
- strcpy(word, talkf(dict, elem, &local_parts[i], parts_max));
+ // Disable formatted output (again!)
+ //char elem[2] = {0, 0};
+ //elem[0] = format[x];
+ strcpy(word, talkf(dict, "x", &local_parts[i], parts_max));
if (*word == s[i]) {
strncat(buf, word, OUTPUT_SIZE_MAX);
if (i < s_len - 1) {
@@ -127,9 +129,11 @@ char *talk_acronym(struct Dictionary *dict[], char *fmt, char *s, char **parts,
break;
}
}
+ /*
if (x < format_len - 1) {
x++;
}
+ */
}
return buf;
}