-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.c
51 lines (42 loc) · 975 Bytes
/
parse.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
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "utils.h"
#ifndef MAX_BUF
#define MAX_BUF 255
#endif
void parse(int argc, char **argv)
{
for(int i = 1; i < argc; i++) // i = 1 beacause the first arg is path
{
if(!strcmp(argv[i], "--help") || !strcmp(argv[i], "--H")) {
displayHelp();
} else if(!strcmp(argv[i], "--version") || !strcmp(argv[i], "-V")) {
displayVersion();
} else if(!strcmp(argv[i], "install-compiler")) {
// installCompiler();
} else if(argc - 1 == 0) {
displayMsgNoArgs();
} else {
// print path
printf("\n\n");
char path[MAX_BUF], ch;
getcwd(path, MAX_BUF);
printf("Current directory is : %s\n", path);
printf("\n\n");
FILE* ftc; // File To Compile
ftc = fopen(argv[i], "r");
if(ftc == NULL)
{
perror("Error opening this file\n");
exit(EXIT_FAILURE);
}
while((ch = fgetc(ftc)) != EOF)
{
printf("%c", ch);
}
fclose(ftc);
printf("\n\n");
}
}
}