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