home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / textplus_465.lzh / TextPlus / SrcE.lzh / SrcE / buchstabeE.c < prev    next >
C/C++ Source or Header  |  1990-08-10  |  25KB  |  884 lines

  1. /*
  2.  *       buchstabeE.c             © by Martin Steppler
  3.  */
  4.  
  5. struct Gadget ArrowGads[2], VertSlider;
  6. struct Image Image3;
  7. extern InitSlider();
  8.  
  9. Buchstabe(c)
  10. UBYTE c;
  11. {
  12.    int len=0, i, r, st, st2, e, e2=FALSE, e3, bloflag=0;
  13.  
  14.    i=SL(s,z); st=SC(s,z,i);
  15.    if(i-st < x) {                      /* x größer string */
  16. spg1: if(!(c==32 && (stil==0 || stil==4 || stil==6))) {
  17.          BelAend(s,z,st,x+st,i);
  18.          for(len=i;len<x+st-1; len++) a[s] [z] [len]=32;
  19.          a[s] [z] [len++] = c; a[s] [z] [len] = EOS;
  20.          r=Testen(stil);
  21.          if(!((!r && !stil) || oflag)) {
  22.             if(x==MAX && ein==FALSE) {
  23.                if(a[s] [s] [x+r-2]<9) {
  24.                   len=stil; if(!len) len=8; a[s] [z] [x+r-2] = len;
  25.                }
  26.                else SpeicherStil(x+st-1, ++st, r);
  27.             }
  28.             else SpeicherStil(x+st-1, ++st, r);
  29.          }
  30.       }
  31.       if(x==MAX && ein==TRUE) {
  32.          if(spe) {
  33.             if(c!=32) { i=x+st; bloflag=5; goto spg2; }
  34.             x=MIX; YZPlus();
  35.             x=0; return();
  36.          }
  37.          if(c!=32) {
  38.             for(len=x+st-1; len>=0;len--) {
  39.                if(a[s] [z] [len] == 32) {
  40.                   x = len+2-st; break;
  41.                }
  42.             }
  43.          }
  44.          if(x>MAX || len<0 || x<MIX) x=MAX;
  45.          e=s; e2=z; Flagge = 256; CarRet();
  46.          if(ausri>LINKS) { e3=s; i=z; s=e; z=e2; meld=2; y--;
  47.             st=Ausrichtung(ausri); meld=FALSE;
  48.             if(st) SonderDruck(y, SL(s,z), 0);
  49.             else   NormalDruck(y, SL(s,z), 0);
  50.             s=e3; z=i; y++;
  51.          }
  52.          if(c==32) x=0;
  53.       }
  54.    }
  55.    else if(ein==TRUE) {                    /* x im string */
  56.       if(i-st==MAX) {        /* Zeile voll */
  57. spg2:    e=x; e2=st;
  58.          for(len=i-1; len>=0; len--) {
  59.             if(a[s] [z] [len] <9) e2--;
  60.             if(a[s] [z] [len] == 32) {
  61.                x = len+2-e2; break;
  62.             }
  63.          }
  64.          if(x>MAX ||len<0) { Flagge=501; x=e; }  /* voll ohne space */
  65.          else if(x>e) Flagge=e;                  /* Crsr vor  Wort   */
  66.          else Flagge = e-x+501;                  /* Crsr im   Wort   */
  67.          if(!zpe && !spe) {          /* zum erstenmal */
  68. yabbadabba: e2=CarRet(); if(meld==TRUE) return(0);
  69.             zpe=z; spe=s+1;
  70.             if(e2) YZMinus();
  71.             i=SL(s,z); st=SC(s,z,i);
  72.             if(i-st<x || bloflag==5) { bloflag=0; goto spg1; }
  73.          }
  74.          else {                      /* nicht zum erstenmal */
  75.             len=SL(--spe,zpe); st2=SC(spe,zpe,len);
  76.             if(i-st-x+1+len-st2>MAX) { meld=FALSE; goto yabbadabba; }
  77.             r=e=e3=meld=0;
  78.             if(st) { e=x; x=MAX; Testen(stil); x=e; e=0;
  79.                if(a[spe] [zpe] [0] != letztes && a[spe] [zpe] [0] <9)
  80.                   e3=a[spe] [zpe] [0];
  81.                else if(a[spe] [zpe] [0] >8 && letztes !=8) {
  82.                   e3=8; meld=1; st2++;
  83.                }
  84.                else if(a[spe] [zpe] [0] == letztes) e=1;
  85.                else if(a[spe] [zpe] [0] >8 && letztes == 8) {
  86.                   e3=9;
  87.                }
  88.                r=Testen(stil);
  89.             }
  90.             st2+=(st-r); if(r) { meld++; st2++; } if(e) st2--;
  91.             BelAend(spe,zpe,st2,len-e+i-x-r+2+meld,len);
  92.             for(e2=len; e2>=0; e2--)
  93.                a[spe] [zpe] [e2+i-e-x-r+2+meld] = a[spe] [zpe] [e2];
  94.             if(r) {
  95.                a[spe] [zpe] [0] = letztes;
  96.                if(meld==2) { meld=1; len++; }
  97.                if(e3<9 && !e) a[spe] [zpe] [i+meld-x-r+2] = e3;
  98.             }
  99.             else if(!e && e3==8) {
  100.                a[spe] [zpe] [i-x-r+2] = e3; len++; meld=FALSE;
  101.             }
  102.             a[spe] [zpe] [i+meld-x-r+1] = 32;
  103.             len+=(i-e-x-r+2+meld);
  104.             for(e2=i-1; e2>=x+r-1; e2--)
  105.                a[spe] [zpe] [e2-x-r+1+meld] = a[s] [z] [e2];
  106.             meld=FALSE;
  107.             if(x>off && (x-MAX1<off)) {
  108.                SetAPen(RP, 0);
  109.                RectFill(RP, ((x-off)*8-8), y*8-8, RRAND, y*8-1);
  110.                SetAPen(RP, 1);
  111.             }
  112.             for(e2=x+r-2; e2>=0; e2--) {
  113.                if(a[s] [z] [e2] < 9) r--;
  114.                else if(a[s] [z] [e2] == 32) x--;
  115.                else break;
  116.             }
  117.             a[s] [z] [x+r-1] = EOS;
  118.             if(x+r-1!=i) BelAend(s, z, r, x+r-1, i);
  119.             i=x+r-1; st=r;
  120.             s=spe; z=zpe; y++; x=((e3=Flagge)>500) ? (Flagge-499):(Flagge+1);
  121.             Flagge=FALSE; e=(x>MAX) ? TRUE:FALSE; x-=e;
  122.             e2 = (bloflag==5) ? TRUE:FALSE; bloflag=0;
  123.             if(st2) SonderDruck(y, len, 0);
  124.             else    NormalDruck(y, len, 0);
  125.             if(!e) x--;
  126.             if(e2) { spe=zpe=0; goto spg3; }
  127.             if(e3<500) { YZMinus(); spe++; if(i-st<x) goto spg1; }
  128.             else { spe=zpe=0; i=len; st=st2; }
  129.          }
  130.       }
  131.       r=Testen(stil);
  132.       BelAend(s,z,st,i+1,i);
  133.       if(r) {
  134.          if(a[s] [z] [x+r-2] <9) {
  135.             if(!((a[s] [z] [x+r-2]==8&&!stil)||a[s] [z] [x+r-2]==stil))
  136.                r--;
  137.          }
  138.       }
  139.       if(i>x-1+r) {
  140.          for(len=i; len>x-1+r; len--) a[s] [z] [len] = a[s] [z] [len-1];
  141.       }
  142.       a[s] [z] [x-1+r] = c; a[s] [z] [i+1] = EOS;
  143.       st=StilPruefungII(i+1, st);
  144.       if(meld==100) return();
  145.       if(x<=off)   { SText(); meld=FALSE; }
  146.       else if(x-MAX1+1>=off) { x++; SText(); x--; meld=FALSE; }
  147.       else if(st) SonderDruck(y, SL(s,z), x);
  148.       else {
  149.          a[s] [z] +=(x-1-off);
  150.          NormalDruck(y, SL(s,z), x-1-off  );
  151.          a[s] [z] -=(x-1-off);
  152.       }
  153. spg3: ;
  154.    }
  155.    else {              /* im string und ein == FALSE */
  156.       r = Testen(stil);
  157.       a[s] [z] [x-1+r] = c;
  158.       StilPruefung(i, r, st);
  159.    }
  160. }
  161. StilPruefung(i, r, st)
  162. int i, r, st;
  163. {
  164.    int len=stil;
  165.  
  166.    if(!((!r && !stil) || oflag)) {
  167.       if(!len) len=8;
  168.       if(r) {
  169.          if(a[s] [z] [x+r-2] < 9) a[s] [z] [x+r-2] = len;
  170.          else SpeicherStil(i++, ++st, r++);
  171.       }
  172.       else SpeicherStil(i++, ++st, r++);
  173.       if(i-st>x) {
  174.          if(a[s] [z] [x+r] > 8) {
  175.             stil=letztes; x++; SpeicherStil(i,++st,r); stil=len; x--;
  176.             if(stil==8) stil=0;
  177.          }
  178.       }
  179.    }
  180. }
  181. BelAend(ss, zz, st, neu, alt) /* BelegungAendern */
  182. int ss, zz, st, neu, alt;
  183. {
  184.    UBYTE *buf;
  185.  
  186.    if(!(buf = (UBYTE *) AllocMem(neu+2, MEMF_CLEAR)))
  187.       SpeicherMangel();
  188.    strcpy(buf, a[ss] [zz]);
  189.    if(!a[ss] [zz] [0]) alt=0;
  190.    FreeMem(a[ss] [zz], alt+2);
  191.    a[ss] [zz]         = buf;
  192.    a[ss] [zz] [neu+1] = st;
  193. }
  194. ErstBelAend(ss, zz, st, neu, e, f) /* BelegungAendern & ErstBel */
  195. int ss, zz, st, neu, e, f;
  196. {
  197.    if(!(a[ss] [zz] = (UBYTE *) AllocMem(neu+2, MEMF_CLEAR)))
  198.       SpeicherMangel();
  199.    strcpy(a[ss] [zz], a[e] [f]);
  200.    a[ss] [zz] [neu+1] = st;
  201. }
  202. ErstBel(ss, zz)             /* ErstBelegung */
  203. int ss, zz;
  204. {
  205.    if(!(a[ss] [zz] = (UBYTE *) AllocMem(2, MEMF_CLEAR)))
  206.       SpeicherMangel();
  207.    a[ss] [zz] [0] = a[ss] [zz] [1] = EOS;
  208. }
  209. StilPruefungII(i, st)
  210. int i, st;
  211. {
  212.    int len=0, r;
  213.  
  214.    r=Testen(stil);
  215.    if(!((!r && !stil) || oflag)) {
  216.       SpeicherStil(i, ++st, r++);
  217.       if(i+1-st>x) {
  218.          if(a[s] [z] [x+r] > 8) {
  219.             len=stil; stil=letztes; if(!stil) stil=8; x++;
  220.             SpeicherStil(i+1,++st,r); stil=len; x--;
  221.          }
  222.       }
  223.    }
  224.    return(st);
  225. }
  226. SText()                /* Schnelltext */
  227. {
  228.    int yalt=y, salt=s, zalt=z;
  229.  
  230.    if(y>MIY) CrsrTop();
  231.    FastText();
  232.    if(!meld || (meld && y>yalt)) y=yalt;
  233.    s=salt; z=zalt;
  234. }
  235. NeueGroesse()
  236. {
  237.    MAY=(Fenster->Height-15)/8;
  238.    YKOD=MAY*8-1;
  239.    y=MIY;
  240.    Image3.Height = VertSlider.Height = Fenster->Height-41-27;
  241.    ArrowGads[0].TopEdge = Fenster->Height-27;
  242.    ArrowGads[1].TopEdge = Fenster->Height-18;
  243.    RefreshGList(&VertSlider, Fenster, NULL, -1);
  244.    InitSlider(&VertSlider);
  245.    SetAPen(RP, 0);
  246.    RectFill(RP, 0, 32, RRAND, Fenster->GZZHeight);
  247.    SetAPen(RP, 1);
  248.    SText(); ZSDisplay();
  249. }
  250. NormalDruck(yk, ln, xk)
  251. int yk, ln, xk;
  252. {
  253.    if(x<=off)           { off=( x      /MAX1  )*OFF1; SText(); }
  254.    else if(x-MAX1>=off) { off=((x-MAX1)/OFF1+1)*OFF1; SText(); }
  255.    else if(ln>off) {
  256.       if(stil) StilAus();
  257.       if(blo) { if(blo==2 || (blo>2 && BloPruef())) SetAPen(RP, ROT); }
  258.       if(off) a[s] [z] += off;
  259.       Move(RP, xk*8, yk*8-2);
  260.       if(ln<off+MAX1) Text(RP, a[s] [z], ln-off);
  261.       else            Text(RP, a[s] [z], MAX1-1);
  262.       if(off) a[s] [z] -= off;
  263.       if(blo) SetAPen(RP, WEISS);
  264.       if(stil) StilAn();
  265.    }
  266. }
  267. Cursor(n)
  268. int n;
  269. {
  270.    static int xalt, yalt, nalt;
  271.  
  272.    if(n==2) { nalt=n; xalt=x; yalt=y; }
  273.    else if(!((xalt==(x-off-1)*8) && (yalt=y*8-2) && (n==nalt))) {
  274.       SetAPen(RP, 3);             /* 0 Aus 1 An  */
  275.       SetDrMd(RP, INVERSVID|COMPLEMENT);
  276.       if(!(!n && !nalt)) {
  277.          if(!n||(n && n==nalt)) {
  278.              Move(RP, xalt, yalt);
  279.              Text(RP, " ", 1);
  280.          }
  281.          if(n) {
  282.             xalt=(x-off-1)*8; yalt=y*8-2;
  283.             Move(RP, xalt, yalt);
  284.             Text(RP, " ", 1);
  285.          }
  286.          nalt=n;
  287.          SetAPen(RP, 1);
  288.          SetDrMd(RP, JAM2);
  289.       }
  290.    }
  291. }
  292. FastText()
  293. {
  294.    int len, ab=0, brel;
  295.  
  296.    SetAPen(RP, 0);
  297.    RectFill(RP, 0, 32, RRAND, YKOD+2);
  298.    SetAPen(RP, 1);
  299.    meld=FALSE; y=MIY;
  300.    if(blo==2 || blo==6 || blo==4) {
  301.       if(blo==4) blo=2;
  302.       if((brel=BloRel(blo))<MAY-MIY && brel>0 && blo==2) ab=1; /* hi ru sp*/
  303.       else if(brel>0) ab=(blo==2) ? 2:3; /* hin runter / hoch */
  304.       else if(brel<0) { ab=4; brel*=(-1); }  /* hin hoch sprung */
  305.       else ab=5;
  306.       blo=0;
  307.    }
  308.    for(len=0; len<=MAY-MIY; len++) {
  309.       if(ab) {
  310.          if((ab==2&&len==MAY-MIY)||(ab==3&&!len)||(ab==1&&len>=brel)
  311.              ||(ab==4&&len<=brel)||ab==5) SetDrMd(RP, COMPLEMENT);
  312.       }
  313.       Rolling();
  314.       if(ab) SetDrMd(RP, JAM2);
  315.       if(len<MAY-MIY)       YZPlus();
  316.       if(meld == TRUE) { sprintf(str, "%s", buffer); break; }
  317.    }
  318.    if(ab) blo=2;
  319.    if(meld==TRUE) { sprintf(buffer, "%s", str); }
  320. }
  321. SonderDruck(len, ii, pos)
  322. int len, ii, pos;
  323. {
  324.    int q,p,i,r;
  325.  
  326.    if(x<=off)           { off=( x      /MAX1  )*OFF1; SText(); }
  327.    else if(x-MAX1>=off) { off=((x-MAX1)/OFF1+1)*OFF1; SText(); }
  328.    else if(ii>off) {
  329.       i = SC(s,z,ii);
  330.       if(i==1 && a[s] [z] [0]<9) {
  331.          p=stil; stil=a[s] [z] [0]; if(stil==8) stil=0;
  332.          StilAn(); if(pos) pos-=(off+1); stil=0;
  333.          a[s] [z] += (pos+1);
  334.          NormalDruck(len, ii-(pos+1), pos);
  335.          stil=p; StilAn(); a[s] [z] -= (pos+1);
  336.       }
  337.       else {
  338.          if(blo) {
  339.             if(blo==2 || (blo>2 && BloPruef())) SetAPen(RP, ROT);
  340.          }
  341.          p=stil; stil=i=q=0; buffer[i] = EOS;
  342.          if(pos || off) {
  343.             if(off && !pos) { q=x; x=off+1; }
  344.             r=Testen(stil); pos=x+r-1; stil=letztes;
  345.             if(q) { x=q; q=0; }
  346.             else q=x-1-off;
  347.          }
  348.          for(r=pos; r<=ii-1; r++) {
  349.             if(a[s] [z] [r] <9) {
  350.                if(i) {
  351.                   buffer[i] = EOS;
  352.                   TeilAusdruck(q,len,i);
  353.                   q+=i; i=0;
  354.                }
  355.                stil = a[s] [z] [r]; if(stil==8) stil=0;
  356.             }
  357.             else buffer[i++] = a[s] [z] [r];
  358.             if(r==ii-1) {
  359.                buffer[i]=EOS; TeilAusdruck(q, len, i);
  360.             }
  361.          }
  362.          StilAus(); stil=p; StilAn(); buffer[0] = EOS;
  363.          if(blo) SetAPen(RP, WEISS);
  364.       }
  365.    }
  366. }
  367. TeilAusdruck(q, len, lenbuf)
  368. int q, len, lenbuf;
  369. {
  370.    StilAn();
  371.    Move(RP, q*8, len*8-2);
  372.    Text(RP, buffer, lenbuf);
  373. }
  374. BloRel(mode)    /* entfernen wir uns von der Blockmarkierung ? */
  375. int mode;
  376. {
  377.    static int altcpos = 0;
  378.    int bpos = (bas*(SEITE+1)+baz), cpos = (s*(SEITE+1)+z), rtwert=FALSE;
  379.    if(cpos==bpos && !mode) rtwert=1;
  380.    else if(cpos>bpos) {
  381.       if(cpos<altcpos)  rtwert=cpos-bpos; /* hin */
  382.    }
  383.    else {
  384.       if(cpos>altcpos) rtwert=bpos-cpos;  /* hin */
  385.       else if(mode==6 && bpos-cpos<MAY-MIY) rtwert=cpos-bpos; /* phasensprung */
  386.    }
  387.    altcpos=cpos; if(mode==2) altcpos+=MAY-MIY;
  388.    return(rtwert);
  389. }
  390. CrsrTop()
  391. {
  392.    int len;
  393.  
  394.    for(len=y;len>MIY;len--)
  395.       YZMinus();
  396. }
  397. CrsrHoch()
  398. {
  399.    int len, fahne = FALSE, altblo=0;
  400.  
  401.    if(blo==2) { blo=0; altblo=1; }
  402.    for(len=0; len<MAY-MIY; len++)
  403.    {
  404.       y=MIY+1;
  405.       YZMinus();
  406.       if(meld==TRUE) {
  407.          fahne = TRUE;
  408.          meld = FALSE;
  409.          break;
  410.       }
  411.    }
  412.    y=MIY;      if(altblo) blo=6;
  413.    FastText(); if(altblo) blo=0;
  414.    CrsrTop();  if(altblo) blo=2;
  415.    if(fahne == TRUE) {
  416.       meld = TRUE;
  417.       sprintf(buffer, "%s", FehlerText[0]);
  418.    }
  419. }
  420. CrsrBot()
  421. {
  422.    int len;
  423.    for(len=y;len<MAY;len++) {
  424.       YZPlus();
  425.       if(meld == TRUE)
  426.          break;
  427.    }
  428. }
  429.  
  430. Hochrollen()
  431. {
  432.    if(blo==2) {
  433.       if(BloRel(0)) {
  434.          if(--z<0) { z=SEITE; s--; } blo=0;
  435.          SetAPen(RP, 0); RectFill(RP, 0, y*8-8, RRAND, y*8-1);
  436.          SetAPen(RP, 1); Rolling();
  437.          blo=2; if(++z>SEITE) { z=0; s++; }
  438.       }
  439.    }
  440.    ScrollRaster(RP, 0, 8, 0, 32, RRAND, YKOD);   /* 632 */
  441.    Rolling();     /* MAY */
  442. }
  443. Runterrollen()
  444. {
  445.    if(blo==2) {
  446.       if(BloRel(0)) {
  447.          if(++z>SEITE) { z=0; s++; } blo=0;
  448.          SetAPen(RP, 0); RectFill(RP, 0, y*8-8, RRAND, y*8-1);
  449.          SetAPen(RP, 1); Rolling();
  450.          blo=2; if(--z<0) { z=SEITE; s--; }
  451.       }
  452.    }
  453.    ScrollRaster(RP, 0, -8, 0, 32, RRAND, YKOD);  /* 632 */
  454.    Rolling();
  455. }
  456. Rollen()
  457. {
  458.    ScrollRaster(RP, 0, -8, 0, (y-1)*8, RRAND, YKOD);
  459.    Rolling();
  460. }
  461. Rolling()
  462. {
  463.    int i;
  464.  
  465.    if(i=SL(s,z)) {
  466.       if(a[s] [z] [i+1]) SonderDruck(y, i, 0);
  467.       else NormalDruck(y, i, 0);
  468.    }
  469. }
  470. ZeileLoeschen()
  471. {
  472.    int xalt=x;
  473.    if(ze==z && se==s) {
  474.      x=1;
  475.      RestLoeschen(0);
  476.      x=xalt;
  477.    }
  478.    else
  479.       BSpaceII();
  480. }
  481. BloPruef()
  482. {
  483.    if(bas<s && s<bes)
  484.       return(TRUE);
  485.    if(bas==s && baz<=z) {
  486.       if(bes>s)
  487.          return(TRUE);
  488.       if(bes==s && bez>=z)
  489.          return(TRUE);
  490.    }
  491.    if(bes==s && bez>=z && bas<s)
  492.       return(TRUE);
  493.    return(FALSE);
  494. }
  495. RestLoeschen(exmeld)
  496. int exmeld;
  497. {
  498.    int len,r,i=SL(s,z);
  499.  
  500.    r=Testen(stil); a[s] [z] [x+r-1] = EOS;
  501.    if((len=x+r-1)>0) {
  502.       for(len=x+r-2;len>0;len--){
  503.          if(a[s] [z] [len] == 32) a[s] [z] [len] = EOS;
  504.          else if(a[s] [z] [len] <9) { r--; a[s] [z] [len] = EOS; }
  505.          else break;
  506.       }
  507.       len++;
  508.    }
  509.    BelAend(s, z, r, len, i);
  510.    if(exmeld!=500) {
  511.       SetAPen(RP, 0);
  512.       RectFill(RP, ((x-off)*8-8), y*8-8, RRAND, y*8-1);
  513.       SetAPen(RP, 1);
  514.    }
  515. }
  516. CarRet()
  517. {
  518.    int len, r, i, e=FALSE, st, exmeld=meld;
  519.  
  520.    if((MAS-se+SEITE-ze)>0) {
  521.       i=SL(s,z); st=SC(s,z,i);
  522.       meld=2; BlockEinfuegen(s,z,s,z); meld=FALSE;
  523.       if(i-st>=x) {
  524.          RestLoeschen(exmeld); len=0;
  525.       }
  526.       else len=1;
  527.       if(++z>SEITE) { z=0; s++; }
  528.       if(len) {
  529.          a[s] [z] [0] = EOS;
  530.          BelAend(s,z, 0, 0, i);
  531.       }
  532.       else {
  533.          r=Testen(stil); st=e=0;
  534.          if(letztes!=0 && letztes!=8) { st=e=1; a[s] [z] [0] = letztes; }
  535.          for(len=x+r-1; len<=i-1; len++, st++) {
  536.             if(a[s] [z] [len] <9) e++;
  537.             a[s] [z] [st] = a[s] [z] [len];
  538.          }
  539.          a[s] [z] [st] = EOS;
  540.          BelAend(s, z, e, st, i);
  541.       }
  542.       if(exmeld==500) return();
  543.       e=FALSE;
  544.       if(Flagge) {
  545.          if(Flagge==256)  StrEnde();
  546.          else if(Flagge>500) x=Flagge-499;
  547.          else { x=Flagge+1; e=TRUE; }
  548.          Flagge=0;
  549.       }
  550.       else x=1;
  551.       if(x<=off) { off=(x/MAX1)*OFF1; if(++y>MAY) y=MAY; SText(); }
  552.       else {
  553.          if(++y>MAY) { y=MAY; Hochrollen(); }
  554.          Rollen();
  555.       }
  556.       if(x!=1) x--;
  557.       meld=FALSE;
  558.    }
  559.    else {
  560.       sprintf(buffer, "%s", FehlerText[2]);
  561.       meld = TRUE;
  562.    }
  563.    return(e);
  564. }
  565. BSpace()
  566. {
  567.    int len, r, i, st, rs=0, rz, st2,e=0;
  568.    UBYTE buf[512];
  569.  
  570.    if(s==0 && z==0 && x==1) {
  571.       sprintf(buffer, "%s", FehlerText[0]);
  572.       meld = TRUE;
  573.    }
  574.    else {
  575.       i=SL(s,z); st=SC(s,z,i);
  576.       if(x>1) {
  577.          if(i-st>=x-1) {
  578.             if(i-st==x-1) { x--; r=Testen(stil); x++;
  579.                for(len=x+r-3; len>=0; len--) {
  580.                   if(a[s] [z] [len]<9)    { rs++; st--; }
  581.                   else if(a[s] [z] [len] == 32)  rs++;
  582.                   else break;
  583.                }
  584.                a[s] [z] [i-1-rs] = EOS;
  585.             }
  586.             else {
  587.                r=Testen(stil);
  588.                if(r>1) { if(a[s] [z] [x+r-2]<9 && a[s] [z] [x+r-4]<9) {
  589.                               r--; st--; rs=1; }}
  590.                if(r && !rs) { if(a[s] [z] [x+r-2]<9) r--; }
  591.                for(len=x+r-1; len<=i; len++)
  592.                   a[s] [z] [len-1-rs] = a[s] [z] [len];
  593.             }
  594.             BelAend(s, z, st, i-1-rs, i);
  595.             if(meld==100) return();
  596.             i=i-1-rs; if((len=i-st-off)<0) len =0;
  597.             SetAPen(RP, 0);
  598.             RectFill(RP,len*8,y*8-8,RRAND,y*8-1);
  599.             SetAPen(RP, 1);
  600.             if(--x<=off)   { SText(); meld=FALSE; }
  601.             else if(i-st>x-1) {
  602.                if(st) SonderDruck(y, SL(s,z), x);
  603.                else {
  604.                   a[s] [z] +=(x-1-off);
  605.                   NormalDruck(y, SL(s,z), x-1-off  );
  606.                   a[s] [z] -=(x-1-off);
  607.                }
  608.             }
  609.          }
  610.          else XMinus();
  611.       }
  612.       else {
  613.          rz=z-1; rs=s; spe=zpe=0;
  614.          if(rz<0) { rz=SEITE; rs--; }
  615.          len=SL(rs,rz); st2=SC(rs,rz,len);
  616.          if(i-st+len-st2<=MAX) {
  617.             if(st2) {
  618.                SchnellTest(rs,rz,len-st2);
  619.                if(a[s] [z] [0] >8 && letztes!=8) e=1;
  620.             }
  621.             x=len-st2+1; strcpy(buf, a[rs] [rz]);
  622.             if(!(a[rs] [rz] = (UBYTE *) AllocMem(i+len+e+2, MEMF_CLEAR)))
  623.                SpeicherMangel();
  624.             strcpy(a[rs] [rz], buf);
  625.             a[rs] [rz] [i+len+e+1] = st2+st+e;
  626.             if(e) a[rs] [rz] [len] = 8;
  627.             for(r=0; r<=i; r++) a[rs] [rz] [r+len+e] = a[s] [z] [r];
  628.             if(x<=off)           { off=( x      /MAX1  )*OFF1; SText(); }
  629.             else if(x-MAX1>=off) { off=((x-MAX1)/OFF1+1)*OFF1; SText(); }
  630.             BSpaceII();
  631.             s=rs; z=rz;
  632.             if(--y<MIY) {
  633.                y=MIY;
  634.                Runterrollen();
  635.             }
  636.             else Rolling();
  637.          }
  638.       }
  639.    }
  640. }
  641. BSpaceII()
  642. {
  643.    int i, r, rz, rs;
  644.  
  645.    rz=z; rs=s; i=y;
  646.    meld=2; BlockLoeschen(s,z,s,z); meld=FALSE;
  647.    if(blo>2) {
  648.       if(BloPruef()) {
  649.          if(bas==bes && baz==bez) blo=0;  /* Block gelöscht */
  650.          else {
  651.             if(--bez<0) { bez=SEITE; bes--; }
  652.          }
  653.       }
  654.       else if(s<bas || (s==bas && z<baz)) {
  655.          if(--baz<0) { baz=SEITE; bas--; }
  656.          if(--bez<0) { bez=SEITE; bes--; }
  657.       }
  658.    }
  659.    if(y<MAY) CrsrBot();
  660.    ScrollRaster(RP, 0, 8, 0, i*8-8, RRAND, YKOD);
  661.    if(meld == FALSE) Rolling();
  662.    z=rz; s=rs; y=i; meld=FALSE;
  663. }
  664. BlockSchieben(n)
  665. int n;
  666. {
  667.    int i, olds=s, oldz=z, oldMAX = MAX;
  668.  
  669.    MAX=ABSMAX;
  670.    FOREVER {
  671.       meld=100; s=bas; z=baz;
  672.       if((!n || n==2) && x==MAX) break;
  673.       else if((n==1 || n==3) && x==MIX) break;
  674.       FOREVER {
  675.          if(!n || n==2) {           /* Block nach rechts verschieben */
  676.             if((i=SL(s,z))-SC(s,z,i)<MAX) {
  677.                Buchstabe((UBYTE *)' ');
  678.             }
  679.          }
  680.          else if(n==1 || n==3) {     /* Block nach links verschieben */
  681.             if((i=SL(s,z))-SC(s,z,i)>=x-1) BSpace();
  682.          }
  683.          if(s==bes && z==bez) break;
  684.          if(++z>SEITE) { z=0; s++; }
  685.       }
  686.       if(!n || n==2) {
  687.          meld=FALSE; XPlus();
  688.          if(n==2 && tab[x-off-1] == '1') break;
  689.          else if(!n) break;
  690.       }
  691.       else {
  692.          meld=FALSE; XMinus();
  693.          if(n==3 && tab[x-off-1] == '1') break;
  694.          else if(n==1) break;
  695.       }
  696.    }
  697.    s=olds; z=oldz; MAX = oldMAX; if(x>MAX) x=MAX;
  698.    SText(); ZSDisplay(); meld=FALSE;
  699. }
  700. JumpWord(n)
  701. int n;
  702. {
  703.    int i, st, len=0, r, durch=0;
  704.    if(n) {
  705.       FOREVER {
  706.          st=SC(s,z,(i=SL(s,z)));
  707.          if(x<=off)           { off=( x      /MAX1  )*OFF1; SText(); }
  708.          else if(x-MAX1>=off) { off=((x-MAX1)/OFF1+1)*OFF1; SText(); }
  709.          if(x==MIX && x==i-st && durch) break;
  710.          durch=1;
  711.          if(x>=i-st) { r=0;
  712.             if(y==MAY) r=1;
  713.             YZPlus(); if(meld) break;
  714.             if(r) {
  715.                st=s; i=z;
  716.                for(len=1; len<=(MAY-MIY)/2; len++) {
  717.                   YZPlus(); if(meld) { meld=0; break; }
  718.                }
  719.                s=st; z=i; y=MAY-len+1;
  720.             }
  721.             x=MIX; len=1; continue;
  722.          }
  723.          if(a[s] [z] [x+Testen(stil)-1] == 32) len=1;
  724.          else if(len) break;
  725.          do {
  726.             XPlus(); if(a[s] [z] [x+(r=Testen(stil))-1] == 32) len=1;
  727.          } while(x<i-st && !(a[s] [z] [x+r-1] != 32 && len));
  728.          if(a[s] [z] [x+r-1] != 32 && len) break;
  729.       }
  730.    }
  731.    else {
  732.       FOREVER {
  733.          st=SC(s,z,(i=SL(s,z)));
  734.          if(x>i-st) { x=i-st; if(x==MIX) break; if(!x) x=MIX; }
  735.          if(x==MIX) { r=0;
  736.             if(y==MIY) r=1;
  737.             YZMinus(); if(meld) break;
  738.             if(r) {
  739.                st=s; i=z;
  740.                for(len=1; len<=(MAY-MIY)/2; len++) {
  741.                   YZMinus(); if(meld) { meld=0; break; }
  742.                }
  743.                s=st; z=i; y=MIY+len-1;
  744.             }
  745.             st=SC(s,z,(i=SL(s,z))); if(!(x=i-st)) { x=MIX; r=2; }
  746.             if(x-MAX1>=off) { off=((x-MAX1)/OFF1+1)*OFF1; SText(); }
  747.             len=1; if(r==2) continue; if(x==MIX) break;
  748.          }
  749.          do {
  750.             XMinus(); if(a[s] [z] [x+(r=Testen(stil))-1] != 32) len=1;
  751.          } while(x>MIX && !(a[s] [z] [x+r-1] == 32 && len));
  752.          if(a[s] [z] [x+r-1] == 32 && len) { XPlus(); break; }
  753.          else if(x==MIX && a[s] [z] [x+r-1] !=32) break;
  754.       }
  755.    }
  756. }
  757. CDel(n)
  758. int n;
  759. {
  760.    int i, st, len, r=0, e, durch=1;
  761.    if(n==2) {    /* Alles links vom Crsr löschen */
  762.       for(len=x; len>MIX; len--) BSpace();
  763.    }
  764.    else {
  765.       st=SC(s,z,(i=SL(s,z)));
  766.       if(x<=i-st) {
  767.          r=Testen(stil);
  768.          if(n==1 || (!n && a[s] [z] [x+r-1] != 32)) {
  769.             if(x>MIX) {
  770.                x--; r=Testen(stil); x++;
  771.                if(!(a[s] [z] [x+r-2] == 32 && !n)) {
  772.                   if(a[s] [z] [x+r-2] != 32 && (e=a[s] [z] [x+Testen(stil)-1]) != 32) n=0;
  773.                   if(e!=32) e=0;
  774.                   for(len=x; len>MIX; len--) {
  775.                      BSpace();
  776.                      if(--x<MIX) { x++; break; }
  777.                      else {
  778.                         r=Testen(stil);
  779.                         if(a[s] [z] [x+r-1] == 32 ) {
  780.                            if(--x<MIX || e) { if(e==33) e++; x+=2; }
  781.                            else {
  782.                               r=Testen(stil); x+=2;
  783.                               if(a[s] [z] [x+r-3] != 32) break;
  784.                            }
  785.                         }
  786.                         else {
  787.                            x++;
  788.                            if(e==32) e++;
  789.                            else if(e==34) break;
  790.                         }
  791.                      }
  792.                   }
  793.                }
  794.             }
  795.          }
  796.          if(n!=1) {
  797.             st=SC(s,z,(i=SL(s,z)));
  798.             r=Testen(stil); e=1;
  799.             if(!n && a[s] [z] [x+r-1] == 32) { e=durch=0; }
  800.             for(len=x, r=0; len<=i-st; len++) {
  801.                if(n) {
  802.                   if(a[s] [z] [x+Testen(stil)-1] != 32) break;
  803.                }
  804.                Del();
  805.                if(!n) {
  806.                   if(a[s] [z] [x+Testen(stil)-1] != 32) e=1;
  807.                   else if(e) r=1;
  808.                   if(r && e) {
  809.                      if(len>i-st-2) break;
  810.                      else {
  811.                         if(durch==2) break;
  812.                         x++; r=Testen(stil); x--;
  813.                         if(a[s] [z] [x+r] != 32) {
  814.                            if(durch) durch=2;
  815.                            else break;
  816.                         }
  817.                         r=1;
  818.                      }
  819.                   }
  820.                }
  821.             }
  822.          }
  823.       }
  824.       else if(n==1 && i-st>MIX) {
  825.          r=st; x=MIX;
  826.          for(len=i-st; len>=MIX; len--) {
  827.             if(a[s] [z] [len+r-1] <9) r--;
  828.             if(a[s] [z] [len+r-1] == 32) { x=len; break; }
  829.          }
  830.          for(len=x; len<=i-st; len++) Del();
  831.       }
  832.    }
  833. }
  834. Del()
  835. {
  836.    int i, r, len, rs=0, st;
  837.  
  838.    i=SL(s,z); st=SC(s,z,i);
  839.    if(i-st>=x) {
  840.       r=Testen(stil);
  841.       if(i-st==x) {
  842.          for(len=x+r-2; len>=0; len--) {
  843.             if(a[s] [z] [len]<9)    { rs++; st--; }
  844.             else if(a[s] [z] [len] == 32)  rs++;
  845.             else break;
  846.          }
  847.          a[s] [z] [i-1-rs] = EOS;
  848.       }
  849.       else {
  850.          if(r) { if(a[s] [z] [x+r-2]<9 && a[s] [z] [x+r]<9) { st--; rs=1; }}
  851.          for(len=x+r; len<=i; len++) a[s] [z] [len-1-rs] = a[s] [z] [len];
  852.       }
  853.       BelAend(s, z, st, i-1-rs, i);
  854.       i=i-1-rs; if((len=i-st-off)<0) len =0;
  855.       SetAPen(RP, 0);
  856.       RectFill(RP,len*8,y*8-8,RRAND,y*8-1);
  857.       SetAPen(RP, 1);
  858.       if(i-st>=x || x<=off) {
  859.          if(st) SonderDruck(y, SL(s,z), x);
  860.          else {
  861.             a[s] [z] +=(x-1-off);
  862.             NormalDruck(y, SL(s,z), x-1-off);
  863.             a[s] [z] -=(x-1-off);
  864.          }
  865.       }
  866.    }
  867. }
  868. StrEnde()
  869. {
  870.    x=SL(s,z); x=x-SC(s,z,x)+1;
  871.    if(x>MAX) x=MAX;
  872.    if(x<MIX) x=MIX;
  873. }
  874. SL(b,c)
  875. int b,c;
  876. {
  877.    return((!a[b] [c] [0]) ? 0:strlen(a[b] [c]));
  878. }
  879. SC(b,c,d)
  880. int b,c,d;
  881. {
  882.    return(a[b] [c] [d+1]);
  883. }
  884.