summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2019-08-27 08:33:51 -0600
committerAaron Ball <nullspoon@oper.io>2019-08-27 08:33:51 -0600
commit7ba805129377963682744a5f750e0fa28e24eb64 (patch)
tree4c5ec60e3c7857d94ff38f9cb3beca39f5b93fdf /src
parent34307035a3cee02a71ae3a5d216aae0f82475b5e (diff)
downloadupwgen-7ba805129377963682744a5f750e0fa28e24eb64.tar.gz
upwgen-7ba805129377963682744a5f750e0fa28e24eb64.tar.xz
Ensure no duplicate character sets
Adds i18n_set_exists function to check the linked list for potential duplicates before adding a new character set.
Diffstat (limited to 'src')
-rw-r--r--src/i18n_set.c10
-rw-r--r--src/i18n_set.h1
-rw-r--r--src/main.c33
3 files changed, 33 insertions, 11 deletions
diff --git a/src/i18n_set.c b/src/i18n_set.c
index 0f6b819..a539752 100644
--- a/src/i18n_set.c
+++ b/src/i18n_set.c
@@ -52,6 +52,16 @@ struct i18n_set* i18n_set_add(struct i18n_set* set, int type) {
}
+struct i18n_set* i18n_set_exists(struct i18n_set* set, int type) {
+ while(set) {
+ if(set->type == type)
+ break;
+ set = set->next;
+ }
+ return set;
+}
+
+
struct i18n_set* i18n_set_rm_type(struct i18n_set* set, int type) {
struct i18n_set* cursor = set;
struct i18n_set* prev = NULL;
diff --git a/src/i18n_set.h b/src/i18n_set.h
index 9a79e83..ccdf2ed 100644
--- a/src/i18n_set.h
+++ b/src/i18n_set.h
@@ -20,6 +20,7 @@ struct i18n_set {
struct i18n_set* i18n_set_new(int);
struct i18n_set* i18n_set_add(struct i18n_set*, int);
+struct i18n_set* i18n_set_exists(struct i18n_set*, int);
struct i18n_set* i18n_set_rm_type(struct i18n_set*, int);
void i18n_set_dump(struct i18n_set*);
void i18n_set_free(struct i18n_set*);
diff --git a/src/main.c b/src/main.c
index faa939b..50d55b9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,31 +84,42 @@ int main(int argc, char* argv[]) {
set = i18n_set_rm_type(set, I18N_TYPE_ASCII_UPPER);
} else if(strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--capitalize") == 0) {
- i18n_set_add(set, I18N_TYPE_ASCII_UPPER);
+ if(!i18n_set_exists(set, I18N_TYPE_ASCII_UPPER))
+ i18n_set_add(set, I18N_TYPE_ASCII_UPPER);
} else if(strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--numerals") == 0) {
- i18n_set_add(set, I18N_TYPE_ASCII_NUMERALS);
+ if(!i18n_set_exists(set, I18N_TYPE_ASCII_NUMERALS))
+ i18n_set_add(set, I18N_TYPE_ASCII_NUMERALS);
} else if(strcmp(argv[i], "-y") == 0 || strcmp(argv[i], "--symbols") == 0) {
- i18n_set_add(set, I18N_TYPE_ASCII_SYMBOLS);
+ if(!i18n_set_exists(set, I18N_TYPE_ASCII_SYMBOLS))
+ i18n_set_add(set, I18N_TYPE_ASCII_SYMBOLS);
} else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--i18n") == 0) {
- i18n_set_add(set, I18N_TYPE_ONE);
- i18n_set_add(set, I18N_TYPE_TWO);
- i18n_set_add(set, I18N_TYPE_THREE);
- i18n_set_add(set, I18N_TYPE_FOUR);
+ if(!i18n_set_exists(set, I18N_TYPE_ONE))
+ i18n_set_add(set, I18N_TYPE_ONE);
+ if(!i18n_set_exists(set, I18N_TYPE_TWO))
+ i18n_set_add(set, I18N_TYPE_TWO);
+ if(!i18n_set_exists(set, I18N_TYPE_THREE))
+ i18n_set_add(set, I18N_TYPE_THREE);
+ if(!i18n_set_exists(set, I18N_TYPE_FOUR))
+ i18n_set_add(set, I18N_TYPE_FOUR);
} else if(strcmp(argv[i], "-1") == 0) {
- i18n_set_add(set, I18N_TYPE_ONE);
+ if(!i18n_set_exists(set, I18N_TYPE_ONE))
+ i18n_set_add(set, I18N_TYPE_ONE);
} else if(strcmp(argv[i], "-2") == 0) {
- i18n_set_add(set, I18N_TYPE_TWO);
+ if(!i18n_set_exists(set, I18N_TYPE_TWO))
+ i18n_set_add(set, I18N_TYPE_TWO);
} else if(strcmp(argv[i], "-3") == 0) {
- i18n_set_add(set, I18N_TYPE_THREE);
+ if(!i18n_set_exists(set, I18N_TYPE_THREE))
+ i18n_set_add(set, I18N_TYPE_THREE);
} else if(strcmp(argv[i], "-4") == 0) {
- i18n_set_add(set, I18N_TYPE_FOUR);
+ if(!i18n_set_exists(set, I18N_TYPE_FOUR))
+ i18n_set_add(set, I18N_TYPE_FOUR);
} else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
usage();

Generated by cgit