diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2013-08-29 19:19:52 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2013-08-29 19:22:50 +0100 |
commit | f55ff50dd5bf050e1e0b25410b7aa912ea3842f3 (patch) | |
tree | 87ef268c95a3b15f4774a31b27984c4f51c6825b | |
parent | 9efaf954c71118d41ba9bf43ed371bbe83093564 (diff) | |
download | swig-f55ff50dd5bf050e1e0b25410b7aa912ea3842f3.tar.gz |
Skip the UTF-8 BOM of including files.
For avoiding illegal token error when parsing include files which have the UTF-8 BOM.
Closes #75.
-rw-r--r-- | CHANGES.current | 4 | ||||
-rw-r--r-- | Examples/test-suite/bom_utf8.i | 9 | ||||
-rw-r--r-- | Examples/test-suite/common.mk | 3 | ||||
-rw-r--r-- | Source/Swig/include.c | 11 |
4 files changed, 25 insertions, 2 deletions
diff --git a/CHANGES.current b/CHANGES.current index dfbe651f0..0a8d722ff 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -6,6 +6,10 @@ Version 2.0.11 (in progress) ============================ 2013-08-29: wsfulton + Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an + 'Illegal token' syntax error. + +2013-08-29: wsfulton [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. 2013-08-28: wsfulton diff --git a/Examples/test-suite/bom_utf8.i b/Examples/test-suite/bom_utf8.i new file mode 100644 index 000000000..010774937 --- /dev/null +++ b/Examples/test-suite/bom_utf8.i @@ -0,0 +1,9 @@ +%module bom_utf8 + +/* Test for UTF8 BOM at start of file */ +%inline %{ +struct NotALotHere { + int n; +}; +%} + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 9a335b46e..b1e5fc3b8 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -552,7 +552,8 @@ C_TEST_CASES += \ typedef_struct \ typemap_subst \ union_parameter \ - unions + unions \ + utf8_bom # Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest) diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 13afb21ae..7e80172ba 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -163,7 +163,8 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_ String *filename; List *spath = 0; char *cname; - int i, ilen; + int i, ilen, nbytes; + char bom[3]; if (!directories) directories = NewList(); @@ -191,6 +192,14 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_ if (f) { Delete(lastpath); lastpath = filename; + + /* Skip the UTF-8 BOM if it's present */ + nbytes = fread(bom, 1, 3, f); + if (nbytes == 3 && bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF) { + /* skip */ + } else { + fseek(f, 0, SEEK_SET); + } } return f; } |