eekmac.c

Go to the documentation of this file.
00001 /* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
00002  *      This software is quasi-public; it may be used freely with
00003  *      like software, but may NOT be sold or made part of licensed
00004  *      products without permission of the author.
00005  */
00006 /*      EEKMAC - Keyboard Macro routines
00007  *              Modelled after the "e_macro.c" for ICONOGRAPHICS
00008  *              by C. D. Tavares, 9/11/82
00009  */
00010 
00011 #include "elle.h"
00012 
00013 #if FX_SKMAC            /* Entire file is under this conditional! */
00014 
00015 int kdef_mode;          /* Set when collecting (a "minor mode") */
00016 static int km_flag = 0; /* 1 = executing, -1 collecting, 0 neither */
00017 static int km_exp;      /* Arg to "Execute Kbd Macro" - # times more to xct */
00018 static struct buffer *km_buf;
00019 
00020 /* EFUN: "Start Kbd Macro" */
00021 
00022 f_skmac()
00023 {       register struct buffer *b;
00024         struct buffer *make_buf();
00025 
00026         if(km_flag)
00027           {     ding("Kbd macro active, ignoring \"Start Kbd Macro\"");
00028                 return;
00029           }
00030         if((b = km_buf) == 0)
00031                 b = km_buf = make_buf(" *KBDMAC*");
00032         ex_reset(b);
00033         km_flag = -1;           /* Say starting macro collection */
00034         kdef_mode = 1;
00035         redp(RD_MODE);
00036 }
00037 
00038 /* EFUN: "End Kbd Macro" */
00039 
00040 f_ekmac()
00041 {
00042         if(km_flag > 0 && (--km_exp >= 0))
00043           {     ex_go((SBBUF *)km_buf, (chroff)0);
00044           }
00045         else if(km_flag)
00046           {     km_flag = 0;
00047                 kdef_mode = 0;  /* Flush minor mode */
00048                 redp(RD_MODE);
00049           }
00050 }
00051 
00052 /* EFUN: "Execute Kbd Macro" */
00053 
00054 f_xkmac()
00055 {
00056         if(km_flag)
00057                 ding("Already in kbd macro!");
00058         else if(km_buf == 0)
00059                 ding("No kbd macro defined");
00060         else if((km_exp = exp-1) >= 0)
00061           {
00062                 ex_go((SBBUF *)km_buf, (chroff) 0);
00063                 km_flag = 1;            /* Start macro execution */
00064           }
00065 }
00066 
00067 /* EFUN: "View Kbd Macro" */
00068 
00069 f_vkmac()
00070 {       register struct buffer *b, *savbuf;
00071         chroff prmplen;
00072 
00073         if(!(b = km_buf))
00074           {     ding("No kbd macro defined");
00075                 return;
00076           }
00077         savbuf = cur_buf;
00078         chg_buf(b);
00079         e_gobob();
00080         e_sputz("Current Kbd macro:\n\n");
00081         prmplen = e_dot();
00082         mk_showin(b);           /* Show the macro buffer temporarily */
00083         e_gobob();
00084         chg_buf(savbuf);
00085         sb_deln((SBBUF *)b, prmplen);   /* Flush the prompt */
00086 }
00087 
00088 /* KM_GETC - return next command char from kbd macro being executed.
00089 **      This is < 0 if not executing kbd macro.  Also responsible for
00090 **      gathering input for kbd macro.
00091 */
00092 km_getc()
00093 {       register int c;
00094 
00095         while (km_flag > 0)             /* Executing macro? */
00096           {     c = sb_getc(((SBBUF *)km_buf)); /* Yes, get char */
00097                 if(c != EOF)
00098                         return(c);              /* and return as cmd */
00099 
00100                 if(--km_exp >= 0)               /* Macro done.  Repeat? */
00101                         ex_go((SBBUF *)km_buf, (chroff)0);      /* Yes */
00102                 else km_flag = 0;               /* No, stop execution */
00103           }
00104         c = tgetc();                    /* Get char from user (TTY) */
00105         if(km_flag < 0)                 /* Save it if collecting macro */
00106           {     sb_putc(((SBBUF *)km_buf), c);
00107           }
00108         return(c);
00109 }
00110 
00111 /* KM_INWAIT() - Return TRUE if any keyboard-macro input waiting.
00112  */
00113 km_inwait()
00114 {       register int c;
00115         if(km_flag > 0)
00116                 if((c = sb_getc(((SBBUF *)km_buf))) != EOF || (km_exp > 0))
00117                   {     sb_backc(((SBBUF *)km_buf));
00118                         return(1);
00119                   }
00120         return(0);
00121 }
00122 
00123 km_abort ()
00124 {
00125         if(km_flag > 0)         /* Executing? */
00126                 km_flag = 0;    /* Stop */
00127         else if(km_flag < 0)    /* Collecting? */
00128                 f_ekmac();      /* Close it out */
00129 }
00130 
00131 #endif /*FX_SKMAC*/
00132 
00133 #if 0   /* Old unused stuff */
00134 static char mode_buf [60];
00135 
00136 add_mode (mode)
00137   char *mode;
00138   {
00139         register char *cur, *c, *m;
00140 
00141         if (cur_mode != mode_buf)
00142            {
00143             strcpy (mode_buf, cur_mode);
00144             cur_mode = mode_buf;
00145            }
00146 
00147         if (cur_mode [0]) strcat (cur_mode, ", ");
00148         strcat (cur_mode, mode);
00149         make_mode ();
00150   }
00151 
00152 remove_mode (mode)
00153   char *mode;
00154   {
00155         register char *cur, *c, *m;
00156 
00157         if (*cur_mode == 0) return;
00158 
00159         if (cur_mode != mode_buf)
00160            {
00161             strcpy (mode_buf, cur_mode);
00162             cur_mode = mode_buf;
00163            }
00164 
00165         for (cur = cur_mode ; *cur ; cur++)
00166             if (*cur == *mode)          /* 1st char matches */
00167                {
00168                 for (c = cur, m = mode ; *m && (*m == *c) ; m++, c++) ;
00169                 if (!(*m))              /* ok, mode matched */
00170                    {                    /* kill leading ", " */
00171                     if (*(cur - 1) == ' ') --cur;
00172                     if (*(cur - 1) == ',') --cur;
00173                     for ( ; *cur = *c ; cur++, c++) ;   /* recopy to end */
00174                     make_mode ();
00175                     return;
00176                    }
00177                }
00178   }
00179 #endif /*COMMENT*/

Generated on Fri Apr 14 22:56:48 2006 for minix by  doxygen 1.4.6