#include "copyright.h" #include "options.h" #include #include #include "tty.h" #include "sm_declare.h" /* * TTYPUTS -- Put a control string to the output file. * The control string consists of an optional delay, followed by the * chars to be sent to the terminal. If the delay is given as a simple * integer number (e.g., ":cl=50\E"), it specifies the delay in milliseconds. * If the delay number is followed by an asterisk (i.e., ":cd=3.5*\E^C:") it * specifies the delay in milliseconds per line affected by the operation. * In the latter case, the AFFLNCNT argument is used to compute the total * delay. Delays are generated by writing a sequence of pad characters * usually NUL); the number of pad chars sent to achieve a particular delay * depends on the baud rate. */ void ttyputs (fd, tty, ctrlstr, nchars, afflncnt) int fd; /* output file */ TTY *tty; /* terminal descriptor */ char *ctrlstr; /* control sequence to be output */ int nchars; /* length of ctrlstr */ int afflncnt; /* number of lines affected */ { char *cptr, /* pointer to ctrlstr */ *ptr; float val; int delay; /* * Determine number of milliseconds of delay req'd, and skip delay in ctrlstr */ cptr = ctrlstr; if (isdigit(ctrlstr[0])) { val = atof2(ctrlstr); while(isdigit(*cptr)) cptr++; /* skip nnn.mmm */ if(*cptr == '.') cptr++; while(isdigit(*cptr)) cptr++; if (*cptr == '*') { delay = val*afflncnt + 0.5; cptr++; } else { delay = val; } nchars -= (cptr - ctrlstr); /* nchars contained delay */ } else { delay = 0; } /* * Output the control sequence. A \377 will be output as a \0, but * \377\377 will be output as \377 */ for (ptr = cptr + nchars;ptr > cptr;) { if(*--ptr == '\377') { /* lint doesn't like this test */ if(*(ptr - 1) == '\377') { /* \377\377 */ char *pt1 = ptr - 1, *pt2 = ptr; while(pt2 < cptr + nchars) { *pt1++ = *pt2++; } nchars--; ptr--; } else { /* an isolated \377 */ *ptr = '\0'; } } } ttwrite(fd,cptr,nchars); if(delay) ttydelay(fd, tty, delay); /* delay if needed */ } /********************************************************************/ /* * TTYDELAY -- Output a sequence of pad characters to create a delay, giving * the terminal time to complete some operation before being passed the next * request. */ void ttydelay (fd, tty, delay) int fd; /* output file */ TTY *tty; /* tty descriptor */ int delay; /* desired milliseconds of delay */ { char padchar; int npadchars; float msec_per_char; /* Add padding if needed to generate delay. (8 = nbits per char, */ /* baud is in units of bits per second). */ if (delay > 0 && tty->t_baud > 0) { padchar = tty->t_padchar & '\177'; msec_per_char = (8 * 1000.) / tty->t_baud; npadchars = (int) (delay / msec_per_char + 0.5); for (;npadchars > 0;npadchars--) ttwrite(fd, &padchar,1); } }