8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / lib / forms / wrform.c
bloba3a21a92cce064837de4f3ce4354f225f006a433
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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.8 */
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
34 #include "sys/types.h"
35 #include "sys/stat.h"
36 #include "stdio.h"
37 #include "string.h"
38 #include "errno.h"
39 #include "stdlib.h"
41 #include "lp.h"
42 #include "form.h"
44 extern struct {
45 char *v;
46 short len;
47 short infile;
48 } formheadings[];
50 int _search_fheading ( char * );
52 static void print_sdn(int, char *, SCALED);
53 static void print_str(int, char *, char *);
55 /**
56 ** wrform()
57 **/
59 int
60 wrform(char *name, FORM *formp, int fd, int (*error_handler)( int , int , int ),
61 int *which_set)
63 int fld;
65 char * cp;
68 errno = 0;
69 for (fld = 0; fld < FO_MAX; fld++)
70 if ((!which_set || which_set[fld]) &&
71 (formheadings[fld].infile || error_handler))
72 switch (fld) {
74 #define HEAD formheadings[fld].v
76 case FO_PLEN:
77 print_sdn(fd, HEAD, formp->plen);
78 break;
80 case FO_PWID:
81 print_sdn(fd, HEAD, formp->pwid);
82 break;
84 case FO_LPI:
85 print_sdn(fd, HEAD, formp->lpi);
86 break;
88 case FO_CPI:
89 if (formp->cpi.val == N_COMPRESSED)
90 print_str(fd, HEAD, NAME_COMPRESSED);
91 else
92 print_sdn(fd, HEAD, formp->cpi);
93 break;
95 case FO_NP:
96 fdprintf(fd, "%s %d\n", HEAD, formp->np);
97 break;
99 case FO_CHSET:
100 fdprintf(fd, "%s %s", HEAD, formp->chset);
101 if (formp->mandatory == 1)
102 fdprintf(fd, ",%s", MANSTR);
103 fdprintf(fd, "\n");
104 break;
106 case FO_RCOLOR:
107 print_str(fd, HEAD, formp->rcolor);
108 break;
110 case FO_CMT:
111 if ((cp = formp->comment) && *cp) {
112 fdprintf(fd, "%s\n", HEAD);
113 do {
114 char * nl = strchr(cp, '\n');
116 if (nl)
117 *nl = 0;
118 if (_search_fheading(cp) < FO_MAX)
119 fdputc ('>', fd);
120 fdprintf(fd, "%s\n", cp);
121 if (nl)
122 *nl = '\n';
123 cp = nl;
124 } while (cp++); /* NOT *cp++ */
126 break;
128 case FO_ALIGN:
129 /* this must always be the last field in the file
130 it is done outside of this loop */
131 break;
133 case FO_PAPER:
134 if (formp->paper) {
135 fdprintf(fd, "%s %s", HEAD, formp->paper);
136 if (formp->isDefault == 1)
137 fdprintf(fd, ",%s", DFTSTR);
138 fdprintf(fd, "\n");
140 break;
144 if ((!which_set || which_set[FO_ALIGN]) &&
145 (formheadings[FO_ALIGN].infile || error_handler)) {
146 print_str(fd, formheadings[FO_ALIGN].v, formp->conttype);
148 * Actual alignment pattern has to be written
149 * out by caller; we leave the file pointer ready.
153 if (errno != 0)
154 return (-1);
157 * Write out comment to a separate file (?)
159 if (!error_handler) {
161 char * path;
164 if (!(path = getformfile(name, COMMENT)))
165 return (-1);
167 if (formp->comment) {
168 if (dumpstring(path, formp->comment) == -1) {
169 Free (path);
170 return (-1);
173 } else
174 Unlink (path);
176 Free (path);
180 return (0);
184 ** print_sdn() - PRINT SCALED DECIMAL NUMBER WITH HEADER
185 ** print_str() - PRINT STRING WITH HEADER
188 static void
189 print_sdn(int fd, char *head, SCALED sdn)
191 if (sdn.val <= 0)
192 return;
194 (void)fdprintf(fd, "%s ", head);
195 fdprintsdn(fd, sdn);
197 return;
200 static void
201 print_str(int fd, char *head, char *str)
203 if (!str || !*str)
204 return;
206 (void)fdprintf(fd, "%s %s\n", head, str);
208 return;