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