[BACK]Return to macro.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/macro.c, Revision 1.10

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