Merge pull request #25 from Servostar/4-Read-Source-File
4 read source file
This commit is contained in:
commit
c5d70fdf7e
38
src/main.c
38
src/main.c
|
@ -4,6 +4,8 @@
|
|||
|
||||
#define LOG_LEVEL LOG_LEVEL_DEBUG
|
||||
|
||||
extern FILE* yyin;
|
||||
|
||||
/**
|
||||
* @brief Log a debug message to inform about beginning exit procedures
|
||||
*
|
||||
|
@ -13,6 +15,19 @@ void notify_exit(void)
|
|||
DEBUG("Exiting gemstone...");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes File after compiling.
|
||||
*
|
||||
*/
|
||||
|
||||
void close_file(void)
|
||||
{
|
||||
if (NULL != yyin)
|
||||
{
|
||||
fclose(yyin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Run compiler setup here
|
||||
*
|
||||
|
@ -33,9 +48,30 @@ void setup(void)
|
|||
DEBUG("finished starting up gemstone...");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
setup();
|
||||
atexit(close_file);
|
||||
|
||||
// Check for file input as argument
|
||||
if (2 != argc)
|
||||
{
|
||||
INFO("Usage: %s <filename>\n", argv[0]);
|
||||
PANIC("No File could be found");
|
||||
}
|
||||
|
||||
// filename as first argument
|
||||
char *filename = argv[1];
|
||||
|
||||
FILE *file = fopen(filename, "r");
|
||||
|
||||
if (NULL == file)
|
||||
{
|
||||
PANIC("File couldn't be opened!");
|
||||
}
|
||||
yyin = file;
|
||||
|
||||
yyparse();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue