8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / lib / printers / printwheels.c
blobe553404fc43d4537af130f50041231fe12d38a6e
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2006 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"
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
34 #include "string.h"
35 #include "errno.h"
36 #include "sys/types.h"
37 #include "stdlib.h"
39 #include "lp.h"
40 #include "printers.h"
42 /**
43 ** getpwheel() - GET PRINT WHEEL INFO FROM DISK
44 **/
46 PWHEEL *
47 #if defined(__STDC__)
48 getpwheel (
49 char * name
51 #else
52 getpwheel (name)
53 char *name;
54 #endif
56 static long lastdir = -1;
58 PWHEEL *pwp;
60 register FALERT *pa;
63 if (!name || !*name) {
64 errno = EINVAL;
65 return (0);
69 * Getting ``all''? If so, jump into the directory
70 * wherever we left off.
72 if (STREQU(NAME_ALL, name)) {
73 if (!(name = next_dir(Lp_A_PrintWheels, &lastdir)))
74 return (0);
75 } else
76 lastdir = -1;
79 * Get the information for the alert.
81 if (!(pa = getalert(Lp_A_PrintWheels, name))) {
84 * Unless the world has turned weird, we shouldn't
85 * get ENOTDIR if we're doing the ``all'' case--because
86 * getting here in the all case meant the printwheel
87 * directory exists, but ENOTDIR means it doesn't!
89 if (errno == ENOTDIR)
90 errno = ENOENT; /* printwheel doesn't exist */
92 return (0);
95 pwp = calloc(1, sizeof (*pwp));
96 pwp->alert = *pa;
97 pwp->name = Strdup(name);
99 return (pwp);
103 ** putpwheel() - PUT PRINT WHEEL INFO TO DISK
107 #if defined(__STDC__)
108 putpwheel (
109 char * name,
110 PWHEEL * pwheelp
112 #else
113 putpwheel (name, pwheelp)
114 char *name;
115 PWHEEL *pwheelp;
116 #endif
118 register char *path;
120 struct stat statbuf;
123 if (!name || !*name) {
124 errno = EINVAL;
125 return (-1);
128 if (STREQU(name, NAME_ALL)) {
129 errno = ENOENT;
130 return (-1);
134 * Create the parent directory for this printer
135 * if it doesn't yet exist.
137 if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
138 return (-1);
139 if (Stat(path, &statbuf) == 0) {
140 if (!S_ISDIR(statbuf.st_mode)) {
141 Free (path);
142 errno = ENOTDIR;
143 return (-1);
145 } else if (errno != ENOENT || mkdir_lpdir(path, MODE_DIR) == -1) {
146 Free (path);
147 return (-1);
149 Free (path);
152 * Now write out the alert condition.
154 if (putalert(Lp_A_PrintWheels, name, &(pwheelp->alert)) == -1)
155 return (-1);
157 return (0);
161 ** delpwheel() - DELETE PRINT WHEEL INFO FROM DISK
164 #if defined(__STDC__)
165 static int _delpwheel ( char * );
166 #else
167 static int _delpwheel();
168 #endif
171 #if defined(__STDC__)
172 delpwheel (
173 char * name
175 #else
176 delpwheel (name)
177 char *name;
178 #endif
180 long lastdir;
183 if (!name || !*name) {
184 errno = EINVAL;
185 return (-1);
188 if (STREQU(NAME_ALL, name)) {
189 lastdir = -1;
190 while ((name = next_dir(Lp_A_PrintWheels, &lastdir)))
191 if (_delpwheel(name) == -1)
192 return (-1);
193 return (0);
194 } else
195 return (_delpwheel(name));
199 ** _delpwheel()
202 static int
203 #if defined(__STDC__)
204 _delpwheel (
205 char * name
207 #else
208 _delpwheel (name)
209 char *name;
210 #endif
212 register char *path;
214 if (delalert(Lp_A_PrintWheels, name) == -1)
215 return (-1);
216 if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
217 return (-1);
218 if (Rmdir(path)) {
219 Free (path);
220 return (-1);
222 Free (path);
223 return (0);
227 ** freepwheel() - FREE MEMORY ALLOCATED FOR PRINT WHEEL STRUCTURE
230 void
231 #if defined(__STDC__)
232 freepwheel (
233 PWHEEL * ppw
235 #else
236 freepwheel (ppw)
237 PWHEEL *ppw;
238 #endif
240 if (!ppw)
241 return;
242 if (ppw->name)
243 Free (ppw->name);
244 if (ppw->alert.shcmd)
245 Free (ppw->alert.shcmd);
246 Free (ppw);
248 return;