diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-06-15 11:45:38 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-06-15 11:45:38 +0530 |
| commit | 151fdb4e61cf8e6a8344d10522a0825d5f6ed675 (patch) | |
| tree | 2fa9a1ebbe40ee9d55bfd1a9e222b9c5b59d265d /src/main.c | |
| parent | 42567a5ac86b20f2a591195e6ec389d5d2cc7ce7 (diff) | |
fixed an issue with length not have a default when mode is specified
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 44 |
1 files changed, 28 insertions, 16 deletions
@@ -6,6 +6,22 @@ #include "modes.h" #include "help.h" +#define IS_WORD(x) ( \ + (strcmp(x, "w") == 0) || \ + (strcmp(x, "word") == 0) \ + ) +#define IS_LINE(x) ( \ + (strcmp(x, "l") == 0) || \ + (strcmp(x, "s") == 0) || \ + (strcmp(x, "line") == 0) || \ + (strcmp(x, "sentence") == 0) \ + ) +#define IS_PARA(x) ( \ + (strcmp(x, "p") == 0) || \ + (strcmp(x, "para") == 0) || \ + (strcmp(x, "paragraph") == 0) \ + ) + int main(int argc, char **argv) { int mode = MODE_SENTENCE; int length = 1; @@ -22,25 +38,21 @@ int main(int argc, char **argv) { } if (argc == 2) { - length = atoi(argv[1]); + if (IS_LINE(argv[1])) { + mode = MODE_SENTENCE; + } else if (IS_PARA(argv[1])) { + mode = MODE_PARAGRAPH; + } else if (IS_WORD(argv[1])) { + mode = MODE_WORD; + } else { + length = atoi(argv[1]); + } } else if (argc == 3) { - if ( - (strcmp(argv[1], "l") == 0) || - (strcmp(argv[1], "line") == 0) || - (strcmp(argv[1], "s") == 0) || - (strcmp(argv[1], "sentence") == 0) - ) { + if (IS_LINE(argv[1])) { mode = MODE_SENTENCE; - } else if ( - (strcmp(argv[1], "p") == 0) || - (strcmp(argv[1], "para") == 0) || - (strcmp(argv[1], "paragraph") == 0) - ) { + } else if (IS_PARA(argv[1])) { mode = MODE_PARAGRAPH; - } else if ( - (strcmp(argv[1], "w") == 0) || - (strcmp(argv[1], "word") == 0) - ) { + } else if (IS_WORD(argv[1])) { mode = MODE_WORD; } length = atoi(argv[2]); |
