-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
52 lines (42 loc) · 1.17 KB
/
init.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "typedefs.h"
#include "reverse.h"
bool IsLtn(char* Input) {
return (strcmp(Input, "linenums")) == 0 || (strcmp(Input, "nolinenums")) == 0;
}
bool IsInt(char* MaxLength) {
size_t StringLength = strlen(MaxLength);
size_t Counter = 0;
while (Counter < StringLength && isdigit(MaxLength[Counter]) != 0)
Counter++;
return Counter >= StringLength;
}
ltn ConvertToLtn(char* Input) {
if (strcmp(Input, "linenums") == 0)
return linenums;
else if (strcmp(Input, "nolinenums") == 0)
return nolinenums;
else
exit(1);
}
bool CheckArgs(char* Ltn, char* MaxLength) {
return IsLtn(Ltn) && IsInt(MaxLength);
}
void NoArgs() {
printf("Usage:\n");
printf("\trev [SHOW LINE NUMBERS] [MAX LINE LENGTH] files...\n");
}
void RevArgs(int argc, char** argv) {
data CrucialInfo = { ConvertToLtn(argv[1]), atoi(argv[2]) + 1 };
if (argc == 3)
Instructions(stdin, CrucialInfo);
// NoFileArgs(CrucialInfo);
else {
for (int i = 3; i < argc; i++)
FileArgs(argv[i], CrucialInfo);
}
}