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