]> andersk Git - moira.git/blob - clients/moira/printer.c
a836f1cae7cfdb1521b281e1407de8d8244ef0da
[moira.git] / clients / moira / printer.c
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 <sms_app.h>
27 #include <menu.h>
28
29 #include "mit-copyright.h"
30 #include "defs.h"
31 #include "f_defs.h"
32 #include "globals.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
52 static char ** 
53 SetDefaults(info, name)
54 char ** info;
55 char * 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
80 static struct qelem *
81 GetPcapInfo(name)
82 char *name;
83
84 {
85     int stat;
86     struct qelem *elem = NULL;
87
88     if ( (stat = do_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
102 static void
103 PrintPcapInfo(info)
104 char ** 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
133 static char **
134 AskPcapInfo(info)
135 char ** 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     info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]);
147     GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]);
148     GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]);
149     GetValueFromUser("Comments", &info[PCAP_COMMENTS]);
150     
151     FreeAndClear(&info[PCAP_MODTIME], TRUE);
152     FreeAndClear(&info[PCAP_MODBY], TRUE);
153     FreeAndClear(&info[PCAP_MODWITH], TRUE);
154     
155     return(info);
156 }
157
158 /* ---------------- Printer Menu ------------------ */
159
160 /*      Function Name: GetPcap
161  *      Description: Get Printcap information
162  *      Arguments: argc, argv - name of filsys in argv[1].
163  *      Returns: DM_NORMAL.
164  */
165
166 /* ARGSUSED */
167 int
168 GetPcap(argc, argv)
169 int argc;
170 char **argv;
171 {
172     struct qelem *top;
173
174     top = GetPcapInfo(argv[1]); /* get info. */
175     Loop(top, (void *) PrintPcapInfo);
176     FreeQueue(top);             /* clean the queue. */
177     return (DM_NORMAL);
178 }
179
180 /*      Function Name: RealDeletePcap
181  *      Description: Does the real deletion work.
182  *      Arguments: info - array of char *'s containing all useful info.
183  *                 one_item - a Boolean that is true if only one item 
184  *                              in queue that dumped us here.
185  *      Returns: none.
186  */
187
188 void
189 RealDeletePcap(info, one_item)
190 char ** info;
191 Bool one_item;
192 {
193     int stat;
194     char temp_buf[BUFSIZ];
195
196     if ( (stat = do_sms_query("delete_printcap", 1,
197                               &info[FS_NAME], Scream, NULL)) != 0)
198             com_err(program_name, stat, " printcap entry not deleted.");
199     else
200             Put_message("Printcap entry deleted.");
201 }
202
203 /*      Function Name: DeletePcap
204  *      Description: Delete a printcap entry given its name.
205  *      Arguments: argc, argv - argv[1] is the name of the printer.
206  *      Returns: none.
207  */
208
209 /* ARGSUSED */
210  
211 int
212 DeletePcap(argc, argv)
213 int argc;
214 char **argv;
215 {
216     struct qelem *elem = GetPcapInfo(argv[1]);
217     QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
218
219     FreeQueue(elem);
220     return (DM_NORMAL);
221 }
222
223 /*      Function Name: AddPcap
224  *      Description: Add a printcap entry
225  *      Arguments: arc, argv - name of printer in argv[1].
226  *      Returns: DM_NORMAL.
227  */
228
229 /* ARGSUSED */
230 int
231 AddPcap(argc, argv)
232 char **argv;
233 int argc;
234 {
235     char *info[MAX_ARGS_SIZE], **args;
236     int stat;
237
238     if ( !ValidName(argv[1]) )
239         return(DM_NORMAL);
240
241     if ( (stat = do_sms_query("get_printcap", 1, argv + 1,
242                               NullFunc, NULL)) == 0) {
243         Put_message ("A Printer by that name already exists.");
244         return(DM_NORMAL);
245     } else if (stat != SMS_NO_MATCH) {
246         com_err(program_name, stat, " in AddPcap");
247         return(DM_NORMAL);
248     } 
249
250     args = AskPcapInfo(SetDefaults(info, argv[1]));
251
252     if ( (stat = do_sms_query("add_printcap", CountArgs(args), args, 
253                               NullFunc, NULL)) != 0)
254         com_err(program_name, stat, " in AddPcap");
255
256     FreeInfo(info);
257     return (DM_NORMAL);
258 }
259
260
261 /*      Function Name: ChangePcap
262  *      Description: Do the work of changing a pcap
263  *      Arguments: argc, argv - printcap info
264  *      Returns: 
265  */
266
267 int
268 ChangePcap(info, one_item)
269 char **info;
270 Bool one_item;
271 {
272     int stat;
273
274     if ((stat = do_sms_query("delete_printcap", 1, &info[FS_NAME],
275                              Scream, NULL)) != 0) {
276         com_err(program_name, stat, " printcap entry not deleted.");
277         return(DM_NORMAL);
278     }
279     AskPcapInfo(info);
280     if ((stat = do_sms_query("add_printcap", CountArgs(info), info,
281                              NullFunc, NULL)) != 0)
282         com_err(program_name, stat, " in ChngPcap");
283     return(DM_NORMAL);
284 }
285
286
287 /*      Function Name: ChngPcap
288  *      Description:   Update the printcap information
289  *      Arguments:     argc, argv - name of printer in argv[1].
290  *      Returns:       DM_NORMAL.
291  */
292
293 int
294 ChngPcap(argc, argv)
295     int argc;
296     char **argv;
297 {
298     struct qelem *elem = GetPcapInfo(argv[1]);
299     QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
300     FreeQueue(elem);
301     return(DM_NORMAL);
302 }
This page took 0.138093 seconds and 3 git commands to generate.