ifparser.h revision d43532a6
10eb10989Smrg/*
20eb10989Smrg *
30eb10989Smrg * Copyright 1992 Network Computing Devices, Inc.
4d43532a6Smrg *
50eb10989Smrg * Permission to use, copy, modify, and distribute this software and its
60eb10989Smrg * documentation for any purpose and without fee is hereby granted, provided
70eb10989Smrg * that the above copyright notice appear in all copies and that both that
80eb10989Smrg * copyright notice and this permission notice appear in supporting
90eb10989Smrg * documentation, and that the name of Network Computing Devices may not be
100eb10989Smrg * used in advertising or publicity pertaining to distribution of the software
110eb10989Smrg * without specific, written prior permission.  Network Computing Devices makes
120eb10989Smrg * no representations about the suitability of this software for any purpose.
130eb10989Smrg * It is provided ``as is'' without express or implied warranty.
14d43532a6Smrg *
150eb10989Smrg * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
160eb10989Smrg * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
170eb10989Smrg * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
180eb10989Smrg * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
190eb10989Smrg * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
200eb10989Smrg * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
210eb10989Smrg * PERFORMANCE OF THIS SOFTWARE.
22d43532a6Smrg *
230eb10989Smrg * Author:  Jim Fulton
240eb10989Smrg *          Network Computing Devices, Inc.
25d43532a6Smrg *
260eb10989Smrg * Simple if statement processor
270eb10989Smrg *
280eb10989Smrg * This module can be used to evaluate string representations of C language
290eb10989Smrg * if constructs.  It accepts the following grammar:
30d43532a6Smrg *
310eb10989Smrg *     EXPRESSION	:=	VALUE
320eb10989Smrg * 			 |	VALUE  BINOP	EXPRESSION
330eb10989Smrg *			 |	VALUE	'?'	EXPRESSION ':'	EXPRESSION
34d43532a6Smrg *
350eb10989Smrg *     VALUE		:=	'('  EXPRESSION  ')'
360eb10989Smrg * 			 |	'!'  VALUE
370eb10989Smrg * 			 |	'-'  VALUE
380eb10989Smrg *			 |	'~'  VALUE
390eb10989Smrg * 			 |	'defined'  '('  variable  ')'
400eb10989Smrg * 			 |	variable
410eb10989Smrg * 			 |	number
42d43532a6Smrg *
430eb10989Smrg *     BINOP		:=	'*'	|  '/'	|  '%'
440eb10989Smrg * 			 |	'+'	|  '-'
450eb10989Smrg * 			 |	'<<'	|  '>>'
460eb10989Smrg * 			 |	'<'	|  '>'	|  '<='  |  '>='
470eb10989Smrg * 			 |	'=='	|  '!='
480eb10989Smrg * 			 |	'&'	|  '^'  |  '|'
490eb10989Smrg * 			 |	'&&'	|  '||'
50d43532a6Smrg *
510eb10989Smrg * The normal C order of precedence is supported.
52d43532a6Smrg *
53d43532a6Smrg *
540eb10989Smrg * External Entry Points:
55d43532a6Smrg *
560eb10989Smrg *     ParseIfExpression		parse a string for #if
570eb10989Smrg */
580eb10989Smrg
590eb10989Smrg
600eb10989Smrg#include <stdio.h>
610eb10989Smrg
620eb10989Smrgtypedef int Bool;
630eb10989Smrg#define False 0
640eb10989Smrg#define True 1
650eb10989Smrg
660eb10989Smrgtypedef struct _if_parser {
670eb10989Smrg    struct {				/* functions */
680eb10989Smrg	const char *(*handle_error) (struct _if_parser *, const char *,
690eb10989Smrg				     const char *);
700eb10989Smrg	long (*eval_variable) (struct _if_parser *, const char *, int);
710eb10989Smrg	int (*eval_defined) (struct _if_parser *, const char *, int);
720eb10989Smrg    } funcs;
730eb10989Smrg    char *data;
740eb10989Smrg} IfParser;
750eb10989Smrg
760eb10989Smrgconst char *ParseIfExpression (
77d43532a6Smrg    IfParser *,
78d43532a6Smrg    const char *,
790eb10989Smrg    long *
800eb10989Smrg);
810eb10989Smrg
82