-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
43 lines (36 loc) · 1.09 KB
/
main.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
/*
* main.c
*
* PCS2056 - Linguagens e Compiladores
* Pedro Napolitano Sant’Ana 8041817
* Rafael Freitas da Silva 6480585
*
*/
#include <stdio.h>
#include <string.h>
#include "sintatico.h"
#define FILENAME_MAX_LENGTH 200
#define FILENAME_ARG_INDEX 1
void copyFileNameFromInputArguments(char *argv[], char filename[]);
FILE* openAndGetPointerToSourceFile(char filename[]);
int main(int argc, char *argv[]){
char filename[FILENAME_MAX_LENGTH];
copyFileNameFromInputArguments(argv, filename);
FILE *pointerToSourceFile = openAndGetPointerToSourceFile(filename);
if (pointerToSourceFile) {
compile(pointerToSourceFile);
}
return 0;
}
void copyFileNameFromInputArguments(char *argv[], char filename[]){
strncpy(filename, argv[FILENAME_ARG_INDEX], FILENAME_MAX_LENGTH);
filename[FILENAME_MAX_LENGTH - 1] = '\0';
}
FILE* openAndGetPointerToSourceFile(char filename[]) {
char *mode = "r";
FILE *pointerToSourceFile = fopen(filename, mode);
if (pointerToSourceFile == NULL) {
printf("Error while reading source file.");
}
return pointerToSourceFile;
}