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