1 /* b-fro.h --- read-only file 2 3 Copyright (C) 2010-2020 Thien-Thi Nguyen 4 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert 5 Copyright (C) 1982, 1988, 1989 Walter Tichy 6 7 This file is part of GNU RCS. 8 9 GNU RCS is free software: you can redistribute it and/or modify it 10 under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 GNU RCS is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty 16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 See the GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 struct range 24 { 25 off_t beg; 26 off_t end; 27 }; 28 29 enum readmethod 30 { 31 RM_MMAP, 32 RM_MEM, 33 RM_STDIO 34 }; 35 36 struct fro 37 { 38 int fd; 39 off_t end; 40 enum readmethod rm; 41 char *ptr, *lim, *base; 42 void (*deallocate) (struct fro *f); 43 FILE *stream; 44 off_t verbatim; 45 }; 46 47 struct atat 48 { 49 size_t count; 50 size_t lno; 51 size_t line_count; 52 struct fro *from; 53 #if WITH_NEEDEXP 54 size_t needexp_count; 55 bool (*ineedexp) (struct atat *atat, size_t i); 56 union needexp 57 { 58 uint64_t direct; 59 uint64_t *bitset; 60 } needexp; 61 #endif /* WITH_NEEDEXP */ 62 /* NB: All of the preceding members should have an aggregate size 63 that is a multiple of 8, so that ‘beg’ is properly aligned. 64 This also requires allocation to be aligned. */ 65 off_t beg; 66 off_t holes[]; 67 }; 68 69 extern struct fro *fro_open (char const *filename, char const *type, 70 struct stat *status) 71 ARG_NONNULL ((1, 2)); 72 extern void fro_zclose (struct fro **p) 73 ALL_NONNULL; 74 extern void fro_close (struct fro *f) 75 ; 76 extern off_t fro_tello (struct fro *f) 77 ALL_NONNULL; 78 extern void fro_move (struct fro *f, off_t change) 79 ALL_NONNULL; 80 extern bool fro_try_getbyte (int *c, struct fro *f) 81 ALL_NONNULL; 82 extern void fro_must_getbyte (int *c, struct fro *f) 83 ALL_NONNULL; 84 extern void fro_trundling (bool sequential, struct fro *f) 85 ALL_NONNULL; 86 extern void fro_spew_partial (FILE *to, struct fro *f, struct range *r) 87 ALL_NONNULL; 88 extern void fro_spew (struct fro *f, FILE *to) 89 ALL_NONNULL; 90 extern struct cbuf string_from_atat (struct divvy *space, struct atat const *atat) 91 ALL_NONNULL; 92 extern void atat_put (FILE *to, struct atat const *atat) 93 ALL_NONNULL; 94 extern void atat_display (FILE *to, struct atat const *atat, 95 bool ensure_end_nl) 96 ALL_NONNULL; 97 98 /* Idioms. */ 99 100 #define fro_bob(f) fro_move (f, 0) 101 102 #define STDIO_P(f) (RM_STDIO == (f)->rm) 103 104 /* Get a char into ‘c’ from ‘f’, executing statement ‘s’ at EOF. */ 105 #define GETCHAR_OR(c,f,s) do \ 106 if (fro_try_getbyte (&(c), (f))) \ 107 { s; } \ 108 while (0) 109 110 /* Like ‘GETCHAR_OR’, except EOF is an error. */ 111 #define GETCHAR(c,f) fro_must_getbyte (&(c), (f)) 112 113 /* The (+2) is for "@\n" (or "@;" for ‘comment’ and ‘expand’). */ 114 #define ATAT_END(atat) ((atat)->holes[(atat)->count - 1]) 115 #define ATAT_TEXT_END(atat) (ATAT_END (atat) + 2) 116 117 /* Arrange for ‘fro_spew (f, ...)’ to (later) start at ‘pos’. */ 118 #define VERBATIM(f,pos) (f)->verbatim = (pos) 119 #define IGNORE_REST(f) VERBATIM ((f), (f)->end) 120 #define SAME_AFTER(f,atat) VERBATIM ((f), ATAT_TEXT_END (atat)) 121 122 /* b-fro.h ends here */ 123