2020-10-29 20:22:03 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "parser.h"
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
if(argc < 2) {
|
|
|
|
fprintf(stderr, "Usage: %s {file}\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* input = fopen(argv[1], "r");
|
|
|
|
|
|
|
|
if(input == NULL) {
|
|
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:06:33 -04:00
|
|
|
// info gathering
|
2020-10-29 20:22:03 -04:00
|
|
|
int lncount, widestln, maxtokens;
|
|
|
|
getinfo(input, &lncount, &widestln, &maxtokens);
|
2020-10-29 21:06:33 -04:00
|
|
|
|
|
|
|
// parsing
|
2020-10-29 20:22:03 -04:00
|
|
|
struct line** lns = parse(input, lncount, widestln, maxtokens);
|
2020-10-29 21:06:33 -04:00
|
|
|
fclose(input);
|
2020-10-29 20:22:03 -04:00
|
|
|
|
2020-10-29 21:06:33 -04:00
|
|
|
// printing
|
2020-10-29 20:22:03 -04:00
|
|
|
for(int i = 0; i < lncount; i++) {
|
|
|
|
int tkcount = lns[i]->tokenscount;
|
|
|
|
for(int j = 0; j < tkcount; j++) {
|
|
|
|
printf("%s ", lns[i]->tokens[j]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:06:33 -04:00
|
|
|
// freeing
|
|
|
|
freelns(lns, lncount);
|
|
|
|
|
2020-10-29 20:22:03 -04:00
|
|
|
return 0;
|
|
|
|
}
|