home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 119_01 / cbind.c < prev    next >
Text File  |  1984-07-13  |  9KB  |  276 lines

  1. /* CBIND.C - Customized BINDINGS.C
  2.    Contributed to the AUG by Mark of the Unicorn 07/20/81 
  3.  
  4. This one has the function MInsRgn, which reads a file name and two
  5. strings and inserts the region in the file delimited by the two strings
  6. (inclusive of the first but not of the second) into the current buffer
  7. (leaving that region in the kill buffer, which it used for temp).  It
  8. replaces page mode (for space) and is bound to C-X I. */
  9.  
  10. /* BINDINGS.C - Set up the key bindings for Mince
  11.  
  12. The seller of this software hereby disclaims any and all
  13. guarantees and warranties, both express and implied.  No
  14. liability of any form shall be assumed by the seller, nor shall
  15. direct, consequential, or other damages be assumed by the seller.
  16. Any user of this software uses it at his or her own risk.
  17.  
  18. Due to the ill-defined nature of "fitness for purpose" or similar
  19. types of guarantees for this type of product, no fitness for any
  20. purpose whatsoever is claimed or implied.
  21.  
  22. The physical medium upon which the software is supplied is
  23. guaranteed for one year against any physical defect.  If it
  24. should fail, return it to the seller, and a new physical medium
  25. with a copy of the purchased software shall be sent.
  26.  
  27. The seller reserve the right to make changes, additions, and
  28. improvements to the software at any time; no guarantee is made
  29. that future versions of the software will be compatible with any
  30. other version.
  31.  
  32. The parts of this disclaimer are severable and fault found in any
  33. one part does not invalidate any other parts.
  34.  
  35.     Copyright (c) 1981 by Mark of the Unicorn
  36.     Created for Version 2.3  10/4/80  JTL
  37.     Updated to version three  1/7/81  JTL
  38.  
  39.     This file contains the function table initializers and mode set up
  40. functions */
  41.  
  42. #include "mince.gbl"
  43.  
  44. finit1()            /* initialize the control and self insert key bindings */
  45. {
  46.     int cnt;
  47.     int MInsert(), MSetMrk(), MBegLin(), MPrevChar();
  48.     int MNotImpl(), MDelChar(), MEndLin(), MNextChar();
  49.     int MAbort(), MDelLin(), NewDsp(), MNewLin();
  50.     int MNextLin(), MOpenLin(), MPrevLin(), MQuote();
  51.     int MRSearch(), MSearch(), MSwapChar(), MArg();
  52.     int MNextPage(), MDelRgn(), MCtrlX(), MYank();
  53.     int MMeta(), MDelIndent(), MRDelChar(), MIndent();
  54.  
  55.  
  56.     for (cnt=0; cnt<128; ++cnt) functs[cnt] = &MInsert;
  57.     TKbChk();
  58.     functs[0] = &MSetMrk;        /* C-@ */
  59.     functs[1] = &MBegLin;        /* C-A */
  60.     functs[2] = &MPrevChar;        /* C-B */
  61.     functs[3] = &MNotImpl;        /* C-C */
  62.     functs[4] = &MDelChar;        /* C-D */
  63.     functs[5] = &MEndLin;        /* C-E */
  64.     functs[6] = &MNextChar;        /* C-F */
  65.     functs[7] = &MAbort;        /* C-G */
  66.     functs[8] = &MRDelChar;        /* C-H */
  67.                             /* C-I */
  68.     functs[10] = &MIndent;        /* C-J */
  69.     functs[11] = &MDelLin;        /* C-K */
  70.     functs[12] = &NewDsp;        /* C-L */
  71.     functs[13] = &MNewLin;        /* C-M */
  72.     functs[14] = &MNextLin;        /* C-N */
  73.     functs[15] = &MOpenLin;        /* C-O */
  74.     functs[16] = &MPrevLin;        /* C-P */
  75.     functs[17] = &MQuote;        /* C-Q */
  76.     functs[18] = &MRSearch;        /* C-R */
  77.     functs[19] = &MSearch;        /* C-S */
  78.     functs[20] = &MSwapChar;        /* C-T */
  79.     functs[21] = &MArg;            /* C-U */
  80.     functs[22] = &MNextPage;        /* C-V */
  81.     functs[23] = &MDelRgn;        /* C-W */
  82.     functs[24] = &MCtrlX;        /* C-X */
  83.     functs[25] = &MYank;        /* C-Y */
  84.     functs[26] = &MNotImpl;        /* C-Z */
  85.     functs[ESC] = &MMeta;        /* ESC */
  86.     functs[28] = &MDelIndent;    /* C-\ */
  87.     functs[29] = &MNotImpl;        /* C-] */
  88.     functs[30] = &MNotImpl;        /* C-^ */
  89.     functs[31] = &MNotImpl;        /* C-_ */
  90.     functs[DEL] = &MRDelChar;    /* DEL */
  91.     }
  92.  
  93. finit2()            /* set up the Meta key bindings */
  94. {
  95.     int cnt;
  96.     int MNotImpl(), MAbort(), MDelELin(), MQryRplc();
  97.     int MMakeDel(), MToStart(), MToEnd(), MBSent();
  98.     int BWord(), MCapWord(), MDelWord(), MFSent();
  99.     int FWord(), MMrkPara(), MDelSent(), MLowWord();
  100.     int MFillPara(), MReplace(), MCntrLine(), MUpWord();
  101.     int MPrevPage(), MCopyRgn(), MBPara(), MDelWhite();
  102.     int MFPara(), MRDelWord(), MSetMrk(), MSwapWord();
  103.  
  104.     for (cnt=128; cnt<256; ++cnt) functs[cnt] = &MNotImpl;
  105.     TKbChk();
  106.     functs[128+7] = &MAbort;                    /* M-C-G */
  107.     functs[128+8] = &MRDelWord;                /* M-C-H */
  108.     functs[128+11] = &MDelELin;                /* M-C-K */
  109.     functs[128+18] = &MQryRplc;                /* M-C-R */
  110.     functs[128+23] = &MMakeDel;                /* M-C-W */
  111.     functs[128+'<'] = &MToStart;                /* M-< */
  112.     functs[128+'>'] = &MToEnd;                /* M-> */
  113.     functs[128+' '] = &MSetMrk;                /* M-  */
  114.     functs[128+'A']=functs[128+'a'] = &MBSent;    /* M-A */
  115.     functs[128+'B']=functs[128+'b'] = &BWord;    /* M-B */
  116.     functs[128+'C']=functs[128+'c'] = &MCapWord;    /* M-C */
  117.     functs[128+'D']=functs[128+'d'] = &MDelWord;    /* M-D */
  118.     functs[128+'E']=functs[128+'e'] = &MFSent;    /* M-E */
  119.     functs[128+'F']=functs[128+'f'] = &FWord;    /* M-F */
  120.     functs[128+'H']=functs[128+'h'] = &MMrkPara;    /* M-H */
  121.     functs[128+'K']=functs[128+'k'] = &MDelSent;    /* M-K */
  122.     functs[128+'L']=functs[128+'l'] = &MLowWord;    /* M-L */
  123.     functs[128+'Q']=functs[128+'q'] = &MFillPara;/* M-Q */
  124.     functs[128+'R']=functs[128+'r'] = &MReplace;    /* M-R */
  125.     functs[128+'S']=functs[128+'s'] = &MCntrLine;/* M-S */
  126.     functs[128+'T']=functs[128+'t'] = &MSwapWord;/* M-T */
  127.     functs[128+'U']=functs[128+'u'] = &MUpWord;    /* M-U */
  128.     functs[128+'V']=functs[128+'v'] = &MPrevPage;/* M-V */
  129.     functs[128+'W']=functs[128+'w'] = &MCopyRgn;    /* M-W */
  130.     functs[128+'['] = &MBPara;                /* M-[ */
  131.     functs[128+'\\'] = &MDelWhite;            /* M-\ */
  132.     functs[128+']'] = &MFPara;                /* M-] */
  133.     functs[128+DEL] = &MRDelWord;                /* M-DEL */
  134.     }
  135.  
  136. finit3()            /* set up the Control-X key bindings */
  137. {
  138.     int cnt;
  139.     int MNotImpl(), MLstBuffs(), MExit(), MFindFile();
  140.     int MAbort(), MSetTabs(), MDelMode(), MFileRead();
  141.     int MFileSave(), MFileWrite(), MSwapMrk(), MSetIndent();
  142.     int MPrintPos(), MSwitchTo(), MKillBuff(), MSetFill();
  143.     int MAddMode(), MOneWind(), MTwoWind(), MSwpWind();
  144.     int MNxtOthrWind(), MPrvOthrWind(), MGrowWind();
  145.     int MInsRgn();
  146. #ifdef UNIX
  147.     int MUnix();
  148. #endif
  149.  
  150.     for (cnt=256; cnt<384; ++cnt) functs[cnt] = &MNotImpl;
  151.     TKbChk();
  152.     functs[256+2] = &MLstBuffs;                /* C-X C-B */
  153.     functs[256+3] = &MExit;                    /* C-X C-C */
  154.     functs[256+6] = &MFindFile;                /* C-X C-F */
  155.     functs[256+7] = &MAbort;                    /* C-X C-G */
  156.     functs[256+9] = &MSetTabs;                /* C-X Tab */
  157.     functs[256+13] = &MDelMode;                /* C-X C-M */
  158.     functs[256+18] = &MFileRead;                /* C-X C-R */
  159.     functs[256+19] = &MFileSave;                /* C-X C-S */
  160.     functs[256+22] = &MNxtOthrWind;            /* C-X C-V */
  161.     functs[256+23] = &MFileWrite;                /* C-X C-W */
  162.     functs[256+24] = &MSwapMrk;                /* C-X C-X */
  163.     functs[256+26] = &MPrvOthrWind;            /* C-X C-Z */
  164.     functs[256+'.'] = &MSetIndent;            /* C-X . */
  165. #ifdef UNIX
  166.     functs[256+'!'] = &MUnix;                /* C-X ! */
  167. #endif
  168.     functs[256+'='] = &MPrintPos;                /* C-X = */
  169.     functs[256+'1'] = &MOneWind;                /* C-X 1 */
  170.     functs[256+'2'] = &MTwoWind;                /* C-X 2 */
  171.     functs[256+'B']=functs[256+'b'] = &MSwitchTo;/* C-X B */
  172.     functs[256+'K']=functs[256+'k'] = &MKillBuff;/* C-X K */
  173.     functs[256+'F']=functs[256+'f'] = &MSetFill;    /* C-X F */
  174.     functs[256+'I']=functs[256+'i'] = &MInsRgn;    /* C-X M */
  175.     functs[256+'M']=functs[256+'m'] = &MAddMode;    /* C-X M */
  176.     functs[256+'O']=functs[256+'o'] = &MSwpWind;    /* C-X O */
  177.     functs[256+'^'] = &MGrowWind;                /* C-X ^ */
  178.     }
  179.  
  180. SetModes()            /* Set the modes according to the bmodes array */
  181. {
  182.     int cnt;
  183.     int MFillChk();
  184. /*    int MInsert(), MOverwrite, MPBegLine();
  185.     int MPBChar(), MPEndLine(), MPFChar(), MPBackSpace();
  186.     int MPNextLine(), MPPrevLine(), MTrimWhite(), MPTab();
  187. */
  188. #ifdef LARGE
  189.     int MNewLin(), MCIndent(), MSInsert();
  190. #endif
  191.  
  192.     *mode='\0';
  193.     finit1();                    /* Set up the key bindings */
  194.     finit2();
  195.     finit3();
  196.     for (cnt=MAXMODES-1; cnt>=0; --cnt) {
  197.         switch (buffs[cbuff].bmodes[cnt]) {
  198.  
  199. #ifdef LARGE
  200.         case 'c':
  201.             functs[13] = &MCIndent;
  202.             strcat(&mode,"C ");
  203.             break;
  204.         case 's':
  205.             Rebind(&MInsert,&MSInsert);
  206.             strcat(&mode,"Save ");
  207.             break;
  208. #endif
  209.         case 'f':
  210.             functs[' '] = &MFillChk;
  211.             strcat(&mode,"Fill ");
  212.             break;
  213. /*        case 'p':                    /* removed to create space */
  214.             Rebind(&MInsert,&MOverwrite);
  215.             functs[1] = &MPBegLine;
  216.             functs[2] = &MPBChar;
  217.             functs[5] = &MPEndLine;
  218.             functs[6] = &MPFChar;
  219.             functs[8] = &MPBackSpace;
  220.             functs[9] = &MPTab;
  221.             functs[14] = &MPNextLine;
  222.             functs[16] = &MPPrevLine;
  223.             functs[256+'\\'] = &MTrimWhite;
  224.             strcat(&mode,"Page ");
  225.             break;
  226. */            }
  227.         }
  228.     if (!*mode) strcpy(&mode,"Normal ");
  229.     mode[strlen(mode)-1]='\0';
  230.     ModeLine();
  231.     }
  232.  
  233. UInit()                /* Do user code initialization */
  234.     /* This function is called once at the very beginning. It may be used
  235.     to do any initialization required for user code */
  236. {
  237.     }
  238.  
  239. MInsRgn()
  240. {
  241.     char tname[FILMAX], initial[STRMAX], final[STRMAX];
  242.     
  243.     arg=0;
  244.     if (!GetArg("File To Insert From <CR>: ",CR,tname,FILMAX))
  245.         return;
  246.     UpCase(tname);
  247.     if (!GetArg("Initial String <ESC>: ",ESC,initial,STRMAX)) return;
  248.     if (!GetArg("Final String <ESC>: ",ESC,final,STRMAX)) return;
  249.     BMrkToPnt(mark);
  250.     BSwitchTo(del_buff);
  251.     if (!BReadFile(tname)) {
  252.         Error("File not found");
  253.         BSwitchTo(buffs[cbuff].bbuff);
  254.         return;
  255.         }
  256.     tmark=BCreMrk();
  257.     if (!StrSrch(initial,FORWARD)) {
  258.         Error ("Initial Not Found");
  259.         BToStart();
  260.         }
  261.     BMove(-strlen(initial));
  262.     BDelToMrk(tmark);
  263.     if (!StrSrch(final,FORWARD)) Error("Final Not Found");
  264.     else BMove(-strlen(final));
  265.     BMrkToPnt(tmark);
  266.     BToEnd();
  267.     BDelToMrk(tmark);
  268.     BToStart();
  269.     BCopyRgn(tmark,buffs[cbuff].bbuff);
  270.     BKillMrk(tmark);
  271.     BSwitchTo(buffs[cbuff].bbuff);
  272.     ClrEcho();
  273.     }
  274.  
  275. /* END OF BINDINGS.C - set up key bindings */
  276. ca