security/nss/coreconf/mkdepend/cppsetup.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* $Xorg: cppsetup.c,v 1.5 2001/02/09 02:03:16 xorgcvs Exp $ */
michael@0 2 /*
michael@0 3
michael@0 4 Copyright (c) 1993, 1994, 1998 The Open Group
michael@0 5
michael@0 6 Permission to use, copy, modify, distribute, and sell this software and its
michael@0 7 documentation for any purpose is hereby granted without fee, provided that
michael@0 8 the above copyright notice appear in all copies and that both that
michael@0 9 copyright notice and this permission notice appear in supporting
michael@0 10 documentation.
michael@0 11
michael@0 12 The above copyright notice and this permission notice shall be included in
michael@0 13 all copies or substantial portions of the Software.
michael@0 14
michael@0 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
michael@0 18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
michael@0 19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
michael@0 20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
michael@0 21
michael@0 22 Except as contained in this notice, the name of The Open Group shall not be
michael@0 23 used in advertising or otherwise to promote the sale, use or other dealings
michael@0 24 in this Software without prior written authorization from The Open Group.
michael@0 25
michael@0 26 */
michael@0 27 /* $XFree86: xc/config/makedepend/cppsetup.c,v 3.11 2001/12/17 20:52:22 dawes Exp $ */
michael@0 28
michael@0 29 #include "def.h"
michael@0 30
michael@0 31 #ifdef CPP
michael@0 32 /*
michael@0 33 * This file is strictly for the sake of cpy.y and yylex.c (if
michael@0 34 * you indeed have the source for cpp).
michael@0 35 */
michael@0 36 #define IB 1
michael@0 37 #define SB 2
michael@0 38 #define NB 4
michael@0 39 #define CB 8
michael@0 40 #define QB 16
michael@0 41 #define WB 32
michael@0 42 #define SALT '#'
michael@0 43 #if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
michael@0 44 #define COFF 128
michael@0 45 #else
michael@0 46 #define COFF 0
michael@0 47 #endif
michael@0 48 /*
michael@0 49 * These variables used by cpy.y and yylex.c
michael@0 50 */
michael@0 51 extern char *outp, *inp, *newp, *pend;
michael@0 52 extern char *ptrtab;
michael@0 53 extern char fastab[];
michael@0 54 extern char slotab[];
michael@0 55
michael@0 56 /*
michael@0 57 * cppsetup
michael@0 58 */
michael@0 59 struct filepointer *currentfile;
michael@0 60 struct inclist *currentinc;
michael@0 61
michael@0 62 int
michael@0 63 cppsetup(char *line, struct filepointer *filep, struct inclist *inc)
michael@0 64 {
michael@0 65 char *p, savec;
michael@0 66 static boolean setupdone = FALSE;
michael@0 67 boolean value;
michael@0 68
michael@0 69 if (!setupdone) {
michael@0 70 cpp_varsetup();
michael@0 71 setupdone = TRUE;
michael@0 72 }
michael@0 73
michael@0 74 currentfile = filep;
michael@0 75 currentinc = inc;
michael@0 76 inp = newp = line;
michael@0 77 for (p=newp; *p; p++)
michael@0 78 ;
michael@0 79
michael@0 80 /*
michael@0 81 * put a newline back on the end, and set up pend, etc.
michael@0 82 */
michael@0 83 *p++ = '\n';
michael@0 84 savec = *p;
michael@0 85 *p = '\0';
michael@0 86 pend = p;
michael@0 87
michael@0 88 ptrtab = slotab+COFF;
michael@0 89 *--inp = SALT;
michael@0 90 outp=inp;
michael@0 91 value = yyparse();
michael@0 92 *p = savec;
michael@0 93 return(value);
michael@0 94 }
michael@0 95
michael@0 96 struct symtab **lookup(symbol)
michael@0 97 char *symbol;
michael@0 98 {
michael@0 99 static struct symtab *undefined;
michael@0 100 struct symtab **sp;
michael@0 101
michael@0 102 sp = isdefined(symbol, currentinc, NULL);
michael@0 103 if (sp == NULL) {
michael@0 104 sp = &undefined;
michael@0 105 (*sp)->s_value = NULL;
michael@0 106 }
michael@0 107 return (sp);
michael@0 108 }
michael@0 109
michael@0 110 pperror(tag, x0,x1,x2,x3,x4)
michael@0 111 int tag,x0,x1,x2,x3,x4;
michael@0 112 {
michael@0 113 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
michael@0 114 warning(x0,x1,x2,x3,x4);
michael@0 115 }
michael@0 116
michael@0 117
michael@0 118 yyerror(s)
michael@0 119 register char *s;
michael@0 120 {
michael@0 121 fatalerr("Fatal error: %s\n", s);
michael@0 122 }
michael@0 123 #else /* not CPP */
michael@0 124
michael@0 125 #include "ifparser.h"
michael@0 126 struct _parse_data {
michael@0 127 struct filepointer *filep;
michael@0 128 struct inclist *inc;
michael@0 129 char *filename;
michael@0 130 const char *line;
michael@0 131 };
michael@0 132
michael@0 133 static const char *
michael@0 134 my_if_errors (IfParser *ip, const char *cp, const char *expecting)
michael@0 135 {
michael@0 136 struct _parse_data *pd = (struct _parse_data *) ip->data;
michael@0 137 int lineno = pd->filep->f_line;
michael@0 138 char *filename = pd->filename;
michael@0 139 char prefix[300];
michael@0 140 int prefixlen;
michael@0 141 int i;
michael@0 142
michael@0 143 sprintf (prefix, "\"%s\":%d", filename, lineno);
michael@0 144 prefixlen = strlen(prefix);
michael@0 145 fprintf (stderr, "%s: %s", prefix, pd->line);
michael@0 146 i = cp - pd->line;
michael@0 147 if (i > 0 && pd->line[i-1] != '\n') {
michael@0 148 putc ('\n', stderr);
michael@0 149 }
michael@0 150 for (i += prefixlen + 3; i > 0; i--) {
michael@0 151 putc (' ', stderr);
michael@0 152 }
michael@0 153 fprintf (stderr, "^--- expecting %s\n", expecting);
michael@0 154 return NULL;
michael@0 155 }
michael@0 156
michael@0 157
michael@0 158 #define MAXNAMELEN 256
michael@0 159
michael@0 160 static struct symtab **
michael@0 161 lookup_variable (IfParser *ip, const char *var, int len)
michael@0 162 {
michael@0 163 char tmpbuf[MAXNAMELEN + 1];
michael@0 164 struct _parse_data *pd = (struct _parse_data *) ip->data;
michael@0 165
michael@0 166 if (len > MAXNAMELEN)
michael@0 167 return 0;
michael@0 168
michael@0 169 strncpy (tmpbuf, var, len);
michael@0 170 tmpbuf[len] = '\0';
michael@0 171 return isdefined (tmpbuf, pd->inc, NULL);
michael@0 172 }
michael@0 173
michael@0 174
michael@0 175 static int
michael@0 176 my_eval_defined (IfParser *ip, const char *var, int len)
michael@0 177 {
michael@0 178 if (lookup_variable (ip, var, len))
michael@0 179 return 1;
michael@0 180 else
michael@0 181 return 0;
michael@0 182 }
michael@0 183
michael@0 184 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
michael@0 185
michael@0 186 static long
michael@0 187 my_eval_variable (IfParser *ip, const char *var, int len)
michael@0 188 {
michael@0 189 long val;
michael@0 190 struct symtab **s;
michael@0 191
michael@0 192 s = lookup_variable (ip, var, len);
michael@0 193 if (!s)
michael@0 194 return 0;
michael@0 195 do {
michael@0 196 var = (*s)->s_value;
michael@0 197 if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var))
michael@0 198 break;
michael@0 199 s = lookup_variable (ip, var, strlen(var));
michael@0 200 } while (s);
michael@0 201
michael@0 202 var = ParseIfExpression(ip, var, &val);
michael@0 203 if (var && *var) debug(4, ("extraneous: '%s'\n", var));
michael@0 204 return val;
michael@0 205 }
michael@0 206
michael@0 207 int
michael@0 208 cppsetup(char *filename,
michael@0 209 char *line,
michael@0 210 struct filepointer *filep,
michael@0 211 struct inclist *inc)
michael@0 212 {
michael@0 213 IfParser ip;
michael@0 214 struct _parse_data pd;
michael@0 215 long val = 0;
michael@0 216
michael@0 217 pd.filep = filep;
michael@0 218 pd.inc = inc;
michael@0 219 pd.line = line;
michael@0 220 pd.filename = filename;
michael@0 221 ip.funcs.handle_error = my_if_errors;
michael@0 222 ip.funcs.eval_defined = my_eval_defined;
michael@0 223 ip.funcs.eval_variable = my_eval_variable;
michael@0 224 ip.data = (char *) &pd;
michael@0 225
michael@0 226 (void) ParseIfExpression (&ip, line, &val);
michael@0 227 if (val)
michael@0 228 return IF;
michael@0 229 else
michael@0 230 return IFFALSE;
michael@0 231 }
michael@0 232 #endif /* CPP */
michael@0 233

mercurial