예제 #1
0
파일: exec.c 프로젝트: k0gaMSX/uemacs
/*
 * dofile:
 *	yank a file into a buffer and execute it
 *	if there are no errors, delete the buffer on exit
 *
 * char *fname;		file name to execute
 */
int dofile(char *fname)
{
	struct buffer *bp;	/* buffer to place file to exeute */
	struct buffer *cb;	/* temp to hold current buf while we read */
	int status;	/* results of various calls */
	char bname[NBUFN];	/* name of buffer */

	makename(bname, fname);	/* derive the name of the buffer */
	unqname(bname);		/* make sure we don't stomp things */
	if ((bp = bfind(bname, TRUE, 0)) == NULL)	/* get the needed buffer */
		return FALSE;

	bp->b_mode = MDVIEW;	/* mark the buffer as read only */
	cb = curbp;		/* save the old buffer */
	curbp = bp;		/* make this one current */
	/* and try to read in the file to execute */
	if ((status = readin(fname)) != TRUE) {
		curbp = cb;	/* restore the current buffer */
		return status;
	}

	/* go execute it! */
	curbp = cb;		/* restore the current buffer */
	if ((status = dobuf(bp)) != TRUE)
		return status;

	/* if not displayed, remove the now unneeded buffer and exit */
	if (bp->b_nwnd == 0)
		zotbuf(bp);
	return TRUE;
}
예제 #2
0
파일: exec.c 프로젝트: k0gaMSX/uemacs
/*
 * execproc:
 *	Execute a procedure
 *
 * int f, n;		default flag and numeric arg
 */
int execproc(int f, int n)
{
	struct buffer *bp;	/* ptr to buffer to execute */
	int status;	/* status return */
	char bufn[NBUFN + 2];	/* name of buffer to execute */

	/* find out what buffer the user wants to execute */
	if ((status =
	     mlreply("Execute procedure: ", &bufn[1], NBUFN)) != TRUE)
		return status;

	/* construct the buffer name */
	bufn[0] = '*';
	strcat(bufn, "*");

	/* find the pointer to that buffer */
	if ((bp = bfind(bufn, FALSE, 0)) == NULL) {
		mlwrite("No such procedure");
		return FALSE;
	}

	/* and now execute it as asked */
	while (n-- > 0)
		if ((status = dobuf(bp)) != TRUE)
			return status;
	return TRUE;
}
예제 #3
0
파일: exec.c 프로젝트: k0gaMSX/uemacs
/*
 * cbuf:
 *	Execute the contents of a numbered buffer
 *
 * int f, n;		default flag and numeric arg
 * int bufnum;		number of buffer to execute
 */
int cbuf(int f, int n, int bufnum)
{
	struct buffer *bp;	/* ptr to buffer to execute */
	int status;	/* status return */
	static char bufname[] = "*Macro xx*";

	/* make the buffer name */
	bufname[7] = '0' + (bufnum / 10);
	bufname[8] = '0' + (bufnum % 10);

	/* find the pointer to that buffer */
	if ((bp = bfind(bufname, FALSE, 0)) == NULL) {
		mlwrite("Macro not defined");
		return FALSE;
	}

	/* and now execute it as asked */
	while (n-- > 0)
		if ((status = dobuf(bp)) != TRUE)
			return status;
	return TRUE;
}
예제 #4
0
파일: exec.c 프로젝트: k0gaMSX/uemacs
/*
 * execbuf:
 *	Execute the contents of a buffer of commands
 *
 * int f, n;		default flag and numeric arg
 */
int execbuf(int f, int n)
{
	struct buffer *bp;	/* ptr to buffer to execute */
	int status;	/* status return */
	char *bufn;	/* name of buffer to execute */

        bufn = alloca(NSTRING * sizeof(char));
	/* find out what buffer the user wants to execute */
	if ((status = mlreply("Execute buffer: ", bufn, NBUFN)) != TRUE)
		return status;

	/* find the pointer to that buffer */
	if ((bp = bfind(bufn, FALSE, 0)) == NULL) {
		mlwrite("No such buffer");
		return FALSE;
	}

	/* and now execute it as asked */
	while (n-- > 0)
		if ((status = dobuf(bp)) != TRUE)
			return status;
	return TRUE;
}
예제 #5
0
/* For the "operator" commands -- the following command is a motion, or
 *  the operator itself is repeated.  All operate on regions.
 */
int
vile_op(int f, int n, OpsFunc fn, const char *str)
{
    int c = 0;
    int thiskey;
    int status;
    const CMDFUNC *cfp;		/* function to execute */
    const CMDFUNC *save_cmd_motion = cmd_motion;
    BUFFER *ourbp;
#if OPT_MOUSE
    WINDOW *wp0 = curwp;
#endif

    TRACE((T_CALLED "vile_op(%s)\n", str));

    doingopcmd = TRUE;

    pre_op_dot = DOT;
    ourbp = curbp;

    if (havemotion != NULL) {
	cfp = havemotion;
	havemotion = NULL;
    } else {
	TBUFF *tok = 0;

	mlwrite("%s operation pending...", str);
	(void) update(FALSE);

	/* get the next command from the keyboard */
	/* or a command line, as approp. */
	if (clexec) {
	    char *value = mac_unquotedarg(&tok);	/* get the next token */
	    if (value != 0 && strcmp(value, "lines"))
		cfp = engl2fnc(value);
	    else
		cfp = &f_godotplus;
	} else {
	    thiskey = lastkey;
	    c = kbd_seq();

#if OPT_MOUSE
	    if (curwp != wp0) {
		unkeystroke(c);
		doingopcmd = FALSE;
		returnCode(FALSE);
	    }
#endif
	    /* allow second chance for entering counts */
	    do_repeats(&c, &f, &n);

	    if (thiskey == lastkey)
		cfp = &f_godotplus;
	    else
		cfp = DefaultKeyBinding(c);

	}
	if (cfp != 0) {
	    mlerase();
	} else {
	    if (!clexec) {
		char temp[NSTRING];
		lsprintf(temp, "(%d)", c);
		tb_scopy(&tok, temp);
	    }
	    (void) no_such_function(tb_values(tok));
	}
	tb_free(&tok);
    }

    if (!cfp) {
	status = FALSE;
    } else if ((cfp->c_flags & MOTION) == 0) {
	kbd_alarm();
	status = ABORT;
    } else {
	/* motion is interpreted as affecting full lines */
	if (regionshape == rgn_EXACT) {
	    if (cfp->c_flags & FL)
		regionshape = rgn_FULLLINE;
	    if (cfp->c_flags & VL_RECT)
		regionshape = rgn_RECTANGLE;
	}

	/* and execute the motion */
	if ((status = execute(cfp, f, n)) == TRUE) {
	    post_op_dot = DOT;
	} else {
	    mlforce("[Motion failed]");
	    status = FALSE;
	}
    }

    if (status == TRUE) {
	opcmd = 0;

	MK = pre_op_dot;

	/* we've successfully set up a region */
	if (!fn) {		/* be defensive */
	    mlforce("BUG -- null func pointer in operator");
	    status = FALSE;
	} else if (fn == user_operator) {
	    swapmark();
	    cmd_motion = cfp;
	    status = dobuf(find_b_name(str), 1, f ? n : 1);
	} else {
	    status = (fn) ();
	}

	if (ourbp == curbp)	/* in case the func switched buffers on us */
	    swapmark();

	if (regionshape == rgn_FULLLINE)
	    (void) firstnonwhite(FALSE, 1);
    }

    regionshape = rgn_EXACT;
    doingopcmd = FALSE;
    haveregion = FALSE;
    cmd_motion = save_cmd_motion;

    returnCode(status);
}