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