-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
61 lines (53 loc) · 1.36 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 <stdlib.h>
#include <stdio.h>
#include "metafile.h"
#include "testscanner.h"
#include "filter.h"
#include "wordlist.h"
#include "token.h"
int
main(int argc, char** argv)
{
// deal with command line arguments or lack thereof
int keyboardin = 1;
char* fname = "out";
FILE* fp = stdin;
// Parse arguments
if (argc > 1) {
keyboardin = 0;
fname = getbasefilename(argv[1]);
if (fname == (char*)NULL) {
perror("Input error");
return 1;
}
fp = openinputfile(fname);
}
if (fp == (FILE*)NULL) {
perror("Input error");
return 1;
}
// filter the file to get a wordlist_t
wordlist_t* filter = filtersource(fp);
fclose(fp);
if (filter == (wordlist_t*)NULL) {
perror("Filter error");
return 1;
}
// Display filtered source
displayfilter(filter);
// Initialize the token list
token_t** tokenlist = (token_t**) malloc(2048*sizeof(token_t*));
if (tokenlist == (token_t**)NULL) {
perror("Memory error");
return 1;
}
// calls testscanner() function until EOF
int numtokens = testscanner(tokenlist, filter);
// Display the final list of tokens
displaytokens(tokenlist, numtokens);
// free fname if it was generated.
if (!keyboardin) {
free(fname);
}
return 0;
}