[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.1

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