home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 199_01 / ged3.c < prev    next >
Text File  |  1987-12-17  |  9KB  |  429 lines

  1. /*
  2. Header:          CUG199;
  3. Title:           Module 3 of ged editor;
  4. Last Updated:    11/22/87;
  5.  
  6. Description:    "PURPOSE: write text to screen";
  7.  
  8. Keywords:        e, editor, ged, qed, DeSmet, MSDOS;
  9. Filename:        ged3.c;
  10. Warnings:       "O file must be present during link for ged";
  11.  
  12. Authors:         G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
  13. Compilers:       DeSmet 3.0;
  14.  
  15. Refrences:
  16. Endref;
  17. */
  18.  
  19. /*
  20. e/qed/ged screen editor
  21.  
  22. (C) G. Nigel Gilbert, MICROLOGY, 1981 - August-December 1981
  23.  
  24. Modified:  Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  25.            March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  26.  
  27.            May       1986:  qed converted to ged         (Mel Tearle)
  28.            August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  29.  
  30. File:      ged3.c
  31.  
  32. Functions: putline, rewrite, putstatusline, putlineno, uspr,
  33.            putpage, putmess, unmess, putstr, rewrite, calcoffset,
  34.            resetcursor, setstatusname
  35. */
  36.  
  37. #ifndef  TC
  38. #include "ged.h"
  39. #else
  40. #include "ged.t"
  41. #endif
  42.  
  43.  
  44. /* write a line to the screen - directly to screen memory
  45.  */
  46. void putline(line,y)
  47. int  line, y;
  48. {
  49. char  vbuf[SWIDTH+2];
  50. char  *getline();
  51. int   bright, lastcol, off, lattr, loff;
  52.  
  53. char  *p;
  54. register int   cp, i;
  55.  
  56. lastcol = SWIDTH;  off = loff = i = 0;  bright = YES;
  57.  
  58. #ifndef  DS
  59.   memset( vbuf, ' ', SWIDTH+1 );
  60. #else
  61.  _setmem( vbuf, SWIDTH+1, ' ' );
  62. #endif
  63.  
  64. vbuf[SWIDTH+1] = '\0';
  65.  
  66. /* if block option and line in range from -> to, then not bright
  67.  */
  68. if ( line <= lastl )  {
  69.      if ( blocking )  {
  70.       if (to)  bright = !( (line >= from)  &&  (line <= to) );
  71.           else  bright = !( (line >= (from > cline ? cline : from) )  &&
  72.           ( line <= (from > cline ? from  : cline)) );
  73.   }
  74.   p = getline(line);
  75.  
  76.   if ( ( line == cline && calcoffset() ) || ( blockscroll && offset ) )  {
  77.          lastcol += offset - 1;
  78.          off = offset;
  79.          if ( !bright )  makebright();  else  makedim();
  80.          loff = lattr = attr;
  81.          i++;
  82.   }
  83.   if ( !bright )  makedim();  else  makebright();
  84.  
  85.   for ( cp = 0; *p  &&  cp  < lastcol; p++ )  {
  86.     if ( cp++ >= off )   {
  87.          if ( *p == '\t' )
  88.                do  {
  89.                  if ( cp >= off  &&  cp < lastcol )
  90.                       vbuf[i++] = ' ';
  91.                }
  92.                while ( ++cp % tabwidth );
  93.           else
  94.                  if ( *p != 10  &&  *p != 26  )
  95.                       vbuf[i++] = *p;
  96.     }
  97.   }
  98.  
  99.   scr_putstr( 0, y, vbuf, attr );
  100.  
  101.   /* take care of offset indicators
  102.    */
  103.   if ( loff )  scr_aputch( 0, y, '', lattr );
  104.  
  105.   if ( *(p)  &&  ( cp >= SWIDTH ) ) {
  106.      if ( bright )  makedim();  else   makebright();
  107.      scr_aputch( SWIDTH, y, '', attr );
  108.   }
  109.   makebright();
  110.   }
  111. }
  112.  
  113.  
  114. /* rewrites current line from char 'cp', col 'x', onwards
  115.  * no re-writes on dim lines
  116.  * »» note: rewrite (0, 0) will force an update of the current line ««
  117.  */
  118. void rewrite(cp,x)
  119. int cp, x;
  120. {
  121. int   i, j, k, begmark;
  122. char  vbuf[SWIDTH+2];
  123. char  c;
  124.  
  125. i = j = k = 0;
  126.  
  127. begmark = ( calcoffset() > 0 );
  128.  
  129. i = x - offset + begmark;
  130.  
  131. if ( i > 0 ) k = i;
  132.  
  133. if ( !x  &&  begmark )  {
  134.      i++;  k++;
  135.      scr_aputch( 0, cursory, '', DIM );
  136. }
  137.  
  138. #ifndef DS
  139.   memset( vbuf, ' ', ( SWIDTH+1 ) - k );
  140. #else
  141.  _setmem( vbuf, (SWIDTH+1) - k, ' ' );
  142. #endif
  143.  
  144. vbuf[(SWIDTH+1)-k] = '\0';
  145.  
  146. while( ( x < SWIDTH+offset-begmark ) && ( ( c = text[cp++] ) != '\0' ) )  {
  147.   if ( c == '\t' )  {
  148.        for ( i = tabwidth-x%tabwidth; i>0 && x<SWIDTH+offset-begmark; x++, i--)
  149.          if ( x >= offset )
  150.               vbuf[j++] = ' ';
  151.   }
  152.   else if ( x++ >= offset  &&  c != 10  &&  c != 26  )
  153.                    vbuf[j++] = c;
  154. }
  155. scr_putstr( k, cursory, vbuf, attr );
  156.  
  157. if ( c )
  158.      scr_aputch( SWIDTH, cursory, '' , DIM );
  159. }
  160.  
  161.  
  162. void putstatusline(line)
  163. int line;
  164. {
  165. scr_delete( 0, 0 );   putlineno( line );   scr_cursoff();
  166.  
  167. if ( caps_on() )  scr_aputs( CAPLK, 0, " Caps ", REVS );
  168.  
  169. scr_aputs( FNPOS, 0, pathname, DIM );
  170.  
  171. if ( overtype )   scr_aputs( OVERT, 0, " Overtype ", REVS );
  172.  
  173. show_time();
  174. }
  175.  
  176.  
  177. /* uses scr_aputs to move the cursor else uspr won't work right
  178.  */
  179. void putlineno(line)
  180. int line;
  181. {
  182. int i;
  183. static int prevline, prevcursor;
  184.  
  185. if ( blankedmess ) prevline = prevcursor = 0;
  186.  
  187. if ( prevline != line || line == 1 )  {
  188.      scr_cursoff();
  189.      scr_aputs( LNPOS, 0, "Line ", DIM );
  190.      for ( i = 5-1-uspr( line, 0L ); i > 0; i-- )  scr_co( ' ' );
  191.      prevline = line;
  192.   }
  193.  
  194. if ( prevcursor != cursorx || cursorx == 0 )  {
  195.      scr_cursoff();
  196.      scr_aputs( COLPOS, 0, "Col ", DIM );
  197.      for ( i = 4-1-uspr( cursorx, 0L ); i > 0; i-- )  scr_co( ' ' );
  198.      prevcursor = cursorx;
  199.   }
  200. }
  201.  
  202.  
  203. /* print 'n' as a number, return number of chars typed
  204.  * useful in debugging
  205.  */
  206. int uspr(sn,ln)
  207. int sn;
  208. long ln;
  209. {
  210. int temp;
  211. long n;
  212.  
  213. n = 0;
  214. if ( !ln ) n = sn;
  215.      else n = ln;
  216.  
  217. if ( n < 10 )  {
  218.      scr_putch( ( char ) n + '0', DIM );
  219.      return 1;
  220. }
  221. temp = uspr( 0, n/10 );
  222. uspr( 0, n%10 );
  223.  
  224. return  temp+1;
  225. }
  226.  
  227.  
  228. /* display page - with current centered
  229.  */
  230. void putpage()
  231. {
  232. int  y, line;
  233. char c;
  234.  
  235. pfirst = loc( cline, ( topline - SHEIGHT)/2 );
  236. plast  = loc( pfirst, SHEIGHT - topline );
  237.  
  238. for ( line = pfirst, y = topline; line <= plast; line++, y++ )  {
  239.       if ( cline == line )  {
  240.            cursory = y;
  241.            adjustc( cursorx );
  242.       }
  243.       putline( line, y );
  244.       if ( inbufp && ( cline != 1 ) && ( cline != lastl ) )
  245.       if ( ( ( c = inbuf[0] ) == tran[DOWNPAGE] )
  246.                || ( c == tran[UPPAGE] ) )  return;
  247. }
  248. if ( y <= SHEIGHT )   scr_cls( y );
  249. }
  250.  
  251.  
  252. /* uses putstr, a special case string writer
  253.  */
  254. void putmess(message)
  255. char *message;
  256. {
  257.  
  258. scr_delete(0,0);
  259. putstr( message );
  260. blankedmess =  YES;
  261.  
  262. }
  263.  
  264.  
  265. /* restore screen from message or window
  266.  */
  267. void unmess()
  268. {
  269. int l, i, newtop, diff;
  270.  
  271. newtop = ( screen ? window : 1 );
  272.  
  273. if ( newtop > window ) newtop = window;
  274.  
  275. if ( !( diff = topline - newtop ) )  return;
  276.  
  277. if ( diff < PAGEOVERLAP && pfirst - diff < 1 )  {
  278.   /*    if ( blankedmess == newtop )  */
  279.      if ( newtop  == 1 )
  280.           return;
  281.  
  282. /*   for ( l = newtop; l < topline; l++ )
  283.            scr_delete( 0, l );  */
  284.  
  285.      for ( l = newtop; l < topline;  )
  286.            scr_delete( 0, l++ );
  287.  
  288. /*   blankedmess = newtop;  */
  289.      blankedmess = YES;
  290.      return;
  291. }
  292. blankedmess = NO;
  293.  
  294. if ( ( pfirst -= diff ) < 1 )  {
  295.        topline = newtop;
  296.        putpage();
  297. }
  298. else  {
  299.   for ( l = newtop, i = 0; l < topline; l++, i++ )
  300.         putline( pfirst + i, l );
  301.   topline = newtop;
  302.  }
  303. }
  304.  
  305.  
  306. /* writes all messages to screen replaced putch with scr_putch
  307.  */
  308. void putstr(s)
  309. char *s;
  310. {
  311. int  on;
  312. char c;
  313.  
  314. on = YES;   high();
  315.  
  316. while( *(s) )  {
  317.   c = *s;
  318.   switch(c)  {
  319.     case BRIDIM :
  320.       if ( on ) dim(); else high();
  321.       on = !on;
  322.       break;
  323.     case '\n':  {
  324.       putret();
  325.       break;
  326.     }
  327.     default :
  328.       scr_putch( c, attr );
  329.   }
  330.   s++;
  331. }
  332. high();
  333. }
  334.  
  335.  
  336. int calcoffset()
  337. {
  338. for ( offset = 0;
  339.       cursorx >= SWIDTH+offset-(offset>0);
  340.       offset += OFFWIDTH );
  341. return  offset;
  342. }
  343.  
  344.  
  345. /* does a rewrite of screen if offsets change
  346.  */
  347. void resetcursor()
  348. {
  349. int line, y;
  350.  
  351. /* compare offsets */
  352. if ( lastoff != calcoffset() )  {
  353. /* ok to horizontal scroll, write everything but current line
  354.  */
  355.    if ( blockscroll )  {
  356.     for ( line = pfirst, y = topline; line <= plast; line++, y++ )
  357.           if ( line != cline )  putline( line, y );
  358.    }
  359.    scr_xy( 0, cursory );   rewrite( 0, 0 );   lastoff = offset;
  360. }
  361. scr_xy( cursorx-offset + ( offset > 0 ), cursory );
  362. }
  363.  
  364.  
  365. /* make full pathname for 'putstatusline' - truncate if too long
  366.  */
  367. char setstatusname()
  368. {
  369. char *np, c;
  370. char temp[FILELEN];
  371.  
  372. int  i , p;
  373.  
  374. pathname[0] = '\0';
  375.  
  376. if ( filename[0] == '\0' )  return( '\0');
  377.  
  378. np = filename;
  379.  
  380. while( *(np) ) np++;             /* find end */
  381.                                  /* find last '\',if any  */
  382. while( ( ( c = *(--np)) != '\\')  &&  c != ':'  &&  ( np != filename ) )  {
  383.   if ( c == '.' )  {             /* save any extension */
  384.        if ( *(np+1) == '\0' )
  385.             *(np) = '\0';
  386.        strcpy( defext, np );
  387.   }
  388. }
  389.  
  390. if ( !( *np ) )
  391.      strcpy( temp, filename );
  392. else
  393.     strcpy( temp, ++np );
  394.  
  395. #ifndef  DS
  396.   memset( pathname, '\0', FILELEN  );
  397. #else
  398.  _setmem( pathname, FILELEN, '\0' );
  399. #endif
  400.  
  401. curdrv( pathname );
  402. getpath( pathname );
  403.  
  404. if ( ( strlen( pathname ) ) > 3 )  strcat( pathname,  "\\" );
  405.  
  406. strcat( pathname, temp );
  407.  
  408. if ( ( p = strlen( pathname ) ) > PATHLEN )  {
  409.        strcpy( temp, pathname );
  410.        for( i = 0; i <= PATHLEN; i++ )
  411.             pathname[i] = temp[--p];
  412.  
  413.     pathname[i++] = '\0';
  414.     strrev( pathname );
  415.     pathname[0] = '*';
  416.   }
  417. else  {
  418.    p = strlen( pathname );
  419.    for ( i = 0; i < ( PATHLEN - p )/2; i++ )
  420.          temp[i] = ' ';
  421.  
  422.    temp[i++] = '\0';
  423.    strcat( temp, pathname );
  424.    strcpy( pathname, temp );
  425.   }
  426. }
  427.  
  428. /* that's all */
  429.