1 /* Id: cpp.h,v 1.68 2014/05/28 08:52:42 plunky Exp */ 2 /* $NetBSD: cpp.h,v 1.1.1.6 2014/07/24 19:22:35 plunky Exp $ */ 3 4 /* 5 * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se). 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <stdio.h> /* for debug/printf */ 30 31 typedef unsigned char usch; 32 extern usch yytext[]; 33 extern usch *stringbuf; 34 35 extern int trulvl; 36 extern int flslvl; 37 extern int elflvl; 38 extern int elslvl; 39 extern int dflag; 40 extern int tflag, Aflag, Cflag, Pflag; 41 extern int Mflag, dMflag, MPflag; 42 extern usch *Mfile, *MPfile; 43 extern int ofd; 44 extern int defining; 45 46 /* args for lookup() */ 47 #define FIND 0 48 #define ENTER 1 49 50 /* buffer used internally */ 51 #ifndef CPPBUF 52 #if defined(mach_pdp11) 53 #define CPPBUF BUFSIZ 54 #define BUF_STACK 55 #elif defined(os_win32) 56 /* winxp seems to fail > 26608 bytes */ 57 #define CPPBUF 16384 58 #else 59 #define CPPBUF (65536*2) 60 #endif 61 #endif 62 63 #define MAXARGS 128 /* Max # of args to a macro. Should be enough */ 64 65 #define NAMEMAX CPPBUF /* currently pushbackbuffer */ 66 #define BBUFSZ (NAMEMAX+CPPBUF+1) 67 68 #define GCCARG 0xfd /* has gcc varargs that may be replaced with 0 */ 69 #define VARG 0xfe /* has varargs */ 70 #define OBJCT 0xff 71 #define WARN 1 /* SOH, not legal char */ 72 #define CONC 2 /* STX, not legal char */ 73 #define SNUFF 3 /* ETX, not legal char */ 74 #define EBLOCK 4 /* EOT, not legal char */ 75 #define PHOLD 5 /* ENQ, not legal char */ 76 77 /* Used in macro expansion */ 78 #define RECMAX 10000 /* max # of recursive macros */ 79 extern struct symtab *norep[RECMAX]; 80 extern int norepptr; 81 extern unsigned short bptr[RECMAX]; 82 extern int bidx; 83 #define MKB(l,h) (l+((h)<<8)) 84 85 /* quick checks for some characters */ 86 #define C_SPEC 0001 /* for fastscan() parsing */ 87 #define C_2 0002 /* for yylex() tokenizing */ 88 #define C_WSNL 0004 /* ' ','\t','\r','\n' */ 89 #define C_ID 0010 /* [_a-zA-Z0-9] */ 90 #define C_ID0 0020 /* [_a-zA-Z] */ 91 #define C_EP 0040 /* [epEP] */ 92 #define C_DIGIT 0100 /* [0-9] */ 93 #define C_HEX 0200 /* [0-9a-fA-F] */ 94 95 extern usch spechr[]; 96 97 #define iswsnl(x) (spechr[x] & (C_WSNL)) 98 99 /* definition for include file info */ 100 struct includ { 101 struct includ *next; 102 const usch *fname; /* current fn, changed if #line found */ 103 const usch *orgfn; /* current fn, not changed */ 104 int lineno; 105 int escln; /* escaped newlines, to be added */ 106 int infil; 107 usch *curptr; 108 usch *maxread; 109 usch *ostr; 110 usch *buffer; 111 int idx; 112 void *incs; 113 const usch *fn; 114 #ifdef BUF_STACK 115 usch bbuf[BBUFSZ]; 116 #else 117 usch *bbuf; 118 #endif 119 }; 120 #define INCINC 0 121 #define SYSINC 1 122 123 extern struct includ *ifiles; 124 125 /* Symbol table entry */ 126 struct symtab { 127 const usch *namep; 128 const usch *value; 129 const usch *file; 130 int line; 131 }; 132 133 struct initar { 134 struct initar *next; 135 int type; 136 char *str; 137 }; 138 139 /* 140 * Struct used in parse tree evaluation. 141 * op is one of: 142 * - number type (NUMBER, UNUMBER) 143 * - zero (0) if divided by zero. 144 */ 145 struct nd { 146 int op; 147 union { 148 long long val; 149 unsigned long long uval; 150 } n; 151 }; 152 153 #define nd_val n.val 154 #define nd_uval n.uval 155 156 struct symtab *lookup(const usch *namep, int enterf); 157 usch *gotident(struct symtab *nl); 158 int submac(struct symtab *nl, int); 159 int kfind(struct symtab *nl); 160 int doexp(void); 161 int donex(void); 162 void ppdir(void); 163 164 void define(void); 165 void include(void); 166 void include_next(void); 167 void line(void); 168 169 int pushfile(const usch *fname, const usch *fn, int idx, void *incs); 170 void popfile(void); 171 void prtline(void); 172 int yylex(void); 173 int sloscan(void); 174 void cunput(int); 175 int curline(void); 176 char *curfile(void); 177 void setline(int); 178 void setfile(char *); 179 int yyparse(void); 180 void unpstr(const usch *); 181 usch *savstr(const usch *str); 182 void savch(int c); 183 void mainscan(void); 184 void putch(int); 185 void putstr(const usch *s); 186 void line(void); 187 usch *sheap(const char *fmt, ...); 188 void warning(const char *fmt, ...); 189 void error(const char *fmt, ...); 190 int cinput(void); 191 void getcmnt(void); 192 void xwrite(int, const void *, unsigned int); 193