2 Generalized console input/output handler
3 A maintanable replacement for readline()
5 Kern Sibbald, December MMIII
7 This code is in part derived from code that I wrote in
8 1981, so some of it is a bit old and could use a cleanup.
12 Copyright (C) 1981-2004 Kern Sibbald and John Walker
13 Yes, that is 1981 no error.
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of
18 the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with this program; if not, write to the Free
27 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34 * If the top bit of a UTF-8 string is 0 (8 bits), then it
35 * is a normal ASCII character.
36 * If the top two bits are 11 (i.e. (c & 0xC0) == 0xC0 then
37 * it is the start of a series of chars (up to 5)
38 * Each subsequent character starts with 10 (i.e. (c & 0xC0) == 0x80)
51 /* We are in Bacula */
58 extern "C" int tgetent(void *, const char *);
59 extern "C" int tgetnum(const char *);
60 extern "C" char *tgetstr (const char*, char**);
61 extern "C" char *tgoto (const char *, int, int);
68 /* From termios library */
72 /* Forward referenced functions */
73 static void sigintcatcher(int);
74 static void add_smap(char *str, int func);
77 /* Global variables */
79 static char *t_up = "\n"; /* scroll up character */
80 static char *t_honk = "\007"; /* sound beep */
81 static char *t_il; /* insert line */
82 static char *t_dl; /* delete line */
83 static char *t_cs; /* clear screen */
84 static char *t_cl; /* clear line */
85 static int t_width = 79; /* terminal width */
86 static int t_height = 24; /* terminal height */
87 static int linsdel_ok = 0; /* set if term has line insert & delete fncs */
89 static char *t_cm; /* cursor positioning */
90 static char *t_ti; /* init sequence */
91 static char *t_te; /* end sequence */
92 static char *t_do; /* down one line */
93 static char *t_sf; /* scroll screen one line up */
95 /* Keypad and Function Keys */
96 static char *kl; /* left key */
97 static char *kr; /* right */
98 static char *ku; /* up */
99 static char *kd; /* down */
100 static char *kh; /* home */
101 static char *kb; /* backspace */
102 static char *kD; /* delete key */
103 static char *kI; /* insert */
104 static char *kN; /* next page */
105 static char *kP; /* previous page */
106 static char *kH; /* home */
107 static char *kE; /* end */
110 #define EOS '\0' /* end of string terminator */
116 * Stab entry. Input chars (str), the length, and the desired
119 typedef struct s_stab {
128 static stab_t **stab = NULL; /* array of stabs by length */
129 static int num_stab; /* size of stab array */
131 static bool old_term_params_set = false;
132 static struct termios old_term_params;
134 /* Maintain lines in a doubly linked circular pool of lines. Each line is
135 preceded by a header defined by the lstr structure */
138 struct lstr { /* line pool structure */
139 struct lstr *prevl; /* link to previous line */
140 struct lstr *nextl; /* link to next line */
141 long len; /* length of line+header */
142 char used; /* set if line valid */
143 char line; /* line is actually varying length */
147 #define POOLEN 128000 /* bytes in line pool */
149 #define POOLEN 500 /* bytes in line pool */
151 char pool[POOLEN]; /* line pool */
152 #define PHDRL ((int)sizeof(struct lstr)) /* length of line header */
154 static struct lstr *lptr; /* current line pointer */
155 static struct lstr *slptr; /* store line pointer */
157 static char *getnext(), *getprev();
158 static int first = 1;
159 static int mode_insert = 0;
160 static int mode_wspace = 1; /* words separated by spaces */
163 static short char_map[600]= {
164 0, F_SOL, /* ^a Line start */
165 F_PRVWRD, /* ^b Previous word */ F_BREAK, /* ^C break */
166 F_DELCHR, /* ^D Delete character */ F_EOL, /* ^e End of line */
167 F_CSRRGT, /* ^f Right */ F_TABBAK, /* ^G Back tab */
168 F_CSRLFT, /* ^H Left */ F_TAB, /* ^I Tab */
169 F_CSRDWN, /* ^J Down */ F_DELEOL, /* ^K kill to eol */
170 F_CLRSCRN,/* ^L clear screen */ F_RETURN, /* ^M Carriage return */
171 F_RETURN, /* ^N enter line */ F_CONCAT, /* ^O Concatenate lines */
172 F_CSRUP, /* ^P cursor up */ F_TINS, /* ^Q Insert character mode */
173 F_PAGUP, /* ^R Page up */ F_CENTER, /* ^S Center text */
174 F_PAGDWN, /* ^T Page down */ F_DELSOL, /* ^U delete to start of line */
175 F_DELWRD, /* ^V Delete word */ F_PRVWRD, /* ^W Previous word */
176 F_NXTMCH, /* ^X Next match */ F_DELEOL, /* ^Y Delete to end of line */
177 F_BACKGND,/* ^Z Background */ 0x1B, /* ^[=ESC escape */
178 F_TENTRY, /* ^\ Entry mode */ F_PASTECB,/* ^]=paste clipboard */
179 F_HOME, /* ^^ Home */ F_ERSLIN, /* ^_ Erase line */
181 ' ','!','"','#','$','%','&','\047',
182 '(',')','*','+','\054','-','.','/',
183 '0','1','2','3','4','5','6','7',
184 '8','9',':',';','<','=','>','?',
185 '@','A','B','C','D','E','F','G',
186 'H','I','J','K','L','M','N','O',
187 'P','Q','R','S','T','U','V','W',
188 'X','Y','Z','[','\\',']','^','_',
189 '\140','a','b','c','d','e','f','g',
190 'h','i','j','k','l','m','n','o',
191 'p','q','r','s','t','u','v','w',
192 'x','y','z','{','|','}','\176',F_ERSCHR /* erase character */
197 /* Local variables */
199 #define CR '\r' /* carriage return */
202 /* Function Prototypes */
204 static unsigned int input_char(void);
205 static unsigned int t_gnc(void);
206 static void insert_space(char *curline, int line_len);
207 static void insert_hole(char *curline, int line_len);
208 static void forward(char *str, int str_len);
209 static void backup(char *curline);
210 static void delchr(int cnt, char *curline, int line_len);
211 static int iswordc(char c);
212 static int next_word(char *ldb_buf);
213 static int prev_word(char *ldb_buf);
214 static void prtcur(char *str);
215 static void poolinit(void);
216 static char * getnext(void);
217 static char * getprev(void);
218 static void putline(char *newl, int newlen);
219 static void t_honk_horn(void);
220 static void t_insert_line(void);
221 static void t_delete_line(void);
222 static void t_clrline(int pos, int width);
223 void t_sendl(const char *msg, int len);
224 void t_send(char *msg);
226 static void asclrs();
227 static void ascurs(int y, int x);
229 static void rawmode(FILE *input);
230 static void normode(void);
231 static unsigned t_getch();
232 static void asclrl(int pos, int width);
233 static void asinsl();
234 static void asdell();
236 int input_line(char *string, int length);
242 void con_init(FILE *input)
252 void con_set_zed_keys(void)
254 char_map[1] = F_NXTWRD; /* ^A Next Word */
255 char_map[2] = F_SPLIT; /* ^B Split line */
256 char_map[3] = F_EOI; /* ^C Quit */
257 char_map[4] = F_DELCHR; /* ^D Delete character */
258 char_map[5] = F_EOF; /* ^E End of file */
259 char_map[6] = F_INSCHR; /* ^F Insert character */
260 char_map[7] = F_TABBAK; /* ^G Back tab */
261 char_map[8] = F_CSRLFT; /* ^H Left */
262 char_map[9] = F_TAB; /* ^I Tab */
263 char_map[10] = F_CSRDWN; /* ^J Down */
264 char_map[11] = F_CSRUP; /* ^K Up */
265 char_map[12] = F_CSRRGT; /* ^L Right */
266 char_map[13] = F_RETURN; /* ^M Carriage return */
267 char_map[14] = F_EOL; /* ^N End of line */
268 char_map[15] = F_CONCAT; /* ^O Concatenate lines */
269 char_map[16] = F_MARK; /* ^P Set marker */
270 char_map[17] = F_TINS; /* ^Q Insert character mode */
271 char_map[18] = F_PAGUP; /* ^R Page up */
272 char_map[19] = F_CENTER; /* ^S Center text */
273 char_map[20] = F_PAGDWN; /* ^T Page down */
274 char_map[21] = F_SOL; /* ^U Line start */
275 char_map[22] = F_DELWRD; /* ^V Delete word */
276 char_map[23] = F_PRVWRD; /* ^W Previous word */
277 char_map[24] = F_NXTMCH; /* ^X Next match */
278 char_map[25] = F_DELEOL; /* ^Y Delete to end of line */
279 char_map[26] = F_DELLIN; /* ^Z Delete line */
281 char_map[28] = F_TENTRY; /* ^\ Entry mode */
282 char_map[29] = F_PASTECB;/* ^]=paste clipboard */
283 char_map[30] = F_HOME; /* ^^ Home */
284 char_map[31] = F_ERSLIN; /* ^_ Erase line */
295 * Guarantee that the string is properly terminated */
296 char *bstrncpy(char *dest, const char *src, int maxlen)
298 strncpy(dest, src, maxlen-1);
306 * New style string mapping to function code
308 static unsigned do_smap(unsigned c)
328 for (i=len-1; i<MAX_STAB; i++) {
329 for (tstab=stab[i]; tstab; tstab=tstab->next) {
330 if (strncmp(str, tstab->str, len) == 0) {
331 if (len == tstab->len) {
335 break; /* found possibility continue searching */
342 /* found partial match, so get next character and retry */
343 str[len++] = t_gnc();
349 static void dump_stab()
355 for (i=0; i<MAX_STAB; i++) {
356 for (tstab=stab[i]; tstab; tstab=tstab->next) {
357 for (j=0; j<tstab->len; j++) {
359 if (c < 0x20 || c > 0x7F) {
360 sprintf(buf, " 0x%x ", c);
368 sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len);
376 * New routine. Add string to string->func mapping table.
378 static void add_smap(char *str, int func)
388 /* errmsg("String for func %d is zero length\n", func); */
391 tstab = (stab_t *)malloc(sizeof(stab_t));
392 memset(tstab, 0, sizeof(stab_t));
394 tstab->str = (char *)malloc(tstab->len + 1);
395 bstrncpy(tstab->str, str, tstab->len + 1);
397 if (tstab->len > num_stab) {
398 printf("stab string too long %d. Max is %d\n", tstab->len, num_stab);
401 tstab->next = stab[tstab->len-1];
402 stab[tstab->len-1] = tstab;
403 /* printf("Add_smap tstab=%x len=%d func=%d tstab->next=%x\n\r", tstab, len,
404 func, tstab->next); */
409 /* Get the next character from the terminal - performs table lookup on
410 the character to do the desired translation */
416 if ((c=t_gnc()) <= 599) { /* IBM generates codes up to 260 */
418 } else if (c > 1000) { /* stuffed function */
419 c -= 1000; /* convert back to function code */
424 /* if we got a screen size escape sequence, read height, width */
427 y = t_gnc() - 0x20; /* y */
428 x = t_gnc() - 0x20; /* x */
435 /* Get a complete input line */
438 input_line(char *string, int length)
440 char curline[2000]; /* edit buffer */
447 poolinit(); /* build line pool */
450 noline = 1; /* no line fetched yet */
451 for (cl=cp=0; cl<length && cl<(int)sizeof(curline); ) {
456 switch (c=input_char()) {
457 case F_RETURN: /* CR */
458 t_sendl("\r\n", 2); /* yes, print it and */
459 goto done; /* get out */
460 case F_CLRSCRN: /* clear screen */
462 t_sendl(curline, cl);
466 if (noline) { /* no line fetched yet */
467 getnext(); /* getnext so getprev gets current */
468 noline = 0; /* we now have line */
470 bstrncpy(curline, getprev(), sizeof(curline));
474 noline = 0; /* mark line fetched */
475 bstrncpy(curline, getnext(), sizeof(curline));
479 insert_space(curline, sizeof(curline));
482 delchr(1, curline, sizeof(curline)); /* delete one character */
484 case F_CSRLFT: /* Backspace */
488 forward(curline, sizeof(curline));
490 case F_ERSCHR: /* Rubout */
492 delchr(1, curline, sizeof(curline));
495 t_clrline(0, t_width);
500 i = next_word(curline);
502 forward(curline, sizeof(curline));
506 i = prev_word(curline);
512 delchr(next_word(curline), curline, sizeof(curline)); /* delete word */
514 case F_NXTMCH: /* Ctl-X */
516 *string = EOS; /* terminate string */
517 return(c); /* give it to him */
519 /* Note fall through */
523 backup(curline); /* backup to beginning of line */
525 t_clrline(0,t_width); /* erase line */
527 cl = 0; /* reset cursor counter */
536 forward(curline, sizeof(curline));
542 case F_TINS: /* toggle insert mode */
543 mode_insert = !mode_insert; /* flip bit */
546 if (c > 255) { /* function key hit */
547 if (cl==0) { /* if first character then */
548 *string = EOS; /* terminate string */
549 return c; /* return it */
551 t_honk_horn(); /* complain */
553 if ((c & 0xC0) == 0xC0) {
554 if ((c & 0xFC) == 0xFC) {
556 } else if ((c & 0xF8) == 0xF8) {
558 } else if ((c & 0xF0) == 0xF0) {
560 } else if ((c & 0xE0) == 0xE0) {
569 insert_space(curline, sizeof(curline));
571 curline[cp++] = c; /* store character in line being built */
572 t_char(c); /* echo character to terminal */
575 insert_hole(curline, sizeof(curline));
576 curline[cp++] = c; /* store character in line being built */
577 t_char(c); /* echo character to terminal */
580 cl = cp; /* keep current length */
587 /* If we fall through here rather than goto done, the line is too long
588 simply return what we have now. */
590 curline[cl++] = EOS; /* terminate */
591 bstrncpy(string,curline,length); /* return line to caller */
592 /* Note, put line zaps curline */
593 putline(curline,cl); /* save line for posterity */
594 return 0; /* give it to him/her */
597 /* Insert a space at the current cursor position */
599 insert_space(char *curline, int curline_len)
603 if (cp > cl || cl+1 > curline_len) {
606 /* Note! source and destination overlap */
607 memmove(&curline[cp+1],&curline[cp],i=cl-cp);
612 forward(curline, curline_len);
622 insert_hole(char *curline, int curline_len)
626 if (cp > cl || cl+1 > curline_len) {
629 /* Note! source and destination overlap */
630 memmove(&curline[cp+1], &curline[cp], i=cl-cp);
636 /* Move cursor forward keeping characters under it */
638 forward(char *str, int str_len)
649 if ((str[cp] & 0xC0) == 0xC0) {
651 while ((str[cp] & 0xC0) == 0x80) {
661 /* How many characters under the cursor */
663 char_count(int cptr, char *str)
669 if ((str[cptr] & 0xC0) == 0xC0) {
671 while ((str[cptr] & 0xC0) == 0x80) {
679 /* Backup cursor keeping characters under it */
686 while ((str[cp] & 0xC0) == 0x80) {
693 /* Delete the character under the cursor */
695 delchr(int del, char *curline, int line_len)
699 if (cp > cl || del == 0) {
702 while (del-- && cp > 0) {
703 cnt = char_count(cp, curline);
704 if ((i=cl-cp-cnt) > 0) {
705 memcpy(&curline[cp], &curline[cp+cnt], i);
709 t_clrline(0, t_width);
712 forward(curline, line_len);
721 /* Determine if character is part of a word */
727 if (c >= '0' && c <= '9')
729 if (c == '$' || c == '%')
734 /* Return number of characters to get to next word */
736 next_word(char *ldb_buf)
743 for ( ; ncp<cl && iswordc(*(ldb_buf+ncp)); ncp++) ;
744 for ( ; ncp<cl && !iswordc(*(ldb_buf+ncp)); ncp++) ;
748 /* Return number of characters to get to previous word */
750 prev_word(char *ldb_buf)
754 if (cp == 0) /* if at begin of line stop now */
756 if (cp > cl) /* if past eol start at eol */
760 /* backup to end of previous word - i.e. skip special chars */
761 for (i=ncp-1; i && !iswordc(*(ldb_buf+i)); i--) ;
762 if (i == 0) { /* at beginning of line? */
763 return cp; /* backup to beginning */
765 /* now move back through word to beginning of word */
766 for ( ; i && iswordc(*(ldb_buf+i)); i--) ;
767 ncp = i+1; /* position to first char of word */
768 if (i==0 && iswordc(*ldb_buf)) /* check for beginning of line */
770 return cp-ncp; /* return count */
773 /* Display new current line */
780 t_clrline(0,t_width);
781 cp = cl = strlen(str);
786 /* Initialize line pool. Split pool into two pieces. */
790 slptr = lptr = (struct lstr *)pool;
799 /* Return pointer to next line in the pool and advance current line pointer */
803 do { /* find next used line */
805 } while (!lptr->used);
806 return (char *)&lptr->line;
809 /* Return pointer to previous line in the pool */
813 do { /* find previous used line */
815 } while (!lptr->used);
816 return (char *)&lptr->line;
820 putline(char *newl, int newlen)
822 struct lstr *nptr; /* points to next line */
825 lptr = slptr; /* get ptr to last line stored */
826 lptr = lptr->nextl; /* advance pointer */
827 if ((char *)lptr-pool+newlen+PHDRL > POOLEN) { /* not enough room */
828 lptr->used = 0; /* delete line */
829 lptr = (struct lstr *)pool; /* start at beginning of buffer */
831 while (lptr->len < newlen+PHDRL) { /* concatenate buffers */
832 nptr = lptr->nextl; /* point to next line */
833 lptr->nextl = nptr->nextl; /* unlink it from list */
834 nptr->nextl->prevl = lptr;
835 lptr->len += nptr->len;
837 if (lptr->len > newlen + 2 * PHDRL) { /* split buffer */
838 nptr = (struct lstr *)((char *)lptr + newlen + PHDRL);
839 /* Appropriate byte alignment - normally 2 byte, but on
840 sparc we need 4 byte alignment, so we always do 4 */
841 if (((long unsigned)nptr & 3) != 0) { /* test four byte alignment */
843 nptr = (struct lstr *)((((long unsigned) p) & ~3) + 4);
845 nptr->len = lptr->len - ((char *)nptr - (char *)lptr);
846 lptr->len -= nptr->len;
847 nptr->nextl = lptr->nextl; /* link in new buffer */
848 lptr->nextl->prevl = nptr;
853 memcpy(&lptr->line,newl,newlen);
854 lptr->used = 1; /* mark line used */
855 slptr = lptr; /* save as stored line */
860 dump(struct lstr *ptr, char *msg)
862 printf("%s buf=%x nextl=%x prevl=%x len=%d used=%d\n",
863 msg,ptr,ptr->nextl,ptr->prevl,ptr->len,ptr->used);
865 printf("line=%s\n",&ptr->line);
867 #endif /* DEBUGOUT */
870 /* Honk horn on terminal */
877 /* Insert line on terminal */
884 /* Delete line from terminal */
891 /* clear line from pos to width */
893 t_clrline(int pos, int width)
895 asclrl(pos, width); /* clear to end of line */
898 /* Helper function to add string preceded by
899 * ESC to smap table */
900 static void add_esc_smap(char *str, int func)
903 buf[0] = 0x1B; /* esc */
904 bstrncpy(buf+1, str, sizeof(buf)-1);
908 /* Set raw mode on terminal file. Basically, get the terminal into a
909 mode in which all characters can be read as they are entered. CBREAK
910 mode is not sufficient.
912 static void rawmode(FILE *input)
915 static char term_buf[2048];
916 static char *term_buffer = term_buf;
917 char *termtype = (char *)getenv("TERM");
919 /* Make sure we are dealing with a terminal */
920 if (!isatty(fileno(input))) {
923 if (tcgetattr(0, &old_term_params) != 0) {
924 printf("conio: Cannot tcgetattr()\n");
927 old_term_params_set = true;
929 t.c_cc[VMIN] = 1; /* satisfy read after 1 char */
931 t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
932 ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
935 t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON |
937 tcflush(0, TCIFLUSH);
938 if (tcsetattr(0, TCSANOW, &t) == -1) {
939 printf("Cannot tcsetattr()\n");
942 /* Defaults, the main program can override these */
943 signal(SIGQUIT, SIG_IGN);
944 signal(SIGHUP, SIG_IGN);
945 // signal(SIGSTOP, SIG_IGN);
946 signal(SIGINT, sigintcatcher);
947 signal(SIGWINCH, SIG_IGN);
948 signal(SIGQUIT, SIG_IGN);
949 signal(SIGCHLD, SIG_IGN);
950 // signal(SIGTSTP, SIG_IGN);
953 printf("Cannot get terminal type.\n");
957 if (tgetent(term_buffer, termtype) < 0) {
958 printf("Cannot get terminal termcap entry.\n");
962 t_width = t_height = -1;
963 t_width = tgetnum("co") - 1;
964 t_height = tgetnum("li");
967 t_cm = (char *)tgetstr("cm", &term_buffer);
968 t_cs = (char *)tgetstr("cl", &term_buffer); /* clear screen */
969 t_cl = (char *)tgetstr("ce", &term_buffer); /* clear line */
970 t_dl = (char *)tgetstr("dl", &term_buffer); /* delete line */
971 t_il = (char *)tgetstr("al", &term_buffer); /* insert line */
972 t_honk = (char *)tgetstr("bl", &term_buffer); /* beep */
973 t_ti = (char *)tgetstr("ti", &term_buffer);
974 t_te = (char *)tgetstr("te", &term_buffer);
975 t_up = (char *)tgetstr("up", &term_buffer);
976 t_do = (char *)tgetstr("do", &term_buffer);
977 t_sf = (char *)tgetstr("sf", &term_buffer);
979 num_stab = MAX_STAB; /* get default stab size */
980 stab = (stab_t **)malloc(sizeof(stab_t *) * num_stab);
981 memset(stab, 0, sizeof(stab_t *) * num_stab);
984 kl = (char *)tgetstr("kl", &term_buffer);
985 kr = (char *)tgetstr("kr", &term_buffer);
986 ku = (char *)tgetstr("ku", &term_buffer);
987 kd = (char *)tgetstr("kd", &term_buffer);
988 kh = (char *)tgetstr("kh", &term_buffer);
989 kb = (char *)tgetstr("kb", &term_buffer);
990 kD = (char *)tgetstr("kD", &term_buffer);
991 kI = (char *)tgetstr("kI", &term_buffer);
992 kN = (char *)tgetstr("kN", &term_buffer);
993 kP = (char *)tgetstr("kP", &term_buffer);
994 kH = (char *)tgetstr("kH", &term_buffer);
995 kE = (char *)tgetstr("kE", &term_buffer);
997 add_smap(kl, F_CSRLFT);
998 add_smap(kr, F_CSRRGT);
999 add_smap(ku, F_CSRUP);
1000 add_smap(kd, F_CSRDWN);
1001 add_smap(kI, F_TINS);
1002 add_smap(kN, F_PAGDWN);
1003 add_smap(kP, F_PAGUP);
1004 add_smap(kH, F_HOME);
1005 add_smap(kE, F_EOF);
1008 add_esc_smap("[A", F_CSRUP);
1009 add_esc_smap("[B", F_CSRDWN);
1010 add_esc_smap("[C", F_CSRRGT);
1011 add_esc_smap("[D", F_CSRLFT);
1012 add_esc_smap("[1~", F_HOME);
1013 add_esc_smap("[2~", F_TINS);
1014 add_esc_smap("[3~", F_DELCHR);
1015 add_esc_smap("[4~", F_EOF);
1016 add_esc_smap("f", F_NXTWRD);
1017 add_esc_smap("b", F_PRVWRD);
1021 /* Restore tty mode */
1022 static void normode()
1024 if (old_term_params_set) {
1025 tcsetattr(0, TCSANOW, &old_term_params);
1026 old_term_params_set = false;
1030 /* Get next character from terminal/script file/unget buffer */
1038 /* Get next character from OS */
1039 static unsigned t_getch(void)
1043 if (read(0, &c, 1) != 1) {
1049 /* Send message to terminal - primitive routine */
1051 t_sendl(const char *msg, int len)
1062 t_sendl(msg, strlen(msg)); /* faster than one char at time */
1065 /* Send single character to terminal - primitive routine - */
1073 static int brkflg = 0; /* set on user break */
1075 /* Routine to return true if user types break */
1081 /* Clear break flag */
1088 /* Interrupt caught here */
1089 static void sigintcatcher(int sig)
1096 signal(SIGINT, sigintcatcher);
1103 signal(SIGINT, sigintcatcher);
1107 /* ASCLRL() -- Clear to end of line from current position */
1108 static void asclrl(int pos, int width)
1113 t_send(t_cl); /* use clear to eol function */
1116 if (pos==1 && linsdel_ok) {
1117 t_delete_line(); /* delete line */
1118 t_insert_line(); /* reinsert it */
1121 for (i=1; i<=width-pos+1; i++)
1122 t_char(' '); /* last resort, blank it out */
1123 for (i=1; i<=width-pos+1; i++) /* backspace to original position */
1130 /* ASCURS -- Set cursor position */
1131 static void ascurs(int y, int x)
1133 t_send((char *)tgoto(t_cm, x, y));
1137 /* ASCLRS -- Clear whole screen */
1138 static void asclrs()
1146 /* ASINSL -- insert new line after cursor */
1147 static void asinsl()
1149 t_clrline(0, t_width);
1150 t_send(t_il); /* insert before */
1153 /* ASDELL -- Delete line at cursor */
1154 static void asdell()