]> andersk Git - moira.git/blame - clients/moira/printer.c
Initial revision
[moira.git] / clients / moira / printer.c
CommitLineData
cc5b487a 1#if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
3#endif lint
4
5/* This is the file printer.c for the SMS Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the SMS database.
7 * It Contains: Functions for handling the printers.
8 *
9 * Created: 8/16/88
10 * By: Theodore Y. Ts'o
11 *
12 * $Source$
13 * $Author$
14 * $Header$
15 *
16 * Copyright 1988 by the Massachusetts Institute of Technology.
17 *
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
20 */
21
22#include <stdio.h>
23#include <strings.h>
24#include <ctype.h>
25#include <sms.h>
26#include <menu.h>
27
28#include "mit-copyright.h"
29#include "defs.h"
30#include "f_defs.h"
31#include "globals.h"
32#include "infodefs.h"
33
34#define PCAP_NAME 0
35#define PCAP_SPOOL_HOST 1
36#define PCAP_SPOOL_DIR 2
37#define PCAP_RPRINTER 3
38#define PCAP_COMMENTS 4
39#define PCAP_MODTIME 5
40#define PCAP_MODBY 6
41#define PCAP_MODWITH 7
42#define PCAP_END 8
43
44#define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU"
45
46/* Function Name: SetDefaults
47 * Description: sets the default values for filesystem additions.
48 * Arguments: info - an array of char pointers to recieve defaults.
49 * Returns: char ** (this array, now filled).
50 */
51
52static char **
53SetDefaults(info, name)
54char ** info;
55char * name;
56{
57 char spool_dir[256];
58
59 strcpy(spool_dir, "/usr/spool/printer/");
60 strcat(spool_dir, name);
61
62 info[PCAP_NAME] = Strsave(name);
63 info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE);
64 info[PCAP_SPOOL_DIR] = Strsave(spool_dir);
65 info[PCAP_RPRINTER] = Strsave(name);
66 info[PCAP_COMMENTS] = Strsave("");
67 info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL;
68
69 info[PCAP_END] = NULL;
70 return(info);
71}
72
73/* Function Name: GetPcapInfo
74 * Description: Stores the info in a queue.
75 * Arguments: name - name of the item to get information on.
76 * Returns: a pointer to the first element in the queue or null
77 * if printer not found.
78 */
79
80static struct qelem *
81GetPcapInfo(name)
82char *name;
83
84{
85 int stat;
86 struct qelem *elem = NULL;
87
88 if ( (stat = sms_query("get_printcap", 1, &name,
89 StoreInfo, (char *)&elem)) != 0) {
90 com_err(program_name, stat, NULL);
91 return(NULL);
92 }
93 return(QueueTop(elem));
94}
95
96/* Function Name: PrintPcapInfo
97 * Description: Yet another specialized print function.
98 * Arguments: info - all info about this Printer.
99 * Returns: none
100 */
101
102static void
103PrintPcapInfo(info)
104char ** info;
105{
106 char buf[BUFSIZ];
107
108 if (!info) { /* If no informaion */
109 Put_message("PrintPcapInfo called with null info!");
110 return;
111 }
112 sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
113 info[PCAP_SPOOL_HOST]);
114 Put_message(buf);
115 sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
116 info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
117 Put_message(buf);
118 sprintf(buf, "Comments: ", info[PCAP_COMMENTS]);
119 Put_message(buf);
120 sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME],
121 info[PCAP_MODWITH]);
122 Put_message(buf);
123}
124
125/* Function Name: AskPcapInfo.
126 * Description: This function askes the user for information about a
127 * printer and saves it into a structure.
128 * Arguments: info - a pointer the the structure to put the
129 * info into.
130 * Returns: none.
131 */
132
133static char **
134AskPcapInfo(info)
135char ** info;
136{
137 char temp_buf[BUFSIZ], *newname;
138
139 Put_message("");
140 sprintf(temp_buf, "Printcap entry for %s.",
141 info[FS_NAME]);
142 Put_message(temp_buf);
143 Put_message("");
144
145 GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]);
146 strcpy(temp_buf, CanonicalizeHostname(info[PCAP_SPOOL_HOST]));
147 free(info[PCAP_SPOOL_HOST]);
148 info[PCAP_SPOOL_HOST] = Strsave(temp_buf);
149 GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]);
150 GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]);
151 GetValueFromUser("Comments", &info[PCAP_COMMENTS]);
152
153 FreeAndClear(&info[PCAP_MODTIME], TRUE);
154 FreeAndClear(&info[PCAP_MODBY], TRUE);
155 FreeAndClear(&info[PCAP_MODWITH], TRUE);
156
157 return(info);
158}
159
160/* ---------------- Printer Menu ------------------ */
161
162/* Function Name: GetPcap
163 * Description: Get Printcap information
164 * Arguments: argc, argv - name of filsys in argv[1].
165 * Returns: DM_NORMAL.
166 */
167
168/* ARGSUSED */
169int
170GetPcap(argc, argv)
171int argc;
172char **argv;
173{
174 struct qelem *top;
175
176 top = GetPcapInfo(argv[1]); /* get info. */
177 Loop(top, (void *) PrintPcapInfo);
178 FreeQueue(top); /* clean the queue. */
179 return (DM_NORMAL);
180}
181
182/* Function Name: RealDeletePcap
183 * Description: Does the real deletion work.
184 * Arguments: info - array of char *'s containing all useful info.
185 * one_item - a Boolean that is true if only one item
186 * in queue that dumped us here.
187 * Returns: none.
188 */
189
190void
191RealDeletePcap(info, one_item)
192char ** info;
193Bool one_item;
194{
195 int stat;
196 char temp_buf[BUFSIZ];
197
198 if ( (stat = sms_query("delete_printcap", 1,
199 &info[FS_NAME], Scream, NULL)) != 0)
200 com_err(program_name, stat, " printcap entry not deleted.");
201 else
202 Put_message("Printcap entry deleted.");
203}
204
205/* Function Name: DeletePcap
206 * Description: Delete a printcap entry given its name.
207 * Arguments: argc, argv - argv[1] is the name of the printer.
208 * Returns: none.
209 */
210
211/* ARGSUSED */
212
213int
214DeletePcap(argc, argv)
215int argc;
216char **argv;
217{
218 struct qelem *elem = GetPcapInfo(argv[1]);
219 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
220
221 FreeQueue(elem);
222 return (DM_NORMAL);
223}
224
225/* Function Name: AddPcap
226 * Description: Add a printcap entry
227 * Arguments: arc, argv - name of printer in argv[1].
228 * Returns: DM_NORMAL.
229 */
230
231/* ARGSUSED */
232int
233AddPcap(argc, argv)
234char **argv;
235int argc;
236{
237 char *info[MAX_ARGS_SIZE], **args;
238 int stat;
239
240 if ( !ValidName(argv[1]) )
241 return(DM_NORMAL);
242
243 if ( (stat = sms_query("get_printcap", 1, argv + 1,
244 NullFunc, NULL)) == 0) {
245 Put_message ("A Printer by that name already exists.");
246 return(DM_NORMAL);
247 } else if (stat != SMS_NO_MATCH) {
248 com_err(program_name, stat, " in AddPcap");
249 return(DM_NORMAL);
250 }
251
252 args = AskPcapInfo(SetDefaults(info, argv[1]));
253
254 if ( (stat = sms_query("add_printcap", CountArgs(args), args,
255 NullFunc, NULL)) != 0)
256 com_err(program_name, stat, " in AddPcap");
257
258 FreeInfo(info);
259 return (DM_NORMAL);
260}
261
262
263
264/*
265 * Local Variables:
266 * mode: c
267 * c-indent-level: 4
268 * c-continued-statement-offset: 4
269 * c-brace-offset: -4
270 * c-argdecl-indent: 4
271 * c-label-offset: -4
272 * End:
273 */
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
This page took 0.088076 seconds and 5 git commands to generate.