Annotation of src/usr.bin/mg/macro.c, Revision 1.3
1.3 ! millert 1: /*
! 2: * Keyboard macros.
! 3: */
1.1 deraadt 4:
5: #ifndef NO_MACRO
6: #include "def.h"
7: #include "key.h"
8: #define EXTERN
9: #define INIT(i) = (i)
10: #include "macro.h"
11:
1.2 millert 12: /* ARGSUSED */
1.3 ! millert 13: int
1.1 deraadt 14: definemacro(f, n)
1.3 ! millert 15: int f, n;
1.1 deraadt 16: {
1.3 ! millert 17: LINE *lp1, *lp2;
1.1 deraadt 18:
19: macrocount = 0;
1.3 ! millert 20:
1.2 millert 21: if (macrodef) {
22: ewprintf("already defining macro");
23: return macrodef = FALSE;
1.1 deraadt 24: }
1.3 ! millert 25:
1.1 deraadt 26: /* free lines allocated for string arguments */
1.2 millert 27: if (maclhead != NULL) {
28: for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) {
29: lp2 = lp1->l_fp;
1.3 ! millert 30: free((char *)lp1);
1.2 millert 31: }
1.3 ! millert 32: free((char *)lp1);
1.1 deraadt 33: }
1.3 ! millert 34:
1.2 millert 35: if ((maclhead = lp1 = lalloc(0)) == NULL)
36: return FALSE;
1.3 ! millert 37:
1.1 deraadt 38: ewprintf("Defining Keyboard Macro...");
39: maclcur = lp1->l_fp = lp1->l_bp = lp1;
40: return macrodef = TRUE;
41: }
42:
1.2 millert 43: /* ARGSUSED */
1.3 ! millert 44: int
1.1 deraadt 45: finishmacro(f, n)
1.3 ! millert 46: int f, n;
1.1 deraadt 47: {
1.2 millert 48: macrodef = FALSE;
49: ewprintf("End Keyboard Macro Definition");
50: return TRUE;
1.1 deraadt 51: }
52:
1.2 millert 53: /* ARGSUSED */
1.3 ! millert 54: int
1.1 deraadt 55: executemacro(f, n)
1.3 ! millert 56: int f, n;
1.1 deraadt 57: {
1.3 ! millert 58: int i, j, flag, num;
! 59: PF funct;
1.2 millert 60:
1.3 ! millert 61: if (macrodef ||
! 62: (macrocount >= MAXMACRO && macro[MAXMACRO].m_funct != finishmacro))
1.1 deraadt 63: return FALSE;
1.3 ! millert 64:
1.2 millert 65: if (macrocount == 0)
66: return TRUE;
1.3 ! millert 67:
1.2 millert 68: inmacro = TRUE;
1.3 ! millert 69:
1.2 millert 70: for (i = n; i > 0; i--) {
71: maclcur = maclhead->l_fp;
72: flag = 0;
73: num = 1;
74: for (j = 0; j < macrocount - 1; j++) {
75: funct = macro[j].m_funct;
76: if (funct == universal_argument) {
77: flag = FFARG;
78: num = macro[++j].m_count;
79: continue;
80: }
1.3 ! millert 81: if ((*funct)(flag, num) != TRUE) {
1.2 millert 82: inmacro = FALSE;
83: return FALSE;
84: }
85: lastflag = thisflag;
86: thisflag = 0;
87: flag = 0;
88: num = 1;
89: }
1.1 deraadt 90: }
1.2 millert 91: inmacro = FALSE;
92: return TRUE;
1.1 deraadt 93: }
1.3 ! millert 94: #endif /* NO_MACRO */