7 static char rcsid_mailmaint_c[] = "$Header$";
10 /***********************************************************************/
11 /* mailmaint.c - pjlevine - 20 August 1987
14 /***********************************************************************/
21 #include <sys/types.h>
23 #include "mit-copyright.h"
31 #define CTL(ch) ((ch) & 037)
32 #define MAX(A,B) ((A) > (B) ? (A) : (B))
37 extern char *strsave();
39 typedef struct list_info {
45 static char *ascbuff = {"0123456789"};
48 static List_info *current_li = (List_info *) NULL;
49 static int get_list_info();
50 static int fetch_list_info();
55 extern char *strsave();
61 typedef struct _menu {
67 MENU *main_menu, *help_menu;
69 int position[2], oldpos[2];
70 int level, found_some, currow, page, num_members;
71 int moreflg, toggle, first_time;
75 /****************************************************/
89 if ((whoami = rindex(argv[0], '/')) == NULL)
93 uname = calloc(20, 1);
94 if ((current_li = (List_info *) malloc(sizeof(List_info)))
95 == (List_info *) NULL) {
96 (void) sprintf(buf, ": allocating list info");
100 current_li->acl = (char *) NULL;
101 current_li->desc = (char *) NULL;
102 current_li->expdate = (char *) NULL;
104 if ((uname = getlogin()) == NULL) {
105 struct passwd *getpwuid();
107 uname = getpwuid((int) getuid())->pw_name;
109 uname = (uname && strlen(uname)) ? strsave(uname) : "";
111 printf("Connecting to database for %s...please hold on.\n", uname);
113 status = sms_connect();
115 (void) sprintf(buf, "\nConnection to SMS server failed");
121 (void) sprintf(buf, "\nAuthorization failed.\n");
127 if ((LINES < 24) || (COLS < 60)) {
128 Put_message("Display window too small.\n\n");
129 (void) sprintf(buf, "Current window parameters are (%d \
130 lines, %d columns)\n", LINES, COLS);
132 Put_message("Please resize your window\n");
133 Put_message("to at least 24 lines and 60 columns.\n");
138 position[0] = oldpos[0] = 1;
142 display_menu(main_menu);
150 com_err(whoami, status, buf);
154 /****************************************************/
161 oldpos[level] = position[level];
163 currow = DISPROW + 2;
165 toggle = num_members = moreflg = 0;
168 if (position[level] == 7)
171 c = ascbuff[position[level]];
175 case 'L' & 037: /* clear screen */
176 display_menu(main_menu);
181 highlight(main_menu);
187 case '1': /* show all lists */
193 case '2': /* get all members of a list */
196 (void) list_members();
199 case '3': /* display list which user is a recipient */
205 case '4': /* show description */
211 case '5': /* add to list */
217 case '6': /* delete */
223 case 27: /* up arrow */
229 if (!position[level])
235 if (position[level] > 7)
245 highlight(main_menu);
249 /****************************************************/
255 show_text(DISPROW, STARTCOL, "Show information about a list.\n\r");
256 buf = calloc((unsigned)1024, 1);
257 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
259 if (fetch_list_info(buf, current_li) == 0) {
260 (void) sprintf(buf, "Description: %s\n\r", current_li->desc);
261 if (strlen(buf) > 60)
262 (void) display_buff(buf);
264 show_text(currow, STARTCOL, buf);
266 (void) sprintf(buf, "List Administrator: %s", current_li->acl);
267 show_text(currow, STARTCOL, buf);
269 (void) sprintf(buf, "Expiration date: %s", current_li->expdate);
270 show_text(currow, STARTCOL, buf);
274 show_text(currow, STARTCOL, "madm: No such list found.");
277 show_text(currow, STARTCOL, "Press any Key to continue...");
283 /****************************************************/
296 printbuf = calloc((unsigned)maxcol, 1);
297 for (i = 0; i <= strlen(buf); i++) {
298 printbuf[cnt] = buf[i];
301 (void) start_display_buff(printbuf);
304 printbuf = calloc((unsigned)maxcol, 1);
307 if (strlen(buf) % maxcol != 0) {
308 (void) start_display_buff(printbuf);
314 /****************************************************/
315 start_display_buff(buff)
323 if (currow >= LINES - 2) {
326 mvcur(0, 0, currow, STARTCOL);
328 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
329 Put_message("Flushing query...");
334 currow = DISPROW + 2;
335 show_text(currow, STARTCOL, "continued");
338 show_text(currow, STARTCOL, buff);
343 /****************************************************/
346 static char *argv[] = {
347 "add_member_to_list",
355 show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r");
356 buf = calloc(LISTMAX, 1);
357 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
359 argv[1] = strsave(buf);
360 argv[2] = strsave("user");
361 argv[3] = strsave(uname);
362 if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
364 com_err(whoami, status, " found.\n");
367 (void) sprintf(buf, "User %s added to list\r", uname);
368 show_text(DISPROW + 3, STARTCOL, buf);
370 currow = DISPROW + 4;
371 show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
377 /****************************************************/
380 static char *argv[] = {
381 "delete_member_from_list",
389 show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r");
390 buf = calloc(LISTMAX, 1);
391 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
393 argv[1] = strsave(buf);
394 argv[2] = strsave("user");
395 argv[3] = strsave(uname);
396 if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
398 com_err(whoami, status, " found.\n");
401 (void) sprintf(buf, "User %s deleted from list\r", uname);
402 show_text(DISPROW + 3, STARTCOL, buf);
404 currow = DISPROW + 4;
405 show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
411 /****************************************************/
418 nargv[1] = strsave("user");
419 nargv[2] = strsave(uname);
420 buf = calloc(BUFSIZ, 1);
421 (void) sprintf(buf, "%s is on the following lists:\r", uname);
422 show_text(DISPROW, STARTCOL, buf);
423 mvcur(0, 0, currow, STARTCOL);
425 if (status = sms_query("get_lists_of_member", 2, nargv + 1,
426 print_1, (char *) NULL)) {
428 com_err(whoami, status, " in get_lists_of_member");
430 show_text(currow, STARTCOL, "Press any Key to continue...");
436 /****************************************************/
441 show_text(DISPROW, STARTCOL, "This function may take a \
442 while... proceed? [y] ");
444 if (c == 'y' || c == 'Y') {
445 move(DISPROW + 1, STARTCOL);
446 addstr("Processing query...please hold");
448 (void) list_all_groups();
451 erase_line(DISPROW, STARTCOL);
456 /****************************************************/
459 print_1(argc, argv, callback)
461 char *argv[], *callback;
465 /* no newline 'cause Put_message adds one */
466 (void) sprintf(buf, "%s\r", argv[0]);
467 (void) start_display(buf);
472 /****************************************************/
475 print_all(argc, argv, callback)
477 char *argv[], *callback;
484 erase_line(DISPROW + 1, STARTCOL);
485 show_text(DISPROW + 1, STARTCOL, "All mailing lists:");
488 (void) sprintf(buf, "%s\r", argv[0]);
489 (void) start_display(buf);
494 /****************************************************/
499 if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL,
500 print_all, (char *) NULL)) {
502 com_err(whoami, status, " in list_all_groups\n");
506 return (DM_NORMAL); /* HA! */
509 /****************************************************/
517 move(DISPROW, STARTCOL);
518 mvcur(0, 0, DISPROW, STARTCOL);
520 buf = calloc(LISTMAX, 1);
521 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
522 (void) sprintf(buffer, "The members of list '%s' are:", buf);
523 show_text(DISPROW + 1, STARTCOL, buffer);
525 if (status = sms_query("get_members_of_list", 1, argv,
526 print_2, (char *) NULL)) {
528 com_err(whoami, status, " found.\n");
532 show_text(currow, STARTCOL, "List is empty (no members).");
539 return (DM_NORMAL); /* HA! */
542 /****************************************************/
545 print_2(argc, argv, callback)
547 char *argv[], *callback;
552 (void) sprintf(buf, "%s %s", argv[0], argv[1]);
553 (void) start_display(buf);
558 /****************************************************/
567 buffer = calloc(50, 1);
568 if (currow >= LINES - 2) {
571 mvcur(0, 0, currow, STARTCOL);
573 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
574 Put_message("Flushing query...");
579 currow = DISPROW + 2;
580 (void) sprintf(buffer, "Continued (Page %d)", page);
581 show_text(currow, STARTCOL, buffer);
586 show_text(currow, STARTCOL, buff);
588 show_text(currow, SECONDCOL, buff);
595 /****************************************************/
605 buffer = calloc(50, 1);
607 (void) sprintf(buffer, "End of List. %d Total Members\r", num_members);
608 show_text(currow, STARTCOL, buffer);
610 show_text(currow, STARTCOL, "Press any key to continue...");
616 /****************************************************/
624 mvcur(0, 0, STARTROW, STARTCOL);
626 for (i = 0; i <= menu->num_items - 1; i++) {
627 move(STARTROW + i, STARTCOL);
629 addstr(menu->items[i]);
632 center_text(STARTROW + menu->num_items + 2,
633 "Enter a number, <up arrow>, or <down arrow>.");
635 center_text(STARTROW + menu->num_items + 3,
636 "Press 'q' to exit, <return> to confirm choice.");
638 center_text(STARTROW + menu->num_items + 3,
639 "Press 'q' to exit, 'r' for main menu, <return> to confirm choice.");
642 highlight(main_menu);
645 /****************************************************/
650 main_menu = (MENU *) malloc((unsigned) sizeof(MENU));
651 main_menu->num_items = 7;
652 main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items);
655 (void) sprintf(buf, "Mail List Program for %s", uname);
656 main_menu->title = strsave(buf);
657 main_menu->items[0] = strsave("1. Show all mailing lists.");
658 main_menu->items[1] = strsave("2. Get all members of a mailing list.");
659 main_menu->items[2] = strsave("3. Display lists of which you are a member.");
660 main_menu->items[3] = strsave("4. Show description of list.");
661 main_menu->items[4] = strsave("5. Add yourself to a mailing list.");
662 main_menu->items[5] = strsave("6. Delete yourself from a mailing list.");
663 main_menu->items[6] = strsave("q. Quit.");
666 /****************************************************/
669 help_menu = (MENU *) malloc((unsigned) sizeof(MENU));
670 help_menu->num_items = 5;
671 help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items);
673 help_menu->title = strsave("madm is designed as a basic mail list administration program.");
674 help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
675 help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
676 help_menu->items[2] = strsave("program listmaint.");
677 help_menu->items[3] = strsave(" ");
678 help_menu->items[4] = strsave("Press any key to continue.");
681 /****************************************************/
687 if (oldpos[level] != position[level]) {
688 move(STARTROW + oldpos[level] - 1, STARTCOL);
690 addstr(menu->items[oldpos[level] - 1]);
694 move(STARTROW + position[level] - 1, STARTCOL);
696 addstr(menu->items[position[level] - 1]);
702 /****************************************************/
706 move(0, MAX(0, (COLS - strlen(buff)) >> 1));
713 /****************************************************/
714 center_text(row, buff)
718 move(row, MAX(0, (COLS - strlen(buff)) >> 1));
723 /****************************************************/
724 show_text(row, col, buff)
728 mvcur(0, 0, row, col);
733 /****************************************************/
740 buff = calloc((unsigned)COLS, 1);
741 for (i = 0; i <= COLS - 2; i++)
743 buff[i] = 0; /* just to be sure ! */
745 mvcur(0, 0, row, col);
750 /****************************************************/
757 /****************************************************/
767 maxcol = 80; /* limit width */
769 buff = calloc((unsigned)maxcol + 1, 1);
770 for (i = 0; i <= maxcol - 1; i++)
772 buff[i] = 0; /* just to be sure ! */
773 mvcur(0, 0, erase_row, STARTCOL);
775 for (i = erase_row; i <= currow - 1; i++) {
776 printf("%s\n\r", buff);
779 mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL);
783 /****************************************************/
788 com_err(whoami, status, "\nAn SMS update returned a value -- programmer \
794 /****************************************************/
797 fetch_list_info(list, li)
804 if ((status = sms_query("get_list_info", 1, argv,
805 get_list_info, (char *) NULL)) == 0) {
809 com_err(whoami, status, " found.\n");
816 get_list_info(argc, argv)
822 free(current_li->acl);
823 current_li->acl = strsave(argv[2]);
824 if (current_li->desc)
825 free(current_li->desc);
826 current_li->desc = strsave(argv[3]);
827 if (current_li->expdate)
828 free(current_li->expdate);
829 current_li->expdate = strsave(argv[4]);
836 /****************************************************/
837 /* Prompt the user for input */
839 Prompt(prompt, buf, buflen)
848 printf("%s", prompt);
850 for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) {
860 display_menu(main_menu);
866 if (strlen(buf) < 1)/* only \n or \r in buff */
887 if (abs(strlen(p) - strlen(buf)) >= buflen) {
897 (void) putchar(CTL('G'));
908 * c-continued-statement-offset: 4
910 * c-argdecl-indent: 4