-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
63 lines (49 loc) · 1.07 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "common.h"
/* globle variable to read the input files */
/****************************************************
It is recommended to avoid global variables. (-3)
*****************************************************/
char* fileNamePointer;
int ic, id;
int main(int argc, char* argv[])
{
char fileName[MAX_PATH];
int line;
int flag = TRUE;
int i;
FILE *file;
if (argc == 1)
{
printf("There is no files to compile\n");
return 0;
}
/* scan for file name */
for (i = 1; i < argc; i++) {
fileNamePointer = argv[i];
strcpy(fileName, argv[i]);
strcat(fileName, ".as");
ic = FIRST_ADDRESS;
id = 0;
file = fopen(fileName, "r");
if (!file)
{
printf("File %s does not exist \n", fileNamePointer);
return 0;
}
line = countLine(file);
rewind(file);
flag = firstPass(file, line);
if (flag)
{
/*if first pass completed with no errors*/
secondPass(line);
printf("\nfile %s is complete\n", fileNamePointer);
}
else
printf("Cannot complete %s\n", fileNamePointer);
free(mat);
/*close file*/
fclose(file);
}
return 0;
}