home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / lemming / part01 / lemalpha.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-05  |  1.7 KB  |  113 lines

  1. /*
  2.  * lemalpha.c - text control
  3.  *
  4.  * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
  5.  */
  6.  
  7. #include "lem.h"
  8.  
  9. charadd(s, ch)
  10.     char *s, ch;
  11.     {
  12.     int end;
  13.     char str[2];
  14.     str[0] = ch;
  15.     str[1] = '\0';
  16.     charshow(str);
  17.     end = strlen(s);
  18.     if (end < MAXCHAR-1)
  19.     {
  20.     s[end] = ch;
  21.     s[end+1] = '\0';
  22.     }
  23.     }
  24.  
  25. chardel(s,n)
  26.     char *s;
  27.     {
  28.     int end;
  29.     end = strlen(s)-n;
  30.     if (end >= 0)
  31.     {
  32.     charunshow(n);
  33.     s[end] = '\0';
  34.     }
  35.     }
  36.  
  37. chardelall(s)
  38.     char *s;
  39.     {
  40.     if (s) chardel(s, strlen(s));
  41.     }
  42.  
  43. char getstroke()
  44.     {
  45.     int ev, t;
  46.     char ch;
  47. /*
  48.  * get next alpha keystroke (null on other event)
  49.  */
  50.     do  {
  51.     ev = getevent(&t, &t, &t, &t, &ch);
  52.     } while ((ev == NOEVT) || ((ev == CNTRL) && (ch == '\0')));
  53.     if ((ev == ALPHA) || (ev == CNTRL)) return(ch);
  54.     return('\0');
  55.     }
  56.  
  57. char *prompt(pstr)
  58.     char *pstr;
  59.     {
  60.     char ch, pout[MAXCHAR], *rstr;
  61.     pout[0] = '\0';
  62.     strncpy(prompttext, pstr, MAXCHAR);
  63.     msgclear();
  64.     chardelall(line);
  65.     charshow(prompttext);
  66.     ch = '\0';
  67.     while((ch != C(M)) && (ch != C(J)))
  68.     {
  69.     ch = getstroke();
  70.     if (ch >= ' ') charadd(pout, ch);
  71.     else if (ch == '\b') chardel(pout,1);
  72.     }
  73.     rstr = salloc(pout);
  74.     chardelall(pout);
  75.     chardelall(prompttext);
  76.     return(rstr);
  77.     }
  78.  
  79. msgpost(s)
  80.     char *s;
  81.     {
  82.     msgclear();
  83.     strncpy(msgtext, s, MAXCHAR);
  84.     charshow(msgtext);
  85.     }
  86.  
  87. msgclear()
  88.     {
  89.     chardelall(msgtext);
  90.     }
  91.  
  92. stringadd()
  93.     {
  94.     textadd(markx, marky, line);
  95.     if (line && strlen(line))
  96.     {
  97.     int hgt;
  98.     hgt = fontleading(gsize);
  99.     markupdate(markx, MAX(marky-hgt, hgt));
  100.     }
  101.     chardelall(line);
  102.     }
  103.     
  104. fontheight(f)
  105.     {
  106.     return(lemfont[(f >= rclen) ? 1 : f].psize);
  107.     }
  108.  
  109. fontleading(f)
  110.     {
  111.     return((fontheight(f)*6+2)/5);
  112.     }
  113.