]>
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 | currow++; | |
448 | show_text(currow, STARTCOL, "Press any Key to continue..."); | |
449 | (void) getchar(); | |
450 | clrwin(DISPROW); | |
451 | return; | |
452 | } | |
453 | ||
454 | /****************************************************/ | |
455 | show_all() | |
456 | { | |
457 | char c; | |
458 | ||
459 | show_text(DISPROW, STARTCOL, "This function may take a \ | |
460 | while... proceed? [y] "); | |
461 | c = getchar(); | |
462 | if (c == 'y' || c == 'Y' || c == '\n') { | |
463 | move(DISPROW + 1, STARTCOL); | |
464 | addstr("Processing query...please hold"); | |
465 | refresh(); | |
466 | (void) list_all_groups(); | |
467 | } | |
468 | else | |
469 | erase_line(DISPROW, STARTCOL); | |
470 | return; | |
471 | ||
472 | } | |
473 | ||
474 | /****************************************************/ | |
475 | /*ARGSUSED*/ | |
476 | static int | |
477 | print_1(argc, argv, callback) | |
478 | int argc; | |
479 | char *argv[], *callback; | |
480 | { | |
481 | char buf[BUFSIZ]; | |
482 | ||
483 | /* no newline 'cause Put_message adds one */ | |
484 | (void) sprintf(buf, "%s\r", argv[0]); | |
485 | (void) start_display(buf); | |
486 | ||
487 | return (0); | |
488 | } | |
489 | ||
490 | /****************************************************/ | |
491 | /*ARGSUSED*/ | |
492 | static int | |
493 | print_all(argc, argv, callback) | |
494 | int argc; | |
495 | char *argv[], *callback; | |
496 | { | |
497 | char buf[BUFSIZ]; | |
498 | ||
499 | if (moreflg) | |
500 | return (0); | |
501 | if (first_time) { | |
502 | erase_line(DISPROW + 1, STARTCOL); | |
503 | show_text(DISPROW + 1, STARTCOL, "All mailing lists:"); | |
504 | first_time = 0; | |
505 | } | |
506 | (void) sprintf(buf, "%s\r", argv[0]); | |
507 | (void) start_display(buf); | |
508 | ||
509 | return (0); | |
510 | } | |
511 | ||
512 | /****************************************************/ | |
513 | list_all_groups() | |
514 | { | |
515 | char *argv[5]; | |
516 | argv[0] = argv[3] = "true"; | |
517 | argv[1] = argv[4] = "dontcare"; | |
518 | argv[2] = "false"; | |
519 | first_time = 1; | |
520 | if (status = sms_query("qualified_get_lists", 5, argv, | |
521 | print_all, (char *) NULL)) { | |
522 | Put_message("\r\n"); | |
523 | com_err(whoami, status, " in list_all_groups\n"); | |
524 | } | |
525 | end_display(); | |
526 | ||
527 | return (DM_NORMAL); /* HA! */ | |
528 | } | |
529 | ||
530 | /****************************************************/ | |
531 | list_members() | |
532 | { | |
533 | char *argv[1]; | |
534 | char *buf; | |
535 | char buffer[80]; | |
536 | ||
537 | found_some = 0; | |
538 | move(DISPROW, STARTCOL); | |
539 | mvcur(0, 0, DISPROW, STARTCOL); | |
540 | refresh(); | |
541 | buf = calloc(LISTMAX, 1); | |
542 | if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { | |
543 | (void) sprintf(buffer, "The members of list '%s' are:", buf); | |
544 | show_text(DISPROW + 1, STARTCOL, buffer); | |
545 | argv[0] = buf; | |
546 | if (status = sms_query("get_members_of_list", 1, argv, | |
547 | print_2, (char *) NULL)) { | |
548 | Put_message("\r\n"); | |
549 | com_err(whoami, status, " found.\n"); | |
550 | currow++; | |
551 | } | |
552 | if (!found_some) { | |
553 | show_text(currow, STARTCOL, "List is empty (no members)."); | |
554 | currow++; | |
555 | show_text(currow, STARTCOL, "Press any key to continue..."); | |
556 | getchar(); | |
557 | clrwin(DISPROW); | |
558 | return; | |
559 | } | |
560 | end_display(); | |
561 | return(0); | |
562 | } | |
563 | clrwin(DISPROW); | |
564 | return (DM_NORMAL); /* HA! */ | |
565 | } | |
566 | ||
567 | /****************************************************/ | |
568 | /*ARGSUSED*/ | |
569 | static int | |
570 | print_2(argc, argv, callback) | |
571 | int argc; | |
572 | char *argv[], *callback; | |
573 | { | |
574 | char buf[BUFSIZ]; | |
575 | ||
576 | found_some = 1; | |
577 | (void) sprintf(buf, "%s %s", argv[0], argv[1]); | |
578 | (void) start_display(buf); | |
579 | ||
580 | return (0); | |
581 | } | |
582 | ||
583 | /****************************************************/ | |
584 | start_display(buff) | |
585 | char *buff; | |
586 | { | |
587 | char *buffer; | |
588 | ||
589 | num_members++; | |
590 | if (moreflg) | |
591 | return(0); | |
592 | buffer = calloc(50, 1); | |
593 | if (currow >= LINES - 2) { | |
594 | page++; | |
595 | currow++; | |
596 | mvcur(0, 0, currow, STARTCOL); | |
597 | refresh(); | |
598 | if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) { | |
599 | Put_message("Flushing query..."); | |
600 | moreflg = 1; | |
601 | return (0); | |
602 | } | |
603 | clrwin(DISPROW + 2); | |
604 | currow = DISPROW + 2; | |
605 | (void) sprintf(buffer, "Continued (Page %d)", page); | |
606 | show_text(currow, STARTCOL, buffer); | |
607 | currow++; | |
608 | toggle = 0; | |
609 | } | |
610 | if (!toggle) | |
611 | show_text(currow, STARTCOL, buff); | |
612 | else { | |
613 | show_text(currow, SECONDCOL, buff); | |
614 | currow++; | |
615 | } | |
616 | toggle = !toggle; | |
617 | return(0); | |
618 | } | |
619 | ||
620 | /****************************************************/ | |
621 | end_display() | |
622 | { | |
623 | char *buffer, c; | |
624 | ||
625 | if (moreflg) { | |
626 | clrwin(DISPROW); | |
627 | return; | |
628 | } | |
629 | ||
630 | buffer = calloc(50, 1); | |
631 | currow++; | |
632 | (void) sprintf(buffer, "End of List. %d Total Members\r", num_members); | |
633 | show_text(currow, STARTCOL, buffer); | |
634 | currow++; | |
635 | show_text(currow, STARTCOL, "Press any key to continue..."); | |
636 | (void) getchar(); | |
637 | clrwin(DISPROW); | |
638 | ||
639 | } | |
640 | ||
641 | /****************************************************/ | |
642 | display_menu(menu) | |
643 | MENU *menu; | |
644 | { | |
645 | int i; | |
646 | ||
647 | cls(); | |
648 | title(menu->title); | |
649 | mvcur(0, 0, STARTROW, STARTCOL); | |
650 | refresh(); | |
651 | for (i = 0; i <= menu->num_items - 1; i++) { | |
652 | move(STARTROW + i, STARTCOL); | |
653 | standend(); | |
654 | addstr(menu->items[i]); | |
655 | refresh(); | |
656 | } | |
657 | center_text(STARTROW + menu->num_items + 2, | |
658 | "Enter a number, <up arrow>, or <down arrow>."); | |
659 | if (!level) | |
660 | center_text(STARTROW + menu->num_items + 3, | |
661 | "Press 'q' to exit, <return> to confirm choice."); | |
662 | else | |
663 | center_text(STARTROW + menu->num_items + 3, | |
664 | "Press 'q' to exit, 'r' for main menu, <return> to confirm choice."); | |
665 | ||
666 | if (!level) | |
667 | highlight(main_menu); | |
668 | } | |
669 | ||
670 | /****************************************************/ | |
671 | pack_main_menu() | |
672 | { | |
673 | char *buf; | |
674 | ||
675 | main_menu = (MENU *) malloc((unsigned) sizeof(MENU)); | |
676 | main_menu->num_items = 7; | |
677 | main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items); | |
678 | ||
679 | buf = calloc(50, 1); | |
680 | (void) sprintf(buf, "Mail List Program for %s", uname); | |
681 | main_menu->title = strsave(buf); | |
682 | main_menu->items[0] = strsave("1. Show all mailing lists."); | |
683 | main_menu->items[1] = strsave("2. Get all members of a mailing list."); | |
684 | main_menu->items[2] = strsave("3. Display lists of which you are a member."); | |
685 | main_menu->items[3] = strsave("4. Show description of list."); | |
686 | main_menu->items[4] = strsave("5. Add yourself to a mailing list."); | |
687 | main_menu->items[5] = strsave("6. Delete yourself from a mailing list."); | |
688 | main_menu->items[6] = strsave("q. Quit."); | |
689 | } | |
690 | ||
691 | /****************************************************/ | |
692 | pack_help_menu() | |
693 | { | |
694 | help_menu = (MENU *) malloc((unsigned) sizeof(MENU)); | |
695 | help_menu->num_items = 5; | |
696 | help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items); | |
697 | ||
698 | help_menu->title = strsave("mailmaint is designed as a basic mail list administration program."); | |
699 | help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like"); | |
700 | help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the"); | |
701 | help_menu->items[2] = strsave("program listmaint."); | |
702 | help_menu->items[3] = strsave(" "); | |
703 | help_menu->items[4] = strsave("Press any key to continue."); | |
704 | } | |
705 | ||
706 | /****************************************************/ | |
707 | highlight(menu) | |
708 | MENU *menu; | |
709 | { | |
710 | ||
711 | ||
712 | if (oldpos[level] != position[level]) { | |
713 | move(STARTROW + oldpos[level] - 1, STARTCOL); | |
714 | standend(); | |
715 | addstr(menu->items[oldpos[level] - 1]); | |
716 | refresh(); | |
717 | } | |
718 | ||
719 | move(STARTROW + position[level] - 1, STARTCOL); | |
720 | standout(); | |
721 | addstr(menu->items[position[level] - 1]); | |
722 | refresh(); | |
723 | standend(); | |
724 | refresh(); | |
725 | } | |
726 | ||
727 | /****************************************************/ | |
728 | title(buff) | |
729 | char *buff; | |
730 | { | |
731 | move(0, MAX(0, (COLS - strlen(buff)) >> 1)); | |
732 | standout(); | |
733 | addstr(buff); | |
734 | refresh(); | |
735 | standend(); | |
736 | } | |
737 | ||
738 | /****************************************************/ | |
739 | center_text(row, buff) | |
740 | int row; | |
741 | char *buff; | |
742 | { | |
743 | move(row, MAX(0, (COLS - strlen(buff)) >> 1)); | |
744 | addstr(buff); | |
745 | refresh(); | |
746 | } | |
747 | ||
748 | /****************************************************/ | |
749 | show_text(row, col, buff) | |
750 | int row, col; | |
751 | char *buff; | |
752 | { | |
753 | mvcur(0, 0, row, col); | |
754 | refresh(); | |
755 | printf("%s", buff); | |
756 | } | |
757 | ||
758 | /****************************************************/ | |
759 | erase_line(row, col) | |
760 | int row, col; | |
761 | { | |
762 | char *buff; | |
763 | int i; | |
764 | ||
765 | buff = calloc((unsigned)COLS, 1); | |
766 | for (i = 0; i <= COLS - 2; i++) | |
767 | buff[i] = ' '; | |
768 | buff[i] = 0; /* just to be sure ! */ | |
769 | move(row, col); | |
770 | mvcur(0, 0, row, col); | |
771 | printf("%s", buff); | |
772 | refresh(); | |
773 | } | |
774 | ||
775 | /****************************************************/ | |
776 | cls() | |
777 | { | |
778 | clear(); | |
779 | refresh(); | |
780 | } | |
781 | ||
782 | /****************************************************/ | |
783 | clrwin(erase_row) | |
784 | int erase_row; | |
785 | { | |
786 | int i; | |
787 | char *buff; | |
788 | int maxcol; | |
789 | ||
790 | maxcol = COLS; | |
791 | if (maxcol > 80) | |
792 | maxcol = 80; /* limit width */ | |
793 | ||
794 | buff = calloc((unsigned)maxcol + 1, 1); | |
795 | for (i = 0; i <= maxcol - 1; i++) | |
796 | buff[i] = ' '; | |
797 | buff[i] = 0; /* just to be sure ! */ | |
798 | mvcur(0, 0, erase_row, STARTCOL); | |
799 | refresh(); | |
800 | for (i = erase_row; i <= currow - 1; i++) { | |
801 | printf("%s\n\r", buff); | |
802 | } | |
803 | printf("%s", buff); | |
804 | mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL); | |
805 | refresh(); | |
806 | } | |
807 | ||
808 | /****************************************************/ | |
809 | ||
810 | static void | |
811 | scream() | |
812 | { | |
813 | com_err(whoami, status, "\nAn SMS update returned a value -- programmer \ | |
814 | botch\n"); | |
815 | sms_disconnect(); | |
816 | exit(1); | |
817 | } | |
818 | ||
819 | /****************************************************/ | |
820 | /*ARGSUSED*/ | |
821 | static int | |
822 | fetch_list_info(list, li) | |
823 | char *list; | |
824 | List_info *li; | |
825 | { | |
826 | char *argv[1]; | |
827 | ||
828 | argv[0] = list; | |
829 | return sms_query("get_list_info", 1, argv, get_list_info, (char *) NULL); | |
830 | } | |
831 | ||
832 | /* ARGSUSED */ | |
833 | static int | |
834 | get_list_info(argc, argv) | |
835 | int argc; | |
836 | char **argv; | |
837 | { | |
838 | ||
839 | if (current_li->acl_type) | |
840 | free(current_li->acl_type); | |
841 | current_li->acl_type = strsave(argv[7]); | |
842 | if (current_li->acl_name) | |
843 | free(current_li->acl_name); | |
844 | current_li->acl_name = strsave(argv[8]); | |
845 | if (current_li->desc) | |
846 | free(current_li->desc); | |
847 | current_li->desc = strsave(argv[9]); | |
848 | if (current_li->modtime) | |
849 | free(current_li->modtime); | |
850 | current_li->modtime = strsave(argv[10]); | |
851 | if (current_li->modby) | |
852 | free(current_li->modby); | |
853 | current_li->modby = strsave(argv[11]); | |
854 | if (current_li->modwith) | |
855 | free(current_li->modwith); | |
856 | current_li->modwith = strsave(argv[12]); | |
857 | return (0); | |
858 | } | |
859 | ||
860 | ||
861 | ||
862 | ||
863 | /****************************************************/ | |
864 | /* Prompt the user for input */ | |
865 | int | |
866 | Prompt(prompt, buf, buflen, crok) | |
867 | char *prompt; | |
868 | char *buf; | |
869 | int buflen; | |
870 | int crok; | |
871 | { | |
872 | int c; | |
873 | char *p; | |
874 | int x, oldx; | |
875 | ||
876 | printf("%s", prompt); | |
877 | refresh(); | |
878 | for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) { | |
879 | refresh(); | |
880 | c = getchar(); | |
881 | switch (c) { | |
882 | case CTL('C'): | |
883 | return 0; | |
884 | case CTL('Z'): | |
885 | return 0; | |
886 | case CTL('L'): | |
887 | cls(); | |
888 | display_menu(main_menu); | |
889 | return (0); | |
890 | case '\n': | |
891 | case '\r': | |
892 | if (crok) | |
893 | Put_message("\r"); | |
894 | *p = '\0'; | |
895 | if (strlen(buf) < 1)/* only \n or \r in buff */ | |
896 | return (-1); | |
897 | else | |
898 | return (1); | |
899 | case '\b': | |
900 | case '\177': | |
901 | if (p > buf) { | |
902 | p--; | |
903 | x--; | |
904 | printf("\b \b"); | |
905 | } | |
906 | break; | |
907 | case CTL('U'): | |
908 | case CTL('G'): | |
909 | case CTL('['): | |
910 | x = oldx; | |
911 | while (p-- > buf) | |
912 | printf("\b \b"); | |
913 | p = buf; | |
914 | break; | |
915 | default: | |
916 | if (abs(strlen(p) - strlen(buf)) >= buflen) { | |
917 | printf("%c", 7); | |
918 | break; | |
919 | } | |
920 | if (isprint(c)) { | |
921 | (void) addch(c); | |
922 | *p++ = c; | |
923 | x++; | |
924 | } | |
925 | else | |
926 | (void) putchar(CTL('G')); | |
927 | break; | |
928 | } | |
929 | } | |
930 | return(0); | |
931 | } | |
932 | ||
933 | ||
934 | /* | |
935 | * Hook function to cause error messages to be printed through | |
936 | * curses instead of around it. | |
937 | */ | |
938 | ||
939 | int | |
940 | menu_err_hook(who, code, fmt, args) | |
941 | char *who; | |
942 | int code; | |
943 | char *fmt; | |
944 | va_list args; | |
945 | { | |
946 | char buf[BUFSIZ], *cp; | |
947 | ||
948 | FILE _strbuf; | |
949 | ||
950 | (void) strcpy(buf, who); | |
951 | for (cp = buf; *cp; cp++); | |
952 | *cp++ = ':'; | |
953 | *cp++ = ' '; | |
954 | if (code) { | |
955 | (void) strcpy(cp, error_message(code)); | |
956 | while (*cp) | |
957 | cp++; | |
958 | } | |
959 | _strbuf._flag = _IOWRT + _IOSTRG; | |
960 | _strbuf._ptr = cp; | |
961 | _strbuf._cnt = BUFSIZ - (cp - buf); | |
962 | _doprnt(fmt, args, &_strbuf); | |
963 | (void) putc('\0', &_strbuf); | |
964 | Put_message(buf); | |
965 | } |