1 |
edhill |
1.1 |
/* |
2 |
|
|
* $XConsortium: ifparser.h,v 1.1 92/08/22 13:05:39 rws Exp $ |
3 |
|
|
* Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved. |
4 |
|
|
* |
5 |
|
|
* Redistribution and use in source and binary forms, with or without |
6 |
|
|
* modification, are permitted provided that the following conditions |
7 |
|
|
* are met: |
8 |
|
|
* |
9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer in |
14 |
|
|
* the documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* 3. The name "Carnegie Mellon University" must not be used to |
18 |
|
|
* endorse or promote products derived from this software without |
19 |
|
|
* prior written permission. For permission or any other legal |
20 |
|
|
* details, please contact |
21 |
|
|
* Office of Technology Transfer |
22 |
|
|
* Carnegie Mellon University |
23 |
|
|
* 5000 Forbes Avenue |
24 |
|
|
* Pittsburgh, PA 15213-3890 |
25 |
|
|
* (412) 268-4387, fax: (412) 268-7395 |
26 |
|
|
* tech-transfer@andrew.cmu.edu |
27 |
|
|
* |
28 |
|
|
* 4. Redistributions of any form whatsoever must retain the following |
29 |
|
|
* acknowledgment: |
30 |
|
|
* "This product includes software developed by Computing Services |
31 |
|
|
* at Carnegie Mellon University (http://www.cmu.edu/computing/)." |
32 |
|
|
* |
33 |
|
|
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO |
34 |
|
|
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
35 |
|
|
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE |
36 |
|
|
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
37 |
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN |
38 |
|
|
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
39 |
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
40 |
|
|
* |
41 |
|
|
* |
42 |
|
|
* Copyright 1992 Network Computing Devices, Inc. |
43 |
|
|
* |
44 |
|
|
* Permission to use, copy, modify, and distribute this software and its |
45 |
|
|
* documentation for any purpose and without fee is hereby granted, provided |
46 |
|
|
* that the above copyright notice appear in all copies and that both that |
47 |
|
|
* copyright notice and this permission notice appear in supporting |
48 |
|
|
* documentation, and that the name of Network Computing Devices may not be |
49 |
|
|
* used in advertising or publicity pertaining to distribution of the software |
50 |
|
|
* without specific, written prior permission. Network Computing Devices makes |
51 |
|
|
* no representations about the suitability of this software for any purpose. |
52 |
|
|
* It is provided ``as is'' without express or implied warranty. |
53 |
|
|
* |
54 |
|
|
* NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS |
55 |
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, |
56 |
|
|
* IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL, |
57 |
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
58 |
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
59 |
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
60 |
|
|
* PERFORMANCE OF THIS SOFTWARE. |
61 |
|
|
* |
62 |
|
|
* Author: Jim Fulton |
63 |
|
|
* Network Computing Devices, Inc. |
64 |
|
|
* |
65 |
|
|
* Simple if statement processor |
66 |
|
|
* |
67 |
|
|
* This module can be used to evaluate string representations of C language |
68 |
|
|
* if constructs. It accepts the following grammar: |
69 |
|
|
* |
70 |
|
|
* EXPRESSION := VALUE |
71 |
|
|
* | VALUE BINOP EXPRESSION |
72 |
|
|
* |
73 |
|
|
* VALUE := '(' EXPRESSION ')' |
74 |
|
|
* | '!' VALUE |
75 |
|
|
* | '-' VALUE |
76 |
|
|
* | 'defined' '(' variable ')' |
77 |
|
|
* | variable |
78 |
|
|
* | number |
79 |
|
|
* |
80 |
|
|
* BINOP := '*' | '/' | '%' |
81 |
|
|
* | '+' | '-' |
82 |
|
|
* | '<<' | '>>' |
83 |
|
|
* | '<' | '>' | '<=' | '>=' |
84 |
|
|
* | '==' | '!=' |
85 |
|
|
* | '&' | '|' |
86 |
|
|
* | '&&' | '||' |
87 |
|
|
* |
88 |
|
|
* The normal C order of precidence is supported. |
89 |
|
|
* |
90 |
|
|
* |
91 |
|
|
* External Entry Points: |
92 |
|
|
* |
93 |
|
|
* ParseIfExpression parse a string for #if |
94 |
|
|
*/ |
95 |
|
|
|
96 |
|
|
#include <stdio.h> |
97 |
|
|
|
98 |
|
|
#define const /**/ |
99 |
|
|
typedef int Bool; |
100 |
|
|
#define False 0 |
101 |
|
|
#define True 1 |
102 |
|
|
|
103 |
|
|
typedef struct _if_parser { |
104 |
|
|
struct { /* functions */ |
105 |
|
|
char *(*handle_error) (/* struct _if_parser *, const char *, |
106 |
|
|
const char * */); |
107 |
|
|
int (*eval_variable) (/* struct _if_parser *, const char *, int */); |
108 |
|
|
int (*eval_defined) (/* struct _if_parser *, const char *, int */); |
109 |
|
|
} funcs; |
110 |
|
|
char *data; |
111 |
|
|
} IfParser; |
112 |
|
|
|
113 |
|
|
char *ParseIfExpression (/* IfParser *, const char *, int * */); |
114 |
|
|
|