mirror of
https://github.com/dschmenk/PLASMA.git
synced 2024-10-18 22:24:28 +00:00
On the road to 1.0: source code cleanup
This commit is contained in:
parent
f1c11d6b97
commit
47ed2014e3
@ -428,8 +428,11 @@ int next_line(void)
|
||||
int len;
|
||||
t_token token;
|
||||
char* new_filename;
|
||||
if (inputfile == NULL) {
|
||||
// First-time init
|
||||
if (inputfile == NULL)
|
||||
{
|
||||
/*
|
||||
* First-time init
|
||||
*/
|
||||
inputfile = stdin;
|
||||
filename = (char*) "<stdin>";
|
||||
}
|
||||
@ -442,11 +445,17 @@ int next_line(void)
|
||||
{
|
||||
statement = inputline;
|
||||
scanpos = inputline;
|
||||
// Read next line from the current file, and strip newline from the end.
|
||||
if (fgets(inputline, 512, inputfile) == NULL) {
|
||||
/*
|
||||
* Read next line from the current file, and strip newline from the end.
|
||||
*/
|
||||
if (fgets(inputline, 512, inputfile) == NULL)
|
||||
{
|
||||
inputline[0] = 0;
|
||||
// At end of file, return to previous file if any, else return EOF_TOKEN
|
||||
if (outer_inputfile != NULL) {
|
||||
/*
|
||||
* At end of file, return to previous file if any, else return EOF_TOKEN
|
||||
*/
|
||||
if (outer_inputfile != NULL)
|
||||
{
|
||||
fclose(inputfile);
|
||||
free(filename);
|
||||
inputfile = outer_inputfile;
|
||||
@ -454,7 +463,8 @@ int next_line(void)
|
||||
lineno = outer_lineno - 1; // -1 because we're about to incr again
|
||||
outer_inputfile = NULL;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
scantoken = EOF_TOKEN;
|
||||
return EOF_TOKEN;
|
||||
}
|
||||
@ -467,15 +477,20 @@ int next_line(void)
|
||||
printf("; %s: %04d: %s\n", filename, lineno, inputline);
|
||||
}
|
||||
token = scan();
|
||||
// Handle single level of file inclusion
|
||||
if (token == INCLUDE_TOKEN) {
|
||||
/*
|
||||
* Handle single level of file inclusion
|
||||
*/
|
||||
if (token == INCLUDE_TOKEN)
|
||||
{
|
||||
token = scan();
|
||||
if (token != STRING_TOKEN) {
|
||||
if (token != STRING_TOKEN)
|
||||
{
|
||||
parse_error("Missing include filename");
|
||||
scantoken = EOF_TOKEN;
|
||||
return EOF_TOKEN;
|
||||
}
|
||||
if (outer_inputfile != NULL) {
|
||||
if (outer_inputfile != NULL)
|
||||
{
|
||||
parse_error("Only one level of includes allowed");
|
||||
scantoken = EOF_TOKEN;
|
||||
return EOF_TOKEN;
|
||||
@ -487,7 +502,8 @@ int next_line(void)
|
||||
strncpy(new_filename, (char*)constval, tokenlen-2);
|
||||
new_filename[tokenlen-2] = 0;
|
||||
inputfile = fopen(new_filename, "r");
|
||||
if (inputfile == NULL) {
|
||||
if (inputfile == NULL)
|
||||
{
|
||||
parse_error("Error opening include file");
|
||||
scantoken = EOF_TOKEN;
|
||||
return EOF_TOKEN;
|
||||
|
Loading…
Reference in New Issue
Block a user