source: trunk/minix/commands/elle/eekmac.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 4.2 KB
Line 
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.
5 */
6/* EEKMAC - Keyboard Macro routines
7 * Modelled after the "e_macro.c" for ICONOGRAPHICS
8 * by C. D. Tavares, 9/11/82
9 */
10
11#include "elle.h"
12
13#if FX_SKMAC /* Entire file is under this conditional! */
14
15int kdef_mode; /* Set when collecting (a "minor mode") */
16static int km_flag = 0; /* 1 = executing, -1 collecting, 0 neither */
17static int km_exp; /* Arg to "Execute Kbd Macro" - # times more to xct */
18static struct buffer *km_buf;
19
20/* EFUN: "Start Kbd Macro" */
21
22f_skmac()
23{ register struct buffer *b;
24 struct buffer *make_buf();
25
26 if(km_flag)
27 { ding("Kbd macro active, ignoring \"Start Kbd Macro\"");
28 return;
29 }
30 if((b = km_buf) == 0)
31 b = km_buf = make_buf(" *KBDMAC*");
32 ex_reset(b);
33 km_flag = -1; /* Say starting macro collection */
34 kdef_mode = 1;
35 redp(RD_MODE);
36}
37
38/* EFUN: "End Kbd Macro" */
39
40f_ekmac()
41{
42 if(km_flag > 0 && (--km_exp >= 0))
43 { ex_go((SBBUF *)km_buf, (chroff)0);
44 }
45 else if(km_flag)
46 { km_flag = 0;
47 kdef_mode = 0; /* Flush minor mode */
48 redp(RD_MODE);
49 }
50}
51
52/* EFUN: "Execute Kbd Macro" */
53
54f_xkmac()
55{
56 if(km_flag)
57 ding("Already in kbd macro!");
58 else if(km_buf == 0)
59 ding("No kbd macro defined");
60 else if((km_exp = exp-1) >= 0)
61 {
62 ex_go((SBBUF *)km_buf, (chroff) 0);
63 km_flag = 1; /* Start macro execution */
64 }
65}
66
67/* EFUN: "View Kbd Macro" */
68
69f_vkmac()
70{ register struct buffer *b, *savbuf;
71 chroff prmplen;
72
73 if(!(b = km_buf))
74 { ding("No kbd macro defined");
75 return;
76 }
77 savbuf = cur_buf;
78 chg_buf(b);
79 e_gobob();
80 e_sputz("Current Kbd macro:\n\n");
81 prmplen = e_dot();
82 mk_showin(b); /* Show the macro buffer temporarily */
83 e_gobob();
84 chg_buf(savbuf);
85 sb_deln((SBBUF *)b, prmplen); /* Flush the prompt */
86}
87
88
89/* KM_GETC - return next command char from kbd macro being executed.
90** This is < 0 if not executing kbd macro. Also responsible for
91** gathering input for kbd macro.
92*/
93km_getc()
94{ register int c;
95
96 while (km_flag > 0) /* Executing macro? */
97 { c = sb_getc(((SBBUF *)km_buf)); /* Yes, get char */
98 if(c != EOF)
99 return(c); /* and return as cmd */
100
101 if(--km_exp >= 0) /* Macro done. Repeat? */
102 ex_go((SBBUF *)km_buf, (chroff)0); /* Yes */
103 else km_flag = 0; /* No, stop execution */
104 }
105 c = tgetc(); /* Get char from user (TTY) */
106 if(km_flag < 0) /* Save it if collecting macro */
107 { sb_putc(((SBBUF *)km_buf), c);
108 }
109 return(c);
110}
111
112/* KM_INWAIT() - Return TRUE if any keyboard-macro input waiting.
113 */
114km_inwait()
115{ register int c;
116 if(km_flag > 0)
117 if((c = sb_getc(((SBBUF *)km_buf))) != EOF || (km_exp > 0))
118 { sb_backc(((SBBUF *)km_buf));
119 return(1);
120 }
121 return(0);
122}
123
124km_abort ()
125{
126 if(km_flag > 0) /* Executing? */
127 km_flag = 0; /* Stop */
128 else if(km_flag < 0) /* Collecting? */
129 f_ekmac(); /* Close it out */
130}
131
132#endif /*FX_SKMAC*/
133
134
135#if 0 /* Old unused stuff */
136static char mode_buf [60];
137
138add_mode (mode)
139 char *mode;
140 {
141 register char *cur, *c, *m;
142
143 if (cur_mode != mode_buf)
144 {
145 strcpy (mode_buf, cur_mode);
146 cur_mode = mode_buf;
147 }
148
149 if (cur_mode [0]) strcat (cur_mode, ", ");
150 strcat (cur_mode, mode);
151 make_mode ();
152 }
153
154remove_mode (mode)
155 char *mode;
156 {
157 register char *cur, *c, *m;
158
159 if (*cur_mode == 0) return;
160
161 if (cur_mode != mode_buf)
162 {
163 strcpy (mode_buf, cur_mode);
164 cur_mode = mode_buf;
165 }
166
167 for (cur = cur_mode ; *cur ; cur++)
168 if (*cur == *mode) /* 1st char matches */
169 {
170 for (c = cur, m = mode ; *m && (*m == *c) ; m++, c++) ;
171 if (!(*m)) /* ok, mode matched */
172 { /* kill leading ", " */
173 if (*(cur - 1) == ' ') --cur;
174 if (*(cur - 1) == ',') --cur;
175 for ( ; *cur = *c ; cur++, c++) ; /* recopy to end */
176 make_mode ();
177 return;
178 }
179 }
180 }
181#endif /*COMMENT*/
Note: See TracBrowser for help on using the repository browser.