xref: /illumos-gate/usr/src/cmd/lp/lib/forms/rdform.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include "stdio.h"
337c478bd9Sstevel@tonic-gate #include "string.h"
347c478bd9Sstevel@tonic-gate #include "errno.h"
357c478bd9Sstevel@tonic-gate #include "sys/types.h"
367c478bd9Sstevel@tonic-gate #include "stdlib.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include "lp.h"
397c478bd9Sstevel@tonic-gate #include "form.h"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate extern struct {
427c478bd9Sstevel@tonic-gate 	char			*v;
437c478bd9Sstevel@tonic-gate 	short			len;
447c478bd9Sstevel@tonic-gate 	short			infile;
457c478bd9Sstevel@tonic-gate }			formheadings[];
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
487c478bd9Sstevel@tonic-gate int		_search_fheading ( char * );
497c478bd9Sstevel@tonic-gate #else
507c478bd9Sstevel@tonic-gate int		_search_fheading();
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate int
rdform(char * name,FORM * formp,int fd,int (* error_handler)(int,int,int),int * which_set)547c478bd9Sstevel@tonic-gate rdform(char *name, FORM *formp, int fd, int (*error_handler)( int , int , int ),
557c478bd9Sstevel@tonic-gate 	int *which_set)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate 	char			buf[BUFSIZ];
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	char *			rest;
607c478bd9Sstevel@tonic-gate 	char *			mandp;
617c478bd9Sstevel@tonic-gate 	char *			dftp;
627c478bd9Sstevel@tonic-gate 	char *			here;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	int			fld;
657c478bd9Sstevel@tonic-gate 	int			have_line_already;
667c478bd9Sstevel@tonic-gate 	int			found_alignment_pattern;
677c478bd9Sstevel@tonic-gate 	int			size;
687c478bd9Sstevel@tonic-gate 	int			add_size;
697c478bd9Sstevel@tonic-gate 	int			linenum;
707c478bd9Sstevel@tonic-gate 	int			i;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	SCALED			sdn;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	register char *		p;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	/*
787c478bd9Sstevel@tonic-gate 	 * Initialize the entire structure, to ensure no random
797c478bd9Sstevel@tonic-gate 	 * values get in it. However, make sure some values won't
807c478bd9Sstevel@tonic-gate 	 * be null or empty. Do the latter here as opposed to
817c478bd9Sstevel@tonic-gate 	 * after reading the file, because sometimes the file
827c478bd9Sstevel@tonic-gate 	 * contains an empty header to FORCE a null/empty value.
837c478bd9Sstevel@tonic-gate 	 */
847c478bd9Sstevel@tonic-gate 	(void)memset ((char *)formp, 0, sizeof(*formp));
857c478bd9Sstevel@tonic-gate 	formp->name = Strdup(name);
867c478bd9Sstevel@tonic-gate 	formp->plen.val = DPLEN;
877c478bd9Sstevel@tonic-gate 	formp->plen.sc = 0;
887c478bd9Sstevel@tonic-gate 	formp->pwid.val = DPWIDTH;
897c478bd9Sstevel@tonic-gate 	formp->pwid.sc = 0;
907c478bd9Sstevel@tonic-gate 	formp->lpi.val = DLPITCH;
917c478bd9Sstevel@tonic-gate 	formp->lpi.sc = 0;
927c478bd9Sstevel@tonic-gate 	formp->cpi.val = DCPITCH;
937c478bd9Sstevel@tonic-gate 	formp->cpi.sc = 0;
947c478bd9Sstevel@tonic-gate 	formp->np = DNP;
957c478bd9Sstevel@tonic-gate 	formp->chset = Strdup(DCHSET);
967c478bd9Sstevel@tonic-gate 	formp->mandatory = 0;
977c478bd9Sstevel@tonic-gate 	formp->rcolor = Strdup(DRCOLOR);
987c478bd9Sstevel@tonic-gate 	formp->conttype = Strdup(DCONTYP);
997c478bd9Sstevel@tonic-gate 	formp->paper = NULL;
1007c478bd9Sstevel@tonic-gate 	formp->isDefault = 0;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	/*
1037c478bd9Sstevel@tonic-gate 	 * Read the file.
1047c478bd9Sstevel@tonic-gate 	 */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define FGETS(B,S,F)	(linenum++, fdgets(B,S,F))
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	have_line_already = 0;
1097c478bd9Sstevel@tonic-gate 	found_alignment_pattern = 0;
1107c478bd9Sstevel@tonic-gate 	linenum = 0;
1117c478bd9Sstevel@tonic-gate 	errno = 0;
1127c478bd9Sstevel@tonic-gate 	while (!found_alignment_pattern
1137c478bd9Sstevel@tonic-gate 	     && (have_line_already || FGETS(buf, BUFSIZ, fd))
1147c478bd9Sstevel@tonic-gate 	) {
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 		int			pos	= strlen(buf) - 1;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 		have_line_already = 0;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 		while (isspace(buf[pos]))
1227c478bd9Sstevel@tonic-gate 			buf[pos--] = 0;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 		fld = _search_fheading(buf);
1257c478bd9Sstevel@tonic-gate 		if (fld >= FO_MAX) {
126*2a8bcb4eSToomas Soome 			lp_errno = LP_EBADHDR;
1277c478bd9Sstevel@tonic-gate BadFile:		errno = EBADF;
1287c478bd9Sstevel@tonic-gate 			if (error_handler) {
1297c478bd9Sstevel@tonic-gate 				if ((*error_handler)(errno, lp_errno, linenum) == -1)
1307c478bd9Sstevel@tonic-gate 					return (-1);
1317c478bd9Sstevel@tonic-gate 				continue;
1327c478bd9Sstevel@tonic-gate 			} else {
1337c478bd9Sstevel@tonic-gate 				/*
1347c478bd9Sstevel@tonic-gate 				 * To allow future extensions to not
1357c478bd9Sstevel@tonic-gate 				 * impact applications using old versions
1367c478bd9Sstevel@tonic-gate 				 * of this routine, ignore strange fields.
1377c478bd9Sstevel@tonic-gate 				 */
1387c478bd9Sstevel@tonic-gate 				continue;
1397c478bd9Sstevel@tonic-gate 			}
1407c478bd9Sstevel@tonic-gate 		}
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 		p = buf + formheadings[fld].len;
1437c478bd9Sstevel@tonic-gate 		while (isspace(*p))
1447c478bd9Sstevel@tonic-gate 			p++;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 		if (which_set)
1477c478bd9Sstevel@tonic-gate 			which_set[fld] = 1;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 		if (
1507c478bd9Sstevel@tonic-gate 			formheadings[fld].infile
1517c478bd9Sstevel@tonic-gate 		     || error_handler
1527c478bd9Sstevel@tonic-gate 		) switch (fld) {
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 		case FO_PLEN:
1557c478bd9Sstevel@tonic-gate 			sdn = getsdn(p);
1567c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
1577c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
1587c478bd9Sstevel@tonic-gate 				goto BadFile;
1597c478bd9Sstevel@tonic-gate 			}
1607c478bd9Sstevel@tonic-gate 			formp->plen = sdn;
1617c478bd9Sstevel@tonic-gate 			break;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 		case FO_PWID:
1647c478bd9Sstevel@tonic-gate 			sdn = getsdn(p);
1657c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
1667c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
1677c478bd9Sstevel@tonic-gate 				goto BadFile;
1687c478bd9Sstevel@tonic-gate 			}
1697c478bd9Sstevel@tonic-gate 			formp->pwid = sdn;
1707c478bd9Sstevel@tonic-gate 			break;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 		case FO_CPI:
1737c478bd9Sstevel@tonic-gate 			sdn = getcpi(p);
1747c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
1757c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
1767c478bd9Sstevel@tonic-gate 				goto BadFile;
1777c478bd9Sstevel@tonic-gate 			}
1787c478bd9Sstevel@tonic-gate 			formp->cpi = sdn;
1797c478bd9Sstevel@tonic-gate 			break;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 		case FO_LPI:
1827c478bd9Sstevel@tonic-gate 			sdn = getsdn(p);
1837c478bd9Sstevel@tonic-gate 			if (errno == EINVAL) {
1847c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADSDN;
1857c478bd9Sstevel@tonic-gate 				goto BadFile;
1867c478bd9Sstevel@tonic-gate 			}
1877c478bd9Sstevel@tonic-gate 			formp->lpi = sdn;
1887c478bd9Sstevel@tonic-gate 			break;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 		case FO_NP:
1917c478bd9Sstevel@tonic-gate 			if (
1927c478bd9Sstevel@tonic-gate 				(i = strtol(p, &rest, 10)) <= 0
1937c478bd9Sstevel@tonic-gate 			     || *rest
1947c478bd9Sstevel@tonic-gate 			) {
1957c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADINT;
1967c478bd9Sstevel@tonic-gate 				goto BadFile;
1977c478bd9Sstevel@tonic-gate 			}
1987c478bd9Sstevel@tonic-gate 			formp->np = i;
1997c478bd9Sstevel@tonic-gate 			break;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 		case FO_CHSET:
2027c478bd9Sstevel@tonic-gate 			if (!(mandp = strchr(p, ',')))
2037c478bd9Sstevel@tonic-gate 				formp->mandatory = 0;
2047c478bd9Sstevel@tonic-gate 			else {
2057c478bd9Sstevel@tonic-gate 				do
2067c478bd9Sstevel@tonic-gate 					*mandp++ = 0;
2077c478bd9Sstevel@tonic-gate 				while (*mandp && isspace(*mandp));
2087c478bd9Sstevel@tonic-gate 				if (CS_STREQU(MANSTR, mandp))
2097c478bd9Sstevel@tonic-gate 					formp->mandatory = 1;
2107c478bd9Sstevel@tonic-gate 				else {
2117c478bd9Sstevel@tonic-gate 					lp_errno = LP_EBADARG;
2127c478bd9Sstevel@tonic-gate 					goto BadFile;
2137c478bd9Sstevel@tonic-gate 				}
2147c478bd9Sstevel@tonic-gate 			}
2157c478bd9Sstevel@tonic-gate 			if (!syn_name(p)) {
2167c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADNAME;
2177c478bd9Sstevel@tonic-gate 				goto BadFile;
2187c478bd9Sstevel@tonic-gate 			}
2197c478bd9Sstevel@tonic-gate 			if (formp->chset)
2207c478bd9Sstevel@tonic-gate 				Free (formp->chset);
2217c478bd9Sstevel@tonic-gate 			formp->chset = Strdup(p);
2227c478bd9Sstevel@tonic-gate 			break;
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 		case FO_RCOLOR:
2257c478bd9Sstevel@tonic-gate 			if (formp->rcolor)
2267c478bd9Sstevel@tonic-gate 				Free (formp->rcolor);
2277c478bd9Sstevel@tonic-gate 			formp->rcolor = Strdup(p);
2287c478bd9Sstevel@tonic-gate 			break;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 		case FO_CMT:
2317c478bd9Sstevel@tonic-gate 			if (*p) {
2327c478bd9Sstevel@tonic-gate 				lp_errno = LP_ETRAILIN;
2337c478bd9Sstevel@tonic-gate 				goto BadFile;
2347c478bd9Sstevel@tonic-gate 			}
2357c478bd9Sstevel@tonic-gate 			if (formp->comment)
2367c478bd9Sstevel@tonic-gate 				Free (formp->comment);
2377c478bd9Sstevel@tonic-gate 			formp->comment = 0;
2387c478bd9Sstevel@tonic-gate 			size = 0;
2397c478bd9Sstevel@tonic-gate 			while (FGETS(buf, BUFSIZ, fd)) {
2407c478bd9Sstevel@tonic-gate 				p = buf;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 				/*
2437c478bd9Sstevel@tonic-gate 				 * A recognized header ends the comment.
2447c478bd9Sstevel@tonic-gate 				 */
2457c478bd9Sstevel@tonic-gate 				if (_search_fheading(p) < FO_MAX) {
2467c478bd9Sstevel@tonic-gate 					have_line_already = 1;
2477c478bd9Sstevel@tonic-gate 					break;
2487c478bd9Sstevel@tonic-gate 				}
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 				/*
2517c478bd9Sstevel@tonic-gate 				 * On the other hand, a '>' may hide what
2527c478bd9Sstevel@tonic-gate 				 * would otherwise look like a header.
2537c478bd9Sstevel@tonic-gate 				 */
2547c478bd9Sstevel@tonic-gate 				if (
2557c478bd9Sstevel@tonic-gate 					p[0] == '>'
2567c478bd9Sstevel@tonic-gate 				     && _search_fheading(p+1) < FO_MAX
2577c478bd9Sstevel@tonic-gate 				)
2587c478bd9Sstevel@tonic-gate 					p++;
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 				/*
2617c478bd9Sstevel@tonic-gate 				 * (Re)allocate space to hold this
2627c478bd9Sstevel@tonic-gate 				 * (additional) line of the comment.
2637c478bd9Sstevel@tonic-gate 				 */
2647c478bd9Sstevel@tonic-gate 				add_size = strlen(p);
2657c478bd9Sstevel@tonic-gate 				if (formp->comment)
2667c478bd9Sstevel@tonic-gate 					formp->comment = Realloc(
2677c478bd9Sstevel@tonic-gate 						formp->comment,
2687c478bd9Sstevel@tonic-gate 						size + add_size + 1
2697c478bd9Sstevel@tonic-gate 					);
2707c478bd9Sstevel@tonic-gate 				else
2717c478bd9Sstevel@tonic-gate 					formp->comment = Malloc(
2727c478bd9Sstevel@tonic-gate 						size + add_size + 1
2737c478bd9Sstevel@tonic-gate 					);
2747c478bd9Sstevel@tonic-gate 				if (!formp->comment) {
2757c478bd9Sstevel@tonic-gate 					freeform (formp);
2767c478bd9Sstevel@tonic-gate 					close(fd);
2777c478bd9Sstevel@tonic-gate 					errno = ENOMEM;
2787c478bd9Sstevel@tonic-gate 					return (-1);
2797c478bd9Sstevel@tonic-gate 				}
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 				/*
2827c478bd9Sstevel@tonic-gate 				 * Copy this (additional) line of the
2837c478bd9Sstevel@tonic-gate 				 * comment to the allocated space. "here"
2847c478bd9Sstevel@tonic-gate 				 * points to where to copy the line.
2857c478bd9Sstevel@tonic-gate 				 */
2867c478bd9Sstevel@tonic-gate 				strcpy (formp->comment + size, p);
2877c478bd9Sstevel@tonic-gate 				size += add_size;
2887c478bd9Sstevel@tonic-gate 			}
2897c478bd9Sstevel@tonic-gate 			if (errno != 0)
2907c478bd9Sstevel@tonic-gate 				goto BadFile;
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 			/*
2937c478bd9Sstevel@tonic-gate 			 * The comment is held internally without a
2947c478bd9Sstevel@tonic-gate 			 * trailing newline.
2957c478bd9Sstevel@tonic-gate 			 */
2967c478bd9Sstevel@tonic-gate 			if (size && formp->comment[size - 1] == '\n')
2977c478bd9Sstevel@tonic-gate 				formp->comment[size - 1] = 0;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 			break;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 		case FO_ALIGN:
3027c478bd9Sstevel@tonic-gate 			if (*p) {
3037c478bd9Sstevel@tonic-gate 				if (!syn_type(p)) {
3047c478bd9Sstevel@tonic-gate 					lp_errno = LP_EBADCTYPE;
3057c478bd9Sstevel@tonic-gate 					goto BadFile;
3067c478bd9Sstevel@tonic-gate 				}
3077c478bd9Sstevel@tonic-gate 				if (formp->conttype)
3087c478bd9Sstevel@tonic-gate 					Free (formp->conttype);
3097c478bd9Sstevel@tonic-gate 				formp->conttype = Strdup(p);
3107c478bd9Sstevel@tonic-gate 			}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 			/*
3137c478bd9Sstevel@tonic-gate 			 * Actual alignment pattern has to be read in
3147c478bd9Sstevel@tonic-gate 			 * by caller; we leave the file pointer ready.
3157c478bd9Sstevel@tonic-gate 			 */
3167c478bd9Sstevel@tonic-gate 			found_alignment_pattern = 1;
3177c478bd9Sstevel@tonic-gate 			break;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 		case FO_PAPER:
3207c478bd9Sstevel@tonic-gate 			if (!(dftp = strchr(p, ',')))
3217c478bd9Sstevel@tonic-gate 				formp->isDefault = 0;
3227c478bd9Sstevel@tonic-gate 			else {
3237c478bd9Sstevel@tonic-gate 				do
3247c478bd9Sstevel@tonic-gate 					*dftp++ = 0;
3257c478bd9Sstevel@tonic-gate 				while (*dftp && isspace(*dftp));
3267c478bd9Sstevel@tonic-gate 				if (CS_STREQU(DFTSTR, dftp))
3277c478bd9Sstevel@tonic-gate 					formp->isDefault = 1;
3287c478bd9Sstevel@tonic-gate 				else {
3297c478bd9Sstevel@tonic-gate 					lp_errno = LP_EBADARG;
3307c478bd9Sstevel@tonic-gate 					goto BadFile;
3317c478bd9Sstevel@tonic-gate 				}
3327c478bd9Sstevel@tonic-gate 			}
3337c478bd9Sstevel@tonic-gate 			if (!syn_name(p)) {
3347c478bd9Sstevel@tonic-gate 				lp_errno = LP_EBADNAME;
3357c478bd9Sstevel@tonic-gate 				goto BadFile;
3367c478bd9Sstevel@tonic-gate 			}
3377c478bd9Sstevel@tonic-gate 			if (formp->paper)
3387c478bd9Sstevel@tonic-gate 				Free (formp->paper);
3397c478bd9Sstevel@tonic-gate 			formp->paper = Strdup(p);
3407c478bd9Sstevel@tonic-gate 			break;
3417c478bd9Sstevel@tonic-gate 		}
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	}
3447c478bd9Sstevel@tonic-gate 	if (errno != 0) {
3457c478bd9Sstevel@tonic-gate 		int			save_errno = errno;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 		freeform (formp);
3487c478bd9Sstevel@tonic-gate 		errno = save_errno;
3497c478bd9Sstevel@tonic-gate 		return (-1);
3507c478bd9Sstevel@tonic-gate 	}
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/*
3537c478bd9Sstevel@tonic-gate 	 * Get the form description (if it exists) (?)
3547c478bd9Sstevel@tonic-gate 	 */
3557c478bd9Sstevel@tonic-gate 	if (!error_handler) {
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 		char *			path;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 		if (!(path = getformfile(name, COMMENTFILE))) {
3617c478bd9Sstevel@tonic-gate 			freeform (formp);
3627c478bd9Sstevel@tonic-gate 			errno = ENOMEM;
3637c478bd9Sstevel@tonic-gate 			return (-1);
3647c478bd9Sstevel@tonic-gate 		}
3657c478bd9Sstevel@tonic-gate 		if (
3667c478bd9Sstevel@tonic-gate 			!(formp->comment = loadstring(path))
3677c478bd9Sstevel@tonic-gate 		     && errno != ENOENT
3687c478bd9Sstevel@tonic-gate 		) {
3697c478bd9Sstevel@tonic-gate 			Free (path);
3707c478bd9Sstevel@tonic-gate 			freeform (formp);
3717c478bd9Sstevel@tonic-gate 			return (-1);
3727c478bd9Sstevel@tonic-gate 		}
3737c478bd9Sstevel@tonic-gate 		Free (path);
3747c478bd9Sstevel@tonic-gate 	}
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	return (0);
3777c478bd9Sstevel@tonic-gate }
378