home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / INPUT.C < prev    next >
C/C++ Source or Header  |  1991-09-05  |  19KB  |  821 lines

  1. /*    Input:    Various input routines for MicroEMACS
  2.         written by Daniel Lawrence
  3.         5/9/86                        */
  4.  
  5. /*
  6.     Notes:
  7.  
  8.     MicroEMACS's kernel processes two distinct forms of
  9.     characters.  One of these is a standard unsigned character
  10.     which is used in the edited text.  The other form, called
  11.     an EMACS Extended Character is a 2 byte value which contains
  12.     both an ascii value, and flags for certain prefixes/events.
  13.  
  14.     Bit    Usage
  15.     ---    -----
  16.     0 -> 7    Standard 8 bit ascii character
  17.     8    Control key flag
  18.     9    META prefix flag
  19.     10    ^X prefix flag
  20.     11    Function key flag
  21.     12    Mouse prefix
  22.     13    Shifted flag (not needed on alpha shifted characters)
  23.     14    Alterate prefix (ALT key on PCs)
  24.  
  25.     The machine dependent driver is responsible for returning
  26.     a byte stream from the various input devices with various
  27.     prefixes/events embedded as escape codes.  Zero is used as the
  28.     value indicating an escape sequence is next.  The format of
  29.     an escape sequence is as follows:
  30.  
  31.     0        Escape indicator
  32.     <prefix byte>    upper byte of extended character
  33.     {<col><row>}    col, row position if the prefix byte
  34.             indicated a mouse event
  35.     <event code>    value of event
  36.  
  37.     Two successive zeroes are used to indicate an actual
  38.     null being input.  These values are then interpreted by
  39.     getkey() to construct the proper extended character
  40.     sequences to pass to the MicroEMACS kernel.
  41. */
  42.  
  43. #include    <stdio.h>
  44. #include    "estruct.h"
  45. #include    "eproto.h"
  46. #include    "edef.h"
  47. #include    "elang.h"
  48.  
  49. /*
  50.  * Ask a yes or no question in the message line. Return either TRUE, FALSE, or
  51.  * ABORT. The ABORT status is returned if the user bumps out of the question
  52.  * with a ^G. Used any time a confirmation is required.
  53.  */
  54.  
  55. PASCAL NEAR mlyesno(prompt)
  56.  
  57. char *prompt;
  58.  
  59. {
  60.     int  c;            /* input character */
  61.     char buf[NPAT];        /* prompt to user */
  62.  
  63.     for (;;) {
  64.         /* build and prompt the user */
  65.         strcpy(buf, prompt);
  66.         strcat(buf, TEXT162);
  67. /*                          " [y/n]? " */
  68.         mlwrite(buf);
  69.  
  70.         /* get the response */
  71.             c = getcmd();   /* getcmd() lets us check for anything that might */
  72.                             /* generate a 'y' or 'Y' in case use screws up */
  73.  
  74.         if (c == ectoc(abortc))        /* Bail out! */
  75.             return(ABORT);
  76.  
  77.             if  ((c == 'n') || (c == 'N')
  78.                 || (c & (SPEC|ALTD|CTRL|META|CTLX|MOUS)))
  79.                     return(FALSE);  /* ONLY 'y' or 'Y' allowed!!! */
  80.  
  81. #if    FRENCH
  82.         if (c=='o' || c=='O')
  83.             return(TRUE);
  84. #endif
  85.  
  86.         if (c=='y' || c=='Y')
  87.             return(TRUE);
  88.  
  89.         return(FALSE);
  90.     }
  91. }
  92.  
  93. /*
  94.  * Write a prompt into the message line, then read back a response. Keep
  95.  * track of the physical position of the cursor. If we are in a keyboard
  96.  * macro throw the prompt away, and return the remembered response. This
  97.  * lets macros run at full speed. The reply is always terminated by a carriage
  98.  * return. Handle erase, kill, and abort keys.
  99.  */
  100.  
  101. PASCAL NEAR mlreply(prompt, buf, nbuf)
  102.  
  103. char *prompt;
  104. char *buf;
  105. int nbuf;
  106.  
  107. {
  108.     return(nextarg(prompt, buf, nbuf, ctoec((int) '\r')));
  109. }
  110.  
  111. PASCAL NEAR mltreply(prompt, buf, nbuf, eolchar)
  112.  
  113. char *prompt;
  114. char *buf;
  115. int nbuf;
  116. int eolchar;
  117.  
  118. {
  119.     return(nextarg(prompt, buf, nbuf, eolchar));
  120. }
  121.  
  122. /*    ectoc:    expanded character to character
  123.         collapse the CTRL and SPEC flags back into an ascii code   */
  124.  
  125. PASCAL NEAR ectoc(c)
  126.  
  127. int c;
  128.  
  129. {
  130.     if (c & CTRL)
  131.         c = c ^ (CTRL | 0x40);
  132.     if (c & SPEC)
  133.         c= c & 255;
  134.     return(c);
  135. }
  136.  
  137. /*    ctoec:    character to extended character
  138.         pull out the CTRL and SPEC prefixes (if possible)    */
  139.  
  140. PASCAL NEAR ctoec(c)
  141.  
  142. int c;
  143.  
  144. {
  145.         if ((c>=0x00 && c<=0x1F) || c == 0x7F)
  146.                 c = CTRL | (c ^ 0x40);
  147.         return(c);
  148. }
  149.  
  150. /* get a command name from the command line. Command completion means
  151.    that pressing a <SPACE> will attempt to complete an unfinished command
  152.    name if it is unique.
  153. */
  154.  
  155. #if    MSC
  156. int (PASCAL NEAR *PASCAL NEAR getname(char *prompt))(void)
  157. #else
  158. int (PASCAL NEAR *PASCAL NEAR getname(prompt))()
  159.  
  160. char *prompt;    /* string to prompt with */
  161. #endif
  162.  
  163. {
  164.     char *sp;    /* ptr to the returned string */
  165.  
  166.     sp = complete(prompt, NULL, CMP_COMMAND, NSTRING);
  167.     if (sp == NULL)
  168.         return(NULL);
  169.  
  170.     return(fncmatch(sp));
  171. }
  172.  
  173. /*    getcbuf:    get a completion from the user for a buffer name.
  174.  
  175.             I was goaded into this by lots of other people's
  176.             completion code.
  177. */
  178.  
  179. BUFFER *PASCAL NEAR getcbuf(prompt, defval, createflag)
  180.  
  181. char *prompt;        /* prompt to user on command line */
  182. char *defval;        /* default value to display to user */
  183. int createflag;        /* should this create a new buffer? */
  184.  
  185. {
  186.     char *sp;    /* ptr to the returned string */
  187.  
  188.     sp = complete(prompt, defval, CMP_BUFFER, NBUFN);
  189.     if (sp == NULL)
  190.         return(NULL);
  191.  
  192.     return(bfind(sp, createflag, 0));
  193. }
  194.  
  195. char *PASCAL NEAR gtfilename(prompt)
  196.  
  197. char *prompt;        /* prompt to user on command line */
  198.  
  199. {
  200.     char *sp;    /* ptr to the returned string */
  201.  
  202.     sp = complete(prompt, NULL, CMP_FILENAME, NFILEN);
  203.     if (sp == NULL)
  204.         return(NULL);
  205.  
  206.     return(sp);
  207. }
  208.  
  209. char *PASCAL NEAR complete(prompt, defval, type, maxlen)
  210.  
  211. char *prompt;        /* prompt to user on command line */
  212. char *defval;        /* default value to display to user */
  213. int type;        /* type of what we are completing */
  214. int maxlen;        /* maximum length of input field */
  215.  
  216. {
  217.     register int c;        /* current input character */
  218.     register int ec;    /* extended input character */
  219.     int cpos;        /* current column on screen output */
  220.     static char buf[NSTRING];/* buffer to hold tentative name */
  221.  
  222.     /* if we are executing a command line get the next arg and match it */
  223.     if (clexec) {
  224.         if (macarg(buf) != TRUE)
  225.             return(NULL);
  226.         return(buf);
  227.     }
  228.  
  229.     /* starting at the beginning of the string buffer */
  230.     cpos = 0;
  231.  
  232.     /* if it exists, prompt the user for a buffer name */
  233.     if (prompt)
  234.         if (type == CMP_COMMAND)
  235.             mlwrite("%s", prompt);
  236.         else if (defval)
  237.             mlwrite("%s[%s]: ", prompt, defval);
  238.         else
  239.             mlwrite("%s: ", prompt);
  240.  
  241.     /* build a name string from the keyboard */
  242.     while (TRUE) {
  243.  
  244.         /* get the keystroke and decode it */
  245.         ec = getkey();
  246.         c = ectoc(ec);        
  247.  
  248.         /* if we are at the end, just match it */
  249.         if (c == '\n'  ||  c == '\r') {
  250.             if (defval && cpos==0)
  251.                 return(defval);
  252.             else {
  253.                 buf[cpos] = 0;
  254.                 return(buf);
  255.             }
  256.  
  257.         } else if (ec == abortc) {    /* Bell, abort */
  258.             ctrlg(FALSE, 0);
  259.             TTflush();
  260.             return(NULL);
  261.  
  262.         } else if (c == 0x7F || c == 0x08) {    /* rubout/erase */
  263.             if (cpos != 0) {
  264.                 mlout('\b');
  265.                 mlout(' ');
  266.                 mlout('\b');
  267.                 --ttcol;
  268.                 --cpos;
  269.                 TTflush();
  270.             }
  271.  
  272.         } else if (c == 0x15) {    /* C-U, kill */
  273.             while (cpos != 0) {
  274.                 mlout('\b');
  275.                 mlout(' ');
  276.                 mlout('\b');
  277.                 --cpos;
  278.                 --ttcol;
  279.             }
  280.             TTflush();
  281.  
  282.         } else if ((c == ' ') || (ec == sterm) || (c == '\t')) {    
  283.             /* attempt a completion */
  284.             switch (type) {
  285.                 case CMP_BUFFER:
  286.                     comp_buffer(buf, &cpos);
  287.                     break;
  288.                 case CMP_COMMAND:
  289.                     comp_command(buf, &cpos);
  290.                     break;
  291.                 case CMP_FILENAME:
  292.                     comp_file(buf, &cpos);
  293.                     break;
  294.             }
  295.  
  296.             TTflush();
  297.             if (buf[cpos - 1] == 0)
  298.                 return(buf);
  299.         } else {
  300.             if (cpos < maxlen && c > ' ') {
  301.                 buf[cpos++] = c;
  302.                 mlout(c);
  303.                 ++ttcol;
  304.                 TTflush();
  305.             }
  306.         }
  307.     }
  308. }
  309.  
  310. /*    comp_command:    Attempt a completion on a command name    */
  311.  
  312. comp_command(name, cpos)
  313.  
  314. char *name;    /* command containing the current name to complete */
  315. int *cpos;    /* ptr to position of next character to insert */
  316.  
  317. {
  318.     register NBIND *bp;    /* trial command to complete */
  319.     register int index;    /* index into strings to compare */
  320.     register int curbind;    /* index into the names[] array */
  321.     register NBIND *match;    /* last command that matches string */
  322.     register int matchflag;    /* did this command name match? */
  323.     register int comflag;    /* was there a completion at all? */
  324.  
  325.     /* start attempting completions, one character at a time */
  326.     comflag = FALSE;
  327.     curbind = 0;
  328.     while (*cpos < NSTRING) {
  329.  
  330.         /* first, we start at the first command and scan the list */
  331.         match = NULL;
  332.         curbind = 0;
  333.         while (curbind <= numfunc) {
  334.  
  335.             /* is this a match? */
  336.             bp = &names[curbind];
  337.             matchflag = TRUE;
  338.             for (index = 0; index < *cpos; index++)
  339.                 if (name[index] != bp->n_name[index]) {
  340.                     matchflag = FALSE;
  341.                     break;
  342.                 }
  343.  
  344.             /* if it is a match */
  345.             if (matchflag) {
  346.  
  347.                 /* if this is the first match, simply record it */
  348.                 if (match == NULL) {
  349.                     match = bp;
  350.                     name[*cpos] = bp->n_name[*cpos];
  351.                 } else {
  352.                     /* if there's a difference, stop here */
  353.                     if (name[*cpos] != bp->n_name[*cpos])
  354.                         return;
  355.                 }
  356.             }
  357.  
  358.             /* on to the next command */
  359.             curbind++;
  360.         }
  361.  
  362.         /* with no match, we are done */
  363.         if (match == NULL) {
  364.             /* beep if we never matched */
  365.             if (comflag == FALSE)
  366.                 TTbeep();
  367.             return;
  368.         }
  369.  
  370.         /* if we have completed all the way... go back */
  371.         if (name[*cpos] == 0) {
  372.             (*cpos)++;
  373.             return;
  374.         }
  375.  
  376.         /* remember we matched, and complete one character */
  377.         comflag = TRUE;
  378.         TTputc(name[(*cpos)++]);
  379.         TTflush();
  380.     }
  381.  
  382.     /* don't allow a completion past the end of the max command name length */
  383.     return;
  384. }
  385.  
  386. /*    comp_buffer:    Attempt a completion on a buffer name    */
  387.  
  388. comp_buffer(name, cpos)
  389.  
  390. char *name;    /* buffer containing the current name to complete */
  391. int *cpos;    /* ptr to position of next character to insert */
  392.  
  393. {
  394.     register BUFFER *bp;    /* trial buffer to complete */
  395.     register int index;    /* index into strings to compare */
  396.     register BUFFER *match;    /* last buffer that matches string */
  397.     register int matchflag;    /* did this buffer name match? */
  398.     register int comflag;    /* was there a completion at all? */
  399.  
  400.     /* start attempting completions, one character at a time */
  401.     comflag = FALSE;
  402.     while (*cpos < NBUFN) {
  403.  
  404.         /* first, we start at the first buffer and scan the list */
  405.         match = NULL;
  406.         bp = bheadp;
  407.         while (bp) {
  408.  
  409.             /* is this a match? */
  410.             matchflag = TRUE;
  411.             for (index = 0; index < *cpos; index++)
  412.                 if (name[index] != bp->b_bname[index]) {
  413.                     matchflag = FALSE;
  414.                     break;
  415.                 }
  416.  
  417.             /* if it is a match */
  418.             if (matchflag) {
  419.  
  420.                 /* if this is the first match, simply record it */
  421.                 if (match == NULL) {
  422.                     match = bp;
  423.                     name[*cpos] = bp->b_bname[*cpos];
  424.                 } else {
  425.                     /* if there's a difference, stop here */
  426.                     if (name[*cpos] != bp->b_bname[*cpos])
  427.                         return;
  428.                 }
  429.             }
  430.  
  431.             /* on to the next buffer */
  432.             bp = bp->b_bufp;
  433.         }
  434.  
  435.         /* with no match, we are done */
  436.         if (match == NULL) {
  437.             /* beep if we never matched */
  438.             if (comflag == FALSE)
  439.                 TTbeep();
  440.             return;
  441.         }
  442.  
  443.         /* if we have completed all the way... go back */
  444.         if (name[*cpos] == 0) {
  445.             (*cpos)++;
  446.             return;
  447.         }
  448.  
  449.         /* remember we matched, and complete one character */
  450.         comflag = TRUE;
  451.         TTputc(name[(*cpos)++]);
  452.         TTflush();
  453.     }
  454.  
  455.     /* don't allow a completion past the end of the max buffer name length */
  456.     return;
  457. }
  458.  
  459. /*    comp_file:    Attempt a completion on a file name    */
  460.  
  461. comp_file(name, cpos)
  462.  
  463. char *name;    /* file containing the current name to complete */
  464. int *cpos;    /* ptr to position of next character to insert */
  465.  
  466. {
  467.     register char *fname;    /* trial file to complete */
  468.     register int index;    /* index into strings to compare */
  469.  
  470.     register int matches;    /* number of matches for name */
  471.     char longestmatch[NSTRING]; /* temp buffer for longest match */
  472.     int longestlen;     /* length of longest match (always > *cpos) */
  473.  
  474.     /* everything (or nothing) matches an empty string */
  475.     if (*cpos == 0)
  476.         return;
  477.  
  478.     /* first, we start at the first file and scan the list */
  479.     matches = 0;
  480.     name[*cpos] = 0;
  481.     fname = getffile(name);
  482.     while (fname) {
  483.  
  484.         /* is this a match? */
  485.         if (strncmp(name,fname,*cpos) == 0) {
  486.  
  487.             /* count the number of matches */
  488.             matches++;
  489.  
  490.             /* if this is the first match, simply record it */
  491.             if (matches == 1) {
  492.                 strcpy(longestmatch,fname);
  493.                 longestlen = strlen(longestmatch);
  494.             } else {
  495.  
  496.                 /* if there's a difference, stop here */
  497.                 if (longestmatch[*cpos] != fname[*cpos])
  498.                     return;
  499.  
  500.                 for (index = (*cpos) + 1; index < longestlen; index++)
  501.                     if (longestmatch[index] != fname[index]) {
  502.                         longestlen = index;
  503.                         longestmatch[longestlen] = 0;
  504.                     }
  505.             }
  506.         }
  507.  
  508.         /* on to the next file */
  509.         fname = getnfile();
  510.     }
  511.  
  512.     /* beep if we never matched */
  513.     if (matches == 0) {
  514.         TTbeep();
  515.         return;
  516.     }
  517.  
  518.     /* the longestmatch array contains the longest match so copy and print it */
  519.     for ( ; (*cpos < (NSTRING-1)) && (*cpos < longestlen); (*cpos)++) {
  520.         name[*cpos] = longestmatch[*cpos];
  521.         TTputc(name[*cpos]);
  522.     }
  523.  
  524.     name[*cpos] = 0;
  525.  
  526.     /* if only one file matched then increment cpos to signal complete() */
  527.     /* that this was a complete match.  If a directory was matched then */
  528.     /* last character will be the DIRSEPCHAR.  In this case we do NOT *
  529.     /* want to signal a complete match. */
  530.     if ((matches == 1) && (name[(*cpos)-1] != DIRSEPCHAR))
  531.         (*cpos)++;
  532.  
  533.     TTflush();
  534.  
  535.     return;
  536. }
  537.  
  538. /*    tgetc:    Get a key from the terminal driver, resolve any keyboard
  539.         macro action                    */
  540.  
  541. int PASCAL NEAR tgetc()
  542.  
  543. {
  544.     int c;    /* fetched character */
  545.  
  546.     /* if we are playing a keyboard macro back, */
  547.     if (kbdmode == PLAY) {
  548.  
  549.         /* if there is some left... */
  550.         if (kbdptr < kbdend)
  551.             return((int)*kbdptr++);
  552.  
  553.         /* at the end of last repitition? */
  554.         if (--kbdrep < 1) {
  555.             kbdmode = STOP;
  556. #if    VISMAC == 0
  557.             /* force a screen update after all is done */
  558.             update(FALSE);
  559. #endif
  560.         } else {
  561.  
  562.             /* reset the macro to the begining for the next rep */
  563.             kbdptr = &kbdm[0];
  564.             return((int)*kbdptr++);
  565.         }
  566.     }
  567.  
  568.     /* if no pending character */
  569.     if (cpending == FALSE) {
  570.  
  571.         /* fetch a character from the terminal driver */
  572.         c = TTgetc();
  573.  
  574.     } else {
  575.         
  576.         c = charpending;
  577.         cpending = FALSE;
  578.     }
  579.  
  580.     /* record it for $lastkey */
  581.     lastkey = c;
  582.  
  583.     /* save it if we need to */
  584.     if (kbdmode == RECORD) {
  585.         *kbdptr++ = c;
  586.         kbdend = kbdptr;
  587.  
  588.         /* don't overrun the buffer */
  589.         if (kbdptr == &kbdm[NKBDM - 1]) {
  590.             kbdmode = STOP;
  591.             TTbeep();
  592.         }
  593.     }
  594.  
  595.     /* and finally give the char back */
  596.     return(c);
  597. }
  598.  
  599. /*    getkey:    Get one keystroke. The legal prefixs here
  600.             are the SPEC, MOUS and CTRL prefixes.
  601. */
  602.  
  603. PASCAL NEAR getkey()
  604.  
  605. {
  606.     int c;        /* next input character */
  607.     int upper;    /* upper byte of the extended sequence */
  608.  
  609.     /* get a keystroke */
  610.         c = tgetc();
  611.  
  612.     /* if it exists, process an escape sequence */
  613.     if (c == 0) {
  614.  
  615.         /* get the event type */
  616.         upper = tgetc();
  617.  
  618.         /* mouse events need us to read in the row/col */
  619.         if (upper & (MOUS >> 8)) {
  620.             /* grab the x/y position of the mouse */
  621.             xpos = tgetc();
  622.             ypos = tgetc();
  623.         }
  624.  
  625.         /* get the event code */
  626.         c = tgetc();
  627.  
  628.         /* if it is a function key... map it */
  629.         c = (upper << 8) | c;
  630.     }
  631.  
  632.     /* yank out the control prefix */
  633.         if (((c & 255) >=0x00 && (c & 255) <= 0x1F) || (c & 255) == 0x7F)
  634.                 c = CTRL | (c ^ 0x40);
  635.  
  636.     /* return the character */
  637.         return(c);
  638. }
  639.  
  640. /*    GETCMD:    Get a command from the keyboard. Process all applicable
  641.         prefix keys
  642.                             */
  643. PASCAL NEAR getcmd()
  644.  
  645. {
  646.     int c;        /* fetched keystroke */
  647.     KEYTAB *key;    /* ptr to a key entry */
  648.  
  649.     /* get initial character */
  650.     c = getkey();
  651.     key = getbind(c);
  652.  
  653.     /* resolve META and CTLX prefixes */
  654.     if (key) {
  655.         if (key->k_ptr.fp == meta) {
  656.             c = getkey();
  657. #if    SMOS
  658.             c = upperc(c&255) | (c & ~255); /* Force to upper */
  659. #else
  660.             c = upperc(c) | (c & ~255);    /* Force to upper */
  661. #endif
  662.             c |= META;
  663.         } else if (key->k_ptr.fp == cex) {
  664.             c = getkey();
  665. #if    SMOS
  666.             c = upperc(c&255) | (c & ~255); /* Force to upper */
  667. #else
  668.             c = upperc(c) | (c & ~255);    /* Force to upper */
  669. #endif
  670.             c |= CTLX;
  671.         }
  672.     }
  673.  
  674.     /* return it */
  675.     return(c);
  676. }
  677.  
  678. /*    A more generalized prompt/reply function allowing the caller
  679.     to specify the proper terminator. If the terminator is not
  680.     a return('\r'), return will echo as "<NL>"
  681.                             */
  682. PASCAL NEAR getstring(prompt, buf, nbuf, eolchar)
  683.  
  684. char *prompt;
  685. char *buf;
  686. int nbuf;
  687. int eolchar;
  688.  
  689. {
  690.     register int cpos;    /* current character position in string */
  691.     register int c;        /* current input character */
  692.     register int quotef;    /* are we quoting the next char? */
  693.  
  694.     cpos = 0;
  695.     quotef = FALSE;
  696.  
  697.     /* prompt the user for the input string */
  698.     if (discmd)
  699.         mlwrite(prompt);
  700.     else
  701.         movecursor(term.t_nrow, 0);
  702.  
  703.     for (;;) {
  704.         /* get a character from the user */
  705.         c = getkey();
  706.  
  707.         /* if they hit the line terminate, wrap it up */
  708.         if (c == eolchar && quotef == FALSE) {
  709.             buf[cpos++] = 0;
  710.  
  711.             /* clear the message line */
  712.             mlerase();
  713.             TTflush();
  714.  
  715.             /* if we default the buffer, return FALSE */
  716.             if (buf[0] == 0)
  717.                 return(FALSE);
  718.  
  719.             return(TRUE);
  720.         }
  721.  
  722.         /* change from command form back to character form */
  723.         c = ectoc(c);
  724.  
  725.         if (c == ectoc(abortc) && quotef == FALSE) {
  726.             /* Abort the input? */
  727.             ctrlg(FALSE, 0);
  728.             TTflush();
  729.             return(ABORT);
  730.         } else if ((c==0x7F || c==0x08) && quotef==FALSE) {
  731.             /* rubout/erase */
  732.             if (cpos != 0) {
  733.                 outstring("\b \b");
  734.                 --ttcol;
  735.  
  736.                 if (buf[--cpos] < 0x20) {
  737.                     outstring("\b \b");
  738.                     --ttcol;
  739.                 }
  740.  
  741.                 if (buf[cpos] == '\r') {
  742.                     outstring("\b\b  \b\b");
  743.                     ttcol -= 2;
  744.                 }
  745.                 TTflush();
  746.             }
  747.  
  748.          } else if (c == 0x0b && quotef == FALSE) {
  749.  
  750.              /* C-K, kill default buffer and return null */
  751.  
  752.              /* clear the buffer */
  753.              buf[0] = 0;
  754.  
  755.              /* clear the message line and return */
  756.              mlwrite("");
  757.              TTflush();
  758.              return(TRUE);
  759.  
  760.         } else if (c == 0x15 && quotef == FALSE) {
  761.  
  762.             /* C-U, kill */
  763.             while (cpos != 0) {
  764.                 outstring("\b \b");
  765.                 --ttcol;
  766.  
  767.                 if (buf[--cpos] < 0x20) {
  768.                     outstring("\b \b");
  769.                     --ttcol;
  770.                 }
  771.             }
  772.             TTflush();
  773.  
  774.         } else if (c == ectoc(quotec) && quotef == FALSE) {
  775.             quotef = TRUE;
  776.         } else {
  777.             quotef = FALSE;
  778.             if (cpos < nbuf-1) {
  779.                 buf[cpos++] = c;
  780.  
  781.                 if ((c < ' ') && (c != '\r')) {
  782.                     outstring("^");
  783.                     ++ttcol;
  784.                     c ^= 0x40;
  785.                 }
  786.  
  787.                 if (c != '\r') {
  788.                     if (disinp)
  789.                         mlout(c);
  790.                 } else {    /* put out <NL> for <ret> */
  791.                     outstring("<NL>");
  792.                     ttcol += 3;
  793.                 }
  794.                 ++ttcol;
  795.                 TTflush();
  796.             }
  797.         }
  798.     }
  799. }
  800.  
  801. PASCAL NEAR outstring(s) /* output a string of input characters */
  802.  
  803. char *s;    /* string to output */
  804.  
  805. {
  806.     if (disinp)
  807.         while (*s)
  808.             mlout(*s++);
  809. }
  810.  
  811. PASCAL NEAR ostring(s)    /* output a string of output characters */
  812.  
  813. char *s;    /* string to output */
  814.  
  815. {
  816.     if (discmd)
  817.         while (*s)
  818.             mlout(*s++);
  819. }
  820.  
  821.