home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / cpm68k / kmince.lbr / BINDINGS.CQ / BINDINGS.C
Text File  |  1986-08-29  |  13KB  |  441 lines

  1. /* -*-C,save,tab:8,indent:4-*- */
  2. /* BINDINGS.C - Set up the key bindings for Mince
  3.  
  4. The seller of this software hereby disclaims any and all
  5. guarantees and warranties, both express and implied.  No
  6. liability of any form shall be assumed by the seller, nor shall
  7. direct, consequential, or other damages be assumed by the seller.
  8. Any user of this software uses it at his or her own risk.
  9.  
  10. Due to the ill-defined nature of "fitness for purpose" or similar
  11. types of guarantees for this type of product, no fitness for any
  12. purpose whatsoever is claimed or implied.
  13.  
  14. The physical medium upon which the software is supplied is
  15. guaranteed for one year against any physical defect.  If it
  16. should fail, return it to the seller, and a new physical medium
  17. with a copy of the purchased software shall be sent.
  18.  
  19. The seller reserve the right to make changes, additions, and
  20. improvements to the software at any time; no guarantee is made
  21. that future versions of the software will be compatible with any
  22. other version.
  23.  
  24. The parts of this disclaimer are severable and fault found in any
  25. one part does not invalidate any other parts.
  26.  
  27.     Copyright (c) 1981 by Mark of the Unicorn
  28.     Created for Version 2.3  10/4/80  JTL
  29.     Updated to version three  1/7/81  JTL
  30.  
  31.     This file contains the function table initializers and mode set up functions */
  32.  
  33. #include "mince.gbl"
  34.  
  35. finit1()            /* initialize the control and self insert key bindings */
  36. {
  37.     int tcnt;
  38.     int MInsert(), MSetMrk(), MBegLin(), MPrevChar();
  39.     int MNotImpl(), MDelChar(), MEndLin(), MNextChar();
  40.     int MAbort(), MDelLin(), NewDsp(), MNewLin();
  41.     int MNextLin(), MOpenLin(), MPrevLin(), MQuote();
  42.     int MRSearch(), MSearch(), MSwapChar(), MArg();
  43.     int MNextPage(), MDelRgn(), MCtrlX(), MYank();
  44.     int MPrevPage(), MMeta(), MDelIndent(), MRDelChar();
  45.     int MIndent();
  46.  
  47.  
  48.     for (tcnt=0; tcnt<128; ++tcnt) functs[tcnt] = MInsert;
  49.     TKbChk();
  50.     functs[0] = MSetMrk;        /* C-@ */
  51.     functs[1] = MBegLin;        /* C-A */
  52.     functs[2] = MPrevChar;        /* C-B */
  53.     functs[3] = MNotImpl;        /* C-C */
  54.     functs[4] = MDelChar;        /* C-D */
  55.     functs[5] = MEndLin;        /* C-E */
  56.     functs[6] = MNextChar;        /* C-F */
  57.     functs[7] = MAbort;            /* C-G */
  58.     functs[8] = MRDelChar;        /* C-H */
  59.                             /* C-I */
  60.     functs[10] = MIndent;        /* C-J */
  61.     functs[11] = MDelLin;        /* C-K */
  62.     functs[12] = NewDsp;        /* C-L */
  63.     functs[13] = MNewLin;        /* C-M */
  64.     functs[14] = MNextLin;        /* C-N */
  65.     functs[15] = MOpenLin;        /* C-O */
  66.     functs[16] = MPrevLin;        /* C-P */
  67.     functs[17] = MQuote;        /* C-Q */
  68.     functs[18] = MRSearch;        /* C-R */
  69.     functs[19] = MSearch;        /* C-S */
  70.     functs[20] = MSwapChar;        /* C-T */
  71.     functs[21] = MArg;            /* C-U */
  72.     functs[22] = MNextPage;        /* C-V */
  73.     functs[23] = MDelRgn;        /* C-W */
  74.     functs[24] = MCtrlX;        /* C-X */
  75.     functs[25] = MYank;            /* C-Y */
  76.     functs[26] = MPrevPage;        /* C-Z */
  77.     functs[ESC] = MMeta;        /* ESC */
  78.     functs[28] = MDelIndent;        /* C-\ */
  79.     functs[29] = MNotImpl;        /* C-] */
  80.     functs[30] = MNotImpl;        /* C-^ */
  81.     functs[31] = MNotImpl;        /* C-_ */
  82.     functs[DEL] = MRDelChar;        /* DEL */
  83.     }
  84.  
  85. finit2()            /* set up the Meta key bindings */
  86. {
  87.     int tcnt;
  88.     int MNotImpl(), MAbort(), MDelELin(), MQryRplc();
  89.     int MMakeDel(), MToStart(), MToEnd(), MBSent();
  90.     int BWord(), MCapWord(), MDelWord(), MFSent();
  91.     int FWord(), MMrkPara(), MDelSent(), MLowWord();
  92.     int MFillPara(), MReplace(), MCntrLine(), MUpWord();
  93.     int MPrevPage(), MCopyRgn(), MBPara(), MDelWhite();
  94.     int MFPara(), MRDelWord(), MSetMrk(), MSwapWord();
  95.  
  96.     for (tcnt=128; tcnt<256; ++tcnt) functs[tcnt] = MNotImpl;
  97.     TKbChk();
  98.     functs[128+7] = MAbort;                    /* M-C-G */
  99.     functs[128+8] = MRDelWord;                /* M-C-H */
  100.     functs[128+11] = MDelELin;                /* M-C-K */
  101.     functs[128+18] = MQryRplc;                /* M-C-R */
  102.     functs[128+23] = MMakeDel;                /* M-C-W */
  103.     functs[128+'<'] = MToStart;                /* M-< */
  104.     functs[128+'>'] = MToEnd;                /* M-> */
  105.     functs[128+' '] = MSetMrk;                /* M-  */
  106.     functs[128+'A']=functs[128+'a'] = MBSent;    /* M-A */
  107.     functs[128+'B']=functs[128+'b'] = BWord;    /* M-B */
  108.     functs[128+'C']=functs[128+'c'] = MCapWord;    /* M-C */
  109.     functs[128+'D']=functs[128+'d'] = MDelWord;    /* M-D */
  110.     functs[128+'E']=functs[128+'e'] = MFSent;    /* M-E */
  111.     functs[128+'F']=functs[128+'f'] = FWord;    /* M-F */
  112.     functs[128+'H']=functs[128+'h'] = MMrkPara;    /* M-H */
  113.     functs[128+'K']=functs[128+'k'] = MDelSent;    /* M-K */
  114.     functs[128+'L']=functs[128+'l'] = MLowWord;    /* M-L */
  115.     functs[128+'Q']=functs[128+'q'] = MFillPara;    /* M-Q */
  116.     functs[128+'R']=functs[128+'r'] = MReplace;    /* M-R */
  117.     functs[128+'S']=functs[128+'s'] = MCntrLine;    /* M-S */
  118.     functs[128+'T']=functs[128+'t'] = MSwapWord;    /* M-T */
  119.     functs[128+'U']=functs[128+'u'] = MUpWord;    /* M-U */
  120.     functs[128+'V']=functs[128+'v'] = MPrevPage;    /* M-V */
  121.     functs[128+'W']=functs[128+'w'] = MCopyRgn;    /* M-W */
  122.     functs[128+'['] = MBPara;                /* M-[ */
  123.     functs[128+'\\'] = MDelWhite;                /* M-\ */
  124.     functs[128+']'] = MFPara;                /* M-] */
  125.     functs[128+DEL] = MRDelWord;                /* M-DEL */
  126.     }
  127.  
  128. finit3()            /* set up the Control-X key bindings */
  129. {
  130.     int tcnt;
  131.     int MNotImpl(), MLstBuffs(), MExit(), MFindFile();
  132.     int MAbort(), MSetTabs(), MDelMode(), MFileRead();
  133.     int MFileSave(), MFileWrite(), MSwapMrk(), MSetIndent();
  134.     int MPrintPos(), MSwitchTo(), MKillBuff(), MSetFill();
  135.     int MAddMode(), MOneWind(), MTwoWind(), MSwpWind();
  136.     int MNxtOthrWind(), MPrvOthrWind(), MGrowWind();
  137. #ifdef UNIX
  138.     int MUnix();
  139. #endif
  140. #ifdef KBMACRO
  141.     int MStrtRem(),MStpRem(),MExcKBMc();
  142. #endif
  143. #ifdef STRIDE
  144.     int MInsTime();
  145. #endif
  146. #ifdef GENHEAD
  147.     int MGenPro();
  148. #endif
  149. #ifdef AUTOMODE
  150.     int InitMode();
  151. #endif
  152.  
  153.     for (tcnt=256; tcnt<384; ++tcnt) functs[tcnt] = MNotImpl;
  154.     TKbChk();
  155.     functs[256+2] = MLstBuffs;                /* C-X C-B */
  156.     functs[256+3] = MExit;                    /* C-X C-C */
  157.     functs[256+6] = MFindFile;                /* C-X C-F */
  158.     functs[256+7] = MAbort;                    /* C-X C-G */
  159.     functs[256+9] = MSetTabs;                /* C-X Tab */
  160.     functs[256+13] = MDelMode;                /* C-X C-M */
  161. #ifdef GENHEAD
  162.     functs[256+16] = MGenPro;
  163. #endif
  164.     functs[256+18] = MFileRead;                /* C-X C-R */
  165.     functs[256+19] = MFileSave;                /* C-X C-S */
  166. #ifdef STRIDE
  167.     functs[256+20] = MInsTime;                /* C-X C-T */
  168. #endif
  169.     functs[256+22] = MNxtOthrWind;            /* C-X C-V */
  170.     functs[256+23] = MFileWrite;                /* C-X C-W */
  171.     functs[256+24] = MSwapMrk;                /* C-X C-X */
  172.     functs[256+26] = MPrvOthrWind;            /* C-X C-Z */
  173.     functs[256+'.'] = MSetIndent;                /* C-X . */
  174. #ifdef UNIX
  175.     functs[256+'!'] = MUnix;                    /* C-X ! */
  176. #endif
  177.     functs[256+'='] = MPrintPos;                /* C-X = */
  178. #ifdef KBMACRO
  179.     functs[256+'('] = MStrtRem;                /* C-X ( */
  180.     functs[256+')'] = MStpRem;                /* C-X ) */
  181. #endif
  182.     functs[256+'1'] = MOneWind;                /* C-X 1 */
  183.     functs[256+'2'] = MTwoWind;                /* C-X 2 */
  184.     functs[256+'B']=functs[256+'b'] = MSwitchTo;    /* C-X B */
  185. #ifdef KBMACRO
  186.     functs[256+'E']=functs[256+'e'] = MExcKBMc;    /* C-X E */
  187. #endif
  188.     functs[256+'K']=functs[256+'k'] = MKillBuff;    /* C-X K */
  189.     functs[256+'F']=functs[256+'f'] = MSetFill;    /* C-X F */
  190. #ifdef AUTOMODE
  191.     functs[256+'I']=functs[256+'i'] = InitMode;    /* C-X I */
  192. #endif
  193.     functs[256+'M']=functs[256+'m'] = MAddMode;    /* C-X M */
  194.     functs[256+'O']=functs[256+'o'] = MSwpWind;    /* C-X O */
  195.     functs[256+'^'] = MGrowWind;                /* C-X ^ */
  196.     }
  197.  
  198. SetModes()            /* Set the modes according to the bmodes array */
  199. {
  200.     int tcnt;
  201.     int MFillChk(), MInsert(), MOverwrite(), MPBegLine();
  202.     int MPBChar(), MPEndLine(), MPFChar(), MPBackSpace();
  203.     int MPNextLine(), MPPrevLine(), MTrimWhite(), MPTab();
  204. #ifdef LARGE
  205.     int MNewLin(), MCIndent(), MSInsert();
  206. #endif
  207. #ifdef FLASHER
  208.     int MFlash();
  209. #endif
  210. #ifdef LISPMODE
  211.     int MLspNLI(), MLspInd(), MForPar(), MBckPar();
  212. #endif
  213. #ifdef GENHEAD
  214.     int MGenCPr();
  215. #ifdef LISPMODE
  216.     int MGenLPr();
  217. #endif
  218. #endif
  219.  
  220.     *mode='\0';
  221.     finit1();                    /* Set up the key bindings */
  222.     finit2();
  223.     finit3();
  224. #ifdef KEYPAD
  225. /* If KEYPAD is set, set up keypad bindings */
  226.     KeyPad();
  227. #endif
  228. #ifdef WY50
  229.     wy50_finit();    /* WY-50 function key bindings - RPH */
  230. #endif
  231. #ifdef FLASHER
  232.     SynCopy(CurSyn,NormSyn,MAXCHARS);
  233. #endif
  234. #ifdef ELECTRIC
  235.     ECpyAbrv(CurAbr,NormAbr,MAXABREVS);
  236. #endif
  237.     for (tcnt=MAXMODES-1; tcnt>=0; --tcnt) {
  238.         switch (buffs[cbuff].bmodes[tcnt]) {
  239.  
  240. #ifdef LARGE
  241.         case 'c':
  242.             functs[13] = MCIndent;
  243. #ifdef FLASHER
  244.             SynCopy(CurSyn,CSyn,MAXCHARS);
  245.             functs[')'] = MFlash;
  246.             functs['}'] = MFlash;
  247. #endif
  248. #ifdef GENHEAD
  249.             functs[256+16] = MGenCPr;
  250. #endif
  251. #ifdef ELECTRIC
  252.             CElecInit();
  253. #endif
  254.             strcat(mode,"C ");
  255.             break;
  256.         case 's':
  257.             Rebind(MInsert,MSInsert);
  258.             strcat(mode,"Save ");
  259.             break;
  260. #endif
  261.         case 'f':
  262.             functs[' '] = MFillChk;
  263.             strcat(mode,"Fill ");
  264.             break;
  265.         case 'p':
  266.             Rebind(MInsert,MOverwrite);
  267.             functs[1] = MPBegLine;
  268.             functs[2] = MPBChar;
  269.             functs[5] = MPEndLine;
  270.             functs[6] = MPFChar;
  271.             functs[8] = MPBackSpace;
  272.             functs[9] = MPTab;
  273.             functs[14] = MPNextLine;
  274.             functs[16] = MPPrevLine;
  275.             functs[256+'\\'] = MTrimWhite;
  276.             strcat(mode,"Page ");
  277.             break;
  278. #ifdef LISPMODE
  279.         case 'l':
  280.             functs[10] = MLspNLI;
  281.             functs[9] = MLspInd;
  282. #ifdef FLASHER
  283.             SynCopy(CurSyn,LispSyn,MAXCHARS);
  284.             functs[')'] = MFlash;
  285.             functs[128+')'] = MForPar;
  286.             functs[128+'('] = MBckPar;
  287. #endif
  288. #ifdef GENHEAD
  289.             functs[256+16] = MGenLPr;
  290. #endif
  291. #ifdef ELECTRIC
  292.             LElecInit();
  293. #endif
  294.             strcat(mode,"Lisp ");
  295.             break;
  296. #endif
  297.             }
  298.         }
  299.     if (!*mode) strcpy(mode,"Normal ");
  300.     mode[strlen(mode)-1]='\0';
  301.     ModeLine();
  302. #ifdef AUTOMODE
  303. /*    Debug("mvars[cbuff].mfill=",mvars[cbuff].mfill);*/
  304. /*    Debug("mvars[cbuff].mindent=",mvars[cbuff].mindent);*/
  305. /*    Debug("mvars[cbuff].mtab=",mvars[cbuff].mtab);*/
  306.     if (mvars[cbuff].mfill > 0) fillwidth = mvars[cbuff].mfill;
  307.     if ((mvars[cbuff].mindent >= 0) &&
  308.         (mvars[cbuff].mfill > 0)) indentcol = mvars[cbuff].mindent;
  309.     if (mvars[cbuff].mtab > 0) tabincr = mvars[cbuff].mtab;
  310. #endif
  311.     }
  312.  
  313. UInit()                /* Do user code initilization */
  314.     /* This function is called once at the very begining. It may be used
  315.     to do any initilization required for user code */
  316. {int i;
  317.  
  318. #ifdef FLASHER
  319.     SynInit();
  320. #endif
  321. #ifdef ELECTRIC
  322.     EInitAbrv();
  323. #endif
  324. #ifdef AUTOMODE
  325. /*    Debug("fillwidth=",fillwidth);*/
  326. /*    Debug("indentcol=",indentcol);*/
  327. /*    Debug("tabincr=",tabincr);*/
  328.     for (i=0;i<BUFFSMAX;i++) {
  329.     mvars[i].mfill = fillwidth;
  330.     mvars[i].mindent = indentcol;
  331.     mvars[i].mtab = tabincr;
  332.     }
  333.     InitMode();
  334. #endif
  335. #ifdef KBMACRO
  336.     remember = FALSE; KBexecuting = FALSE; GAbort = FALSE;
  337. #endif
  338.     }
  339. #ifdef AUTOMODE
  340. #define MODEIDENT "-*-"    /* mode indent strings */
  341. InitMode()
  342. {
  343.     int mmark,    /* mode mark */
  344.         md;        /* holds mode */
  345.     char mbuf[80],    /* mode name buffer */
  346.          *p,*q,    /* temp pointers */
  347.          sep;    /* separater character */
  348.  
  349.     BToStart();    /* beginning of buffer */
  350.     NLSrch();    /* find first newline */
  351.     if (!StrSrch(MODEIDENT,BACKWARD)) { /* find second MODEIDENT. if none, then */
  352.         BToStart();    /* clean up, etc. */
  353.         return;
  354.         }
  355.     mmark = BCreMrk();    /* save our place for later */
  356. /*    Debug("After BCreMrk - ",mmark);*/
  357.     /* find first MODEIDENT */
  358.     if (!StrSrch(MODEIDENT,BACKWARD)) {
  359.         BToStart();    /* clean up, etc. */
  360. /*    Debug("About to kill mark (no -*-) ",mmark);*/
  361.         BKillMrk(mmark);
  362.         return;
  363.         }
  364.     else StrSrch(MODEIDENT,FORWARD); /* else backup to just before mode str */
  365.     /* now copy from user's buffer to temp space */
  366.     p = &mbuf[0];
  367. /*    Debug("Before copy loop ",mmark);*/
  368.     while (BIsBeforeMrk(mmark)) {
  369.         *p++ = tolower(Buff());
  370.         BMove(1);
  371.         }
  372.     *p++ = '\0'; *p++ = '\0'; /* eos. (put two in to be sure) */
  373.     /* kill off mark */
  374. /*    Debug("About to kill mark ",mmark);*/
  375.     BKillMrk(mmark);
  376.     BToStart();    /* reset position */
  377.     p = q = &mbuf[0]; /* reset pointers */
  378.     while (*p != '\0') {    /* while not eob */
  379.         while(!isalpha(*q) && *q != '\0') q++; /* skip boring junk */
  380.         if (*q == '\0') break;
  381.         p = q;
  382.         while(isalpha(*p)) p++; /* find end of interesting stuff */
  383.         sep = *p;    /* save separater */
  384.         *p++ = '\0';    /* terminate piece */
  385.         md = CheckMode(q);    /* get mode id from mode name */
  386.         if (md) insmode(md);    /* insert mode */
  387.         else if (sep == ':') CheckVar(q,&p); /* else check for xxx:n stuff */
  388.         q = p;        /* advance to next */
  389.         }
  390. /*    Debug("mvars[cbuff].mfill=",mvars[cbuff].mfill);*/
  391. /*    Debug("mvars[cbuff].mindent=",mvars[cbuff].mindent);*/
  392. /*    Debug("mvars[cbuff].mtab=",mvars[cbuff].mtab);*/
  393.     SetModes();    /* set up selected modes */
  394.     }
  395. static insmode(md)
  396. int md;
  397. {
  398.     int i;
  399.  
  400.     for (i=MAXMODES-1;i>=0;--i)
  401.         if (!buffs[cbuff].bmodes[i]) {
  402.             buffs[cbuff].bmodes[i] = md;
  403.             return;
  404.             }
  405.     }
  406. static CheckVar(name,next)
  407. char *name,**next;
  408. {
  409.     char *p,*q;
  410.     static char *names[] = {"fillw","indent","tab",NULL};
  411.     char **n2;
  412.     static int *vars[] = {NULL,NULL,NULL,NULL};
  413.     int i,j;
  414.  
  415.     vars[0] = (&mvars[cbuff].mfill);
  416.     vars[1] = (&mvars[cbuff].mindent);
  417.     vars[2] = (&mvars[cbuff].mtab);
  418.     i = 0;
  419.     for (n2=(&names[0]);*n2!=NULL;n2++)
  420.         if (strcmp(name,*n2) == 0) {
  421.         p = q = *next;
  422.         while(isdigit(*p)) p++;
  423.         *p++ ='\0';
  424.         *next = p;
  425.         j = atoi(q);
  426. /*        Debug(q,j);*/
  427.         *vars[i] = j;
  428.         return;
  429.         }
  430.     else i++;
  431.     }
  432. #endif
  433.  
  434. /* END OF BINDINGS.C - set up key bindings */
  435. q,j);*/
  436.         *vars[i] = j;
  437.         return;
  438.         }
  439.     else i++;
  440.     }
  441.