]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | ||
6 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ | |
7 | /* For copying and distribution information, please see the file */ | |
8 | /* <mit-copyright.h>. */ | |
9 | ||
10 | #ifndef lint | |
11 | static char rcsid_mailmaint_c[] = "$Header$"; | |
12 | #endif lint | |
13 | ||
14 | /***********************************************************************/ | |
15 | /* mailmaint.c - pjlevine - 20 August 1987 | |
16 | ||
17 | */ | |
18 | /***********************************************************************/ | |
19 | #include <stdio.h> | |
20 | #include <pwd.h> | |
21 | #include <menu.h> | |
22 | #include <signal.h> | |
23 | #include <strings.h> | |
24 | #include <curses.h> | |
25 | #include <sys/types.h> | |
26 | #include <varargs.h> | |
27 | #include <com_err.h> | |
28 | #include <ctype.h> | |
29 | #include <sms.h> | |
30 | #include <sms_app.h> | |
31 | #include <mit-copyright.h> | |
32 | ||
33 | #define STARTCOL 0 | |
34 | #define STARTROW 3 | |
35 | #define SECONDCOL 30 | |
36 | #define DISPROW 15 | |
37 | #define LISTMAX 50 | |
38 | #define LISTSIZE 32 | |
39 | #define CTL(ch) ((ch) & 037) | |
40 | #define MAX(A,B) ((A) > (B) ? (A) : (B)) | |
41 | ||
42 | char *whoami; /* should not be static, for logging package */ | |
43 | static int status; | |
44 | static void scream(); | |
45 | extern char *strsave(); | |
46 | int menu_err_hook(); | |
47 | ||
48 | typedef struct list_info { | |
49 | int active; | |
50 | int public; | |
51 | int hidden; | |
52 | int maillist; | |
53 | int group; | |
54 | char *acl_type; | |
55 | char *acl_name; | |
56 | char *desc; | |
57 | char *modtime; | |
58 | char *modby; | |
59 | char *modwith; | |
60 | } List_info; | |
61 | ||
62 | static char *ascbuff = {"0123456789"}; | |
63 | static int | |
64 | print_2(), print_1(); | |
65 | static List_info *current_li = (List_info *) NULL; | |
66 | static int get_list_info(); | |
67 | static int fetch_list_info(); | |
68 | ||
69 | char *malloc(); | |
70 | char *rindex(); | |
71 | char *getlogin(); | |
72 | extern char *strsave(); | |
73 | char *getenv(); | |
74 | char *calloc(); | |
75 | ||
76 | uid_t getuid(); | |
77 | ||
78 | typedef struct _menu { | |
79 | int num_items; | |
80 | char *title; | |
81 | char **items; | |
82 | } MENU; | |
83 | ||
84 | MENU *main_menu, *help_menu; | |
85 | ||
86 | int position[2], oldpos[2]; | |
87 | int level, found_some, currow, page, num_members; | |
88 | int moreflg, toggle, first_time; | |
89 | char *uname; | |
90 | ||
91 | ||
92 | /****************************************************/ | |
93 | /*ARGSUSED*/ | |
94 | main(argc, argv) | |
95 | int argc; | |
96 | char *argv[]; | |
97 | ||
98 | { | |
99 | int (*old_hook)(); | |
100 | int use_menu = 1; | |
101 | char buf[BUFSIZ]; | |
102 | ||
103 | init_sms_err_tbl(); | |
104 | init_krb_err_tbl(); | |
105 | ||
106 | if ((whoami = rindex(argv[0], '/')) == NULL) | |
107 | whoami = argv[0]; | |
108 | else | |
109 | whoami++; | |
110 | uname = calloc(20, 1); | |
111 | if ((current_li = (List_info *) malloc(sizeof(List_info))) | |
112 | == (List_info *) NULL) { | |
113 | (void) sprintf(buf, ": allocating list info"); | |
114 | goto punt; | |
115 | } | |
116 | else { | |
117 | current_li->acl_type = (char *) NULL; | |
118 | current_li->acl_name = (char *) NULL; | |
119 | current_li->desc = (char *) NULL; | |
120 | current_li->modtime = (char *) NULL; | |
121 | current_li->modby = (char *) NULL; | |
122 | current_li->modwith = (char *) NULL; | |
123 | } | |
124 | if ((uname = getlogin()) == NULL) { | |
125 | struct passwd *getpwuid(); | |
126 | ||
127 | uname = getpwuid((int) getuid())->pw_name; | |
128 | } | |
129 | uname = (uname && strlen(uname)) ? strsave(uname) : ""; | |
130 | ||
131 | printf("Connecting to database for %s...please hold on.\n", uname); | |
132 | ||
133 | status = sms_connect(SMS_SERVER); | |
134 | if (status) { | |
135 | (void) sprintf(buf, "\nConnection to SMS server failed"); | |
136 | goto punt; | |
137 | } | |
138 | ||
139 | status = sms_auth("mailmaint"); | |
140 | if (status) { | |
141 | (void) sprintf(buf, "\nAuthorization failed.\n"); | |
142 | goto punt; | |
143 | } | |
144 | ||
145 | if (use_menu) { | |
146 | (void) initscr(); | |
147 | if ((LINES < 24) || (COLS < 60)) { | |
148 | Put_message("Display window too small.\n\n"); | |
149 | (void) sprintf(buf, "Current window parameters are (%d \ | |
150 | lines, %d columns)\n", LINES, COLS); | |
151 | Put_message(buf); | |
152 | Put_message("Please resize your window\n"); | |
153 | Put_message("to at least 24 lines and 60 columns.\n"); | |
154 | exit(0); | |
155 | } | |
156 | raw(); | |
157 | noecho(); | |
158 | old_hook = set_com_err_hook(menu_err_hook); | |
159 | position[0] = oldpos[0] = 1; | |
160 | level = 0; | |
161 | pack_main_menu(); | |
162 | pack_help_menu(); | |
163 | display_menu(main_menu); | |
164 | get_main_input(); | |
165 | cls(); | |
166 | endwin(); | |
167 | set_com_err_hook(old_hook); | |
168 | } | |
169 | exit(0); | |
170 | ||
171 | punt: | |
172 | com_err(whoami, status, buf); | |
173 | exit(1); | |
174 | } | |
175 | ||
176 | /****************************************************/ | |
177 | get_main_input() | |
178 | { | |
179 | int c; | |
180 | int retflg; | |
181 | ||
182 | while (1) { | |
183 | oldpos[level] = position[level]; | |
184 | retflg = 0; | |
185 | currow = DISPROW + 2; | |
186 | page = 1; | |
187 | toggle = num_members = moreflg = 0; | |
188 | c = getchar(); | |
189 | if (c == 13) { | |
190 | if (position[level] == 7) | |
191 | c = 'q'; | |
192 | else | |
193 | c = ascbuff[position[level]]; | |
194 | retflg = 1; | |
195 | } | |
196 | switch (c) { | |
197 | case 'L' & 037: /* clear screen */ | |
198 | display_menu(main_menu); | |
199 | break; | |
200 | case 'q': | |
201 | case 'Q': /* quit */ | |
202 | position[level] = 7; | |
203 | highlight(main_menu); | |
204 | if (retflg) { | |
205 | cls(); | |
206 | return; | |
207 | } | |
208 | break; | |
209 | case '1': /* show all lists */ | |
210 | position[level] = 1; | |
211 | if (retflg) { | |
212 | show_all(); | |
213 | } | |
214 | break; | |
215 | case '2': /* get all members of a list */ | |
216 | position[level] = 2; | |
217 | if (retflg) { | |
218 | (void) list_members(); | |
219 | } | |
220 | break; | |
221 | case '3': /* display list which user is a recipient */ | |
222 | position[level] = 3; | |
223 | if (retflg) { | |
224 | list_by_member(); | |
225 | } | |
226 | break; | |
227 | case '4': /* show description */ | |
228 | position[level] = 4; | |
229 | if (retflg) { | |
230 | show_list_info(); | |
231 | } | |
232 | break; | |
233 | case '5': /* add to list */ | |
234 | position[level] = 5; | |
235 | if (retflg) { | |
236 | add_member(); | |
237 | } | |
238 | break; | |
239 | case '6': /* delete */ | |
240 | position[level] = 6; | |
241 | if (retflg) { | |
242 | delete_member(); | |
243 | } | |
244 | break; | |
245 | case 27: /* up arrow */ | |
246 | c = getchar(); | |
247 | if (c == 91) { | |
248 | c = getchar(); | |
249 | if (c == 65) { | |
250 | position[level]--; | |
251 | if (!position[level]) | |
252 | position[level] = 7; | |
253 | } | |
254 | else { | |
255 | if (c == 66) { | |
256 | position[level]++; | |
257 | if (position[level] > 7) | |
258 | position[level] = 1; | |
259 | } | |
260 | } | |
261 | } | |
262 | break; | |
263 | default: | |
264 | printf("%c", 7); | |
265 | break; | |
266 | } | |
267 | highlight(main_menu); | |
268 | } | |
269 | } | |
270 | ||
271 | /****************************************************/ | |
272 | show_list_info() | |
273 | { | |
274 | char *buf; | |
275 | char c; | |
276 | ||
277 | show_text(DISPROW, STARTCOL, "Show information about a list.\n\r"); | |
278 | buf = calloc((unsigned)1024, 1); | |
279 | if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { | |
280 | Put_message("\n\r"); | |
281 | if (fetch_list_info(buf, current_li) == 0) { | |
282 | (void) sprintf(buf, "Description: %s\n\r", current_li->desc); | |
283 | if (strlen(buf) > 60) | |
284 | (void) display_buff(buf); | |
285 | else | |
286 | show_text(currow, STARTCOL, buf); | |
287 | currow++; | |
288 | (void) sprintf(buf, "List Administrator: %s %s", | |
289 | current_li->acl_type, current_li->acl_name); | |
290 | show_text(currow, STARTCOL, buf); | |
291 | currow++; | |
292 | (void) sprintf(buf, "Modified on %s by user %s with %s", | |
293 | current_li->modtime, current_li->modby, | |
294 | current_li->modwith); | |
295 | show_text(currow, STARTCOL, buf); | |
296 | currow++; | |
297 | } | |
298 | else { | |
299 | show_text(currow, STARTCOL, "mailmaint: No such list found."); | |
300 | currow++; | |
301 | } | |
302 | show_text(currow, STARTCOL, "Press any Key to continue..."); | |
303 | (void) getchar(); | |
304 | } | |
305 | clrwin(DISPROW); | |
306 | } | |
307 | ||
308 | /****************************************************/ | |
309 | display_buff(buf) | |
310 | char *buf; | |
311 | { | |
312 | int i, cnt; | |
313 | char *printbuf; | |
314 | int maxcol; | |
315 | ||
316 | maxcol = COLS; | |
317 | if (maxcol >= 80) | |
318 | maxcol = 80; | |
319 | ||
320 | cnt = 0; | |
321 | printbuf = calloc((unsigned)maxcol, 1); | |
322 | for (i = 0; i <= strlen(buf); i++) { | |
323 | printbuf[cnt] = buf[i]; | |
324 | cnt++; | |
325 | if (cnt >= maxcol) { | |
326 | (void) start_display_buff(printbuf); | |
327 | cnt = 0; | |
328 | free(printbuf); | |
329 | printbuf = calloc((unsigned)maxcol, 1); | |
330 | } | |
331 | } | |
332 | if (strlen(buf) % maxcol != 0) { | |
333 | (void) start_display_buff(printbuf); | |
334 | free(printbuf); | |
335 | } | |
336 | return (0); | |
337 | } | |
338 | ||
339 | /****************************************************/ | |
340 | start_display_buff(buff) | |
341 | char *buff; | |
342 | { | |
343 | char buffer[5]; | |
344 | ||
345 | num_members++; | |
346 | if (moreflg) | |
347 | return (0); | |
348 | if (currow >= LINES - 2) { | |
349 | page++; | |
350 | currow++; | |
351 | mvcur(0, 0, currow, STARTCOL); | |
352 | refresh(); | |
353 | if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) { | |
354 | Put_message("Flushing query..."); | |
355 | moreflg = 1; | |
356 | return (0); | |
357 | } | |
358 | clrwin(DISPROW + 2); | |
359 | currow = DISPROW + 2; | |
360 | show_text(currow, STARTCOL, "continued"); | |
361 | currow++; | |
362 | } | |
363 | show_text(currow, STARTCOL, buff); | |
364 | currow++; | |
365 | return (0); | |
366 | } | |
367 | ||
368 | /****************************************************/ | |
369 | add_member() | |
370 | { | |
371 | char *argv[3]; | |
372 | char *buf; | |
373 | char c; | |
374 | ||
375 | show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r"); | |
376 | buf = calloc(LISTMAX, 1); | |
377 | if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { | |
378 | Put_message("\r\n"); | |
379 | argv[0] = strsave(buf); | |
380 | argv[1] = strsave("user"); | |
381 | argv[2] = strsave(uname); | |
382 | if (status = sms_query("add_member_to_list", 3, argv, | |
383 | scream, (char *) NULL)) { | |
384 | Put_message("\r\n"); | |
385 | com_err(whoami, status, " found.\n"); | |
386 | } | |
387 | else { | |
388 | (void) sprintf(buf, "User %s added to list\r", uname); | |
389 | show_text(DISPROW + 3, STARTCOL, buf); | |
390 | } | |
391 | currow = DISPROW + 4; | |
392 | show_text(DISPROW + 4, STARTCOL, "Press any Key to continue..."); | |
393 | (void) getchar(); | |
394 | } | |
395 | clrwin(DISPROW); | |
396 | } | |
397 | ||
398 | /****************************************************/ | |
399 | delete_member() | |
400 | { | |
401 | char *argv[3]; | |
402 | char *buf; | |
403 | char c; | |
404 | ||
405 | show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r"); | |
406 | buf = calloc(LISTMAX, 1); | |
407 | if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { | |
408 | Put_message("\r\n"); | |
409 | argv[0] = strsave(buf); | |
410 | argv[1] = strsave("user"); | |
411 | argv[2] = strsave(uname); | |
412 | if (status = sms_query("delete_member_from_list", 3, argv, | |
413 | scream, (char *) NULL)) { | |
414 | Put_message("\r\n"); | |
415 | com_err(whoami, status, " found.\n"); | |
416 | } | |
417 | else { | |
418 | (void) sprintf(buf, "User %s deleted from list\r", uname); | |
419 | show_text(DISPROW + 3, STARTCOL, buf); | |
420 | } | |
421 | currow = DISPROW + 4; | |
422 | show_text(DISPROW + 4, STARTCOL, "Press any Key to continue..."); | |
423 | (void) getchar(); | |
424 | } | |
425 | clrwin(DISPROW); | |
426 | } | |
427 | ||
428 | /****************************************************/ | |
429 | list_by_member() | |
430 | { | |
431 | char *nargv[3]; | |
432 | char *buf; | |
433 | char c; | |
434 | ||
435 | nargv[1] = strsave("ruser"); | |
436 | nargv[2] = strsave(uname); | |
437 | buf = calloc(BUFSIZ, 1); | |
438 | (void) sprintf(buf, "%s is on the following lists:\r", uname); | |
439 | show_text(DISPROW, STARTCOL, buf); | |
440 | mvcur(0, 0, currow, STARTCOL); | |
441 | refresh(); | |
442 | if (status = sms_query("get_lists_of_member", 2, nargv + 1, | |
443 | print_1, (char *) NULL)) { | |
444 | Put_message("\r\n"); | |
445 | com_err(whoami, status, " in get_lists_of_member"); | |
446 | } | |
447 | show_text(currow, STARTCOL, "Press any Key to continue..."); | |
448 | (void) getchar(); | |
449 | clrwin(DISPROW); | |
450 | return; | |
451 | } | |
452 | ||
453 | /****************************************************/ | |
454 | show_all() | |
455 | { | |
456 | char c; | |
457 | ||
458 | show_text(DISPROW, STARTCOL, "This function may take a \ | |
459 | while... proceed? [y] "); | |
460 | c = getchar(); | |
461 | if (c == 'y' || c == 'Y' || c == '\n') { | |
462 | move(DISPROW + 1, STARTCOL); | |
463 | addstr("Processing query...please hold"); | |
464 | refresh(); | |
465 | (void) list_all_groups(); | |
466 | } | |
467 | else | |
468 | erase_line(DISPROW, STARTCOL); | |
469 | return; | |
470 | ||
471 | } | |
472 | ||
473 | /****************************************************/ | |
474 | /*ARGSUSED*/ | |
475 | static int | |
476 | print_1(argc, argv, callback) | |
477 | int argc; | |
478 | char *argv[], *callback; | |
479 | { | |
480 | char buf[BUFSIZ]; | |
481 | ||
482 | /* no newline 'cause Put_message adds one */ | |
483 | (void) sprintf(buf, "%s\r", argv[0]); | |
484 | (void) start_display(buf); | |
485 | ||
486 | return (0); | |
487 | } | |
488 | ||
489 | /****************************************************/ | |
490 | /*ARGSUSED*/ | |
491 | static int | |
492 | print_all(argc, argv, callback) | |
493 | int argc; | |
494 | char *argv[], *callback; | |
495 | { | |
496 | char buf[BUFSIZ]; | |
497 | ||
498 | if (moreflg) | |
499 | return (0); | |
500 | if (first_time) { | |
501 | erase_line(DISPROW + 1, STARTCOL); | |
502 | show_text(DISPROW + 1, STARTCOL, "All mailing lists:"); | |
503 | first_time = 0; | |
504 | } | |
505 | (void) sprintf(buf, "%s\r", argv[0]); | |
506 | (void) start_display(buf); | |
507 | ||
508 | return (0); | |
509 | } | |
510 | ||
511 | /****************************************************/ | |
512 | list_all_groups() | |
513 | { | |
514 | char *argv[5]; | |
515 | argv[0] = argv[3] = "true"; | |
516 | argv[1] = argv[4] = "dontcare"; | |
517 | argv[2] = "false"; | |
518 | first_time = 1; | |
519 | if (status = sms_query("qualified_get_lists", 5, argv, | |
520 | print_all, (char *) NULL)) { | |
521 | Put_message("\r\n"); | |
522 | com_err(whoami, status, " in list_all_groups\n"); | |
523 | } | |
524 | end_display(); | |
525 | ||
526 | return (DM_NORMAL); /* HA! */ | |
527 | } | |
528 | ||
529 | /****************************************************/ | |
530 | list_members() | |
531 | { | |
532 | char *argv[1]; | |
533 | char *buf; | |
534 | char buffer[80]; | |
535 | ||
536 | found_some = 0; | |
537 | move(DISPROW, STARTCOL); | |
538 | mvcur(0, 0, DISPROW, STARTCOL); | |
539 | refresh(); | |
540 | buf = calloc(LISTMAX, 1); | |
541 | if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { | |
542 | (void) sprintf(buffer, "The members of list '%s' are:", buf); | |
543 | show_text(DISPROW + 1, STARTCOL, buffer); | |
544 | argv[0] = buf; | |
545 | if (status = sms_query("get_members_of_list", 1, argv, | |
546 | print_2, (char *) NULL)) { | |
547 | Put_message("\r\n"); | |
548 | com_err(whoami, status, " found.\n"); | |
549 | currow++; | |
550 | } | |
551 | if (!found_some) { | |
552 | show_text(currow, STARTCOL, "List is empty (no members)."); | |
553 | currow++; | |
554 | show_text(currow, STARTCOL, "Press any key to continue..."); | |
555 | getchar(); | |
556 | clrwin(DISPROW); | |
557 | return; | |
558 | } | |
559 | end_display(); | |
560 | return(0); | |
561 | } | |
562 | clrwin(DISPROW); | |
563 | return (DM_NORMAL); /* HA! */ | |
564 | } | |
565 | ||
566 | /****************************************************/ | |
567 | /*ARGSUSED*/ | |
568 | static int | |
569 | print_2(argc, argv, callback) | |
570 | int argc; | |
571 | char *argv[], *callback; | |
572 | { | |
573 | char buf[BUFSIZ]; | |
574 | ||
575 | found_some = 1; | |
576 | (void) sprintf(buf, "%s %s", argv[0], argv[1]); | |
577 | (void) start_display(buf); | |
578 | ||
579 | return (0); | |
580 | } | |
581 | ||
582 | /****************************************************/ | |
583 | start_display(buff) | |
584 | char *buff; | |
585 | { | |
586 | char *buffer; | |
587 | ||
588 | num_members++; | |
589 | if (moreflg) | |
590 | return(0); | |
591 | buffer = calloc(50, 1); | |
592 | if (currow >= LINES - 2) { | |
593 | page++; | |
594 | currow++; | |
595 | mvcur(0, 0, currow, STARTCOL); | |
596 | refresh(); | |
597 | if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) { | |
598 | Put_message("Flushing query..."); | |
599 | moreflg = 1; | |
600 | return (0); | |
601 | } | |
602 | clrwin(DISPROW + 2); | |
603 | currow = DISPROW + 2; | |
604 | (void) sprintf(buffer, "Continued (Page %d)", page); | |
605 | show_text(currow, STARTCOL, buffer); | |
606 | currow++; | |
607 | toggle = 0; | |
608 | } | |
609 | if (!toggle) | |
610 | show_text(currow, STARTCOL, buff); | |
611 | else { | |
612 | show_text(currow, SECONDCOL, buff); | |
613 | currow++; | |
614 | } | |
615 | toggle = !toggle; | |
616 | return(0); | |
617 | } | |
618 | ||
619 | /****************************************************/ | |
620 | end_display() | |
621 | { | |
622 | char *buffer, c; | |
623 | ||
624 | if (moreflg) { | |
625 | clrwin(DISPROW); | |
626 | return; | |
627 | } | |
628 | ||
629 | buffer = calloc(50, 1); | |
630 | currow++; | |
631 | (void) sprintf(buffer, "End of List. %d Total Members\r", num_members); | |
632 | show_text(currow, STARTCOL, buffer); | |
633 | currow++; | |
634 | show_text(currow, STARTCOL, "Press any key to continue..."); | |
635 | (void) getchar(); | |
636 | clrwin(DISPROW); | |
637 | ||
638 | } | |
639 | ||
640 | /****************************************************/ | |
641 | display_menu(menu) | |
642 | MENU *menu; | |
643 | { | |
644 | int i; | |
645 | ||
646 | cls(); | |
647 | title(menu->title); | |
648 | mvcur(0, 0, STARTROW, STARTCOL); | |
649 | refresh(); | |
650 | for (i = 0; i <= menu->num_items - 1; i++) { | |
651 | move(STARTROW + i, STARTCOL); | |
652 | standend(); | |
653 | addstr(menu->items[i]); | |
654 | refresh(); | |
655 | } | |
656 | center_text(STARTROW + menu->num_items + 2, | |
657 | "Enter a number, <up arrow>, or <down arrow>."); | |
658 | if (!level) | |
659 | center_text(STARTROW + menu->num_items + 3, | |
660 | "Press 'q' to exit, <return> to confirm choice."); | |
661 | else | |
662 | center_text(STARTROW + menu->num_items + 3, | |
663 | "Press 'q' to exit, 'r' for main menu, <return> to confirm choice."); | |
664 | ||
665 | if (!level) | |
666 | highlight(main_menu); | |
667 | } | |
668 | ||
669 | /****************************************************/ | |
670 | pack_main_menu() | |
671 | { | |
672 | char *buf; | |
673 | ||
674 | main_menu = (MENU *) malloc((unsigned) sizeof(MENU)); | |
675 | main_menu->num_items = 7; | |
676 | main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items); | |
677 | ||
678 | buf = calloc(50, 1); | |
679 | (void) sprintf(buf, "Mail List Program for %s", uname); | |
680 | main_menu->title = strsave(buf); | |
681 | main_menu->items[0] = strsave("1. Show all mailing lists."); | |
682 | main_menu->items[1] = strsave("2. Get all members of a mailing list."); | |
683 | main_menu->items[2] = strsave("3. Display lists of which you are a member."); | |
684 | main_menu->items[3] = strsave("4. Show description of list."); | |
685 | main_menu->items[4] = strsave("5. Add yourself to a mailing list."); | |
686 | main_menu->items[5] = strsave("6. Delete yourself from a mailing list."); | |
687 | main_menu->items[6] = strsave("q. Quit."); | |
688 | } | |
689 | ||
690 | /****************************************************/ | |
691 | pack_help_menu() | |
692 | { | |
693 | help_menu = (MENU *) malloc((unsigned) sizeof(MENU)); | |
694 | help_menu->num_items = 5; | |
695 | help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items); | |
696 | ||
697 | help_menu->title = strsave("mailmaint is designed as a basic mail list administration program."); | |
698 | help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like"); | |
699 | help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the"); | |
700 | help_menu->items[2] = strsave("program listmaint."); | |
701 | help_menu->items[3] = strsave(" "); | |
702 | help_menu->items[4] = strsave("Press any key to continue."); | |
703 | } | |
704 | ||
705 | /****************************************************/ | |
706 | highlight(menu) | |
707 | MENU *menu; | |
708 | { | |
709 | ||
710 | ||
711 | if (oldpos[level] != position[level]) { | |
712 | move(STARTROW + oldpos[level] - 1, STARTCOL); | |
713 | standend(); | |
714 | addstr(menu->items[oldpos[level] - 1]); | |
715 | refresh(); | |
716 | } | |
717 | ||
718 | move(STARTROW + position[level] - 1, STARTCOL); | |
719 | standout(); | |
720 | addstr(menu->items[position[level] - 1]); | |
721 | refresh(); | |
722 | standend(); | |
723 | refresh(); | |
724 | } | |
725 | ||
726 | /****************************************************/ | |
727 | title(buff) | |
728 | char *buff; | |
729 | { | |
730 | move(0, MAX(0, (COLS - strlen(buff)) >> 1)); | |
731 | standout(); | |
732 | addstr(buff); | |
733 | refresh(); | |
734 | standend(); | |
735 | } | |
736 | ||
737 | /****************************************************/ | |
738 | center_text(row, buff) | |
739 | int row; | |
740 | char *buff; | |
741 | { | |
742 | move(row, MAX(0, (COLS - strlen(buff)) >> 1)); | |
743 | addstr(buff); | |
744 | refresh(); | |
745 | } | |
746 | ||
747 | /****************************************************/ | |
748 | show_text(row, col, buff) | |
749 | int row, col; | |
750 | char *buff; | |
751 | { | |
752 | mvcur(0, 0, row, col); | |
753 | refresh(); | |
754 | printf("%s", buff); | |
755 | } | |
756 | ||
757 | /****************************************************/ | |
758 | erase_line(row, col) | |
759 | int row, col; | |
760 | { | |
761 | char *buff; | |
762 | int i; | |
763 | ||
764 | buff = calloc((unsigned)COLS, 1); | |
765 | for (i = 0; i <= COLS - 2; i++) | |
766 | buff[i] = ' '; | |
767 | buff[i] = 0; /* just to be sure ! */ | |
768 | move(row, col); | |
769 | mvcur(0, 0, row, col); | |
770 | printf("%s", buff); | |
771 | refresh(); | |
772 | } | |
773 | ||
774 | /****************************************************/ | |
775 | cls() | |
776 | { | |
777 | clear(); | |
778 | refresh(); | |
779 | } | |
780 | ||
781 | /****************************************************/ | |
782 | clrwin(erase_row) | |
783 | int erase_row; | |
784 | { | |
785 | int i; | |
786 | char *buff; | |
787 | int maxcol; | |
788 | ||
789 | maxcol = COLS; | |
790 | if (maxcol > 80) | |
791 | maxcol = 80; /* limit width */ | |
792 | ||
793 | buff = calloc((unsigned)maxcol + 1, 1); | |
794 | for (i = 0; i <= maxcol - 1; i++) | |
795 | buff[i] = ' '; | |
796 | buff[i] = 0; /* just to be sure ! */ | |
797 | mvcur(0, 0, erase_row, STARTCOL); | |
798 | refresh(); | |
799 | for (i = erase_row; i <= currow - 1; i++) { | |
800 | printf("%s\n\r", buff); | |
801 | } | |
802 | printf("%s", buff); | |
803 | mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL); | |
804 | refresh(); | |
805 | } | |
806 | ||
807 | /****************************************************/ | |
808 | ||
809 | static void | |
810 | scream() | |
811 | { | |
812 | com_err(whoami, status, "\nAn SMS update returned a value -- programmer \ | |
813 | botch\n"); | |
814 | sms_disconnect(); | |
815 | exit(1); | |
816 | } | |
817 | ||
818 | /****************************************************/ | |
819 | /*ARGSUSED*/ | |
820 | static int | |
821 | fetch_list_info(list, li) | |
822 | char *list; | |
823 | List_info *li; | |
824 | { | |
825 | char *argv[1]; | |
826 | ||
827 | argv[0] = list; | |
828 | return sms_query("get_list_info", 1, argv, get_list_info, (char *) NULL); | |
829 | } | |
830 | ||
831 | /* ARGSUSED */ | |
832 | static int | |
833 | get_list_info(argc, argv) | |
834 | int argc; | |
835 | char **argv; | |
836 | { | |
837 | ||
838 | if (current_li->acl_type) | |
839 | free(current_li->acl_type); | |
840 | current_li->acl_type = strsave(argv[7]); | |
841 | if (current_li->acl_name) | |
842 | free(current_li->acl_name); | |
843 | current_li->acl_name = strsave(argv[8]); | |
844 | if (current_li->desc) | |
845 | free(current_li->desc); | |
846 | current_li->desc = strsave(argv[9]); | |
847 | if (current_li->modtime) | |
848 | free(current_li->modtime); | |
849 | current_li->modtime = strsave(argv[10]); | |
850 | if (current_li->modby) | |
851 | free(current_li->modby); | |
852 | current_li->modby = strsave(argv[11]); | |
853 | if (current_li->modwith) | |
854 | free(current_li->modwith); | |
855 | current_li->modwith = strsave(argv[12]); | |
856 | return (0); | |
857 | } | |
858 | ||
859 | ||
860 | ||
861 | ||
862 | /****************************************************/ | |
863 | /* Prompt the user for input */ | |
864 | int | |
865 | Prompt(prompt, buf, buflen, crok) | |
866 | char *prompt; | |
867 | char *buf; | |
868 | int buflen; | |
869 | int crok; | |
870 | { | |
871 | int c; | |
872 | char *p; | |
873 | int x, oldx; | |
874 | ||
875 | printf("%s", prompt); | |
876 | refresh(); | |
877 | for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) { | |
878 | refresh(); | |
879 | c = getchar(); | |
880 | switch (c) { | |
881 | case CTL('C'): | |
882 | return 0; | |
883 | case CTL('Z'): | |
884 | return 0; | |
885 | case CTL('L'): | |
886 | cls(); | |
887 | display_menu(main_menu); | |
888 | return (0); | |
889 | case '\n': | |
890 | case '\r': | |
891 | if (crok) | |
892 | Put_message("\r"); | |
893 | *p = '\0'; | |
894 | if (strlen(buf) < 1)/* only \n or \r in buff */ | |
895 | return (-1); | |
896 | else | |
897 | return (1); | |
898 | case '\b': | |
899 | case '\177': | |
900 | if (p > buf) { | |
901 | p--; | |
902 | x--; | |
903 | printf("\b \b"); | |
904 | } | |
905 | break; | |
906 | case CTL('U'): | |
907 | case CTL('G'): | |
908 | case CTL('['): | |
909 | x = oldx; | |
910 | while (p-- > buf) | |
911 | printf("\b \b"); | |
912 | p = buf; | |
913 | break; | |
914 | default: | |
915 | if (abs(strlen(p) - strlen(buf)) >= buflen) { | |
916 | printf("%c", 7); | |
917 | break; | |
918 | } | |
919 | if (isprint(c)) { | |
920 | (void) addch(c); | |
921 | *p++ = c; | |
922 | x++; | |
923 | } | |
924 | else | |
925 | (void) putchar(CTL('G')); | |
926 | break; | |
927 | } | |
928 | } | |
929 | return(0); | |
930 | } | |
931 | ||
932 | ||
933 | /* | |
934 | * Hook function to cause error messages to be printed through | |
935 | * curses instead of around it. | |
936 | */ | |
937 | ||
938 | int | |
939 | menu_err_hook(who, code, fmt, args) | |
940 | char *who; | |
941 | int code; | |
942 | char *fmt; | |
943 | va_list args; | |
944 | { | |
945 | char buf[BUFSIZ], *cp; | |
946 | ||
947 | FILE _strbuf; | |
948 | ||
949 | (void) strcpy(buf, who); | |
950 | for (cp = buf; *cp; cp++); | |
951 | *cp++ = ':'; | |
952 | *cp++ = ' '; | |
953 | if (code) { | |
954 | (void) strcpy(cp, error_message(code)); | |
955 | while (*cp) | |
956 | cp++; | |
957 | } | |
958 | _strbuf._flag = _IOWRT + _IOSTRG; | |
959 | _strbuf._ptr = cp; | |
960 | _strbuf._cnt = BUFSIZ - (cp - buf); | |
961 | _doprnt(fmt, args, &_strbuf); | |
962 | (void) putc('\0', &_strbuf); | |
963 | Put_message(buf); | |
964 | } |