1/*
2 * CDDL HEADER START
3 *
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.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28/*	  All Rights Reserved  	*/
29
30
31#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.11	*/
32
33#include <stdio.h>
34#include <string.h>
35#include <errno.h>
36#include <sys/types.h>
37#include <stdlib.h>
38#include <libintl.h>
39
40#include "lp.h"
41#include "printers.h"
42#include "msgs.h"
43
44#define	WHO_AM_I	I_AM_LPADMIN
45#include "oam.h"
46
47#include "lpadmin.h"
48
49
50extern char		*nameit(),
51			*label;
52
53static void		configure_pwheel();
54
55/**
56 ** do_pwheel() - SET ALERT FOR NEED TO MOUNT PRINT WHEEL
57 **/
58
59void			do_pwheel ()
60{
61	int			rc;
62
63
64	if (A && STREQU(A, NAME_NONE)) {
65		BEGIN_CRITICAL
66			if (delpwheel(*S) == -1) {
67				LP_ERRMSG1 (WARNING, E_ADM_BADPWHEEL, *S);
68				return;
69			}
70		END_CRITICAL
71
72	} else if (strlen(modifications))
73		configure_pwheel (modifications);
74
75	if (A && STREQU(A, NAME_LIST)) {
76		if (label)
77			(void) printf(gettext("Print wheel %s: "), label);
78		printalert (stdout, &(oldS->alert), 0);
79		return;
80	}
81
82	if (A && STREQU(A, NAME_QUIET)) {
83
84		send_message(S_QUIET_ALERT, *S, (char *)QA_PRINTWHEEL, "");
85		rc = output(R_QUIET_ALERT);
86
87		switch(rc) {
88		case MOK:
89			break;
90
91		case MNODEST:	/* not quite, but not a lie either */
92		case MERRDEST:
93			LP_ERRMSG1 (WARNING, E_LP_NOQUIET, *S);
94			break;
95
96		case MNOPERM:	/* taken care of up front */
97		default:
98			LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
99			done (1);
100			/*NOTREACHED*/
101		}
102
103		return;
104	}
105
106	if (A && STREQU(A, NAME_NONE)) {
107		send_message(S_UNLOAD_PRINTWHEEL, *S);
108		rc = output(R_UNLOAD_PRINTWHEEL);
109	} else {
110		send_message(S_LOAD_PRINTWHEEL, *S);
111		rc = output(R_LOAD_PRINTWHEEL);
112	}
113
114	switch(rc) {
115	case MOK:
116		break;
117
118	case MNODEST:
119		/*
120		 * Should only occur if we're deleting a print wheel
121		 * alert that doesn't exist.
122		 */
123		break;
124
125	case MERRDEST:
126		LP_ERRMSG (ERROR, E_ADM_ERRDEST);
127		done (1);
128		/*NOTREACHED*/
129
130	case MNOSPACE:
131		LP_ERRMSG (WARNING, E_ADM_NOPWSPACE);
132		break;
133
134	case MNOPERM:	/* taken care of up front */
135	default:
136		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
137		done (1);
138		/*NOTREACHED*/
139	}
140	return;
141}
142
143/**
144 ** configure_pwheel() - SET OR CHANGE CONFIGURATION OF A PRINT WHEEL
145 **/
146
147static void		configure_pwheel (list)
148	char			*list;
149{
150	register PWHEEL		*ppw;
151
152	PWHEEL			pwheel_buf;
153
154	char			type;
155
156
157	if (oldS)
158		ppw = oldS;
159	else {
160		ppw = &pwheel_buf;
161		ppw->alert.shcmd = 0;
162		ppw->alert.Q = 0;
163		ppw->alert.W = 0;
164	}
165
166	while ((type = *list++) != '\0')  switch(type) {
167
168	case 'A':
169		if (STREQU(A, NAME_MAIL) || STREQU(A, NAME_WRITE))
170			ppw->alert.shcmd = nameit(A);
171		else
172			ppw->alert.shcmd = A;
173
174		break;
175
176	case 'Q':
177		ppw->alert.Q = Q;
178		break;
179
180	case 'W':
181		ppw->alert.W = W;
182		break;
183
184	}
185
186	BEGIN_CRITICAL
187		if (putpwheel(*S, ppw) == -1) {
188			LP_ERRMSG2 (
189				ERROR,
190				E_ADM_PUTPWHEEL,
191				*S,
192				PERROR
193			);
194			done(1);
195		}
196	END_CRITICAL
197
198	return;
199}
200