-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_utils.c
50 lines (42 loc) · 1 KB
/
cli_utils.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
#include "flags.h"
#include "data_io.h"
#include <ctype.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
void sanitize_input(char *str) {
char *src = str;
char *dst = str;
while (*src) {
if (!isspace((unsigned char)*src)) {
*dst++ = *src;
}
src++;
}
*dst = '\0';
}
int process_flags(char *flag, char *arg) {
if (strcmp(flag, "-i") == 0) {
flag_i(arg);
} else if (strcmp(flag, "-g") == 0) {
Configuration conf = readToml("fastx.toml");
char cwd[MAX_INPUT_LENGTH];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
perror("Error getting current working directory");
return 1;
}
char str[MAX_INPUT_LENGTH];
sprintf(str, "%s/%s/%s", cwd, conf.routesDir, arg);
flag_g(str);
printf("Route files has been generated!\n");
} else if (strcmp(flag, "-h") == 0) {
flag_h(arg);
}
else {
printf("Invalid flag \"%s\". Run fastx -h show for more info.\n", flag);
return 1;
}
return 0;
}