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