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