]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/window/parser3.c
This commit was generated by cvs2svn to compensate for changes in r73188,
[FreeBSD/FreeBSD.git] / usr.bin / window / parser3.c
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #ifndef lint
38 static char sccsid[] = "@(#)parser3.c   8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
40 #endif /* not lint */
41
42 #include "parser.h"
43
44 /*
45  * =
46  * ? :
47  * ||
48  * &&
49  * |
50  * ^
51  * &
52  * == !=
53  * <= >=
54  * << >>
55  * + -
56  * * / %
57  * unary - + ~ !
58  */
59 p_expr(v, flag)
60 register struct value *v;
61 char flag;
62 {
63         struct value t;
64         int ret;
65
66         if (p_expr0(&t, flag) < 0)
67                 return -1;
68
69         if (token != T_ASSIGN) {
70                 *v = t;
71                 return 0;
72         }
73         switch (t.v_type) {
74         case V_NUM:
75                 p_error("%d: Not a variable.", t.v_num);
76         case V_ERR:
77                 t.v_str = 0;
78                 break;
79         }
80         ret = p_assign(t.v_str, v, flag);
81         if (t.v_str != 0)
82                 str_free(t.v_str);
83         return ret;
84 }
85
86 /*
87  * ? :
88  */
89 p_expr0(v, flag)
90 register struct value *v;
91 char flag;
92 {
93         struct value t;
94         char true;
95
96         if (p_expr1(v, flag) < 0)
97                 return -1;
98         if (token != T_QUEST)
99                 return 0;
100         switch (v->v_type) {
101         case V_NUM:
102                 true = v->v_num != 0;
103                 break;
104         case V_STR:
105                 p_error("?: Numeric left operand required.");
106                 str_free(v->v_str);
107                 v->v_type = V_ERR;
108         case V_ERR:
109                 flag = 0;
110                 break;
111         }
112         (void) s_gettok();
113         v->v_type = V_ERR;
114         if ((flag && true ? p_expr1(v, 1) : p_expr1(&t, 0)) < 0)
115                 return -1;
116         if (token != T_COLON) {
117                 val_free(*v);
118                 p_synerror();
119                 return -1;
120         }
121         (void) s_gettok();
122         return flag && !true ? p_expr1(v, 1) : p_expr1(&t, 0);
123 }
124
125 /*
126  * ||
127  */
128 p_expr1(v, flag)
129 register struct value *v;
130 char flag;
131 {
132         char true = 0;
133
134         if (p_expr2(v, flag) < 0)
135                 return -1;
136         if (token != T_OROR)
137                 return 0;
138         for (;;) {
139                 switch (v->v_type) {
140                 case V_NUM:
141                         v->v_num = true = true || v->v_num != 0;
142                         break;
143                 case V_STR:
144                         p_error("||: Numeric operands required.");
145                         str_free(v->v_str);
146                         v->v_type = V_ERR;
147                 case V_ERR:
148                         flag = 0;
149                         break;
150                 }
151                 if (token != T_OROR)
152                         return 0;
153                 (void) s_gettok();
154                 if (p_expr2(v, flag && !true) < 0)
155                         return -1;
156         }
157 }
158
159 /*
160  * &&
161  */
162 p_expr2(v, flag)
163 register struct value *v;
164 char flag;
165 {
166         char true = 1;
167
168         if (p_expr3_10(3, v, flag) < 0)
169                 return -1;
170         if (token != T_ANDAND)
171                 return 0;
172         for (;;) {
173                 switch (v->v_type) {
174                 case V_NUM:
175                         v->v_num = true = true && v->v_num != 0;
176                         break;
177                 case V_STR:
178                         p_error("&&: Numeric operands required.");
179                         str_free(v->v_str);
180                         v->v_type = V_ERR;
181                 case V_ERR:
182                         flag = 0;
183                         break;
184                 }
185                 if (token != T_ANDAND)
186                         return 0;
187                 (void) s_gettok();
188                 if (p_expr3_10(3, v, flag && true) < 0)
189                         return -1;
190         }
191         /*NOTREACHED*/
192 }