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