added support for hashbang lines (if file starts with '#', line is ignored)

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@270 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-06-29 09:53:03 +00:00
parent 21cc635bc8
commit 94f36db2e5
4 changed files with 16 additions and 3 deletions

View File

@ -246,7 +246,6 @@ void flow_do_while(struct do_while *loop)
// parse a whole source code file
void flow_parse_and_close_file(FILE *fd, const char *filename)
{
//TODO - check for bogus/malformed BOM and ignore!
// be verbose
if (config.process_verbosity > 2)
printf("Parsing source file '%s'\n", filename);

View File

@ -48,7 +48,7 @@ void Input_new_file(const char *filename, FILE *fd)
Input_now->original_filename = filename;
Input_now->line_number = 1;
Input_now->source = INPUTSRC_FILE;
Input_now->state = INPUTSTATE_NORMAL;
Input_now->state = INPUTSTATE_SOF;
Input_now->src.fd = fd;
}
@ -117,6 +117,19 @@ static char get_processed_from_file(void)
for (;;) {
switch (Input_now->state) {
case INPUTSTATE_SOF:
// fetch first byte from the current source file
from_file = getc(Input_now->src.fd);
IF_WANTED_REPORT_SRCCHAR(from_file);
//TODO - check for bogus/malformed BOM and ignore?
// check for hashbang line and ignore
if (from_file == '#') {
// remember to skip remainder of line
Input_now->state = INPUTSTATE_COMMENT;
return CHAR_EOS; // end of statement
}
Input_now->state = INPUTSTATE_AGAIN;
break;
case INPUTSTATE_NORMAL:
// fetch a fresh byte from the current source file
from_file = getc(Input_now->src.fd);

View File

@ -15,6 +15,7 @@
// values for input component "src.state"
enum inputstate {
INPUTSTATE_SOF, // start of file (check for hashbang)
INPUTSTATE_NORMAL, // everything's fine
INPUTSTATE_AGAIN, // re-process last byte
INPUTSTATE_SKIPBLANKS, // shrink multiple spaces

View File

@ -9,7 +9,7 @@
#define RELEASE "0.97" // update before release FIXME
#define CODENAME "Zem" // update before release
#define CHANGE_DATE "28 June" // update before release FIXME
#define CHANGE_DATE "29 June" // update before release FIXME
#define CHANGE_YEAR "2020" // update before release
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/"
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME