home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 133_01 / e3 < prev    next >
Text File  |  1985-03-10  |  5KB  |  269 lines

  1. /*
  2.     e screen editor
  3.  
  4.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  5.  
  6.     August-December 1981
  7.  
  8.     FILE: e3
  9.  
  10.     FUNCTIONS: putline,putoffset,putstatusline,putlineno,,putpage,
  11.             putmess,unmess,puts,rewrite,calcoffset,resetcursor
  12.  
  13.     PURPOSE: write text to screen
  14.  
  15. */
  16.  
  17. #include "e.h"
  18.  
  19. putline(line,y)
  20. int line, y;
  21. {
  22.     char *getline(), *p, c;
  23.     int cp, bright, lastcol, off, x, nblank;
  24.  
  25.     deleteline(0,y);
  26.     if (line <= lastl) {
  27.  
  28.         bright= !hilight || line == cline;
  29.         if (blocking && !bright) {
  30.             if (to) bright= (line >= from) && (line <= to);
  31.             else bright= (line >= (from > cline ? cline : from)) &&
  32.             (line <= (from > cline ? from  : cline));
  33.             }
  34.  
  35.         lastcol=SWIDTH;
  36.         off=x=0;
  37.         p=getline(line);
  38.         if ( (line == cline && calcoffset()) || (blockscroll && offset) ) {
  39.             lastcol+=offset-1;
  40.             off=offset;
  41.             x=1;
  42.             makedim();
  43.             putch('<');
  44.             makebright();
  45.             }
  46.  
  47.         if (!bright) makedim();
  48.  
  49.         for (cp=nblank=0; *p && cp < lastcol; p++) {
  50.             if (*p == '\t')
  51.                 do {
  52.                     if (cp >= off && cp < lastcol)
  53.                         nblank++;
  54.                     }
  55.                 while (++cp % tabwidth);
  56.             else {
  57.                 if (cp++ >= off) {
  58.                     if (*p == ' ') nblank++;
  59.                     else {
  60.                         if (nblank) {
  61.                             x+=nblank;
  62.                             if (nblank < GOTOLEN)
  63.                                 for (; nblank; nblank--)
  64.                                     putch(' ');
  65.                             else {
  66.                                 gotoxy(x,y);
  67.                                 nblank=0;
  68.                                 }
  69.                             }
  70.                         dispch(*p);
  71.                         x++;
  72.                         }
  73.                     }
  74.                 }
  75.             }
  76.         if (*p && y < SHEIGHT) {
  77.             if (bright) makedim();
  78.             else makebright();
  79.             gotoxy(SWIDTH,y);
  80.             putch('>');
  81.             }
  82.         makebright();
  83.         }
  84. }
  85.  
  86. putoffset()
  87. {
  88.     int i;
  89.  
  90.     gotoxy(0,0);
  91.     if (offset) for(i=3-uspr(offset); i>0; i--) putch(' ');
  92.     else puts("   ");
  93.     gotoxy(0,cursory);
  94. }
  95.  
  96. putstatusline(line)
  97. int line;
  98. {
  99.     deleteline(FNPOS,0);
  100.     makedim();
  101.     puts(filename);
  102.     putlineno(line);
  103.     makebright();
  104.     if (errmess != NULL) {
  105.         gotoxy(EMPOS,0);
  106.         puts(errmess);
  107.         }
  108. }
  109.  
  110. putlineno(line)
  111. int line;
  112. {
  113.     int i;
  114.  
  115.     if (!displaypos) return;
  116.     gotoxy(LNPOS,0);
  117.     makedim();
  118.     i=uspr(line);
  119.     putch(':');
  120.     for (i=8-i-uspr(cursorx+1); i > 0; i--) putch(' ');
  121.     makebright();
  122. }
  123.  
  124. putpage()    /*display page more or less centered about 'cline'*/
  125. {
  126.     int y,line;
  127.  
  128.     pfirst= loc(cline,(topline-SHEIGHT)/2);
  129.     plast = loc(pfirst,SHEIGHT-topline);
  130.     putstatusline(cline);
  131.     for (line=pfirst, y=topline; line <= plast; line++, y++) {
  132.         if (cline == line) {
  133.             cursory = y;
  134.             adjustc(cursorx);
  135.             }
  136.         putline(line,  y);
  137.         }
  138.     if (y <= SHEIGHT) delpage(y);
  139. }
  140.  
  141. putmess(message)
  142. char *message;
  143. {
  144.     int lines;
  145.     
  146.     if (blankedmess && topline > blankedmess) {
  147.         gotoxy(3,blankedmess++);
  148.         puts(message);
  149.         return;
  150.         }
  151.  
  152.     if (topline == (helpon ? HELPLINES : 1)) lines=2;
  153.     else lines=1;
  154.     if (cursory < (topline+=lines)) {
  155.         gotoxy(0,cursory);
  156.         for ( ; cursory < topline; cursory++) {
  157.                 insertline();
  158.                 if (plast != lastl) plast--;
  159.                 }
  160.         }
  161.     else pfirst+= lines;
  162.     deleteline(0,topline-2);
  163.     deleteline(0,topline-1);
  164.     gotoxy(3,topline-2);
  165.     puts(message);
  166. }
  167.  
  168. unmess()
  169. {
  170.     int l, i, newtop, diff;
  171.  
  172.     newtop= (helpon ? HELPLINES : 1);
  173.     if (!(diff=topline-newtop)) return;
  174.     if (diff < PAGEOVERLAP && pfirst-diff < 1) {
  175.         if (blankedmess == newtop) return;
  176.         for (l=newtop; l < topline; l++) deleteline(0,l);
  177.         blankedmess=newtop;
  178.         return;
  179.         }
  180.     blankedmess=NO;
  181.     if ((pfirst-=diff) < 1) {
  182.         topline=newtop;
  183.         putpage();
  184.         }
  185.     else {
  186.         for (l=newtop, i=0; l < topline; l++, i++) putline(pfirst+i,l);
  187.         topline=newtop;
  188.         }
  189. }
  190.  
  191. puts(s)        /*as usual, but turns text bright or dim as required*/
  192. char *s;
  193. {
  194.     int dim;
  195.     char c;
  196.  
  197.     dim=NO;
  198.     while ( (c=*s++) )
  199.         switch(c) {
  200.         case BRIDIM :
  201.             (dim=!dim) ? begdim() : enddim(); 
  202.             break;
  203.         case '\n':    
  204.             putch('\r');
  205.         default  :    
  206.             putch(c);
  207.             }
  208.     if (dim) enddim();
  209. }
  210.  
  211. rewrite(cp,x)    /*rewrites current line from char 'cp', col 'x', onwards*/
  212. int cp, x;
  213. {
  214.     int i, begmark;
  215.     char c;
  216.  
  217.     begmark= (calcoffset() > 0);
  218.     i= x-offset+begmark;
  219.     deleteline((i>0 ? i : 0),cursory);
  220.     if (!x && begmark) { 
  221.         begdim(); 
  222.         putch('<'); 
  223.         enddim(); 
  224.         }
  225.     while (x < SWIDTH+offset-begmark && (c=text[cp++])) {
  226.         if (c == '\t') {
  227.             for (i=tabwidth-x%tabwidth; i>0 && x<SWIDTH+offset-begmark; x++, i--)
  228.                 if (x >= offset) putch(' ');
  229.             }
  230.         else if (x++ >= offset) dispch(c);
  231.         }
  232.     if (c && cursory < SHEIGHT) {
  233.         begdim(); 
  234.         putch('>'); 
  235.         enddim(); 
  236.         }
  237. }
  238.  
  239. calcoffset()        /*calculate horizontal screen offset required for
  240.             cursor to be on screen*/
  241. {
  242.     for (offset=(!blockscroll || cursorx < lastoff ? 0 : lastoff);
  243.         cursorx >= SWIDTH+offset-(offset>0); offset+=OFFWIDTH);
  244.     return offset;
  245. }
  246.  
  247. resetcursor()        /*put cursor on current character, coping with
  248.             horizontal scroll */
  249. {
  250.     int line, y;
  251.  
  252.     if (lastoff != calcoffset()) {
  253.         if (blockscroll) {
  254.             for (line=pfirst, y=topline; line <= plast; line++, y++)
  255.                 if (line != cline) putline(line,y);
  256.             }
  257.         putoffset();
  258.         rewrite(0,0);
  259.         lastoff=offset;
  260.         }
  261.     gotoxy(cursorx-offset+(offset>0),cursory);
  262. }
  263. (3,topline-2);
  264.     puts(message);
  265. }
  266.  
  267. unmess()
  268. {
  269.     int l, i, newtop, diff;