home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / emacs / src / meml.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-07  |  4.3 KB  |  233 lines

  1. #include "medisp.h"
  2. /*
  3.  * Erase the message line.
  4.  * This is a special routine because
  5.  * the message line is not considered to be
  6.  * part of the virtual screen. It always works
  7.  * immediately; the terminal buffer is flushed
  8.  * via a call to the flusher.
  9.  */
  10. mlerase()
  11. {
  12.     movecursor(23, 0);
  13.     ansieeol();
  14.     mpresf = FALSE;
  15. }
  16.  
  17. /*
  18.  * Ask a yes or no question in
  19.  * the message line. Return either TRUE,
  20.  * FALSE, or ABORT. The ABORT status is returned
  21.  * if the user bumps out of the question with
  22.  * a ^G. Used any time a confirmation is
  23.  * required.
  24.  */
  25. mlyesno(prompt)
  26. char    *prompt;
  27. {
  28.     register int    s;
  29.     char    buf[64];
  30.  
  31.     strcpy(buf, prompt);
  32.     strcat(buf, " [y/n]? ");
  33.     s = mlreply(buf, buf, sizeof(buf));
  34.     if ( s == ABORT ) return (ABORT);
  35.     if ( s != FALSE && ( buf[0] == 'y' || buf[0] == 'Y' ))
  36.         return ( 1 );
  37.     return ( 0 );
  38. }
  39.  
  40. /*
  41.  * Write a prompt into the message
  42.  * line, then read back a response. Keep
  43.  * track of the physical position of the cursor.
  44.  * If we are in a keyboard macro throw the prompt
  45.  * away, and return the remembered response. This
  46.  * lets macros run at full speed. The reply is
  47.  * always terminated by a carriage return. Handle
  48.  * erase, kill, and abort keys.
  49.  */
  50. mlreply(prompt, buf, nbuf)
  51. char    *prompt;
  52. char    *buf;
  53. {
  54.     register int    cpos;
  55.     register int    c;
  56.  
  57.     cpos = 0;
  58.     mlwrite(prompt);
  59.     for (;;)
  60.     {    switch ( c = getstroke())
  61.         {
  62.         case 0x0D:            /* Return, end of line    */
  63.             buf[cpos++] = 0;
  64.             conout( '\r' );
  65.             ttcol = 0;
  66.             if (buf[0] == 0)
  67.                 return (FALSE);
  68.             return (TRUE);
  69.  
  70.         case 0x07:            /* Bell, abort        */
  71.             conout( '^' );
  72.             conout( 'G' );
  73.             ttcol += 2;
  74.             ctrlg();
  75.             return (ABORT);
  76.  
  77.         case 0x7F:            /* Rubout, erase    */
  78.         case 0x08:            /* Backspace, erase    */
  79.             if (cpos != 0)
  80.             {    crtbs();
  81.                 if (buf[--cpos] < 0x20)
  82.                 {    crtbs();
  83.                 }
  84.             }
  85.             break;
  86. #ifdef NEVER
  87.         case 0x15:            /* C-U, kill        */
  88.             while (cpos != 0)
  89.             {    crtbs();
  90.                 if (buf[--cpos] < 0x20)
  91.                 {    crtbs();
  92.                 }
  93.             }
  94.             break;
  95. #endif
  96.         default:
  97.             if (cpos < nbuf-1)
  98.             {    buf[cpos++] = c;
  99.                 if (c < ' ')
  100.                 {    conout( '^' );
  101.                     ++ttcol;
  102.                     c ^= 0x40;
  103.                 }
  104.                 conout( c );
  105.                 ++ttcol;
  106.             }
  107.         }
  108.     }
  109. }
  110. crtbs()
  111. {    conout( '\b' );
  112.     conout( ' '  );
  113.     conout( '\b' );
  114.     --ttcol;
  115. }
  116. conout( c )
  117. {    bios( 4, c );
  118. }
  119. /*
  120.  * Write a message into the message
  121.  * line. Keep track of the physical cursor
  122.  * position. A small class of printf like format
  123.  * items is handled. Assumes the stack grows
  124.  * down; this assumption is made by the "++"
  125.  * in the argument scan loop. Set the "message
  126.  * line" flag TRUE.
  127.  */
  128. mlwrite(fmt, arg)
  129. char    *fmt;
  130. {
  131.     register int    c;
  132.     register char    *ap;
  133.  
  134.     movecursor(23, 0);
  135.     ap = (char *) &arg;
  136.     while ((c = *fmt++) != 0)
  137.     {    if (c != '%') goto out_it;
  138.         c = *fmt++;
  139.         switch (c)
  140.         {    case 'd':
  141.                 mlputi(*(int *)ap, 10);
  142.                 ap += sizeof(int);
  143.                 break;
  144.  
  145. #ifdef NEVER
  146.             case 'o':
  147.                 mlputi(*(int *)ap,  8);
  148.                 ap += sizeof(int);
  149.                 break;
  150.  
  151.             case 'x':
  152.                 mlputi(*(int *)ap, 16);
  153.                 ap += sizeof(int);
  154.                 break;
  155.  
  156.             case 'D':
  157.                 mlputli(*(long *)ap, 10);
  158.                 ap += sizeof(long);
  159.                 break;
  160. #endif
  161.             case 's':
  162.                 mlputs(*(char **)ap);
  163.                 ap += sizeof(char *);
  164.                 break;
  165.  
  166.             default:
  167. out_it:                conout( c );
  168.                 ++ttcol;
  169.         }
  170.     }
  171.     ansieeol();
  172.     mpresf = TRUE;
  173. }
  174.  
  175. /*
  176.  * Write out a string.
  177.  * Update the physical cursor position.
  178.  * This assumes that the characters in the
  179.  * string all have width "1"; if this is
  180.  * not the case things will get screwed up
  181.  * a little.
  182.  */
  183. mlputs(s)
  184. char    *s;
  185. {
  186.     register int    c;
  187.  
  188.     while ((c = *s++) != 0)
  189.     {    conout( c );
  190.         ++ttcol;
  191.     }
  192. }
  193.  
  194. /*
  195.  * Write out an integer, in
  196.  * the specified radix. Update the physical
  197.  * cursor position. This will not handle any
  198.  * negative numbers; maybe it should.
  199.  */
  200. mlputi(i, r)
  201. {
  202.     register int    q;
  203.     static char hexdigits[] = "0123456789ABCDEF";
  204.  
  205.     if (i < 0)
  206.     {    i = -i;
  207.         conout( '-');
  208.     }
  209.     q = i/r;
  210.     if (q != 0) mlputi(q, r);
  211.     conout( hexdigits[i%r]);
  212.     ++ttcol;
  213. }
  214. #ifdef NEVER
  215. /*
  216.  * do the same except as a long integer.
  217.  */
  218. mlputli(l, r)
  219. long l;
  220. {
  221.     register long q;
  222.  
  223.     if (l < 0)
  224.     {    l = -l;
  225.         conout( '-');
  226.     }
  227.     q = l/r;
  228.     if (q != 0) mlputli(q, r);
  229.     conout( (int)(l%r)+'0');
  230.     ++ttcol;
  231. }
  232. #endif
  233.