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