xref: /illumos-gate/usr/src/cmd/lp/lib/filters/conv.c (revision 2a8bcb4e)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include "string.h"
33*7c478bd9Sstevel@tonic-gate #include "errno.h"
34*7c478bd9Sstevel@tonic-gate #include "stdlib.h"
35*7c478bd9Sstevel@tonic-gate #include "regexpr.h"
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include "lp.h"
38*7c478bd9Sstevel@tonic-gate #include "filters.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate static char		*keyword_list[] = {
41*7c478bd9Sstevel@tonic-gate 	PARM_INPUT,
42*7c478bd9Sstevel@tonic-gate 	PARM_OUTPUT,
43*7c478bd9Sstevel@tonic-gate 	PARM_TERM,
44*7c478bd9Sstevel@tonic-gate 	PARM_PRINTER,
45*7c478bd9Sstevel@tonic-gate 	PARM_CPI,
46*7c478bd9Sstevel@tonic-gate 	PARM_LPI,
47*7c478bd9Sstevel@tonic-gate 	PARM_LENGTH,
48*7c478bd9Sstevel@tonic-gate 	PARM_WIDTH,
49*7c478bd9Sstevel@tonic-gate 	PARM_PAGES,
50*7c478bd9Sstevel@tonic-gate 	PARM_CHARSET,
51*7c478bd9Sstevel@tonic-gate 	PARM_FORM,
52*7c478bd9Sstevel@tonic-gate 	PARM_COPIES,
53*7c478bd9Sstevel@tonic-gate 	PARM_MODES,
54*7c478bd9Sstevel@tonic-gate 	0
55*7c478bd9Sstevel@tonic-gate };
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
58*7c478bd9Sstevel@tonic-gate static char *		q_strchr ( char * , char );
59*7c478bd9Sstevel@tonic-gate static char *		q_strdup ( char * );
60*7c478bd9Sstevel@tonic-gate #else
61*7c478bd9Sstevel@tonic-gate static char		*q_strchr(),
62*7c478bd9Sstevel@tonic-gate 			*q_strdup();
63*7c478bd9Sstevel@tonic-gate #endif
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /**
66*7c478bd9Sstevel@tonic-gate  ** s_to_filtertype() - CONVERT (char *) TO (FILTERTYPE)
67*7c478bd9Sstevel@tonic-gate  **/
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate FILTERTYPE
70*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
s_to_filtertype(char * str)71*7c478bd9Sstevel@tonic-gate s_to_filtertype (
72*7c478bd9Sstevel@tonic-gate 	char *			str
73*7c478bd9Sstevel@tonic-gate )
74*7c478bd9Sstevel@tonic-gate #else
75*7c478bd9Sstevel@tonic-gate s_to_filtertype (str)
76*7c478bd9Sstevel@tonic-gate 	char			*str;
77*7c478bd9Sstevel@tonic-gate #endif
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	/*
80*7c478bd9Sstevel@tonic-gate 	 * The default type, if none is given, is ``slow''.
81*7c478bd9Sstevel@tonic-gate 	 */
82*7c478bd9Sstevel@tonic-gate 	if (STREQU(str, FL_FAST))
83*7c478bd9Sstevel@tonic-gate 		return (fl_fast);
84*7c478bd9Sstevel@tonic-gate 	else
85*7c478bd9Sstevel@tonic-gate 		return (fl_slow);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /**
89*7c478bd9Sstevel@tonic-gate  ** s_to_type() - CONVERT (char *) TO (TYPE)
90*7c478bd9Sstevel@tonic-gate  **/
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate TYPE
93*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
s_to_type(char * str)94*7c478bd9Sstevel@tonic-gate s_to_type (
95*7c478bd9Sstevel@tonic-gate 	char *			str
96*7c478bd9Sstevel@tonic-gate )
97*7c478bd9Sstevel@tonic-gate #else
98*7c478bd9Sstevel@tonic-gate s_to_type (str)
99*7c478bd9Sstevel@tonic-gate 	register char		*str;
100*7c478bd9Sstevel@tonic-gate #endif
101*7c478bd9Sstevel@tonic-gate {
102*7c478bd9Sstevel@tonic-gate 	TYPE			ret;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	if ((ret.name = Strdup(str)))
105*7c478bd9Sstevel@tonic-gate 		ret.info = isterminfo(str);
106*7c478bd9Sstevel@tonic-gate 	return (ret);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /**
110*7c478bd9Sstevel@tonic-gate  ** s_to_template() - CONVERT (char *) TO (TEMPLATE)
111*7c478bd9Sstevel@tonic-gate  **/
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate TEMPLATE
114*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
s_to_template(char * str)115*7c478bd9Sstevel@tonic-gate s_to_template (
116*7c478bd9Sstevel@tonic-gate 	char *			str
117*7c478bd9Sstevel@tonic-gate )
118*7c478bd9Sstevel@tonic-gate #else
119*7c478bd9Sstevel@tonic-gate s_to_template (str)
120*7c478bd9Sstevel@tonic-gate 	register char		*str;
121*7c478bd9Sstevel@tonic-gate #endif
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	TEMPLATE		ret;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	register char		*p,
126*7c478bd9Sstevel@tonic-gate 				c;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	if (!*(str += strspn(str, " "))) {
130*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_ETEMPLATE;
131*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
132*7c478bd9Sstevel@tonic-gate 		goto Done;
133*7c478bd9Sstevel@tonic-gate 	}
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	if (!(p = strchr(str, ' '))) {
136*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_EPATTERN;
137*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
138*7c478bd9Sstevel@tonic-gate 		goto Done;
139*7c478bd9Sstevel@tonic-gate 	}
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	c = *p;
142*7c478bd9Sstevel@tonic-gate 	*p = 0;
143*7c478bd9Sstevel@tonic-gate 	ret.keyword = Strdup(str);
144*7c478bd9Sstevel@tonic-gate 	*p = c;
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	if (!ret.keyword) {
147*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_ENOMEM;
148*7c478bd9Sstevel@tonic-gate 		goto Done;
149*7c478bd9Sstevel@tonic-gate 	}
150*7c478bd9Sstevel@tonic-gate 	if (!searchlist(ret.keyword, keyword_list)) {
151*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_EKEYWORD;
152*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
153*7c478bd9Sstevel@tonic-gate 		goto Done;
154*7c478bd9Sstevel@tonic-gate 	}
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	str = p + strspn(p, " ");
157*7c478bd9Sstevel@tonic-gate 	if (!(p = q_strchr(str, '='))) {
158*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_ERESULT;
159*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
160*7c478bd9Sstevel@tonic-gate 		goto Done;
161*7c478bd9Sstevel@tonic-gate 	}
162*7c478bd9Sstevel@tonic-gate 	while (p[-1] == ' ' && p > str)
163*7c478bd9Sstevel@tonic-gate 		p--;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	c = *p;
166*7c478bd9Sstevel@tonic-gate 	*p = 0;
167*7c478bd9Sstevel@tonic-gate 	ret.pattern = q_strdup(str);
168*7c478bd9Sstevel@tonic-gate 	*p = c;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	if (!ret.pattern) {
171*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_ENOMEM;
172*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
173*7c478bd9Sstevel@tonic-gate 		goto Done;
174*7c478bd9Sstevel@tonic-gate 	}
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 	if (!*ret.pattern) {
177*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_EPATTERN;
178*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
179*7c478bd9Sstevel@tonic-gate 		goto Done;
180*7c478bd9Sstevel@tonic-gate 	}
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 	if (!(ret.re = compile(ret.pattern, (char *)0, (char *)0))) {
183*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_EREGEX;
184*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
185*7c478bd9Sstevel@tonic-gate 		goto Done;
186*7c478bd9Sstevel@tonic-gate 	}
187*7c478bd9Sstevel@tonic-gate 	ret.nbra = nbra;
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate 	if (!*(str = p + strspn(p, " ="))) {
190*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_ERESULT;
191*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
192*7c478bd9Sstevel@tonic-gate 		goto Done;
193*7c478bd9Sstevel@tonic-gate 	}
194*7c478bd9Sstevel@tonic-gate 	ret.result = q_strdup(str);
195*7c478bd9Sstevel@tonic-gate 	if (!ret.result) {
196*7c478bd9Sstevel@tonic-gate 		lp_errno = LP_ENOMEM;
197*7c478bd9Sstevel@tonic-gate 		ret.keyword = 0;
198*7c478bd9Sstevel@tonic-gate 	}
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate Done:	return (ret);
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate /**
204*7c478bd9Sstevel@tonic-gate  ** sl_to_typel() - CONVERT (char **) LIST TO (TYPE *) LIST
205*7c478bd9Sstevel@tonic-gate  **/
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate TYPE *
208*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
sl_to_typel(char ** src)209*7c478bd9Sstevel@tonic-gate sl_to_typel (
210*7c478bd9Sstevel@tonic-gate 	char **			src
211*7c478bd9Sstevel@tonic-gate )
212*7c478bd9Sstevel@tonic-gate #else
213*7c478bd9Sstevel@tonic-gate sl_to_typel (src)
214*7c478bd9Sstevel@tonic-gate 	char			**src;
215*7c478bd9Sstevel@tonic-gate #endif
216*7c478bd9Sstevel@tonic-gate {
217*7c478bd9Sstevel@tonic-gate 	register TYPE		*dst;
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	register int		nitems,
220*7c478bd9Sstevel@tonic-gate 				n;
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	if (!src || !*src)
223*7c478bd9Sstevel@tonic-gate 		return (0);
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	for (nitems = 0; src[nitems]; nitems++)
226*7c478bd9Sstevel@tonic-gate 		;
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate 	if (!(dst = (TYPE *)Malloc((nitems + 1) * sizeof(TYPE)))) {
229*7c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
230*7c478bd9Sstevel@tonic-gate 		return (0);
231*7c478bd9Sstevel@tonic-gate 	}
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 	for (n = 0; n < nitems; n++)
234*7c478bd9Sstevel@tonic-gate 		dst[n] = s_to_type(src[n]);
235*7c478bd9Sstevel@tonic-gate 	dst[nitems].name = 0;
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 	return (dst);
238*7c478bd9Sstevel@tonic-gate }
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate /**
241*7c478bd9Sstevel@tonic-gate  ** sl_to_templatel() - DUPLICATE A (char **) LIST AS (TEMPLATE *) LIST
242*7c478bd9Sstevel@tonic-gate  **/
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate TEMPLATE *
245*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
sl_to_templatel(char ** src)246*7c478bd9Sstevel@tonic-gate sl_to_templatel (
247*7c478bd9Sstevel@tonic-gate 	char **			src
248*7c478bd9Sstevel@tonic-gate )
249*7c478bd9Sstevel@tonic-gate #else
250*7c478bd9Sstevel@tonic-gate sl_to_templatel (src)
251*7c478bd9Sstevel@tonic-gate 	register char		**src;
252*7c478bd9Sstevel@tonic-gate #endif
253*7c478bd9Sstevel@tonic-gate {
254*7c478bd9Sstevel@tonic-gate 	register TEMPLATE	*dst;
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 	register int		nitems,
257*7c478bd9Sstevel@tonic-gate 				n;
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	if (!src || !*src)
260*7c478bd9Sstevel@tonic-gate 		return (0);
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate 	for (nitems = 0; src[nitems]; nitems++)
263*7c478bd9Sstevel@tonic-gate 		;
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 	if (!(dst = (TEMPLATE *)Malloc((nitems + 1) * sizeof(TEMPLATE)))){
266*7c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
267*7c478bd9Sstevel@tonic-gate 		return (0);
268*7c478bd9Sstevel@tonic-gate 	}
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate 	for (n = 0; n < nitems; n++) {
271*7c478bd9Sstevel@tonic-gate 		dst[n] = s_to_template(src[n]);
272*7c478bd9Sstevel@tonic-gate 		if (dst[n].keyword == 0) {
273*7c478bd9Sstevel@tonic-gate 			freetempl (dst);
274*7c478bd9Sstevel@tonic-gate 			return (0);
275*7c478bd9Sstevel@tonic-gate 		}
276*7c478bd9Sstevel@tonic-gate 	}
277*7c478bd9Sstevel@tonic-gate 	dst[nitems].keyword = 0;
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 	return (dst);
280*7c478bd9Sstevel@tonic-gate }
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate /**
283*7c478bd9Sstevel@tonic-gate  ** type_to_s() - CONVERT (TYPE) TO (char *)
284*7c478bd9Sstevel@tonic-gate  **/
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate char *
287*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
type_to_s(TYPE t)288*7c478bd9Sstevel@tonic-gate type_to_s (
289*7c478bd9Sstevel@tonic-gate 	TYPE			t
290*7c478bd9Sstevel@tonic-gate )
291*7c478bd9Sstevel@tonic-gate #else
292*7c478bd9Sstevel@tonic-gate type_to_s (t)
293*7c478bd9Sstevel@tonic-gate 	TYPE			t;
294*7c478bd9Sstevel@tonic-gate #endif
295*7c478bd9Sstevel@tonic-gate {
296*7c478bd9Sstevel@tonic-gate 	return (Strdup(t.name));
297*7c478bd9Sstevel@tonic-gate }
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate /**
300*7c478bd9Sstevel@tonic-gate  ** template_to_s() - CONVERT (TEMPLATE) TO (char *)
301*7c478bd9Sstevel@tonic-gate  **/
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate char *
304*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
template_to_s(TEMPLATE t)305*7c478bd9Sstevel@tonic-gate template_to_s (
306*7c478bd9Sstevel@tonic-gate 	TEMPLATE		t
307*7c478bd9Sstevel@tonic-gate )
308*7c478bd9Sstevel@tonic-gate #else
309*7c478bd9Sstevel@tonic-gate template_to_s (t)
310*7c478bd9Sstevel@tonic-gate 	TEMPLATE		t;
311*7c478bd9Sstevel@tonic-gate #endif
312*7c478bd9Sstevel@tonic-gate {
313*7c478bd9Sstevel@tonic-gate 	register char		*ret,
314*7c478bd9Sstevel@tonic-gate 				*p,
315*7c478bd9Sstevel@tonic-gate 				*r;
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate 	register size_t		len;
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	len  = strlen(t.keyword) + 1;
321*7c478bd9Sstevel@tonic-gate 	for (p = t.pattern; *p; p++) {
322*7c478bd9Sstevel@tonic-gate 		if (*p == '=')
323*7c478bd9Sstevel@tonic-gate 			len++;
324*7c478bd9Sstevel@tonic-gate 		len++;
325*7c478bd9Sstevel@tonic-gate 	}
326*7c478bd9Sstevel@tonic-gate 	len += 3 + strlen(t.result);
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	ret = Malloc(len + 1);
329*7c478bd9Sstevel@tonic-gate 	if (!ret) {
330*7c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
331*7c478bd9Sstevel@tonic-gate 		return (0);
332*7c478bd9Sstevel@tonic-gate 	}
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	r = ret;
335*7c478bd9Sstevel@tonic-gate 	for (p = t.keyword; *p; )
336*7c478bd9Sstevel@tonic-gate 		*r++ = *p++;
337*7c478bd9Sstevel@tonic-gate 	*r++ = ' ';
338*7c478bd9Sstevel@tonic-gate 	for (p = t.pattern; *p; ) {
339*7c478bd9Sstevel@tonic-gate 		if (*p == '=')
340*7c478bd9Sstevel@tonic-gate 			*r++ = '\\';
341*7c478bd9Sstevel@tonic-gate 		*r++ = *p++;
342*7c478bd9Sstevel@tonic-gate 	}
343*7c478bd9Sstevel@tonic-gate 	*r++ = ' ';
344*7c478bd9Sstevel@tonic-gate 	*r++ = '=';
345*7c478bd9Sstevel@tonic-gate 	*r++ = ' ';
346*7c478bd9Sstevel@tonic-gate 	for (p = t.result; *p; )
347*7c478bd9Sstevel@tonic-gate 		*r++ = *p++;
348*7c478bd9Sstevel@tonic-gate 	*r = 0;
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate 	return (ret);
351*7c478bd9Sstevel@tonic-gate }
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate /**
354*7c478bd9Sstevel@tonic-gate  ** typel_to_sl() - DUPLICATE (TYPE *) LIST AS (char **) LIST
355*7c478bd9Sstevel@tonic-gate  **/
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate char **
358*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
typel_to_sl(TYPE * src)359*7c478bd9Sstevel@tonic-gate typel_to_sl (
360*7c478bd9Sstevel@tonic-gate 	TYPE *			src
361*7c478bd9Sstevel@tonic-gate )
362*7c478bd9Sstevel@tonic-gate #else
363*7c478bd9Sstevel@tonic-gate typel_to_sl (src)
364*7c478bd9Sstevel@tonic-gate 	TYPE			*src;
365*7c478bd9Sstevel@tonic-gate #endif
366*7c478bd9Sstevel@tonic-gate {
367*7c478bd9Sstevel@tonic-gate 	register char		**dst;
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 	register size_t		nitems;
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate 	register int		n;
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate 
374*7c478bd9Sstevel@tonic-gate 	if (!src || !src->name)
375*7c478bd9Sstevel@tonic-gate 		return (0);
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	for (nitems = 0; src[nitems].name; nitems++)
378*7c478bd9Sstevel@tonic-gate 		;
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate 	if (!(dst = (char **)Malloc((nitems + 1) * sizeof(char *)))) {
381*7c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
382*7c478bd9Sstevel@tonic-gate 		return (0);
383*7c478bd9Sstevel@tonic-gate 	}
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate 	for (n = 0; n < nitems; n++)
386*7c478bd9Sstevel@tonic-gate 		dst[n] = type_to_s(src[n]);
387*7c478bd9Sstevel@tonic-gate 	dst[nitems] = 0;
388*7c478bd9Sstevel@tonic-gate 
389*7c478bd9Sstevel@tonic-gate 	return (dst);
390*7c478bd9Sstevel@tonic-gate }
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate /**
393*7c478bd9Sstevel@tonic-gate  ** templatel_to_sl() - DUPLICATE A (TEMPLATE *) LIST AS (char **) LIST
394*7c478bd9Sstevel@tonic-gate  **/
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate char **
397*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
templatel_to_sl(TEMPLATE * src)398*7c478bd9Sstevel@tonic-gate templatel_to_sl (
399*7c478bd9Sstevel@tonic-gate 	TEMPLATE *		src
400*7c478bd9Sstevel@tonic-gate )
401*7c478bd9Sstevel@tonic-gate #else
402*7c478bd9Sstevel@tonic-gate templatel_to_sl (src)
403*7c478bd9Sstevel@tonic-gate 	register TEMPLATE	*src;
404*7c478bd9Sstevel@tonic-gate #endif
405*7c478bd9Sstevel@tonic-gate {
406*7c478bd9Sstevel@tonic-gate 	register char		**dst;
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	register size_t		nitems;
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate 	register int		n;
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate 
413*7c478bd9Sstevel@tonic-gate 	if (!src || !src->keyword)
414*7c478bd9Sstevel@tonic-gate 		return (0);
415*7c478bd9Sstevel@tonic-gate 
416*7c478bd9Sstevel@tonic-gate 	for (nitems = 0; src[nitems].keyword; nitems++)
417*7c478bd9Sstevel@tonic-gate 		;
418*7c478bd9Sstevel@tonic-gate 
419*7c478bd9Sstevel@tonic-gate 	if (!(dst = (char **)Malloc((nitems + 1) * sizeof(char *)))) {
420*7c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
421*7c478bd9Sstevel@tonic-gate 		return (0);
422*7c478bd9Sstevel@tonic-gate 	}
423*7c478bd9Sstevel@tonic-gate 
424*7c478bd9Sstevel@tonic-gate 	for (n = 0; n < nitems; n++)
425*7c478bd9Sstevel@tonic-gate 		dst[n] = template_to_s(src[n]);
426*7c478bd9Sstevel@tonic-gate 	dst[nitems] = 0;
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate 	return (dst);
429*7c478bd9Sstevel@tonic-gate }
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate /**
432*7c478bd9Sstevel@tonic-gate  ** q_strpbrk() - strpbrk() WITH BACKSLASH QUOTING
433*7c478bd9Sstevel@tonic-gate  ** q_strdup() - strdup() WITH BACKSLASHES OMITTED
434*7c478bd9Sstevel@tonic-gate  **/
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate static char *
437*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
q_strchr(char * sp,char c)438*7c478bd9Sstevel@tonic-gate q_strchr (
439*7c478bd9Sstevel@tonic-gate 	char *			sp,
440*7c478bd9Sstevel@tonic-gate 	char			c
441*7c478bd9Sstevel@tonic-gate )
442*7c478bd9Sstevel@tonic-gate #else
443*7c478bd9Sstevel@tonic-gate q_strchr (sp, c)
444*7c478bd9Sstevel@tonic-gate 	register char		*sp,
445*7c478bd9Sstevel@tonic-gate 				c;
446*7c478bd9Sstevel@tonic-gate #endif
447*7c478bd9Sstevel@tonic-gate {
448*7c478bd9Sstevel@tonic-gate 	do {
449*7c478bd9Sstevel@tonic-gate 		if (*sp == '\\' && sp[1])
450*7c478bd9Sstevel@tonic-gate 			sp += 2;
451*7c478bd9Sstevel@tonic-gate 		if (*sp == c)
452*7c478bd9Sstevel@tonic-gate 			return (sp);
453*7c478bd9Sstevel@tonic-gate 	} while (*sp++);
454*7c478bd9Sstevel@tonic-gate 	return (0);
455*7c478bd9Sstevel@tonic-gate }
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate static char *
458*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
q_strdup(char * str)459*7c478bd9Sstevel@tonic-gate q_strdup (
460*7c478bd9Sstevel@tonic-gate 	char *			str
461*7c478bd9Sstevel@tonic-gate )
462*7c478bd9Sstevel@tonic-gate #else
463*7c478bd9Sstevel@tonic-gate q_strdup (str)
464*7c478bd9Sstevel@tonic-gate 	char			*str;
465*7c478bd9Sstevel@tonic-gate #endif
466*7c478bd9Sstevel@tonic-gate {
467*7c478bd9Sstevel@tonic-gate 	char			*ret;
468*7c478bd9Sstevel@tonic-gate 
469*7c478bd9Sstevel@tonic-gate 	register char		*p,
470*7c478bd9Sstevel@tonic-gate 				*q;
471*7c478bd9Sstevel@tonic-gate 
472*7c478bd9Sstevel@tonic-gate 	register int		len	= 0;
473*7c478bd9Sstevel@tonic-gate 
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate 	for (p = str; *p; p++) {
476*7c478bd9Sstevel@tonic-gate 		if (*p == '\\' && p[1] == '=')
477*7c478bd9Sstevel@tonic-gate 			p++;
478*7c478bd9Sstevel@tonic-gate 		len++;
479*7c478bd9Sstevel@tonic-gate 	}
480*7c478bd9Sstevel@tonic-gate 
481*7c478bd9Sstevel@tonic-gate 	if (!(ret = q = Malloc(len + 1)))
482*7c478bd9Sstevel@tonic-gate 		return (0);
483*7c478bd9Sstevel@tonic-gate 
484*7c478bd9Sstevel@tonic-gate 	for (p = str; *p; p++) {
485*7c478bd9Sstevel@tonic-gate 		if (*p == '\\' && p[1] == '=')
486*7c478bd9Sstevel@tonic-gate 			p++;
487*7c478bd9Sstevel@tonic-gate 		*q++ = *p;
488*7c478bd9Sstevel@tonic-gate 	}
489*7c478bd9Sstevel@tonic-gate 	*q = 0;
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate 	return (ret);
492*7c478bd9Sstevel@tonic-gate }
493