1 /********************************************************************/ 2 /* */ 3 /* s7 Seed7 interpreter */ 4 /* Copyright (C) 1990 - 2013 Thomas Mertes */ 5 /* */ 6 /* This program is free software; you can redistribute it and/or */ 7 /* modify it under the terms of the GNU General Public License as */ 8 /* published by the Free Software Foundation; either version 2 of */ 9 /* the License, or (at your option) any later version. */ 10 /* */ 11 /* This program is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public */ 17 /* License along with this program; if not, write to the */ 18 /* Free Software Foundation, Inc., 51 Franklin Street, */ 19 /* Fifth Floor, Boston, MA 02110-1301, USA. */ 20 /* */ 21 /* Module: Analyzer - Infile */ 22 /* File: seed7/src/infile.h */ 23 /* Changes: 1990 - 1994, 2013 Thomas Mertes */ 24 /* Content: Procedures to open, close and read the source file. */ 25 /* */ 26 /* The next_character macro is the key macro for all parsing */ 27 /* operations. All read operations for source file(s) are based */ 28 /* on next_character. All other macros and functions read from */ 29 /* the source files(s) only via next_character. Note the two */ 30 /* versions of the next_character macro for conventional and for */ 31 /* mmap use. If wide characters should be used this is the right */ 32 /* place to substitute a new wide-getc function. */ 33 /* */ 34 /********************************************************************/ 35 36 #if USE_ALTERNATE_NEXT_CHARACTER 37 #define next_character() (in_file.nextch >= in_file.beyond ? fill_buf() : (int) *in_file.nextch++) 38 #define FILE_TELL() (ftell(in_file.fil) + (long) (in_file.nextch - in_file.beyond)) 39 #define FILE_SEEK(POS) (fseek(in_file.fil, (POS), SEEK_SET), in_file.nextch = in_file.beyond) 40 #define MEM_TELL() ((long) (in_file.nextch - in_file.start)) 41 #define MEM_SEEK(POS) (in_file.nextch = in_file.start + (POS)) 42 #if HAS_MMAP 43 #define IN_FILE_TELL() MEM_TELL() 44 #define IN_FILE_SEEK(POS) MEM_SEEK(POS) 45 #else 46 #define IN_FILE_TELL() (in_file.fil ? FILE_TELL():MEM_TELL()) 47 #define IN_FILE_SEEK(POS) (in_file.fil ? FILE_SEEK(POS):MEM_SEEK(POS)) 48 #endif 49 #else 50 #define next_character() getc(in_file.fil) 51 #define IN_FILE_TELL() (ftell(in_file.fil)) 52 #define IN_FILE_SEEK(POS) (fseek(in_file.fil, (POS), SEEK_SET)) 53 #endif 54 55 56 #define SKIP_SPACE(CH) do CH = next_character(); while (CH == ' ' || CH == '\t') 57 #define SKIP_CR_SP(CH) do CH = next_character(); while (CH == ' ' || CH == '\t' || CH == '\r') 58 #define SKIP_TO_NL(CH) do { CH = next_character(); } while (CH != '\n' && CH != EOF); 59 60 #define LARGE_INCR 16383 61 62 63 #ifdef DO_INIT 64 inFileRecord in_file = { 65 NULL, /* fil */ 66 NULL, /* name_ustri */ 67 NULL, /* name */ 68 #if USE_ALTERNATE_NEXT_CHARACTER 69 NULL, /* start */ 70 NULL, /* nextch */ 71 NULL, /* beyond */ 72 0, /* buffer_size */ 73 #else 74 #if USE_INFILE_BUFFER 75 NULL, /* buffer */ 76 #endif 77 #endif 78 ' ', /* character */ 79 NULL, /* curr_infile */ 80 NULL, /* up_infile */ 81 NULL, /* next */ 82 #if WITH_COMPILATION_INFO 83 FALSE, /* write_library_names */ 84 FALSE, /* write_line_numbers */ 85 #endif 86 0, /* line */ 87 0, /* incr_message_line */ 88 LARGE_INCR, /* next_msg_line */ 89 0, /* file_number */ 90 NULL, /* owningProg */ 91 TRUE /* end_of_file */ 92 }; 93 #else 94 EXTERN inFileRecord in_file; 95 #endif 96 97 98 int fill_buf (void); 99 boolType openInfile (const_striType sourceFileName, boolType write_library_names, 100 boolType write_line_numbers, errInfoType *err_info); 101 void closeInfile (void); 102 boolType openString (bstriType inputString, boolType write_library_names, 103 boolType write_line_numbers, errInfoType *err_info); 104 void removeProgFiles (progType currentProg); 105 void next_file (void); 106 int next_line (void); 107 striType get_file_name (fileNumType file_num); 108 const_ustriType get_file_name_ustri (fileNumType file_num); 109