2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: actutil.c /main/3 1995/11/08 10:14:39 rswiston $ */
25 Copyright 1986 Tandem Computers Incorporated.
26 This product and information is proprietary of Tandem Computers Incorporated.
27 Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
30 /* Actutil.c contains utility procedures for processing actions specified
31 in the interface definition.*/
49 /* When an explicit or implied end-tag occurs */
50 void m_endaction(m_elt)
54 char buffer[2*MAXD+M_NAMELEN+1];
57 if (m_element[m_elt - 1].content != M_NONE) {
58 if (m_toptstat == M_OTHER) {
71 if (m_action = m_findact(m_elt, m_ecarray)) {
72 m_stackpar = m_stacktop;
75 if (m_action = m_findact(m_elt, m_etarray)) {
76 m_stackpar = m_stacktop->stparam;
77 m_textout(&m_string[m_action - 1], FALSE, TRUE);
81 /* Find appropriate action according to current stack */
82 int m_findact(elt, array)
89 if (! array[elt - 1]) return(FALSE);
90 if (m_stacktop->element != elt) {
91 m_error("Program error in findact");
94 /* There is an action for this element with no context specification */
95 if (m_action[array[elt - 1] - 1].data) {
97 index = array[elt - 1];
99 /* Only actions for this element have context specified */
104 m_findchain(m_stacktop->oldtop, array[elt - 1], chainlen, &chainlen,
106 return(index ? m_action[index - 1].data : FALSE);
109 /* Recursive procedure called by findact() to search m_action */
111 void m_findchain(M_PARSE *stackptr, int start, int chainin, int *chainout, int *index, LOGICAL wild)
113 void m_findchain(stackptr, start, chainin, chainout, index, wild)
125 for (node = m_action[start - 1].son ; node;
126 node = m_action[node - 1].next) {
127 if (m_action[node - 1].element == 1)
128 m_findchain(stackptr, node, chainin, chainout, index, TRUE);
129 else for (stackp = stackptr;
131 stackp = stackp->oldtop) {
132 if (stackp->element == m_action[node - 1].element - 1) {
133 if (m_action[node - 1].data)
134 if (chainin + 1 > *chainout ||
135 (chainin + 1 == *chainout && node < *index)) {
136 *chainout = chainin + 1;
139 m_findchain(stackp->oldtop, node, chainin + 1, chainout,
147 /* Process global end string. In separate procedure to keep all references
148 to if.h in one source file and minimize recompilation if interface
150 void m_globes(M_NOPAR)
154 wc_string = MakeWideCharString(&m_string[m_ges]);
155 if (m_ges) m_stcaction(wc_string, FALSE, TRUE);
156 m_free(wc_string,"wide character string");
159 /* Process global start string. In separate procedure to keep all references
160 to if.h in one source file and minimize recompilation if interface
162 void m_globss(M_NOPAR)
166 wc_string = MakeWideCharString(&m_string[m_gss]);
167 if (m_gss) m_stcaction(wc_string, TRUE, FALSE);
168 m_free(wc_string,"wide character string");
171 /* When an explicit or implied start-tag occurs */
172 void m_strtaction(m_elt)
178 static char newpar[] = "\n ";
179 static char quote[] = " = \"";
180 char buffer[M_NAMELEN + 1 +
181 (sizeof(quote) + sizeof(newpar) - 2 > MAXD ?
182 sizeof(quote) + sizeof(newpar) - 2 :
187 m_getline(&m_stacktop->file, &m_stacktop->line);
189 sprintf(buffer, "%s%s", m_stago, m_nameofelt(m_elt));
191 for (m_i = 0, m_par = m_element[m_elt - 1].parptr;
192 m_i < m_element[m_elt - 1].parcount;
194 if (m_stacktop->param[m_i]) {
195 sprintf(buffer, "%s%s%s",
196 newpar, &m_pname[m_parameter[m_par - 1].paramname], quote);
199 for (m_p = m_stacktop->param[m_i] ; *m_p ; m_p++)
205 sprintf(buffer, "%s%d", m_cro, '"');
212 if (m_element[m_elt - 1].parcount) {
217 sprintf(buffer, "%s\n", m_tagc);
219 m_toptstat = M_TOPTSTARTTAG;
221 if (m_action = m_findact(m_elt, m_scarray)) {
222 m_stackpar = m_stacktop;
223 m_strtcase(m_action);
225 if (m_action = m_findact(m_elt, m_stcarray)) {
226 m_stacktop->stccase = m_action;
227 m_stacktop->stparam = m_stacktop;
229 if (m_action = m_findact(m_elt, m_starray)) {
230 m_stackpar = m_stacktop->stparam;
231 m_textout(&m_string[m_action - 1], TRUE, FALSE);
233 if (m_action = m_findact(m_elt, m_tcarray)) {
234 m_stacktop->cdcase = m_action;
235 m_stacktop->cdparam = m_stacktop;
237 if (m_action = m_findact(m_elt, m_pcarray)) {
238 m_stacktop->picase = m_action;
239 m_stacktop->piparam = m_stacktop;
243 /* Output a start-string or end-string */
245 void m_textout(char *format, LOGICAL start, LOGICAL end)
247 void m_textout(format, start, end)
253 M_WCHAR name[M_NAMELEN + 1];
266 stringlen = strlen(format) + 1;
268 string = (M_WCHAR *) m_malloc(stringlen, "string space");
269 for (p = string ; *format ; )
271 if (*format == M_ESCAPECHAR)
273 for (i = 0, format++ ; i < M_NAMELEN ; i++, format++)
275 mbtowc(&name[i], format, 1);
276 if (m_cttype(name[i]) == M_NONNAME ||
277 (m_cttype(name[i]) != M_NMSTART && i == 0)
287 /* Double escape character used to insert a single escape character
288 in the output string */
289 if (*format == M_ESCAPECHAR) format++;
293 for (found = FALSE, i = 0,
294 par = m_element[m_stacktop->element - 1].parptr;
295 i < m_element[m_stacktop->element - 1].parcount;
297 if (! m_wcupstrcmp(&m_pname[m_parameter[par - 1].paramname], name))
299 q = m_stacktop->param[i];
303 unused += w_strlen(name) + 1;
306 changelen = w_strlen(q) - w_strlen(name) - 1 - unused;
309 new = (M_WCHAR *) m_malloc(stringlen + changelen,
311 for (r = string, s = new ; r < p ; ) *s++ = *r++;
312 m_free(string, "string space");
314 stringlen = stringlen + changelen;
318 else if (changelen < 0) unused = -changelen;
331 if (q) while (*q) *p++ = *q++;
333 else *p++ = *format++;
336 m_stcaction(string, start, end);
337 m_free(string, "string space");