xref: /illumos-gate/usr/src/cmd/lp/lib/forms/rdform.c (revision 7c478bd9)
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 1997 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 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.17	*/
32*7c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include "stdio.h"
35*7c478bd9Sstevel@tonic-gate #include "string.h"
36*7c478bd9Sstevel@tonic-gate #include "errno.h"
37*7c478bd9Sstevel@tonic-gate #include "sys/types.h"
38*7c478bd9Sstevel@tonic-gate #include "stdlib.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include "lp.h"
41*7c478bd9Sstevel@tonic-gate #include "form.h"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate extern struct {
44*7c478bd9Sstevel@tonic-gate 	char			*v;
45*7c478bd9Sstevel@tonic-gate 	short			len;
46*7c478bd9Sstevel@tonic-gate 	short			infile;
47*7c478bd9Sstevel@tonic-gate }			formheadings[];
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
50*7c478bd9Sstevel@tonic-gate int		_search_fheading ( char * );
51*7c478bd9Sstevel@tonic-gate #else
52*7c478bd9Sstevel@tonic-gate int		_search_fheading();
53*7c478bd9Sstevel@tonic-gate #endif
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate int
rdform(char * name,FORM * formp,int fd,int (* error_handler)(int,int,int),int * which_set)56*7c478bd9Sstevel@tonic-gate rdform(char *name, FORM *formp, int fd, int (*error_handler)( int , int , int ),
57*7c478bd9Sstevel@tonic-gate 	int *which_set)
58*7c478bd9Sstevel@tonic-gate {
59*7c478bd9Sstevel@tonic-gate 	char			buf[BUFSIZ];
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	char *			rest;
62*7c478bd9Sstevel@tonic-gate 	char *			mandp;
63*7c478bd9Sstevel@tonic-gate 	char *			dftp;
64*7c478bd9Sstevel@tonic-gate 	char *			here;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 	int			fld;
67*7c478bd9Sstevel@tonic-gate 	int			have_line_already;
68*7c478bd9Sstevel@tonic-gate 	int			found_alignment_pattern;
69*7c478bd9Sstevel@tonic-gate 	int			size;
70*7c478bd9Sstevel@tonic-gate 	int			add_size;
71*7c478bd9Sstevel@tonic-gate 	int			linenum;
72*7c478bd9Sstevel@tonic-gate 	int			i;
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	SCALED			sdn;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	register char *		p;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 	/*
80*7c478bd9Sstevel@tonic-gate 	 * Initialize the entire structure, to ensure no random
81*7c478bd9Sstevel@tonic-gate 	 * values get in it. However, make sure some values won't
82*7c478bd9Sstevel@tonic-gate 	 * be null or empty. Do the latter here as opposed to
83*7c478bd9Sstevel@tonic-gate 	 * after reading the file, because sometimes the file
84*7c478bd9Sstevel@tonic-gate 	 * contains an empty header to FORCE a null/empty value.
85*7c478bd9Sstevel@tonic-gate 	 */
86*7c478bd9Sstevel@tonic-gate 	(void)memset ((char *)formp, 0, sizeof(*formp));
87*7c478bd9Sstevel@tonic-gate 	formp->name = Strdup(name);
88*7c478bd9Sstevel@tonic-gate 	formp->plen.val = DPLEN;
89*7c478bd9Sstevel@tonic-gate 	formp->plen.sc = 0;
90*7c478bd9Sstevel@tonic-gate 	formp->pwid.val = DPWIDTH;
91*7c478bd9Sstevel@tonic-gate 	formp->pwid.sc = 0;
92*7c478bd9Sstevel@tonic-gate 	formp->lpi.val = DLPITCH;
93*7c478bd9Sstevel@tonic-gate 	formp->lpi.sc = 0;
94*7c478bd9Sstevel@tonic-gate 	formp->cpi.val = DCPITCH;
95*7c478bd9Sstevel@tonic-gate 	formp->cpi.sc = 0;
96*7c478bd9Sstevel@tonic-gate 	formp->np = DNP;
97*7c478bd9Sstevel@tonic-gate 	formp->chset = Strdup(DCHSET);
98*7c478bd9Sstevel@tonic-gate 	formp->mandatory = 0;
99*7c478bd9Sstevel@tonic-gate 	formp->rcolor = Strdup(DRCOLOR);
100*7c478bd9Sstevel@tonic-gate 	formp->conttype = Strdup(DCONTYP);
101*7c478bd9Sstevel@tonic-gate 	formp->paper = NULL;
102*7c478bd9Sstevel@tonic-gate 	formp->isDefault = 0;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	/*
105*7c478bd9Sstevel@tonic-gate 	 * Read the file.
106*7c478bd9Sstevel@tonic-gate 	 */
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #define FGETS(B,S,F)	(linenum++, fdgets(B,S,F))
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	have_line_already = 0;
111*7c478bd9Sstevel@tonic-gate 	found_alignment_pattern = 0;
112*7c478bd9Sstevel@tonic-gate 	linenum = 0;
113*7c478bd9Sstevel@tonic-gate 	errno = 0;
114*7c478bd9Sstevel@tonic-gate 	while (!found_alignment_pattern
115*7c478bd9Sstevel@tonic-gate 	     && (have_line_already || FGETS(buf, BUFSIZ, fd))
116*7c478bd9Sstevel@tonic-gate 	) {
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 		int			pos	= strlen(buf) - 1;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 		have_line_already = 0;
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 		while (isspace(buf[pos]))
124*7c478bd9Sstevel@tonic-gate 			buf[pos--] = 0;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 		fld = _search_fheading(buf);
127*7c478bd9Sstevel@tonic-gate 		if (fld >= FO_MAX) {
128*7c478bd9Sstevel@tonic-gate 			lp_errno = LP_EBADHDR;
129*7c478bd9Sstevel@tonic-gate BadFile:		errno = EBADF;
130*7c478bd9Sstevel@tonic-gate 			if (error_handler) {
131*7c478bd9Sstevel@tonic-gate 				if ((*error_handler)(errno, lp_errno, linenum) == -1)
132*7c478bd9Sstevel@tonic-gate 					return (-1);
133*7c478bd9Sstevel@tonic-gate 				continue;
134*7c478bd9Sstevel@tonic-gate 			} else {
135*7c478bd9Sstevel@tonic-gate 				/*
136*7c478bd9Sstevel@tonic-gate 				 * To allow future extensions to not
137*7c478bd9Sstevel@tonic-gate 				 * impact applications using old versions
138*7c478bd9Sstevel@tonic-gate 				 * of this routine, ignore strange fields.
139*7c478bd9Sstevel@tonic-gate 				 */
140*7c478bd9Sstevel@tonic-gate 				continue;
141*7c478bd9Sstevel@tonic-gate 			}
142*7c478bd9Sstevel@tonic-gate 		}
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 		p = buf + formheadings[fld].len;
145*7c478bd9Sstevel@tonic-gate 		while (isspace(*p))
146*7c478bd9Sstevel@tonic-gate 			p++;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 		if (which_set)
149*7c478bd9Sstevel@tonic-gate 			which_set[fld] = 1;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 		if (
152*7c478bd9Sstevel@tonic-gate 			formheadings[fld].infile
153*7c478bd9Sstevel@tonic-gate 		     || error_handler
154*7c478bd9Sstevel@tonic-gate 		) switch (fld) {
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 		case FO_PLEN:
157*7c478bd9Sstevel@tonic-gate 			sdn = getsdn(p);
158*7c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
159*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
160*7c478bd9Sstevel@tonic-gate 				goto BadFile;
161*7c478bd9Sstevel@tonic-gate 			}
162*7c478bd9Sstevel@tonic-gate 			formp->plen = sdn;
163*7c478bd9Sstevel@tonic-gate 			break;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 		case FO_PWID:
166*7c478bd9Sstevel@tonic-gate 			sdn = getsdn(p);
167*7c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
168*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
169*7c478bd9Sstevel@tonic-gate 				goto BadFile;
170*7c478bd9Sstevel@tonic-gate 			}
171*7c478bd9Sstevel@tonic-gate 			formp->pwid = sdn;
172*7c478bd9Sstevel@tonic-gate 			break;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 		case FO_CPI:
175*7c478bd9Sstevel@tonic-gate 			sdn = getcpi(p);
176*7c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
177*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
178*7c478bd9Sstevel@tonic-gate 				goto BadFile;
179*7c478bd9Sstevel@tonic-gate 			}
180*7c478bd9Sstevel@tonic-gate 			formp->cpi = sdn;
181*7c478bd9Sstevel@tonic-gate 			break;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 		case FO_LPI:
184*7c478bd9Sstevel@tonic-gate 			sdn = getsdn(p);
185*7c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
186*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
187*7c478bd9Sstevel@tonic-gate 				goto BadFile;
188*7c478bd9Sstevel@tonic-gate 			}
189*7c478bd9Sstevel@tonic-gate 			formp->lpi = sdn;
190*7c478bd9Sstevel@tonic-gate 			break;
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 		case FO_NP:
193*7c478bd9Sstevel@tonic-gate 			if (
194*7c478bd9Sstevel@tonic-gate 				(i = strtol(p, &rest, 10)) <= 0
195*7c478bd9Sstevel@tonic-gate 			     || *rest
196*7c478bd9Sstevel@tonic-gate 			) {
197*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADINT;
198*7c478bd9Sstevel@tonic-gate 				goto BadFile;
199*7c478bd9Sstevel@tonic-gate 			}
200*7c478bd9Sstevel@tonic-gate 			formp->np = i;
201*7c478bd9Sstevel@tonic-gate 			break;
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 		case FO_CHSET:
204*7c478bd9Sstevel@tonic-gate 			if (!(mandp = strchr(p, ',')))
205*7c478bd9Sstevel@tonic-gate 				formp->mandatory = 0;
206*7c478bd9Sstevel@tonic-gate 			else {
207*7c478bd9Sstevel@tonic-gate 				do
208*7c478bd9Sstevel@tonic-gate 					*mandp++ = 0;
209*7c478bd9Sstevel@tonic-gate 				while (*mandp && isspace(*mandp));
210*7c478bd9Sstevel@tonic-gate 				if (CS_STREQU(MANSTR, mandp))
211*7c478bd9Sstevel@tonic-gate 					formp->mandatory = 1;
212*7c478bd9Sstevel@tonic-gate 				else {
213*7c478bd9Sstevel@tonic-gate 					lp_errno = LP_EBADARG;
214*7c478bd9Sstevel@tonic-gate 					goto BadFile;
215*7c478bd9Sstevel@tonic-gate 				}
216*7c478bd9Sstevel@tonic-gate 			}
217*7c478bd9Sstevel@tonic-gate 			if (!syn_name(p)) {
218*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADNAME;
219*7c478bd9Sstevel@tonic-gate 				goto BadFile;
220*7c478bd9Sstevel@tonic-gate 			}
221*7c478bd9Sstevel@tonic-gate 			if (formp->chset)
222*7c478bd9Sstevel@tonic-gate 				Free (formp->chset);
223*7c478bd9Sstevel@tonic-gate 			formp->chset = Strdup(p);
224*7c478bd9Sstevel@tonic-gate 			break;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 		case FO_RCOLOR:
227*7c478bd9Sstevel@tonic-gate 			if (formp->rcolor)
228*7c478bd9Sstevel@tonic-gate 				Free (formp->rcolor);
229*7c478bd9Sstevel@tonic-gate 			formp->rcolor = Strdup(p);
230*7c478bd9Sstevel@tonic-gate 			break;
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 		case FO_CMT:
233*7c478bd9Sstevel@tonic-gate 			if (*p) {
234*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_ETRAILIN;
235*7c478bd9Sstevel@tonic-gate 				goto BadFile;
236*7c478bd9Sstevel@tonic-gate 			}
237*7c478bd9Sstevel@tonic-gate 			if (formp->comment)
238*7c478bd9Sstevel@tonic-gate 				Free (formp->comment);
239*7c478bd9Sstevel@tonic-gate 			formp->comment = 0;
240*7c478bd9Sstevel@tonic-gate 			size = 0;
241*7c478bd9Sstevel@tonic-gate 			while (FGETS(buf, BUFSIZ, fd)) {
242*7c478bd9Sstevel@tonic-gate 				p = buf;
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 				/*
245*7c478bd9Sstevel@tonic-gate 				 * A recognized header ends the comment.
246*7c478bd9Sstevel@tonic-gate 				 */
247*7c478bd9Sstevel@tonic-gate 				if (_search_fheading(p) < FO_MAX) {
248*7c478bd9Sstevel@tonic-gate 					have_line_already = 1;
249*7c478bd9Sstevel@tonic-gate 					break;
250*7c478bd9Sstevel@tonic-gate 				}
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 				/*
253*7c478bd9Sstevel@tonic-gate 				 * On the other hand, a '>' may hide what
254*7c478bd9Sstevel@tonic-gate 				 * would otherwise look like a header.
255*7c478bd9Sstevel@tonic-gate 				 */
256*7c478bd9Sstevel@tonic-gate 				if (
257*7c478bd9Sstevel@tonic-gate 					p[0] == '>'
258*7c478bd9Sstevel@tonic-gate 				     && _search_fheading(p+1) < FO_MAX
259*7c478bd9Sstevel@tonic-gate 				)
260*7c478bd9Sstevel@tonic-gate 					p++;
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate 				/*
263*7c478bd9Sstevel@tonic-gate 				 * (Re)allocate space to hold this
264*7c478bd9Sstevel@tonic-gate 				 * (additional) line of the comment.
265*7c478bd9Sstevel@tonic-gate 				 */
266*7c478bd9Sstevel@tonic-gate 				add_size = strlen(p);
267*7c478bd9Sstevel@tonic-gate 				if (formp->comment)
268*7c478bd9Sstevel@tonic-gate 					formp->comment = Realloc(
269*7c478bd9Sstevel@tonic-gate 						formp->comment,
270*7c478bd9Sstevel@tonic-gate 						size + add_size + 1
271*7c478bd9Sstevel@tonic-gate 					);
272*7c478bd9Sstevel@tonic-gate 				else
273*7c478bd9Sstevel@tonic-gate 					formp->comment = Malloc(
274*7c478bd9Sstevel@tonic-gate 						size + add_size + 1
275*7c478bd9Sstevel@tonic-gate 					);
276*7c478bd9Sstevel@tonic-gate 				if (!formp->comment) {
277*7c478bd9Sstevel@tonic-gate 					freeform (formp);
278*7c478bd9Sstevel@tonic-gate 					close(fd);
279*7c478bd9Sstevel@tonic-gate 					errno = ENOMEM;
280*7c478bd9Sstevel@tonic-gate 					return (-1);
281*7c478bd9Sstevel@tonic-gate 				}
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 				/*
284*7c478bd9Sstevel@tonic-gate 				 * Copy this (additional) line of the
285*7c478bd9Sstevel@tonic-gate 				 * comment to the allocated space. "here"
286*7c478bd9Sstevel@tonic-gate 				 * points to where to copy the line.
287*7c478bd9Sstevel@tonic-gate 				 */
288*7c478bd9Sstevel@tonic-gate 				strcpy (formp->comment + size, p);
289*7c478bd9Sstevel@tonic-gate 				size += add_size;
290*7c478bd9Sstevel@tonic-gate 			}
291*7c478bd9Sstevel@tonic-gate 			if (errno != 0)
292*7c478bd9Sstevel@tonic-gate 				goto BadFile;
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate 			/*
295*7c478bd9Sstevel@tonic-gate 			 * The comment is held internally without a
296*7c478bd9Sstevel@tonic-gate 			 * trailing newline.
297*7c478bd9Sstevel@tonic-gate 			 */
298*7c478bd9Sstevel@tonic-gate 			if (size && formp->comment[size - 1] == '\n')
299*7c478bd9Sstevel@tonic-gate 				formp->comment[size - 1] = 0;
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 			break;
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 		case FO_ALIGN:
304*7c478bd9Sstevel@tonic-gate 			if (*p) {
305*7c478bd9Sstevel@tonic-gate 				if (!syn_type(p)) {
306*7c478bd9Sstevel@tonic-gate 					lp_errno = LP_EBADCTYPE;
307*7c478bd9Sstevel@tonic-gate 					goto BadFile;
308*7c478bd9Sstevel@tonic-gate 				}
309*7c478bd9Sstevel@tonic-gate 				if (formp->conttype)
310*7c478bd9Sstevel@tonic-gate 					Free (formp->conttype);
311*7c478bd9Sstevel@tonic-gate 				formp->conttype = Strdup(p);
312*7c478bd9Sstevel@tonic-gate 			}
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 			/*
315*7c478bd9Sstevel@tonic-gate 			 * Actual alignment pattern has to be read in
316*7c478bd9Sstevel@tonic-gate 			 * by caller; we leave the file pointer ready.
317*7c478bd9Sstevel@tonic-gate 			 */
318*7c478bd9Sstevel@tonic-gate 			found_alignment_pattern = 1;
319*7c478bd9Sstevel@tonic-gate 			break;
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 		case FO_PAPER:
322*7c478bd9Sstevel@tonic-gate 			if (!(dftp = strchr(p, ',')))
323*7c478bd9Sstevel@tonic-gate 				formp->isDefault = 0;
324*7c478bd9Sstevel@tonic-gate 			else {
325*7c478bd9Sstevel@tonic-gate 				do
326*7c478bd9Sstevel@tonic-gate 					*dftp++ = 0;
327*7c478bd9Sstevel@tonic-gate 				while (*dftp && isspace(*dftp));
328*7c478bd9Sstevel@tonic-gate 				if (CS_STREQU(DFTSTR, dftp))
329*7c478bd9Sstevel@tonic-gate 					formp->isDefault = 1;
330*7c478bd9Sstevel@tonic-gate 				else {
331*7c478bd9Sstevel@tonic-gate 					lp_errno = LP_EBADARG;
332*7c478bd9Sstevel@tonic-gate 					goto BadFile;
333*7c478bd9Sstevel@tonic-gate 				}
334*7c478bd9Sstevel@tonic-gate 			}
335*7c478bd9Sstevel@tonic-gate 			if (!syn_name(p)) {
336*7c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADNAME;
337*7c478bd9Sstevel@tonic-gate 				goto BadFile;
338*7c478bd9Sstevel@tonic-gate 			}
339*7c478bd9Sstevel@tonic-gate 			if (formp->paper)
340*7c478bd9Sstevel@tonic-gate 				Free (formp->paper);
341*7c478bd9Sstevel@tonic-gate 			formp->paper = Strdup(p);
342*7c478bd9Sstevel@tonic-gate 			break;
343*7c478bd9Sstevel@tonic-gate 		}
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	}
346*7c478bd9Sstevel@tonic-gate 	if (errno != 0) {
347*7c478bd9Sstevel@tonic-gate 		int			save_errno = errno;
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 		freeform (formp);
350*7c478bd9Sstevel@tonic-gate 		errno = save_errno;
351*7c478bd9Sstevel@tonic-gate 		return (-1);
352*7c478bd9Sstevel@tonic-gate 	}
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 	/*
355*7c478bd9Sstevel@tonic-gate 	 * Get the form description (if it exists) (?)
356*7c478bd9Sstevel@tonic-gate 	 */
357*7c478bd9Sstevel@tonic-gate 	if (!error_handler) {
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate 		char *			path;
360*7c478bd9Sstevel@tonic-gate 
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 		if (!(path = getformfile(name, COMMENTFILE))) {
363*7c478bd9Sstevel@tonic-gate 			freeform (formp);
364*7c478bd9Sstevel@tonic-gate 			errno = ENOMEM;
365*7c478bd9Sstevel@tonic-gate 			return (-1);
366*7c478bd9Sstevel@tonic-gate 		}
367*7c478bd9Sstevel@tonic-gate 		if (
368*7c478bd9Sstevel@tonic-gate 			!(formp->comment = loadstring(path))
369*7c478bd9Sstevel@tonic-gate 		     && errno != ENOENT
370*7c478bd9Sstevel@tonic-gate 		) {
371*7c478bd9Sstevel@tonic-gate 			Free (path);
372*7c478bd9Sstevel@tonic-gate 			freeform (formp);
373*7c478bd9Sstevel@tonic-gate 			return (-1);
374*7c478bd9Sstevel@tonic-gate 		}
375*7c478bd9Sstevel@tonic-gate 		Free (path);
376*7c478bd9Sstevel@tonic-gate 	}
377*7c478bd9Sstevel@tonic-gate 
378*7c478bd9Sstevel@tonic-gate 	return (0);
379*7c478bd9Sstevel@tonic-gate }
380