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