]> andersk Git - moira.git/blob - clients/moira/printer.c
added change printcap functions
[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 <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
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 = 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     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 */
169 int
170 GetPcap(argc, argv)
171 int argc;
172 char **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
190 void
191 RealDeletePcap(info, one_item)
192 char ** info;
193 Bool 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  
213 int
214 DeletePcap(argc, argv)
215 int argc;
216 char **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 */
232 int
233 AddPcap(argc, argv)
234 char **argv;
235 int 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 /*      Function Name: ChangePcap
264  *      Description: Do the work of changing a pcap
265  *      Arguments: argc, argv - printcap info
266  *      Returns: 
267  */
268
269 int
270 ChangePcap(info, one_item)
271 char **info;
272 Bool one_item;
273 {
274     int stat;
275
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.");
279         return(DM_NORMAL);
280     }
281     AskPcapInfo(info);
282     if ((stat = sms_query("add_printcap", CountArgs(info), info,
283                           NullFunc, NULL)) != 0)
284         com_err(program_name, stat, " in ChngPcap");
285     return(DM_NORMAL);
286 }
287
288
289 /*      Function Name: ChngPcap
290  *      Description:   Update the printcap information
291  *      Arguments:     argc, argv - name of printer in argv[1].
292  *      Returns:       DM_NORMAL.
293  */
294
295 int
296 ChngPcap(argc, argv)
297     int argc;
298     char **argv;
299 {
300     struct qelem *elem = GetPcapInfo(argv[1]);
301     QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
302     FreeQueue(elem);
303     return(DM_NORMAL);
304 }
305
306
307 /*
308  * Local Variables:
309  * mode: c
310  * c-indent-level: 4
311  * c-continued-statement-offset: 4
312  * c-brace-offset: -4
313  * c-argdecl-indent: 4
314  * c-label-offset: -4
315  * End:
316  */
317
This page took 0.162399 seconds and 5 git commands to generate.