1 /* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
6 /* EEKMAC - Keyboard Macro routines
7 * Modelled after the "e_macro.c" for ICONOGRAPHICS
8 * by C. D. Tavares, 9/11/82
13 #if FX_SKMAC /* Entire file is under this conditional! */
15 int kdef_mode
; /* Set when collecting (a "minor mode") */
16 static int km_flag
= 0; /* 1 = executing, -1 collecting, 0 neither */
17 static int km_exp
; /* Arg to "Execute Kbd Macro" - # times more to xct */
18 static struct buffer
*km_buf
;
20 /* EFUN: "Start Kbd Macro" */
23 { register struct buffer
*b
;
24 struct buffer
*make_buf();
27 { ding("Kbd macro active, ignoring \"Start Kbd Macro\"");
31 b
= km_buf
= make_buf(" *KBDMAC*");
33 km_flag
= -1; /* Say starting macro collection */
38 /* EFUN: "End Kbd Macro" */
42 if(km_flag
> 0 && (--km_exp
>= 0))
43 { ex_go((SBBUF
*)km_buf
, (chroff
)0);
47 kdef_mode
= 0; /* Flush minor mode */
52 /* EFUN: "Execute Kbd Macro" */
57 ding("Already in kbd macro!");
59 ding("No kbd macro defined");
60 else if((km_exp
= exp
-1) >= 0)
62 ex_go((SBBUF
*)km_buf
, (chroff
) 0);
63 km_flag
= 1; /* Start macro execution */
67 /* EFUN: "View Kbd Macro" */
70 { register struct buffer
*b
, *savbuf
;
74 { ding("No kbd macro defined");
80 e_sputz("Current Kbd macro:\n\n");
82 mk_showin(b
); /* Show the macro buffer temporarily */
85 sb_deln((SBBUF
*)b
, prmplen
); /* Flush the prompt */
88 /* KM_GETC - return next command char from kbd macro being executed.
89 ** This is < 0 if not executing kbd macro. Also responsible for
90 ** gathering input for kbd macro.
95 while (km_flag
> 0) /* Executing macro? */
96 { c
= sb_getc(((SBBUF
*)km_buf
)); /* Yes, get char */
98 return(c
); /* and return as cmd */
100 if(--km_exp
>= 0) /* Macro done. Repeat? */
101 ex_go((SBBUF
*)km_buf
, (chroff
)0); /* Yes */
102 else km_flag
= 0; /* No, stop execution */
104 c
= tgetc(); /* Get char from user (TTY) */
105 if(km_flag
< 0) /* Save it if collecting macro */
106 { sb_putc(((SBBUF
*)km_buf
), c
);
111 /* KM_INWAIT() - Return TRUE if any keyboard-macro input waiting.
116 if((c
= sb_getc(((SBBUF
*)km_buf
))) != EOF
|| (km_exp
> 0))
117 { sb_backc(((SBBUF
*)km_buf
));
125 if(km_flag
> 0) /* Executing? */
126 km_flag
= 0; /* Stop */
127 else if(km_flag
< 0) /* Collecting? */
128 f_ekmac(); /* Close it out */
133 #if 0 /* Old unused stuff */
134 static char mode_buf
[60];
139 register char *cur
, *c
, *m
;
141 if (cur_mode
!= mode_buf
)
143 strcpy (mode_buf
, cur_mode
);
147 if (cur_mode
[0]) strcat (cur_mode
, ", ");
148 strcat (cur_mode
, mode
);
155 register char *cur
, *c
, *m
;
157 if (*cur_mode
== 0) return;
159 if (cur_mode
!= mode_buf
)
161 strcpy (mode_buf
, cur_mode
);
165 for (cur
= cur_mode
; *cur
; cur
++)
166 if (*cur
== *mode
) /* 1st char matches */
168 for (c
= cur
, m
= mode
; *m
&& (*m
== *c
) ; m
++, c
++) ;
169 if (!(*m
)) /* ok, mode matched */
170 { /* kill leading ", " */
171 if (*(cur
- 1) == ' ') --cur
;
172 if (*(cur
- 1) == ',') --cur
;
173 for ( ; *cur
= *c
; cur
++, c
++) ; /* recopy to end */