]> andersk Git - moira.git/blame_incremental - clients/mailmaint/mailmaint.c
New database and column names for Moira2.
[moira.git] / clients / mailmaint / mailmaint.c
... / ...
CommitLineData
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
11static char rcsid_mailmaint_c[] = "$Header$";
12#endif lint
13
14/***********************************************************************/
15/* mailmaint.c - pjlevine - 20 August 1987
16
17*/
18/***********************************************************************/
19#include <stdio.h>
20#include <pwd.h>
21#include <signal.h>
22#include <strings.h>
23#include <curses.h>
24#include <sys/types.h>
25#ifndef sun
26#include <varargs.h>
27#endif
28#include <com_err.h>
29#include <ctype.h>
30#include <moira.h>
31#include <moira_site.h>
32#include <mit-copyright.h>
33
34
35#define STARTCOL 0
36#define STARTROW 3
37#define SECONDCOL 30
38#define DISPROW 15
39#define LISTMAX 50
40#define LISTSIZE 32
41#define CTL(ch) ((ch) & 037)
42#define MAX(A,B) ((A) > (B) ? (A) : (B))
43
44char *whoami; /* should not be static, for logging package */
45static int status;
46static int scream();
47extern char *strsave();
48#ifdef __STDC__
49void menu_err_hook(const char *who, long code, const char *fmt, va_list args);
50#else
51void menu_err_hook();
52#define const
53#endif
54
55typedef struct list_info {
56 int active;
57 int public;
58 int hidden;
59 int maillist;
60 int group;
61 char *acl_type;
62 char *acl_name;
63 char *desc;
64 char *modtime;
65 char *modby;
66 char *modwith;
67} List_info;
68
69static char *ascbuff = {"0123456789"};
70static int print_2(), print_1();
71static List_info *current_li = (List_info *) NULL;
72static int get_list_info();
73static int fetch_list_info();
74
75char *malloc();
76char *getlogin();
77extern char *strsave();
78char *getenv();
79char *calloc();
80
81uid_t getuid();
82
83typedef struct _menu {
84 int num_items;
85 char *title;
86 char **items;
87} MENU;
88
89MENU *main_menu, *help_menu;
90
91int position[2], oldpos[2];
92int level, found_some, currow, page, num_members;
93int moreflg, toggle, first_time;
94char *uname;
95
96/* This crock is because the original code was very broken and this makes
97 * it work. Someday, we should abandon the code or fix it right.
98 */
99#define mvcur(oy,ox,ny,nx) move(ny,nx)
100
101/****************************************************/
102/*ARGSUSED*/
103main(argc, argv)
104 int argc;
105 char *argv[];
106
107{
108#ifdef __STDC__
109 void (*old_hook)(const char *, long, const char *, va_list);
110#else
111 void (*old_hook)();
112#endif
113 int use_menu = 1;
114 char buf[BUFSIZ], *motd;
115
116 if ((whoami = rindex(argv[0], '/')) == NULL)
117 whoami = argv[0];
118 else
119 whoami++;
120 uname = calloc(20, 1);
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 ((uname = getlogin()) == NULL) {
135 struct passwd *getpwuid();
136
137 uname = getpwuid((int) getuid())->pw_name;
138 }
139 uname = (uname && strlen(uname)) ? strsave(uname) : "";
140
141 printf("Connecting to database for %s...please hold on.\n", uname);
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 \
171lines, %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
192punt:
193 com_err(whoami, status, buf);
194 exit(1);
195}
196
197/****************************************************/
198get_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/****************************************************/
293show_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/****************************************************/
329display_buff(buf)
330 char *buf;
331{
332 int i, cnt;
333 char *printbuf;
334 int maxcol;
335
336 maxcol = COLS;
337 if (maxcol >= 80)
338 maxcol = 80;
339
340 cnt = 0;
341 printbuf = calloc((unsigned)maxcol, 1);
342 for (i = 0; i <= strlen(buf); i++) {
343 printbuf[cnt] = buf[i];
344 cnt++;
345 if (cnt >= maxcol) {
346 (void) start_display_buff(printbuf);
347 cnt = 0;
348 free(printbuf);
349 printbuf = calloc((unsigned)maxcol, 1);
350 }
351 }
352 if (strlen(buf) % maxcol != 0) {
353 (void) start_display_buff(printbuf);
354 free(printbuf);
355 }
356 return (0);
357}
358
359/****************************************************/
360start_display_buff(buff)
361 char *buff;
362{
363 char buffer[5];
364
365 num_members++;
366 if (moreflg)
367 return (0);
368 if (currow >= LINES - 2) {
369 page++;
370 currow++;
371 mvcur(0, 0, currow, STARTCOL);
372 refresh();
373 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) {
374 display_buff("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/****************************************************/
389add_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(uname);
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", uname);
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/****************************************************/
418delete_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(uname);
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", uname);
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/****************************************************/
447list_by_member()
448{
449 char *nargv[3];
450 char *buf;
451
452 nargv[1] = strsave("ruser");
453 nargv[2] = strsave(uname);
454 buf = calloc(BUFSIZ, 1);
455 (void) sprintf(buf, "%s is on the following lists:\n", uname);
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/****************************************************/
472show_all()
473{
474 char c;
475
476 show_text(DISPROW, STARTCOL, "This function may take a \
477while... proceed? [y] ");
478 c = getchar() & 0x7f;
479 if (c == 'y' || c == 'Y' || c == '\n') {
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*/
493static int
494print_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*/
509static int
510print_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/****************************************************/
530list_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/****************************************************/
548list_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*/
586static int
587print_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/****************************************************/
601start_display(buff)
602 char *buff;
603{
604 char *buffer;
605
606 num_members++;
607 if (moreflg)
608 return(0);
609 buffer = calloc(50, 1);
610 if (currow >= LINES - 2) {
611 page++;
612 mvcur(0, 0, currow, STARTCOL);
613 refresh();
614 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) {
615 display_buff("Flushing query...");
616 moreflg = 1;
617 return (0);
618 }
619 clrwin(DISPROW + 2);
620 currow = DISPROW + 2;
621 (void) sprintf(buffer, "Continued (Page %d)", page);
622 show_text(currow, STARTCOL, buffer);
623 currow++;
624 toggle = 0;
625 }
626 if (!toggle)
627 show_text(currow, STARTCOL, buff);
628 else {
629 show_text(currow, SECONDCOL, buff);
630 currow++;
631 }
632 toggle = !toggle;
633 return(0);
634}
635
636/****************************************************/
637end_display()
638{
639 char *buffer;
640
641 if (moreflg) {
642 clrwin(DISPROW);
643 return;
644 }
645
646 buffer = calloc(50, 1);
647 currow++;
648 (void) sprintf(buffer, "End of List. %d Total Members\n", num_members - 1);
649 show_text(currow, STARTCOL, buffer);
650 currow++;
651 show_text(currow, STARTCOL, "Press any key to continue...");
652 (void) getchar();
653 clrwin(DISPROW);
654
655}
656
657/****************************************************/
658display_menu(menu)
659 MENU *menu;
660{
661 int i;
662
663 cls();
664 title(menu->title);
665 mvcur(0, 0, STARTROW, STARTCOL);
666 refresh();
667 for (i = 0; i <= menu->num_items - 1; i++) {
668 move(STARTROW + i, STARTCOL);
669 standend();
670 addstr(menu->items[i]);
671 refresh();
672 }
673 center_text(STARTROW + menu->num_items + 2,
674 "Enter a number, <up arrow>, or <down arrow>.");
675 if (!level)
676 center_text(STARTROW + menu->num_items + 3,
677 "Press 'q' to exit, <return> to confirm choice.");
678 else
679 center_text(STARTROW + menu->num_items + 3,
680 "Press 'q' to exit, 'r' for main menu, <return> to confirm choice.");
681
682 if (!level)
683 highlight(main_menu);
684}
685
686/****************************************************/
687pack_main_menu()
688{
689 char *buf;
690
691 main_menu = (MENU *) malloc((unsigned) sizeof(MENU));
692 main_menu->num_items = 7;
693 main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items);
694
695 buf = calloc(50, 1);
696 (void) sprintf(buf, "Mail List Program for %s", uname);
697 main_menu->title = strsave(buf);
698 main_menu->items[0] = strsave("1. Show all public mailing lists.");
699 main_menu->items[1] = strsave("2. Get all members of a mailing list.");
700 main_menu->items[2] = strsave("3. Display lists of which you are a member.");
701 main_menu->items[3] = strsave("4. Show description of list.");
702 main_menu->items[4] = strsave("5. Add yourself to a mailing list.");
703 main_menu->items[5] = strsave("6. Delete yourself from a mailing list.");
704 main_menu->items[6] = strsave("q. Quit.");
705}
706
707/****************************************************/
708pack_help_menu()
709{
710 help_menu = (MENU *) malloc((unsigned) sizeof(MENU));
711 help_menu->num_items = 5;
712 help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items);
713
714 help_menu->title = strsave("mailmaint is designed as a basic mail list administration program.");
715 help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
716 help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
717 help_menu->items[2] = strsave("program listmaint.");
718 help_menu->items[3] = strsave(" ");
719 help_menu->items[4] = strsave("Press any key to continue.");
720}
721
722/****************************************************/
723highlight(menu)
724 MENU *menu;
725{
726
727
728 if (oldpos[level] != position[level]) {
729 move(STARTROW + oldpos[level] - 1, STARTCOL);
730 standend();
731 addstr(menu->items[oldpos[level] - 1]);
732 refresh();
733 }
734
735 move(STARTROW + position[level] - 1, STARTCOL);
736 standout();
737 addstr(menu->items[position[level] - 1]);
738 refresh();
739 standend();
740 refresh();
741}
742
743/****************************************************/
744title(buff)
745 char *buff;
746{
747 move(0, MAX(0, (COLS - strlen(buff)) >> 1));
748 standout();
749 addstr(buff);
750 refresh();
751 standend();
752}
753
754/****************************************************/
755center_text(row, buff)
756 int row;
757 char *buff;
758{
759 move(row, MAX(0, (COLS - strlen(buff)) >> 1));
760 addstr(buff);
761 refresh();
762}
763
764/****************************************************/
765show_text(row, col, buff)
766 int row, col;
767 char *buff;
768{
769 mvcur(0, 0, row, col);
770 addstr(buff);
771 refresh();
772}
773
774/****************************************************/
775erase_line(row, col)
776 int row, col;
777{
778 char *buff;
779 int i;
780
781 buff = calloc((unsigned)COLS, 1);
782 for (i = 0; i <= COLS - 2; i++)
783 buff[i] = ' ';
784 buff[i] = 0; /* just to be sure ! */
785 move(row, col);
786 mvcur(0, 0, row, col);
787 addstr(buff);
788 refresh();
789}
790
791/****************************************************/
792cls()
793{
794 clear();
795 refresh();
796}
797
798/****************************************************/
799clrwin(erase_row)
800 int erase_row;
801{
802 int i;
803 char *buff;
804 int maxcol;
805
806 maxcol = COLS;
807 if (maxcol > 80)
808 maxcol = 80; /* limit width */
809
810 buff = calloc((unsigned)maxcol + 1, 1);
811 for (i = 0; i <= maxcol - 1; i++)
812 buff[i] = ' ';
813 buff[i] = 0; /* just to be sure ! */
814 mvcur(0, 0, erase_row, STARTCOL);
815 refresh();
816 for (i = erase_row; i <= currow - 1; i++) {
817 addstr(buff);
818 }
819 addstr(buff);
820 mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL);
821 refresh();
822}
823
824/****************************************************/
825
826static int
827scream()
828{
829 com_err(whoami, status, "\nA Moira update returned a value -- programmer \
830botch\n");
831 mr_disconnect();
832 exit(1);
833 return(0); /* to keep compiler happy */
834}
835
836/****************************************************/
837/*ARGSUSED*/
838static int
839fetch_list_info(list, li)
840 char *list;
841 List_info *li;
842{
843 char *argv[1];
844
845 argv[0] = list;
846 return mr_query("get_list_info", 1, argv, get_list_info, (char *) NULL);
847}
848
849/* ARGSUSED */
850static int
851get_list_info(argc, argv)
852 int argc;
853 char **argv;
854{
855
856 if (current_li->acl_type)
857 free(current_li->acl_type);
858 current_li->acl_type = strsave(argv[7]);
859 if (current_li->acl_name)
860 free(current_li->acl_name);
861 current_li->acl_name = strsave(argv[8]);
862 if (current_li->desc)
863 free(current_li->desc);
864 current_li->desc = strsave(argv[9]);
865 if (current_li->modtime)
866 free(current_li->modtime);
867 current_li->modtime = strsave(argv[10]);
868 if (current_li->modby)
869 free(current_li->modby);
870 current_li->modby = strsave(argv[11]);
871 if (current_li->modwith)
872 free(current_li->modwith);
873 current_li->modwith = strsave(argv[12]);
874 return (0);
875}
876
877
878
879
880/****************************************************/
881/* Prompt the user for input */
882int
883Prompt(prompt, buf, buflen, crok)
884 char *prompt;
885 char *buf;
886 int buflen;
887 int crok;
888{
889 int c;
890 char *p;
891
892 addstr(prompt);
893 refresh();
894 for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) {
895 refresh();
896 c = getchar() & 0x7f;
897 switch (c) {
898 case CTL('C'):
899 return 0;
900 case CTL('Z'):
901 return 0;
902 case CTL('L'):
903 cls();
904 display_menu(main_menu);
905 return (0);
906 case '\n':
907 case '\r':
908 if (crok)
909 display_buff("\n");
910 *p = '\0';
911 if (strlen(buf) < 1)/* only \n or \r in buff */
912 return (-1);
913 else
914 return (1);
915 case '\b':
916 case '\177':
917 if (p > buf) {
918 p--;
919 printf("\b \b");
920 }
921 break;
922 case CTL('U'):
923 case CTL('G'):
924 case CTL('['):
925 while (p-- > buf)
926 printf("\b \b");
927 p = buf;
928 break;
929 default:
930 if (abs(strlen(p) - strlen(buf)) >= buflen) {
931 printf("%c", 7);
932 break;
933 }
934 if (isprint(c)) {
935 (void) addch(c);
936 *p++ = c;
937 }
938 else
939 (void) putchar(CTL('G'));
940 break;
941 }
942 }
943 return(0);
944}
945
946
947/*
948 * Hook function to cause error messages to be printed through
949 * curses instead of around it.
950 */
951
952void
953menu_err_hook(who, code, fmt, args)
954 const char *who;
955 long code;
956 const char *fmt;
957 va_list args;
958{
959 char buf[BUFSIZ], *cp;
960
961 (void) strcpy(buf, who);
962 for (cp = buf; *cp; cp++);
963 *cp++ = ':';
964 *cp++ = ' ';
965 if (code) {
966 (void) strcpy(cp, error_message(code));
967 while (*cp)
968 cp++;
969 }
970#if defined(AIX386) || defined(sun)
971 vsprintf(cp, fmt, args);
972#else
973 /* can do this because we never pass more than 1 arg here anyway... */
974 sprintf(cp, fmt, args);
975#endif
976 display_buff(buf);
977}
This page took 0.045143 seconds and 5 git commands to generate.