1/* 2 * 3 * Copyright 1992 Network Computing Devices, Inc. 4 * 5 * Permission to use, copy, modify, and distribute this software and its 6 * documentation for any purpose and without fee is hereby granted, provided 7 * that the above copyright notice appear in all copies and that both that 8 * copyright notice and this permission notice appear in supporting 9 * documentation, and that the name of Network Computing Devices may not be 10 * used in advertising or publicity pertaining to distribution of the software 11 * without specific, written prior permission. Network Computing Devices makes 12 * no representations about the suitability of this software for any purpose. 13 * It is provided ``as is'' without express or implied warranty. 14 * 15 * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 17 * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL, 18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 19 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 20 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 21 * PERFORMANCE OF THIS SOFTWARE. 22 * 23 * Author: Jim Fulton 24 * Network Computing Devices, Inc. 25 * 26 * Simple if statement processor 27 * 28 * This module can be used to evaluate string representations of C language 29 * if constructs. It accepts the following grammar: 30 * 31 * EXPRESSION := VALUE 32 * | VALUE BINOP EXPRESSION 33 * | VALUE '?' EXPRESSION ':' EXPRESSION 34 * 35 * VALUE := '(' EXPRESSION ')' 36 * | '!' VALUE 37 * | '-' VALUE 38 * | '~' VALUE 39 * | 'defined' '(' variable ')' 40 * | variable 41 * | number 42 * 43 * BINOP := '*' | '/' | '%' 44 * | '+' | '-' 45 * | '<<' | '>>' 46 * | '<' | '>' | '<=' | '>=' 47 * | '==' | '!=' 48 * | '&' | '^' | '|' 49 * | '&&' | '||' 50 * 51 * The normal C order of precedence is supported. 52 * 53 * 54 * External Entry Points: 55 * 56 * ParseIfExpression parse a string for #if 57 */ 58 59#include <stdio.h> 60 61typedef int Bool; 62 63#define False 0 64#define True 1 65 66typedef struct _if_parser { 67 struct { /* functions */ 68 const char *(*handle_error)(struct _if_parser *, const char *, 69 const char *); 70 long (*eval_variable)(struct _if_parser *, const char *, int); 71 int (*eval_defined)(struct _if_parser *, const char *, int); 72 } funcs; 73 struct _parse_data *data; 74} IfParser; 75 76const char *ParseIfExpression(IfParser *, const char *, long *); 77