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