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

  1. /*
  2.     e screen editor
  3.  
  4.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  5.  
  6.     August-December 1981
  7.  
  8.     FILE: e6
  9.  
  10.     FUNCTIONS: blockpos,blockops,putpart,listfile
  11.  
  12.     PURPOSE: performs block commands
  13.  
  14. */
  15.  
  16. #include "e.h"
  17.  
  18. blockpos(oldpos)
  19. int oldpos;
  20. {
  21.     char c, getkey();
  22.     int to;
  23.  
  24.     if (oldpos) puts("| or |P|rev.");
  25.     do {
  26.         putlineno(cline);
  27.         resetcursor();
  28.         switch ((c=getkey())) {
  29.         case DOWNKEY    :
  30.             moveline(1);
  31.             break;
  32.         case UPKEY    :
  33.             moveline(-1);
  34.             break;
  35.         case LEFTKEY    :
  36.             movechar(-1);
  37.             break;
  38.         case RIGHTKEY    :
  39.             movechar(1);
  40.             break;
  41.         case LEFTWKEY    :
  42.             moveword(-1);
  43.             break;
  44.         case RIGHTWKEY    :
  45.             moveword(1);
  46.             break;
  47.         case BOLKEY    :
  48.             sync(0);
  49.             break;
  50.         case EOLKEY    :
  51.             sync(strlen(text));
  52.             break;
  53.         case UPPAGE    :
  54.             movepage(-1);
  55.             break;
  56.         case DOWNPAGE    :
  57.             movepage(0);
  58.             break;
  59.         case HOMEKEY    :
  60.             if (jumpline(lastl-cline)) sync(strlen(text));
  61.             break;
  62.         case BOFKEY    :
  63.             if (jumpline(1-cline)) sync(0);
  64.             break;
  65.         case JUMPKEY    :
  66.             putmess("Jump to? ");
  67.             scans(ans,6);
  68.             if ((to=atoi(ans)))
  69.                 jumpline(to-cline);
  70.             break;
  71.         case FINDKEY    :
  72.             replace=NO;
  73.             findorrep();
  74.             break;
  75.         case REPKEY    :
  76.             repeat=YES;
  77.             dofindrep(1);
  78.             repeat=NO;
  79.             break;
  80.         case 'p'    :
  81.         case 'P'    :
  82.             if (oldpos) return PREV;
  83.             break;
  84.         case ESCKEY    :
  85.             return FAIL;
  86.         default        :
  87.             ;
  88.             }
  89.         }
  90.     while (c != CR);
  91.     return cline;
  92. }
  93.  
  94. blockops()
  95. {
  96.     int oldcline, oldcharn, oldto, oldfrom, op;
  97.     int l, ll, line, *t, shifts, shiftx, cp, y;
  98.     char  *txt, c, shift[LLIM], *getline(), getlow(), getkey();
  99.  
  100.     puttext();
  101.     oldcline=cline;
  102.     oldcharn=charn;
  103.     oldfrom=from;
  104.     oldto=to;
  105.     putmess("W|rite to file, |P|rint, |S|hift, |M|ove, |C|opy, or |D|elete block ? ");
  106.     while (YES) {
  107.         switch ((op=getlow())) {
  108.         case ESCKEY :
  109.             return;
  110.         case 'w':
  111.             puts("Write");
  112.             break;
  113.         case 'p':
  114.             puts("Print");
  115.             break;
  116.         case 's':
  117.             puts("Shift");
  118.             break;
  119.         case 'm':
  120.             puts("Move");
  121.             break;
  122.         case 'c':
  123.             puts("Copy");
  124.             break;
  125.         case 'd':
  126.             puts("Delete");
  127.             break;
  128.         default:
  129.             continue;
  130.             }
  131.         break;
  132.         }
  133.     from=cline;
  134.     to=0;
  135.     blocking=YES;
  136.     putmess("|Put cursor on line |end|ing block and press [return]");
  137.     if ( (to=blockpos(oldto)) == FAIL) {
  138.         to=cline;
  139.         goto abort;
  140.         }
  141.     if (to == PREV) {
  142.         moveline(oldfrom-cline);
  143.         to=loc(oldto,0);;
  144.         for (l=from=cline, y=cursory, ll= (oldto < plast ? oldto : plast);
  145.             l <= ll; l++, y++) putline(l,y);
  146.         }
  147.     if (to < from) {
  148.         l=to;
  149.         to=from;
  150.         from=l;
  151.         }
  152.     switch (op) {
  153.     case 'w':
  154.         putmess("File to write to? ");
  155.         if (scans(name,15) != ESCKEY)
  156.             if (exists(name)) writefile(from,to,name,name,NO);
  157.         break;
  158.     case 'p':
  159.         listfile(from,to);
  160.         break;
  161.     case 's':
  162.         putmess("Delete/insert spaces/tabs| to shift line, and press [return]");
  163.         moveline(from-cline);
  164.         sync(0);
  165.         resetcursor();
  166.         for (shifts=0; (c=getkey()) != CR; ) {
  167.             switch (c) {
  168.             case DELRIGHT:
  169.                 if (text[0] == ' ' || text[0] == '\t')
  170.                     deletechar(0);
  171.                 break;
  172.             case ' ':
  173.                 insertchar(' ');
  174.                 break;
  175.             case TAB:
  176.                 insertchar('\t');
  177.                 break;
  178.             case ESCKEY:
  179.                 goto abort;
  180.             default:
  181.                 continue;     /*ignore other characters*/
  182.                 }
  183.             shift[shifts++]=c;
  184.             sync(0);
  185.             resetcursor();
  186.             }
  187.         puttext();
  188.         for (l=from+1; l <= to; l++) {
  189.             gettext(l);
  190.             for (shiftx=0; shiftx < shifts; shiftx++) {
  191.                 switch((c=shift[shiftx])) {
  192.                 case DELRIGHT:
  193.                     if (*(txt=&text[0]) == ' ' || *txt == '\t')
  194.                         while ( (*txt=*(txt+1))) txt++;
  195.                     break;
  196.                 case ' ':
  197.                 case TAB:
  198.                     if ((cp=strlen(text)) < (LLIM-1)) {
  199.                         for (; cp >= 0; cp--)
  200.                             text[cp+1]=text[cp];
  201.                         text[0]= (c == ' ' ? ' ':'\t');
  202.                         }
  203.                     break;
  204.                     }
  205.                 }
  206.             altered=YES;
  207.             puttext();
  208.             }
  209.         break;
  210.     case 'd':
  211.         for (l=from; l <= to; l++) delete(from);
  212.         gettext(loc(from,0));
  213.         adjustc(cursorx);
  214.         from=to=0;
  215.         break;
  216.     case 'm':
  217.     case 'c':
  218.         putmess("|Put cursor on |line under which  block is to go |and press [return]");
  219.         if ( (cline=line=blockpos(0)) == FAIL) {
  220.             cline=oldcline;
  221.             break;
  222.             }
  223.         for (l=from; l <= to; l++) {
  224.             if ((line=inject(line,getline(l))) == FAIL) break;
  225.             if (op == 'm') {
  226.                 delete( (l<line?l:l+1) );
  227.                 if (to < line) {
  228.                     to--;
  229.                     l--;
  230.                     line--;
  231.                     cline--;
  232.                     }
  233.                 }
  234.             else {
  235.                 if (to >= line) to++;
  236.                 if (l >= line) l++;
  237.                 if (l == cline) l=line;
  238.                 }
  239.             }
  240.         from=cline+1;
  241.         to=line;
  242.         break;
  243.         }
  244. abort:
  245.     blocking=NO;
  246.     switch (op) {
  247.     case 'w':
  248.     case 'p':
  249.     case 's':
  250.         cline=oldcline;
  251.         charn=oldcharn;
  252.         putpart(from,to);
  253.         break;
  254.     case 'd':
  255.         putpart(cline,cline+SHEIGHT);
  256.         break;
  257.     case 'm':
  258.     case 'c':
  259.         putpage();
  260.         break;
  261.         }
  262. }
  263.  
  264. putpart(start,fin)
  265. int start,fin;
  266. {
  267.     int l, y;
  268.  
  269.     if (start < pfirst) putpage();
  270.     else
  271.     for (l=start, y=topline+(start-pfirst); l <= fin && y <= SHEIGHT;
  272.             l++, y++) {
  273.             if (l == cline) cursory=y;
  274.         putline(l,y);
  275.         }
  276.     gettext(cline);
  277. }
  278.  
  279. listfile(from,to)
  280. int from,to;
  281. {
  282.     int l,cp,i;
  283.     char *t;
  284.  
  285.     puttext();
  286.     for (l=from; l<=to; l++) {
  287.         if (l%10 == 0) putlineno(l);
  288.         for (cp=0, t=getline(l); *t; t++)
  289.             if (*t == '\t') for (i=tabwidth-cp%tabwidth; i>0 ; cp++, i--)
  290.                 bdos(LSTOUT,' ');
  291.             else {
  292.                 if (*t > CTRL) bdos(LSTOUT,*t);
  293.                 else {
  294.                     bdos(LSTOUT,'^');
  295.                     bdos(LSTOUT,*t+64);
  296.                     }
  297.                 cp++;
  298.                 }
  299.         bdos(LSTOUT,'\r');
  300.         bdos(LSTOUT,'\n');
  301.         if (testkey() == ESCKEY) {
  302.             error("Listing aborted");
  303.             return;
  304.             }
  305.         }
  306. }
  307. '\t')
  308.                         while ( (*txt=*(txt+1))) txt++;
  309.                     break;