home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / YADME10.LHA / YADME10 / src / mods.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  4.6 KB  |  220 lines

  1.  
  2. /*
  3.  *  KTS.C
  4.  *
  5.  *  Additional DME commands written by Kevin T. Seghetti fixed up and
  6.  *  incorporated by Matt Dillon 17 April 1988.
  7.  *
  8.  *  Additions made by Karl Lukas 9/94 for blocktype character
  9.  */
  10.  
  11. #include "defs.h"
  12. #include <intuition/intuitionbase.h>
  13.  
  14.  
  15. #define BLOCKDEPTH  5
  16. #define PINGDEPTH   10
  17.  
  18. static long BSstack[BLOCKDEPTH];
  19. static long BEstack[BLOCKDEPTH];
  20. static long CSstack[BLOCKDEPTH]; /* KL */
  21. static long CEstack[BLOCKDEPTH]; /* KL */
  22. static ED   *Bp[BLOCKDEPTH];
  23. static int  CurrDepth = 0;
  24. static char DoSel = 1;
  25.  
  26. static long PingLine[PINGDEPTH];
  27. static long PingCol[PINGDEPTH];
  28. static ED   *PingWin[PINGDEPTH];
  29.  
  30. void PMAdd(void)
  31. {
  32. }
  33.  
  34. void PMRem(void)
  35. {
  36. }
  37.  
  38. void PMKill(ED *ep)
  39. {
  40.     short i, j;
  41.  
  42.     for (i = 0; i < PINGDEPTH; ++i) {       /*  remove ping-pong marks  */
  43.         if (PingWin[i] == ep)
  44.             PingWin[i] = NULL;
  45.     }
  46.     for (i = j = 0; i < CurrDepth; ++i) {   /*  remove block marks      */
  47.         Bp[j] = Bp[i];
  48.         if (Bp[i] != ep)
  49.             ++j;
  50.     }
  51.     CurrDepth = j;
  52. }
  53.  
  54. do_pushmark(void)
  55. {
  56.     text_sync();
  57.     if (blockok()) {
  58.         if (CurrDepth == BLOCKDEPTH) {
  59.             title("pushmark: stack limit reached");
  60.             return(-1);
  61.         }
  62.         BSstack[CurrDepth] = BSline;
  63.         BEstack[CurrDepth] = BEline;
  64.         CSstack[CurrDepth] = BSchar; /* KL */
  65.         CEstack[CurrDepth] = BEchar; /* KL */
  66.         Bp[CurrDepth] = BEp;
  67.         ++CurrDepth;
  68.         text_redrawblock(0);
  69.     }
  70.     return(0);
  71. }
  72.  
  73. void do_popmark(void)
  74. {
  75.     text_sync();
  76.  
  77.     if (!CurrDepth) {           /*  no error message on purpose */
  78.         text_redrawblock(0);    /*  remove any existing block   */
  79.         return;
  80.     }
  81.     text_redrawblock(0);
  82.     --CurrDepth;
  83.     BSline = BSstack[CurrDepth];
  84.     BEline = BEstack[CurrDepth];
  85.     BSchar = CSstack[CurrDepth]; /* KL */
  86.     BEchar = CEstack[CurrDepth]; /* KL */
  87.     BEp = Bp[CurrDepth];
  88.     if (BEp == NULL || BEline >= BEp->Lines) {
  89.         BEp = NULL;
  90.         BSline = BEline = -1;
  91.         BSchar = BEchar = -1; /* KL */
  92.     } else
  93.         text_redrawblock(1);
  94. }
  95.  
  96. void do_swapmark(void)
  97. {
  98.     short i;
  99.     long *ptmp;
  100.     long tmp;
  101.  
  102.     if (do_pushmark() < 0)
  103.         return;
  104.     i = CurrDepth - 2;
  105.     if (i >= 0) {
  106.         ptmp = PingLine + i;
  107.         tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  108.         ptmp = PingCol + i;
  109.         tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  110.         ptmp = (long *)PingWin + i;
  111.         tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  112.     }
  113.     do_popmark();
  114. }
  115.  
  116. void do_purgemark(void)
  117. {
  118.     CurrDepth = 0;
  119. }
  120.  
  121. void do_ping(void)
  122. {
  123.     uword num = atoi(av[1]);
  124.  
  125.     if (num >= PINGDEPTH) {
  126.         title("ping: out of range");
  127.         return;
  128.     }
  129.     PingLine[num]= Ep->Line;
  130.     PingCol[num] = Ep->Column;
  131.     PingWin[num] = Ep;
  132.     title("Line marked");
  133. }
  134.  
  135. void do_pong(void)
  136. {
  137.     uword num = atoi(av[1]);
  138.     extern IBASE *IntuitionBase;
  139.  
  140.     text_sync();
  141.     if (num < 0 || num >= PINGDEPTH || !PingWin[num]) {
  142.         title("pong: range error or nothing marked");
  143.         return;
  144.     }
  145.     text_cursor(1);
  146.     text_switch(PingWin[num]->Win);
  147.     text_cursor(0);
  148.  
  149.     if (DoSel && IntuitionBase->ActiveWindow != Ep->Win) {
  150.         WindowToFront(Ep->Win);
  151.         ActivateWindow(Ep->Win);
  152.     }
  153.     if ((Ep->Line = PingLine[num]) >= Ep->Lines) {
  154.         PingLine[num] = Ep->Line = Ep->Lines - 1;
  155.     }
  156.     Ep->Column = PingCol[num];
  157.     text_load();
  158.     text_sync();
  159. }
  160.  
  161. void do_winsel(void)
  162. {
  163.     if (av[1][0]) {
  164.         switch(av[1][1] & 0x1F) {
  165.         case 'n' & 0x1F:
  166.             DoSel = 1;
  167.             break;
  168.         case 'f' & 0x1F:
  169.             DoSel = 0;
  170.             break;
  171.         case 'o' & 0x1F:
  172.             DoSel ^= 1;
  173.             break;
  174.         }
  175.     }
  176. }
  177.  
  178. void do_findfile(void)
  179. {
  180.     ED *ep;
  181.     short i,l = strlen(av[1]);
  182.     /* uword num = atoi(av[1]); */
  183.     extern IBASE *IntuitionBase;
  184.  
  185.     text_sync();
  186.     for (ep = Ep;ep;ep = (ED *)(ep->Node.mln_Succ)) {
  187.         i = strlen(ep->Name);
  188.         if(i >= l && !strcmp(av[1],ep->Name+i-l) && (i == l || ep->Name[i-l-1] == ':' || ep->Name[i-l-1] == '/'))
  189.             break;
  190.     }
  191.     if(!ep)
  192.         for (ep = (ED *)(Ep->Node.mln_Pred);ep;ep = (ED *)(ep->Node.mln_Pred)) {
  193.             i = strlen(ep->Name);
  194.             if(i >= l && !strcmp(av[1],ep->Name+i-l) && (i == l || ep->Name[i-l-1] == ':' || ep->Name[i-l-1] == '/'))
  195.                 break;
  196.         }
  197.     if(!ep) {
  198.         title("No buffer by that name");
  199.         return;
  200.     }
  201.  
  202.     text_cursor(1);
  203.     text_switch(ep->Win);
  204.     text_cursor(0);
  205.  
  206.     if (IntuitionBase->ActiveWindow != Ep->Win) {
  207.         WindowToFront(Ep->Win);
  208.         ActivateWindow(Ep->Win);
  209.     }
  210.     text_load();
  211.     text_sync();
  212. }
  213.  
  214. void do_undo(void)
  215. {
  216.     text_load();
  217.     text_redisplaycurrline();
  218. }
  219.  
  220.