1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/coreconf/mkdepend/cppsetup.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,233 @@ 1.4 +/* $Xorg: cppsetup.c,v 1.5 2001/02/09 02:03:16 xorgcvs Exp $ */ 1.5 +/* 1.6 + 1.7 +Copyright (c) 1993, 1994, 1998 The Open Group 1.8 + 1.9 +Permission to use, copy, modify, distribute, and sell this software and its 1.10 +documentation for any purpose is hereby granted without fee, provided that 1.11 +the above copyright notice appear in all copies and that both that 1.12 +copyright notice and this permission notice appear in supporting 1.13 +documentation. 1.14 + 1.15 +The above copyright notice and this permission notice shall be included in 1.16 +all copies or substantial portions of the Software. 1.17 + 1.18 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.19 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.20 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.21 +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1.22 +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1.23 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1.24 + 1.25 +Except as contained in this notice, the name of The Open Group shall not be 1.26 +used in advertising or otherwise to promote the sale, use or other dealings 1.27 +in this Software without prior written authorization from The Open Group. 1.28 + 1.29 +*/ 1.30 +/* $XFree86: xc/config/makedepend/cppsetup.c,v 3.11 2001/12/17 20:52:22 dawes Exp $ */ 1.31 + 1.32 +#include "def.h" 1.33 + 1.34 +#ifdef CPP 1.35 +/* 1.36 + * This file is strictly for the sake of cpy.y and yylex.c (if 1.37 + * you indeed have the source for cpp). 1.38 + */ 1.39 +#define IB 1 1.40 +#define SB 2 1.41 +#define NB 4 1.42 +#define CB 8 1.43 +#define QB 16 1.44 +#define WB 32 1.45 +#define SALT '#' 1.46 +#if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032) 1.47 +#define COFF 128 1.48 +#else 1.49 +#define COFF 0 1.50 +#endif 1.51 +/* 1.52 + * These variables used by cpy.y and yylex.c 1.53 + */ 1.54 +extern char *outp, *inp, *newp, *pend; 1.55 +extern char *ptrtab; 1.56 +extern char fastab[]; 1.57 +extern char slotab[]; 1.58 + 1.59 +/* 1.60 + * cppsetup 1.61 + */ 1.62 +struct filepointer *currentfile; 1.63 +struct inclist *currentinc; 1.64 + 1.65 +int 1.66 +cppsetup(char *line, struct filepointer *filep, struct inclist *inc) 1.67 +{ 1.68 + char *p, savec; 1.69 + static boolean setupdone = FALSE; 1.70 + boolean value; 1.71 + 1.72 + if (!setupdone) { 1.73 + cpp_varsetup(); 1.74 + setupdone = TRUE; 1.75 + } 1.76 + 1.77 + currentfile = filep; 1.78 + currentinc = inc; 1.79 + inp = newp = line; 1.80 + for (p=newp; *p; p++) 1.81 + ; 1.82 + 1.83 + /* 1.84 + * put a newline back on the end, and set up pend, etc. 1.85 + */ 1.86 + *p++ = '\n'; 1.87 + savec = *p; 1.88 + *p = '\0'; 1.89 + pend = p; 1.90 + 1.91 + ptrtab = slotab+COFF; 1.92 + *--inp = SALT; 1.93 + outp=inp; 1.94 + value = yyparse(); 1.95 + *p = savec; 1.96 + return(value); 1.97 +} 1.98 + 1.99 +struct symtab **lookup(symbol) 1.100 + char *symbol; 1.101 +{ 1.102 + static struct symtab *undefined; 1.103 + struct symtab **sp; 1.104 + 1.105 + sp = isdefined(symbol, currentinc, NULL); 1.106 + if (sp == NULL) { 1.107 + sp = &undefined; 1.108 + (*sp)->s_value = NULL; 1.109 + } 1.110 + return (sp); 1.111 +} 1.112 + 1.113 +pperror(tag, x0,x1,x2,x3,x4) 1.114 + int tag,x0,x1,x2,x3,x4; 1.115 +{ 1.116 + warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line); 1.117 + warning(x0,x1,x2,x3,x4); 1.118 +} 1.119 + 1.120 + 1.121 +yyerror(s) 1.122 + register char *s; 1.123 +{ 1.124 + fatalerr("Fatal error: %s\n", s); 1.125 +} 1.126 +#else /* not CPP */ 1.127 + 1.128 +#include "ifparser.h" 1.129 +struct _parse_data { 1.130 + struct filepointer *filep; 1.131 + struct inclist *inc; 1.132 + char *filename; 1.133 + const char *line; 1.134 +}; 1.135 + 1.136 +static const char * 1.137 +my_if_errors (IfParser *ip, const char *cp, const char *expecting) 1.138 +{ 1.139 + struct _parse_data *pd = (struct _parse_data *) ip->data; 1.140 + int lineno = pd->filep->f_line; 1.141 + char *filename = pd->filename; 1.142 + char prefix[300]; 1.143 + int prefixlen; 1.144 + int i; 1.145 + 1.146 + sprintf (prefix, "\"%s\":%d", filename, lineno); 1.147 + prefixlen = strlen(prefix); 1.148 + fprintf (stderr, "%s: %s", prefix, pd->line); 1.149 + i = cp - pd->line; 1.150 + if (i > 0 && pd->line[i-1] != '\n') { 1.151 + putc ('\n', stderr); 1.152 + } 1.153 + for (i += prefixlen + 3; i > 0; i--) { 1.154 + putc (' ', stderr); 1.155 + } 1.156 + fprintf (stderr, "^--- expecting %s\n", expecting); 1.157 + return NULL; 1.158 +} 1.159 + 1.160 + 1.161 +#define MAXNAMELEN 256 1.162 + 1.163 +static struct symtab ** 1.164 +lookup_variable (IfParser *ip, const char *var, int len) 1.165 +{ 1.166 + char tmpbuf[MAXNAMELEN + 1]; 1.167 + struct _parse_data *pd = (struct _parse_data *) ip->data; 1.168 + 1.169 + if (len > MAXNAMELEN) 1.170 + return 0; 1.171 + 1.172 + strncpy (tmpbuf, var, len); 1.173 + tmpbuf[len] = '\0'; 1.174 + return isdefined (tmpbuf, pd->inc, NULL); 1.175 +} 1.176 + 1.177 + 1.178 +static int 1.179 +my_eval_defined (IfParser *ip, const char *var, int len) 1.180 +{ 1.181 + if (lookup_variable (ip, var, len)) 1.182 + return 1; 1.183 + else 1.184 + return 0; 1.185 +} 1.186 + 1.187 +#define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_') 1.188 + 1.189 +static long 1.190 +my_eval_variable (IfParser *ip, const char *var, int len) 1.191 +{ 1.192 + long val; 1.193 + struct symtab **s; 1.194 + 1.195 + s = lookup_variable (ip, var, len); 1.196 + if (!s) 1.197 + return 0; 1.198 + do { 1.199 + var = (*s)->s_value; 1.200 + if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var)) 1.201 + break; 1.202 + s = lookup_variable (ip, var, strlen(var)); 1.203 + } while (s); 1.204 + 1.205 + var = ParseIfExpression(ip, var, &val); 1.206 + if (var && *var) debug(4, ("extraneous: '%s'\n", var)); 1.207 + return val; 1.208 +} 1.209 + 1.210 +int 1.211 +cppsetup(char *filename, 1.212 + char *line, 1.213 + struct filepointer *filep, 1.214 + struct inclist *inc) 1.215 +{ 1.216 + IfParser ip; 1.217 + struct _parse_data pd; 1.218 + long val = 0; 1.219 + 1.220 + pd.filep = filep; 1.221 + pd.inc = inc; 1.222 + pd.line = line; 1.223 + pd.filename = filename; 1.224 + ip.funcs.handle_error = my_if_errors; 1.225 + ip.funcs.eval_defined = my_eval_defined; 1.226 + ip.funcs.eval_variable = my_eval_variable; 1.227 + ip.data = (char *) &pd; 1.228 + 1.229 + (void) ParseIfExpression (&ip, line, &val); 1.230 + if (val) 1.231 + return IF; 1.232 + else 1.233 + return IFFALSE; 1.234 +} 1.235 +#endif /* CPP */ 1.236 +