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