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