home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 158_01 / qe3a < prev    next >
Text File  |  1987-10-12  |  6KB  |  301 lines

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