44 lines
902 B
C
44 lines
902 B
C
|
#include <parcel.h>
|
||
|
#include <ast.h>
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
char * load_file(char *path)
|
||
|
{
|
||
|
FILE *file = fopen(path, "r");
|
||
|
if(file == NULL)
|
||
|
{
|
||
|
printf("Failed opening file at '%s'\n", path);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
fseek(file, 0, SEEK_END);
|
||
|
long length = ftell(file);
|
||
|
fseek(file, 0, SEEK_SET);
|
||
|
|
||
|
char *content = malloc(length+1);
|
||
|
content[length] = 0x00;
|
||
|
fread(content, 1, length, file);
|
||
|
|
||
|
fclose(file);
|
||
|
return content;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
if(argc != 2)
|
||
|
{
|
||
|
printf("Usage: %s <filename>\n", argv[0]);
|
||
|
return -1;
|
||
|
}
|
||
|
char *source = load_file(argv[1]);
|
||
|
if(source == NULL)
|
||
|
{
|
||
|
puts("Stopping due to previous error!");
|
||
|
return -2;
|
||
|
}
|
||
|
pac_convert_grammar(source);
|
||
|
return 0;
|
||
|
}
|