aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: ccdd1193b2f9f94b226be75c60cfa6e78dc110ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#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;

  if (
    argc >= 2 && (
      strcmp(argv[1], "help") == 0 ||
      strcmp(argv[1], "h") == 0 ||
      strcmp(argv[1], "--help") == 0 ||
      strcmp(argv[1], "-h") == 0
    )
  ) {
    return print_help();
  }

  if (argc == 2) {
    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 (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;
    }
    length = atoi(argv[2]);
  }
  
  srand(time(NULL));
  if (mode == MODE_WORD) return word_mode(length, true, false);
  printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
  if (mode == MODE_SENTENCE) {
    printf("\n");
    return sentence_mode(length - 1, true);
  }
  return paragraph_mode(length, true);
}

#include "modes.c"
#include "help.c"