home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 331_01 / block.c < prev    next >
Text File  |  1990-06-14  |  11KB  |  424 lines

  1. /*
  2. HEADER:         CUG199.06;
  3. TITLE:          GED (nee QED) screen editor -- part six;
  4. DATE:           12/15/86;
  5.  
  6. DESCRIPTION:   "Block operation commands for the GED editor";
  7. KEYWORDS:       block operations;
  8. SYSTEM:         MS-DOS;
  9. FILENAME:       GED6.C;
  10. AUTHORS:        G. Nigel Gilbert, James W. Haefner,  Mel Tearle, G. Osborn;
  11. COMPILERS:      Microsoft 4.0;
  12. */
  13.  
  14. /*
  15.      e/qed/ged  screen editor
  16.  
  17.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  18.            August-December 1981
  19.  
  20.     Modified:  Aug-Dec   1984:   BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  21.                March     1985:   BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  22.                May       1986:   converted to ged - Mel Tearle
  23.  
  24.     FILE:      ged6.c
  25.  
  26.     FUNCTIONS: blockpos, blockops, putpart, listfile
  27.  
  28.     PURPOSE:   performs block commands
  29.  
  30. */
  31.  
  32. #include <stdio.h>
  33. #include "ged.h"
  34.  
  35.  
  36. blockpos(oldpos)
  37. int  oldpos;
  38. {
  39.     unsigned char getkey();
  40.     char  c;
  41.     int to;
  42.  
  43.     do  {
  44.         switch ( (c = getkey()) )  {
  45.         case DOWNKEY :
  46.             moveline(1);
  47.             break;
  48.         case UPKEY :
  49.             moveline(-1);
  50.             break;
  51.         case LEFTKEY :
  52.             movechar(-1);
  53.             break;
  54.         case RIGHTKEY :
  55.             movechar(1);
  56.             break;
  57.         case LEFTWKEY :
  58.             moveword(-1);
  59.             break;
  60.         case RIGHTWKEY :
  61.             moveword(1);
  62.             break;
  63.         case BOLKEY :
  64.             sync(0);
  65.             break;
  66.         case EOLKEY :
  67.             sync(strlen(text));
  68.             break;
  69.         case UPPAGE :
  70.             movepage(-1);
  71.             break;
  72.         case DOWNPAGE :
  73.             movepage(0);
  74.             break;
  75.         case HOMEKEY :
  76.             jumpline(lastl-cline);
  77.             break;
  78.         case BOFKEY :
  79.             jumpline(1-cline);
  80.             break;
  81.         case JUMPKEY :
  82.             dojump();
  83.             break;
  84.         case QWIKKEY :
  85.             info();
  86.             break;
  87.         case REPKEY :
  88.             repeat = YES;
  89.             dofindrep(1);
  90.             repeat = NO;
  91.             break;
  92.         case 'p' :
  93.         case 'P' :
  94.             if ( oldpos )  return  PREV;
  95.             break;
  96.         case ESCKEY :
  97.             return  FAIL;
  98.         default :
  99.             ;
  100.         }
  101.     }
  102.     while ( c != CR );
  103.     return  cline;
  104. }
  105.  
  106.  
  107. /* 'K'- key block options
  108.  * some mods to print routine - mt.
  109.  */
  110. blockops()
  111. {
  112.     unsigned char getkey();
  113.     int   oldcline, oldcharn, oldto, oldfrom, op;
  114.     int   l, ll, line, *t, shifts, shiftx, cp;
  115.     char  *txt, c, shift[LLIM];
  116.  
  117.     puttext();
  118.     blankedmess = YES;  /* disable time of day display */
  119.     oldcline = cline;
  120.     oldcharn = charn;
  121.     oldfrom  = vbord1;
  122.     oldto    = vbord2;
  123.  
  124.     putmess("|Q|uit, e|X|it with save, |R|ead file, |B|lock/output operations ");
  125.     while ( (op = getlow()) != 'q'  &&  op != 'x'  &&  op != 'r' &&
  126.         op != 'b'  &&  op != 'j' &&
  127.         op != ESCKEY );
  128.     if ( op == ESCKEY  )
  129.         return;
  130.  
  131.     putch(op);
  132.     switch (op)  {
  133.     case 'q':
  134.         return('q');
  135.         break;
  136.     case 'x':
  137.         return('x');
  138.         break;
  139.     case 'r':
  140.         putmess("Wait");
  141.         return('r');
  142.         break;
  143.     case F7KEY:
  144.         return  (NO);
  145.         break;
  146.     default:
  147. /* block commands */
  148.         vbord1 = cline;
  149.         vbord2 = 0;      /* use updated cline for second limit */
  150.         blocking = YES;
  151.  
  152.         putline(cline, cursory, NULL);  /* reverse field current line */
  153.         putmess( "Move cursor then press <return>");
  154.  
  155.         if (blockpos(oldto) == FAIL) {
  156.             goto abort;
  157.         }
  158.         if ( vbord2 == PREV )  {
  159.             moveline( oldfrom-cline );
  160.             vbord1 = cline;
  161.             moveline( oldto-cline );
  162.             vbord2 = cline;
  163.         }
  164.         if (vbord2 == 0)
  165.             vbord2 = cline;
  166.  
  167.         if ( vbord2 < vbord1 )  {
  168.             l = vbord2;
  169.             vbord2 = vbord1;
  170.             vbord1 = l;
  171.         }
  172.  
  173.  
  174.         putmess("|W|rite to file, |P|rint, |S|hift, |M|ove, |C|opy, or |D|elete block ? ");
  175.         while ((op=getlow()) != 'w' && op != 'p' && op != 's' && op != 'm'
  176.             && op != 'c' && op != 'd' && op != ESCKEY);
  177.  
  178.         switch (op)  {
  179.         case ESCKEY:
  180.            goto abort;
  181.            break;
  182.         case 'w':
  183.             putmess( " File to write to? ");
  184.             if ( scans( name, FILELEN ) != ESCKEY )
  185.                 if ( exists( name ) )
  186.                     writefile( vbord1, vbord2, name, name );
  187.             break;
  188.  
  189.         case 'p':
  190.             if ( !prnstat() )
  191.                 goto abort;      /* add 12/13/86 */
  192.             cleareol( 0, 0 );
  193.             putstatusline( vbord1 );
  194.             listfile( vbord1, vbord2 );
  195.             putmess( "Any |Function Key| to form feed ");
  196.             c = getkey();
  197.             if ( c >= F1KEY  &&  c <= F10KEY )
  198.                 listout(  0x0c );
  199.             break;
  200.  
  201.         case 's':
  202.             charn=0;
  203.             moveline( vbord1 - cline );
  204.             putmess( "Insert or delete spaces/tabs to shift block, press <return>");
  205.             shifts = 0;
  206.             while ( (c = getkey()) != CR )  {
  207.                 switch (c)  {
  208.                 case DELRIGHT:
  209.                     if ( text[0] == ' ' || text[0] == '\t' )
  210.                         deletechar(0);
  211.                     break;
  212.                 case ' ':
  213.                     insertchar(' ');
  214.                     break;
  215.                 case TAB:
  216.                     insertchar('\t');
  217.                     break;
  218.                 case ESCKEY:
  219.                     goto abort;
  220.                 }
  221.                 shift[shifts++] = c;
  222.                 sync(0);
  223.                 rewrite(0);
  224.             }
  225.             puttext();
  226.             for ( l = vbord1 + 1; l <= vbord2; l++ )  {
  227.                 gettext(l, charn);
  228.                 for ( shiftx = 0; shiftx < shifts; shiftx++ )  {
  229.                     switch( ( c = shift[shiftx] ) )  {
  230.                     case DELRIGHT:
  231.                         if ( *(txt=&text[0]) == ' ' || *txt == '\t' )
  232.                             while ( (*txt=*(txt+1)) ) txt++;
  233.                         break;
  234.                     case ' ':
  235.                     case TAB:
  236.                         if ( (cp = strlen( text ) ) < (LLIM-1) )  {
  237.                             for ( ; cp >= 0; cp-- )
  238.                                 text[cp+1]=text[cp];
  239.                             text[0] = ( c == ' ' ? ' ': '\t' );
  240.                         }
  241.                         break;
  242.                     }
  243.                 }
  244.                 altered = YES;
  245.                 puttext();
  246.             }
  247.             break;
  248.  
  249. /* block delete */
  250.         case 'd':
  251.             deltp( vbord1, vbord2-vbord1+1 );
  252.             blocking = NO;
  253.             plast = -1;
  254.             moveline(vbord1-cline);
  255.             break;
  256.  
  257. /* block copy or move */
  258.         case 'm':
  259.         case 'c':
  260.             if (op == 'm')
  261.                 putmess("Put cursor under |move| destination and press <return>");
  262.             else
  263.                 putmess("Put cursor under |copy| destination and press <return>");
  264.             if ( (line = blockpos(0)) == FAIL )  {
  265.                 break;
  266.             }
  267.             putmess("Wait");
  268.             line--;
  269.             for ( l = vbord1; l <= vbord2; l++ )  {
  270.                 if ( (line = inject( line, getline(l)) ) == FAIL )
  271.                     break;
  272.                 if ( op == 'm' )  {
  273.                     deltp( ( l < line ? l : l + 1 ), 1 );
  274.                     if ( vbord2 < line )  {
  275.                         vbord2--;
  276.                         l--;
  277.                         line--;
  278.                         cline--;
  279.                     }
  280.                 }
  281.                 else {
  282.                     if (vbord2 >= line)
  283.                         vbord2++;
  284.                     if (l >= line)
  285.                         l++;
  286.                     if (l == cline)
  287.                         l = line;
  288.                 }
  289.             }
  290.  
  291.             vbord1 = cline;
  292.             vbord2   = line;
  293.             blocking=TRUE;
  294.             calp();
  295.             if (vbord2 >= plast)
  296.                 cursory += plast - vbord2 -1;  /* limit checked in calp() */
  297.  
  298.             plast = -1;
  299.             moveline(0);    /* show the new block */
  300.             while (chkbuf() == 0)
  301.                 ;
  302.             blocking=FALSE;  /* clear the reverse field on the first keystroke */
  303. /* the keystroke is then used normally */
  304.             break;
  305.         }
  306. abort:
  307.         blocking = NO;
  308.         switch (op)  {
  309.         case 'w':
  310.         case 'p':
  311.         case 's':
  312.             break;
  313.         case 'd':
  314.             break;
  315.         case 'm':
  316.         case 'c':
  317.         break;
  318.         }
  319.  
  320.         plast = -1;
  321.         moveline(0);
  322.         return NO;
  323.     }   /* outer case */
  324.  
  325. }       /* func blockops */
  326.  
  327.  
  328. /* get status of parallel printer port - is the printer turned on?
  329.  * report if error
  330.  */
  331. prnstat()
  332. {
  333.     rax = ( 0x02 << 8 );
  334.     rdx = 0;                  /* 0 = prn */
  335.     syscall();
  336.  
  337.     if ( ( ( rax >> 8 ) & 0x80 ) ||
  338.         ( ( rax >> 8 ) & 0x40 ) ||
  339.         ( ( rax >> 8 ) & 0x10 ) )
  340.         return( 1 );
  341.     else  {
  342.         putch( '\07' );
  343.         error( " error on printer " );
  344.         return( 0 );
  345.     }
  346. }
  347.  
  348.  
  349. /* printer routine
  350.  */
  351. listfile(from,to)
  352. int  from, to;
  353. {
  354.     unsigned char testkey();
  355.     int  cp, i, k, l;
  356.     char *t;
  357.  
  358.     k = 0;
  359.  
  360.     puttext();
  361.     for ( l = from; l <= to; l++, k++ )  {
  362.         curson(NO);
  363.         if ( l%10 == 0  && l > 1 )  putlineno(l);
  364.         if ( k >= PAGELEN - NLINES )  {
  365.             for ( i = k; i < PAGELEN; i++ )  {
  366.                 listout('\r');
  367.                 listout('\n');
  368.             }
  369.             k = 0;
  370.         }
  371.         for ( cp = 0, t = getline(l); *t; t++ )
  372.             if (*t == '\t') for (i=tabwidth-cp%tabwidth; i>0 ; cp++, i--)
  373.                 listout(' ');
  374.         else {
  375.             if (*t > 0x19) listout(*t);      /* send some ctrl char */
  376.             else {                              /* for OKI & CITOH */
  377.                 switch (*t)  {
  378.                     case (0x08):
  379.                     case (0x0a):
  380.                     case (0x0c):
  381.                     case (0x0d):
  382.                     case (0x18):
  383.                     listout(*t);
  384.                     break;
  385.                 default:
  386.                     {
  387.                         listout('^');
  388.                         listout(*t+64);
  389.                     }
  390.                 }
  391.             }
  392.             cp++;
  393.         }
  394.         listout('\r');
  395.         listout('\n');
  396.  
  397.         if ( testkey() == ESCKEY )  {
  398.             error(" Listing aborted ");
  399.             goto ret1;
  400.         }
  401.     }
  402. ret1:;
  403.     curson(YES);
  404.     calp();
  405.     return;
  406. }
  407. listout(c)
  408. int c;
  409. {
  410.     rdx = c;
  411.     rax = 05 << 8;
  412.     syscall();
  413.     return;
  414. }
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.