1 /* Id: cpp.h,v 1.43 2010/02/25 15:49:00 ragge Exp */ 2 /* $NetBSD: cpp.h,v 1.1.1.3 2010/06/03 18:57:35 plunky Exp $ */ 3 4 /* 5 * Copyright (c) 2004 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 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include <stdio.h> /* for obuf */ 32 #include <stdlib.h> 33 34 #include "config.h" 35 36 typedef unsigned char usch; 37 #ifdef YYTEXT_POINTER 38 extern char *yytext; 39 #else 40 extern char yytext[]; 41 #endif 42 extern usch *stringbuf; 43 44 extern int trulvl; 45 extern int flslvl; 46 extern int elflvl; 47 extern int elslvl; 48 extern int tflag, Cflag, Pflag; 49 extern int Mflag, dMflag; 50 extern usch *Mfile; 51 extern int ofd; 52 53 /* args for lookup() */ 54 #define FIND 0 55 #define ENTER 1 56 57 /* buffer used internally */ 58 #ifndef CPPBUF 59 #if defined(__pdp11__) 60 #define CPPBUF BUFSIZ 61 #elif defined(WIN32) 62 /* winxp seems to fail > 26608 bytes */ 63 #define CPPBUF 16384 64 #else 65 #define CPPBUF 65536 66 #endif 67 #endif 68 69 #define NAMEMAX CPPBUF /* currently pushbackbuffer */ 70 71 /* definition for include file info */ 72 struct includ { 73 struct includ *next; 74 const usch *fname; /* current fn, changed if #line found */ 75 const usch *orgfn; /* current fn, not changed */ 76 int lineno; 77 int infil; 78 usch *curptr; 79 usch *maxread; 80 usch *ostr; 81 usch *buffer; 82 int idx; 83 void *incs; 84 const usch *fn; 85 usch bbuf[NAMEMAX+CPPBUF+1]; 86 } *ifiles; 87 88 /* Symbol table entry */ 89 struct symtab { 90 const usch *namep; 91 const usch *value; 92 const usch *file; 93 int line; 94 }; 95 96 struct initar { 97 struct initar *next; 98 int type; 99 char *str; 100 }; 101 102 /* 103 * Struct used in parse tree evaluation. 104 * op is one of: 105 * - number type (NUMBER, UNUMBER) 106 * - zero (0) if divided by zero. 107 */ 108 struct nd { 109 int op; 110 union { 111 long long val; 112 unsigned long long uval; 113 } n; 114 }; 115 116 #define nd_val n.val 117 #define nd_uval n.uval 118 119 struct recur; /* not used outside cpp.c */ 120 int subst(struct symtab *, struct recur *); 121 struct symtab *lookup(const usch *namep, int enterf); 122 usch *gotident(struct symtab *nl); 123 int slow; /* scan slowly for new tokens */ 124 125 int pushfile(const usch *fname, const usch *fn, int idx, void *incs); 126 void popfile(void); 127 void prtline(void); 128 int yylex(void); 129 int sloscan(void); 130 void cunput(int); 131 int curline(void); 132 char *curfile(void); 133 void setline(int); 134 void setfile(char *); 135 int yyparse(void); 136 void yyerror(const char *); 137 void unpstr(const usch *); 138 usch *savstr(const usch *str); 139 void savch(int c); 140 void mainscan(void); 141 void putch(int); 142 void putstr(const usch *s); 143 void line(void); 144 usch *sheap(const char *fmt, ...); 145 void xwarning(usch *); 146 void xerror(usch *); 147 #ifdef HAVE_CPP_VARARG_MACRO_GCC 148 #define warning(...) xwarning(sheap(__VA_ARGS__)) 149 #define error(...) xerror(sheap(__VA_ARGS__)) 150 #else 151 #define warning printf 152 #define error printf 153 #endif 154 void expmac(struct recur *); 155 int cinput(void); 156 void getcmnt(void); 157