4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.17 */
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
37 #include "sys/types.h"
50 int _search_fheading ( char * );
52 int _search_fheading();
56 rdform(char *name
, FORM
*formp
, int fd
, int (*error_handler
)( int , int , int ),
67 int have_line_already
;
68 int found_alignment_pattern
;
80 * Initialize the entire structure, to ensure no random
81 * values get in it. However, make sure some values won't
82 * be null or empty. Do the latter here as opposed to
83 * after reading the file, because sometimes the file
84 * contains an empty header to FORCE a null/empty value.
86 (void)memset ((char *)formp
, 0, sizeof(*formp
));
87 formp
->name
= Strdup(name
);
88 formp
->plen
.val
= DPLEN
;
90 formp
->pwid
.val
= DPWIDTH
;
92 formp
->lpi
.val
= DLPITCH
;
94 formp
->cpi
.val
= DCPITCH
;
97 formp
->chset
= Strdup(DCHSET
);
99 formp
->rcolor
= Strdup(DRCOLOR
);
100 formp
->conttype
= Strdup(DCONTYP
);
102 formp
->isDefault
= 0;
108 #define FGETS(B,S,F) (linenum++, fdgets(B,S,F))
110 have_line_already
= 0;
111 found_alignment_pattern
= 0;
114 while (!found_alignment_pattern
115 && (have_line_already
|| FGETS(buf
, BUFSIZ
, fd
))
118 int pos
= strlen(buf
) - 1;
121 have_line_already
= 0;
123 while (isspace(buf
[pos
]))
126 fld
= _search_fheading(buf
);
128 lp_errno
= LP_EBADHDR
;
129 BadFile
: errno
= EBADF
;
131 if ((*error_handler
)(errno
, lp_errno
, linenum
) == -1)
136 * To allow future extensions to not
137 * impact applications using old versions
138 * of this routine, ignore strange fields.
144 p
= buf
+ formheadings
[fld
].len
;
152 formheadings
[fld
].infile
158 if (errno
== EINVAL
) {
159 lp_errno
= LP_EBADSDN
;
167 if (errno
== EINVAL
) {
168 lp_errno
= LP_EBADSDN
;
176 if (errno
== EINVAL
) {
177 lp_errno
= LP_EBADSDN
;
185 if (errno
== EINVAL
) {
186 lp_errno
= LP_EBADSDN
;
194 (i
= strtol(p
, &rest
, 10)) <= 0
197 lp_errno
= LP_EBADINT
;
204 if (!(mandp
= strchr(p
, ',')))
205 formp
->mandatory
= 0;
209 while (*mandp
&& isspace(*mandp
));
210 if (CS_STREQU(MANSTR
, mandp
))
211 formp
->mandatory
= 1;
213 lp_errno
= LP_EBADARG
;
218 lp_errno
= LP_EBADNAME
;
223 formp
->chset
= Strdup(p
);
228 Free (formp
->rcolor
);
229 formp
->rcolor
= Strdup(p
);
234 lp_errno
= LP_ETRAILIN
;
238 Free (formp
->comment
);
241 while (FGETS(buf
, BUFSIZ
, fd
)) {
245 * A recognized header ends the comment.
247 if (_search_fheading(p
) < FO_MAX
) {
248 have_line_already
= 1;
253 * On the other hand, a '>' may hide what
254 * would otherwise look like a header.
258 && _search_fheading(p
+1) < FO_MAX
263 * (Re)allocate space to hold this
264 * (additional) line of the comment.
266 add_size
= strlen(p
);
268 formp
->comment
= Realloc(
273 formp
->comment
= Malloc(
276 if (!formp
->comment
) {
284 * Copy this (additional) line of the
285 * comment to the allocated space. "here"
286 * points to where to copy the line.
288 strcpy (formp
->comment
+ size
, p
);
295 * The comment is held internally without a
298 if (size
&& formp
->comment
[size
- 1] == '\n')
299 formp
->comment
[size
- 1] = 0;
306 lp_errno
= LP_EBADCTYPE
;
310 Free (formp
->conttype
);
311 formp
->conttype
= Strdup(p
);
315 * Actual alignment pattern has to be read in
316 * by caller; we leave the file pointer ready.
318 found_alignment_pattern
= 1;
322 if (!(dftp
= strchr(p
, ',')))
323 formp
->isDefault
= 0;
327 while (*dftp
&& isspace(*dftp
));
328 if (CS_STREQU(DFTSTR
, dftp
))
329 formp
->isDefault
= 1;
331 lp_errno
= LP_EBADARG
;
336 lp_errno
= LP_EBADNAME
;
341 formp
->paper
= Strdup(p
);
347 int save_errno
= errno
;
355 * Get the form description (if it exists) (?)
357 if (!error_handler
) {
362 if (!(path
= getformfile(name
, COMMENTFILE
))) {
368 !(formp
->comment
= loadstring(path
))