1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
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.
10 * By: Theodore Y. Ts'o
16 * Copyright 1988 by the Massachusetts Institute of Technology.
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
28 #include "mit-copyright.h"
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
41 #define PCAP_MODWITH 7
44 #define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU"
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).
53 SetDefaults(info, name)
59 strcpy(spool_dir, "/usr/spool/printer/");
60 strcat(spool_dir, name);
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;
69 info[PCAP_END] = NULL;
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.
86 struct qelem *elem = NULL;
88 if ( (stat = sms_query("get_printcap", 1, &name,
89 StoreInfo, (char *)&elem)) != 0) {
90 com_err(program_name, stat, NULL);
93 return(QueueTop(elem));
96 /* Function Name: PrintPcapInfo
97 * Description: Yet another specialized print function.
98 * Arguments: info - all info about this Printer.
108 if (!info) { /* If no informaion */
109 Put_message("PrintPcapInfo called with null info!");
112 sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
113 info[PCAP_SPOOL_HOST]);
115 sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
116 info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
118 sprintf(buf, "Comments: ", info[PCAP_COMMENTS]);
120 sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME],
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
137 char temp_buf[BUFSIZ], *newname;
140 sprintf(temp_buf, "Printcap entry for %s.",
142 Put_message(temp_buf);
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]);
153 FreeAndClear(&info[PCAP_MODTIME], TRUE);
154 FreeAndClear(&info[PCAP_MODBY], TRUE);
155 FreeAndClear(&info[PCAP_MODWITH], TRUE);
160 /* ---------------- Printer Menu ------------------ */
162 /* Function Name: GetPcap
163 * Description: Get Printcap information
164 * Arguments: argc, argv - name of filsys in argv[1].
165 * Returns: DM_NORMAL.
176 top = GetPcapInfo(argv[1]); /* get info. */
177 Loop(top, (void *) PrintPcapInfo);
178 FreeQueue(top); /* clean the queue. */
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.
191 RealDeletePcap(info, one_item)
196 char temp_buf[BUFSIZ];
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.");
202 Put_message("Printcap entry deleted.");
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.
214 DeletePcap(argc, argv)
218 struct qelem *elem = GetPcapInfo(argv[1]);
219 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
225 /* Function Name: AddPcap
226 * Description: Add a printcap entry
227 * Arguments: arc, argv - name of printer in argv[1].
228 * Returns: DM_NORMAL.
237 char *info[MAX_ARGS_SIZE], **args;
240 if ( !ValidName(argv[1]) )
243 if ( (stat = sms_query("get_printcap", 1, argv + 1,
244 NullFunc, NULL)) == 0) {
245 Put_message ("A Printer by that name already exists.");
247 } else if (stat != SMS_NO_MATCH) {
248 com_err(program_name, stat, " in AddPcap");
252 args = AskPcapInfo(SetDefaults(info, argv[1]));
254 if ( (stat = sms_query("add_printcap", CountArgs(args), args,
255 NullFunc, NULL)) != 0)
256 com_err(program_name, stat, " in AddPcap");
263 /* Function Name: ChangePcap
264 * Description: Do the work of changing a pcap
265 * Arguments: argc, argv - printcap info
270 ChangePcap(info, one_item)
276 if ((stat = sms_query("delete_printcap", 1, &info[FS_NAME],
277 Scream, NULL)) != 0) {
278 com_err(program_name, stat, " printcap entry not deleted.");
282 if ((stat = sms_query("add_printcap", CountArgs(info), info,
283 NullFunc, NULL)) != 0)
284 com_err(program_name, stat, " in ChngPcap");
289 /* Function Name: ChngPcap
290 * Description: Update the printcap information
291 * Arguments: argc, argv - name of printer in argv[1].
292 * Returns: DM_NORMAL.
300 struct qelem *elem = GetPcapInfo(argv[1]);
301 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
311 * c-continued-statement-offset: 4
313 * c-argdecl-indent: 4