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