aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2021-12-06 00:30:18 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2021-12-06 00:30:18 -0500
commitbf6b57adcd220c3704469cd06f21445e0eb13888 (patch)
tree95a88339186c834b57946ff36933aea666770ed6
parent61b4313d03a93f50c5cb9d7320f3db7c21caa9f3 (diff)
downloadjdtalkc-bf6b57adcd220c3704469cd06f21445e0eb13888.tar.gz
Add DEFAULT_FORMAT define
-rw-r--r--dictionary.c2
-rw-r--r--jdtalk.h4
-rw-r--r--main.c3
-rw-r--r--talk.c3
4 files changed, 8 insertions, 4 deletions
diff --git a/dictionary.c b/dictionary.c
index a0c8f72..3766525 100644
--- a/dictionary.c
+++ b/dictionary.c
@@ -172,7 +172,7 @@ struct Dictionary *dictionary_populate() {
* @param s dictionary word to search for
* @return a string containing the word types (i.e. n,a,d,v)
*/
-char *dictionary_word_formats(struct Dictionary *dict, char *s) {
+char *dictionary_word_formats(struct Dictionary *dict, const char *s) {
static char buf[OUTPUT_SIZE_MAX];
buf[0] = '\0';
diff --git a/jdtalk.h b/jdtalk.h
index 1e7a1ad..e8237cd 100644
--- a/jdtalk.h
+++ b/jdtalk.h
@@ -15,6 +15,8 @@
#define OUTPUT_PART_MAX 255
#define OUTPUT_SIZE_MAX 1024
+#define DEFAULT_FORMAT "andv"
+
#define WT_ICASE 0x80
#define WT_ANY 0
#define WT_NOUN 1
@@ -40,7 +42,7 @@ 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);
char *dictionary_word(struct Dictionary *dict, unsigned type);
-char *dictionary_word_formats(struct Dictionary *dict, char *s);
+char *dictionary_word_formats(struct Dictionary *dict, const char *s);
struct Dictionary *dictionary_of(struct Dictionary **src, unsigned type);
void dictionary_free(struct Dictionary *dict);
diff --git a/main.c b/main.c
index 81ce730..1de43c7 100644
--- a/main.c
+++ b/main.c
@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
limit = 0;
salad_limit = 10;
- strcpy(format, "andv");
+ strcpy(format, DEFAULT_FORMAT);
pattern[0] = '\0';
buf[0] = '\0';
acronym[0] = '\0';
@@ -241,6 +241,7 @@ int main(int argc, char *argv[]) {
if (do_salad) {
strcpy(buf, talk_salad(dicts, salad_limit, part, OUTPUT_PART_MAX));
} else if (do_acronym) {
+ if (strcmp(format, DEFAULT_FORMAT) == 0) strcpy(format, "xxxx");
strcpy(buf, talk_acronym(dicts, format, acronym, part, OUTPUT_PART_MAX));
} else {
strcpy(buf, talkf(dicts, format, part, OUTPUT_PART_MAX));
diff --git a/talk.c b/talk.c
index 456939f..9ed5824 100644
--- a/talk.c
+++ b/talk.c
@@ -46,6 +46,7 @@ char *talkf(struct Dictionary *dict[], char *fmt, char **parts, size_t parts_max
word = dictionary_word(dict[WT_VERB], WT_VERB);
break;
default:
+ fprintf(stderr, "INVALID FORMAT: %x\n", fmt[i]);
break;
}
@@ -173,7 +174,7 @@ int acronym_safe(struct Dictionary *dict, const char *acronym, const char *patte
int format_safe(char *s) {
size_t valid;
- const char *formatter = "nadvx";
+ const char *formatter = DEFAULT_FORMAT"x";
valid = 0;
for (size_t i = 0; i < strlen(formatter); i++) {