/* ibicc - The Ibi C Compiler Copyright (C) 2004 Antti-Juhani Kaijanaho Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FILE_H #define FILE_H #include "strutil.h" #include #include struct actual_file { unsigned real_file : 1; #ifdef _POSIX_MAPPED_FILES unsigned mmapped : 1; #endif char *fname; int fd; size_t bn; size_t bmaxn; unsigned char *buf; /* file buffer (mmapped if possible) */ }; struct file { struct actual_file *af; int current_line; struct file *parent; int is_beginning_of_logical_line; int is_system_file; size_t bi; }; #define get_substr(st, f) ((st)->buf = (f)->af->buf, \ (st)->start = (f)->bi, \ (st)->len = 0) #define file_substr_add(st, f) ((assert((st)->buf == (f)->af->buf)), \ (assert(file_peek((f)) != -1)), \ (++(st)->len)) #define file_peek(f) ((f)->bi >= (f)->af->bn \ || (f)->af->buf[(f)->bi] == '\\' \ ? file_peek_((f)) : (f)->af->buf[(f)->bi]) struct file *new_string_file(char const *filename, int line, struct file *parent, char const *buf); struct file *new_file(char const *filename, struct file *parent, int system_file); struct file *close_file(struct file *file); int file_peek_(struct file *f); int file_get(struct file *f); void file_eat(struct file *f, int c1); #endif /* FILE_H */