VPDF compiles and links but exits early after start.
[AROS-Contrib.git] / rexx / src / template.c
blob5fae672668fa98bdc3627f1838b3781e528b5f60
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:39 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/11/26 13:13:47 bnv
8 * Changed: To use the new macros.
10 * Revision 1.1 1998/07/02 17:34:50 bnv
11 * Initial revision
15 #include <lerror.h>
16 #include <lstring.h>
18 #include <rexx.h>
19 #include <trace.h>
20 #include <compile.h>
22 /* ----------- vrefp --------- */
23 /* variable reference position */
24 static void
25 vrefp( void )
27 nextsymbol(); /* skip left parenthesis */
29 if (symbol != ident_sy)
30 Lerror( ERR_STRING_EXPECTED,7,&symbolstr);
32 _CodeAddByte( load_mn );
33 _CodeAddPtr( SYMBOLADD2LITS );
34 TraceByte( nothing_middle );
35 nextsymbol();
37 _mustbe(ri_parent,ERR_INV_VAR_REFERENCE,1);
38 } /* vrefp */
40 /* -------- position ------- */
41 /* variable reference position */
42 static void
43 position(void)
45 int type;
47 if (symbol==le_parent)
48 vrefp();
49 else
50 if (symbol==literal_sy) {
51 type = _Lisnum(&symbolstr);
52 if (type==LREAL_TY)
53 Lerror(ERR_INVALID_INTEGER,4,&symbolstr);
54 else
55 if (type==LSTRING_TY)
56 Lerror(ERR_INVALID_TEMPLATE,2,&symbolstr);
57 _CodeAddByte(push_mn);
58 _CodeAddPtr(SYMBOLADD2LITS_KEY);
59 TraceByte( nothing_middle );
60 nextsymbol();
61 } else
62 Lerror(ERR_INVALID_TEMPLATE,2,&symbolstr);
63 _CodeAddByte(toint_mn);
64 } /* position */
66 /* -------------------------------------------------------------- */
67 /* template_list := template | [template] ',' [template_list] */
68 /* template := (trigger | target | Msg38.1)+ */
69 /* target := VAR_SYMBOL | '.' */
70 /* trigger := pattern | positional */
71 /* pattern := STRING | vrefp */
72 /* vrefp := '(' (VAR_SYMBOL | Msg19.7) (')' | Msg46.1) */
73 /* positional := absolute_pos | relative_pos */
74 /* absolute_pos := NUMBER | '=' position */
75 /* position := NUMBER | vrefp | Msg38.2 */
76 /* relative_pos := ('+' | '-') position */
77 /* -------------------------------------------------------------- */
78 void
79 C_template(void)
81 void *target_ptr=NULL;
82 bool trigger, dot=FALSE;
83 bool sign;
84 int type;
86 _CodeAddByte(parse_mn);
87 while ((symbol!=semicolon_sy) && (symbol!=comma_sy)) {
88 trigger = FALSE;
89 switch (symbol) {
90 case ident_sy:
91 case dot_sy:
92 if (target_ptr || dot) {
93 /* trigger space */
94 trigger = TRUE;
95 _CodeAddByte(tr_space_mn);
96 /* do not go to next symbol */
97 } else {
98 if (symbol==ident_sy)
99 target_ptr = SYMBOLADD2LITS;
100 else
101 dot = TRUE;
102 nextsymbol();
104 break;
106 case minus_sy:
107 case plus_sy:
108 trigger = TRUE;
109 sign = (symbol==minus_sy);
110 nextsymbol();
111 position();
112 if (sign) {
113 _CodeAddByte(neg_mn);
114 TraceByte( nothing_middle );
116 _CodeAddByte(tr_rel_mn);
117 break;
119 case literal_sy:
120 trigger = TRUE;
122 if (symbolisstr) {
123 _CodeAddByte(push_mn);
124 _CodeAddPtr(SYMBOLADD2LITS_KEY);
125 TraceByte( nothing_middle );
126 _CodeAddByte(tr_lit_mn);
127 nextsymbol();
128 } else {
129 type = _Lisnum(&symbolstr);
130 if (type==LREAL_TY)
131 Lerror(ERR_INVALID_INTEGER,4,&symbolstr);
132 else
133 if (type==LSTRING_TY)
134 Lerror(ERR_INVALID_TEMPLATE,1,&symbolstr);
136 _CodeAddByte(push_mn);
137 _CodeAddPtr(SYMBOLADD2LITS_KEY);
138 TraceByte( nothing_middle );
139 _CodeAddByte(toint_mn);
140 _CodeAddByte(tr_abs_mn);
141 nextsymbol();
143 break;
145 case le_parent:
146 trigger = TRUE;
147 vrefp();
148 _CodeAddByte(tr_lit_mn);
149 break;
151 case eq_sy:
152 trigger = TRUE;
153 nextsymbol();
154 position();
155 _CodeAddByte(toint_mn);
156 _CodeAddByte(tr_abs_mn);
157 break;
159 default:
160 Lerror(ERR_INVALID_TEMPLATE,0);
161 } /* end of switch */
162 if (trigger) {
163 if (target_ptr) {
164 _CodeAddByte(create_mn);
165 _CodeAddPtr(target_ptr);
166 _CodeAddByte(pvar_mn);
167 TraceByte( other_middle );
168 target_ptr = NULL;
169 } else
170 if (dot) {
171 _CodeAddByte(pdot_mn);
172 TraceByte( dot_middle );
173 dot = FALSE;
176 } /* end of while */
178 if (target_ptr) { /* assign the remaining part */
179 _CodeAddByte(tr_end_mn);
180 _CodeAddByte(create_mn);
181 _CodeAddPtr(target_ptr);
182 _CodeAddByte(pvar_mn);
183 TraceByte( other_middle );
184 } else
185 if (dot) {
186 _CodeAddByte(tr_end_mn);
187 _CodeAddByte(pdot_mn);
188 TraceByte( dot_middle );
191 _CodeAddByte(pop_mn);
192 _CodeAddByte(1);
193 } /* C_template */