diff options
author | Nicholas Tay <nick@windblume.net> | 2021-12-01 01:19:20 +1100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2021-12-01 01:27:27 +1100 |
commit | 14a419380f7e0d9e24cb663d5ae27f18449b26dc (patch) | |
tree | b0c9c68c957f13913906a9e088207b885c6eae28 | |
parent | e588d66d4e36ae6f7d8d08f9c48182365dc259a5 (diff) | |
download | passgen-14a419380f7e0d9e24cb663d5ae27f18449b26dc.tar.gz passgen-14a419380f7e0d9e24cb663d5ae27f18449b26dc.tar.bz2 passgen-14a419380f7e0d9e24cb663d5ae27f18449b26dc.zip |
Add config file, refactor classes to be cleaner with macros
-rw-r--r-- | config.h | 10 | ||||
-rw-r--r-- | passgen.c | 28 |
2 files changed, 18 insertions, 20 deletions
diff --git a/config.h b/config.h new file mode 100644 index 0000000..1160580 --- /dev/null +++ b/config.h @@ -0,0 +1,10 @@ +#define DEFAULT_GRAMMAR "Cvccvc!##"
+
+// For vowels:
+// i, o excluded due to potentially confusing 1/l/i + 0/o
+// y included as a vowel because it kinda is one
+#define CLASSES \
+ CLASS('v', "aeuy") \
+ CLASS('c', "bcdfghkmnprstvwxz") \
+ CLASS('#', "1234567890") \
+ CLASS('!', "@#$%^&*_-+=()[]{}")
@@ -1,3 +1,5 @@ +#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -5,14 +7,12 @@ #include <unistd.h>
#include <string.h>
-#define DEFAULT_GRAMMAR "Cvccvc!##"
+#define CLASS(c, chars) \
+ case c: \
+ class = chars; \
+ class_size = sizeof(chars)-1; \
+ break;
-// i, o excluded due to potentially confusing 1/l/i + 0/o
-// y included as a vowel because it kinda is one
-#define VOWELS "aeuy"
-#define CONSONANTS "bcdfghkmnprstvwxz"
-#define NUMBERS "1234567890"
-#define SYMBOLS "@#$%^&*_-+=()[]{}"
int main(int argc, char *argv[])
{
@@ -64,20 +64,8 @@ int main(int argc, char *argv[]) char *class;
int class_size = 0;
-#define setClass(cl) \
- class = cl; \
- class_size = sizeof(cl)-1; \
- break;
-
switch (c) {
- case 'c':
- setClass(CONSONANTS);
- case 'v':
- setClass(VOWELS);
- case '!':
- setClass(SYMBOLS);
- case '#':
- setClass(NUMBERS);
+ CLASSES
default:
printf("ERROR: Invalid grammar character '%c'.\n", c);
if (grammar != (char*)DEFAULT_GRAMMAR)
|