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

File: [local] / src / usr.bin / mg / macro.c (download)

Revision 1.2, Thu Apr 13 06:12:16 2000 UTC (24 years, 2 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_2_7_BASE, OPENBSD_2_7
Changes since 1.1: +55 -53 lines

The start of KNF + -Wall.  The code has been run through indent but
needs hand fixup.  I stopped at keymap.c...

/* keyboard macros for Mg 2 */

#ifndef NO_MACRO
#include "def.h"
#include "key.h"
#define EXTERN
#define INIT(i) = (i)
#include "macro.h"

/* ARGSUSED */
definemacro(f, n)
	int             f, n;
{
	register LINE  *lp1;
	LINE           *lp2;

	macrocount = 0;
	if (macrodef) {
		ewprintf("already defining macro");
		return macrodef = FALSE;
	}
	/* free lines allocated for string arguments */
	if (maclhead != NULL) {
		for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) {
			lp2 = lp1->l_fp;
			free((char *) lp1);
		}
		free((char *) lp1);
	}
	if ((maclhead = lp1 = lalloc(0)) == NULL)
		return FALSE;
	ewprintf("Defining Keyboard Macro...");
	maclcur = lp1->l_fp = lp1->l_bp = lp1;
	return macrodef = TRUE;
}

/* ARGSUSED */
finishmacro(f, n)
	int             f, n;
{
	macrodef = FALSE;
	ewprintf("End Keyboard Macro Definition");
	return TRUE;
}

/* ARGSUSED */
executemacro(f, n)
	int             f, n;
{
	int             i, j;
	PF              funct;
	int             universal_argument();
	int             flag, num;

	if (macrodef ||
	 (macrocount >= MAXMACRO && macro[MAXMACRO].m_funct != finishmacro))
		return FALSE;
	if (macrocount == 0)
		return TRUE;
	inmacro = TRUE;
	for (i = n; i > 0; i--) {
		maclcur = maclhead->l_fp;
		flag = 0;
		num = 1;
		for (j = 0; j < macrocount - 1; j++) {
			funct = macro[j].m_funct;
			if (funct == universal_argument) {
				flag = FFARG;
				num = macro[++j].m_count;
				continue;
			}
			if ((*funct) (flag, num) != TRUE) {
				inmacro = FALSE;
				return FALSE;
			}
			lastflag = thisflag;
			thisflag = 0;
			flag = 0;
			num = 1;
		}
	}
	inmacro = FALSE;
	return TRUE;
}
#endif