示例#1
0
文件: unix.c 项目: axelmuhr/Helios-NG
/*
 * Run a one-liner in a subjob. When the command returns, wait for a single
 * character to be typed, then mark the screen as garbage so a full repaint is
 * done. Bound to "C-X !".
 */
spawn(f, n)
{
        register int    s;
        char            line[NLINE];

	/* don't allow this command if restricted */
	if (restflag)
		return(resterr());

        if ((s=mlreply("!", line, NLINE)) != TRUE)
                return(s);
        TTputc('\n');                /* Already have '\r'    */
        TTflush();
        TTclose();                              /* stty to old modes    */
        system(line);
        TTopen();
        TTflush();
	/* if we are interactive, pause here */
	if (clexec == FALSE) {
	        mlputs(TEXT6);
/*                     "\r\n\n[End]" */
        	tgetc();
        }
        sgarbf = TRUE;
        return(TRUE);
}
示例#2
0
文件: unix.c 项目: axelmuhr/Helios-NG
execprg(f, n)

{
        register int    s;
        char            line[NLINE];

	/* don't allow this command if restricted */
	if (restflag)
		return(resterr());

        if ((s=mlreply("!", line, NLINE)) != TRUE)
                return(s);
        TTputc('\n');                /* Already have '\r'    */
        TTflush();
        TTclose();                              /* stty to old modes    */
        system(line);
        TTopen();
        mlputs(TEXT188);                        /* Pause.               */
/*             "[End]" */
        TTflush();
        while ((s = tgetc()) != '\r' && s != ' ')
                ;
        sgarbf = TRUE;
        return(TRUE);
}
示例#3
0
文件: spawn.c 项目: ytoto/uemacs
int execprg(int f, int n)
{
#ifndef WINNT
	int s;
	char line[NLINE];
#endif
	/* don't allow this command if restricted */
	if (restflag)
		return resterr();
#if WINNT
	mlwrite("(unsupported)");
	return FALSE;
#endif

#if     VMS
	if ((s = mlreply("!", line, NLINE)) != TRUE)
		return s;
	TTflush();
	s = sys(line);		/* Run the command.     */
	mlputs("\r\n\n(End)");	/* Pause.               */
	TTflush();
	tgetc();
	sgarbf = TRUE;
	return s;
#endif

#if     MSDOS
	if ((s = mlreply("$", line, NLINE)) != TRUE)
		return s;
	movecursor(term.t_nrow, 0);
	TTkclose();
	execprog(line);
	TTkopen();
	/* if we are interactive, pause here */
	if (clexec == FALSE) {
		mlputs("\r\n(End)");
		tgetc();
	}
	sgarbf = TRUE;
	return TRUE;
#endif

#if     V7 | USG | BSD
	if ((s = mlreply("!", line, NLINE)) != TRUE)
		return s;
	TTputc('\n');		/* Already have '\r'    */
	TTflush();
	TTclose();		/* stty to old modes    */
	TTkclose();
	system(line);
	fflush(stdout);		/* to be sure P.K.      */
	TTopen();
	mlputs("(End)");	/* Pause.               */
	TTflush();
	while ((s = tgetc()) != '\r' && s != ' ');
	sgarbf = TRUE;
	return TRUE;
#endif
}
示例#4
0
/* ARGSUSED */
int
spawncli(int f, int n)
{
/* i never thought i'd see an ifdef like this one... strange bedfellows */
#if DISP_X11 || SYS_WIN31
	mlforce("[This version of vile cannot spawn an interactive shell]");
	return FALSE;
#else
#if	SYS_UNIX
	bottomleft();
	ttclean(TRUE);
	TTputc('\n');
	(void)system_SHELL((char *)0);
	TTflush();
	ttunclean();
	sgarbf = TRUE;
	return AfterShell();
#endif /* SYS_UNIX */


#if	SYS_VMS
	bottomleft();
	mlforce("[Starting DCL]\r\n");
	TTflush();				/* Ignore "ttcol".	*/
	sgarbf = TRUE;
	return sys(NULL);			/* NULL => DCL.		*/
#endif
#if	SYS_MSDOS || SYS_OS2 || SYS_WINNT
	bottomleft();
	TTflush();
	TTkclose();
	{ 
		char *shell;
		if ((shell = getenv("COMSPEC")) == NULL) {
#if SYS_OS2
			shell = "cmd.exe";
#else
			shell = "command.com";
#endif
			system(shell);          /* Will search path     */
		} else {
#if SYS_OS2
/*
 *	spawn it if we know it.  Some 3rd party command processors fail
 *	if they system themselves (eg 4OS2).  CCM 24-MAR-94
 */
			spawnl( P_WAIT, shell, shell, NULL);
#else
			system(shell);
#endif
		}
	}
	TTkopen();
	sgarbf = TRUE;
	return AfterShell();
#endif
#endif
}
示例#5
0
文件: unix.c 项目: axelmuhr/Helios-NG
/*
 * Create a subjob with a copy of the command intrepreter in it. When the
 * command interpreter exits, mark the screen as garbage so that you do a full
 * repaint. Bound to "^X C". The message at the start in VMS puts out a newline.
 * Under some (unknown) condition, you don't get one free when DCL starts up.
 */
spawncli(f, n)
{
        register char *cp;
        char    *getenv();

	/* don't allow this command if restricted */
	if (restflag)
		return(resterr());

        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
        TTflush();
        TTclose();                              /* stty to old settings */
        if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
                system(cp);
        else
#if	BSD | SUN
                system("exec /bin/csh");
#else
                system("exec /bin/sh");
#endif
        sgarbf = TRUE;
	sleep(2);
        TTopen();
        return(TRUE);
}
示例#6
0
void vttidy()
{
    mlerase();
    movecursor(term.t_nrow, 0);
    TTflush();
    TTclose();
    TTkclose();
}
示例#7
0
/*
 * Clean up the virtual terminal system, in anticipation for a return to the
 * operating system. Move down to the last line and clear it out (the next
 * system prompt will be written in the line). Shut down the channel to the
 * terminal.
 */
void vttidy(void)
{
	mlerase();
	movecursor(term.t_nrow, 0);
	TTflush();
	TTclose();
	TTkclose();
#ifdef PKCODE
	write(1, "\r", 1);
#endif
}
示例#8
0
// Clean up the virtual terminal system, in anticipation for a return to the operating system.  Move down to the last line and
// clear it out (the next system prompt will be written in the line).  Shut down the channel to the terminal.  Return status.
int vttidy(bool force) {

	// Don't close it if it ain't open.
	if(opflags & OPVTOPEN) {
		mlerase(MLFORCE);
		if((TTflush() == SUCCESS || force) && (TTclose() == SUCCESS || force))
			(void) TTkclose();
		opflags &= ~OPVTOPEN;
		}
	return rc.status;
	}
示例#9
0
文件: os2.c 项目: axelmuhr/Helios-NG
/*
 * Create a subjob with a copy of the command intrepreter in it. When the
 * command interpreter exits, mark the screen as garbage so that you do a full
 * repaint. Bound to "^X C". The message at the start in VMS puts out a newline.
 * Under some (unknown) condition, you don't get one free when DCL starts up.
 */
spawncli(f, n)
{
	/* don't allow this command if restricted */
	if (restflag)
		return(resterr());

        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
        TTflush();
	TTkclose();
	shell();
	TTkopen();
        sgarbf = TRUE;
        return(TRUE);
}
示例#10
0
static void
tcapkclose(void)
{
#if OPT_XTERM
	if (i_am_xterm && global_g_val(GMDXTERM_MOUSE))
		putpad(XTERM_DISABLE_TRACKING);
#endif
	if (keyboard_open) {
		keyboard_open = FALSE;
		if (TE)
			putnpad(TE, (int)strlen(TE));
		if (KE)
			putpad(KE);
	}
	TTflush();
}
示例#11
0
void
pressreturn(void)
{
	int c;
	int odiscmd;

	odiscmd = discmd;
	discmd = TRUE;
	mlprompt("[Press return to continue]");
	discmd = odiscmd;
	TTflush();
	/* loop for a CR, a space, or a : to do another named command */
	while ((c = keystroke()) != '\r' &&
			c != '\n' && 
			c != ' ' && 
			!ABORTED(c)) {
		if (kcod2fnc(c) == &f_namedcmd) {
			unkeystroke(c);
			break;
		}
	}
	TTputc('\r');
	TTputc('\n');
}
示例#12
0
/*
 * Make sure that the display is right. This is a three part process. First,
 * scan through all of the windows looking for dirty ones. Check the framing,
 * and refresh the screen. Second, make sure that "currow" and "curcol" are
 * correct for the current window. Third, make the virtual and physical
 * screens the same.
 *
 * int force;		force update past type ahead?
 */
int update(int force)
{
	struct window *wp;

#if	TYPEAH && ! PKCODE
	if (force == FALSE && typahead())
		return TRUE;
#endif
#if	VISMAC == 0
	if (force == FALSE && kbdmode == PLAY)
		return TRUE;
#endif

	displaying = TRUE;

#if SCROLLCODE

	/* first, propagate mode line changes to all instances of
	   a buffer displayed in more than one window */
	wp = wheadp;
	while (wp != NULL) {
		if (wp->w_flag & WFMODE) {
			if (wp->w_bufp->b_nwnd > 1) {
				/* make sure all previous windows have this */
				struct window *owp;
				owp = wheadp;
				while (owp != NULL) {
					if (owp->w_bufp == wp->w_bufp)
						owp->w_flag |= WFMODE;
					owp = owp->w_wndp;
				}
			}
		}
		wp = wp->w_wndp;
	}

#endif

	/* update any windows that need refreshing */
	wp = wheadp;
	while (wp != NULL) {
		if (wp->w_flag) {
			/* if the window has changed, service it */
			reframe(wp);	/* check the framing */
#if SCROLLCODE
			if (wp->w_flag & (WFKILLS | WFINS)) {
				scrflags |=
				    (wp->w_flag & (WFINS | WFKILLS));
				wp->w_flag &= ~(WFKILLS | WFINS);
			}
#endif
			if ((wp->w_flag & ~WFMODE) == WFEDIT)
				updone(wp);	/* update EDITed line */
			else if (wp->w_flag & ~WFMOVE)
				updall(wp);	/* update all lines */
#if SCROLLCODE
			if (scrflags || (wp->w_flag & WFMODE))
#else
			if (wp->w_flag & WFMODE)
#endif
				modeline(wp);	/* update modeline */
			wp->w_flag = 0;
			wp->w_force = 0;
		}
		/* on to the next window */
		wp = wp->w_wndp;
	}

	/* recalc the current hardware cursor location */
	updpos();

#if	MEMMAP && ! SCROLLCODE
	/* update the cursor and flush the buffers */
	movecursor(currow, curcol - lbound);
#endif

	/* check for lines to de-extend */
	upddex();

	/* if screen is garbage, re-plot it */
	if (sgarbf != FALSE)
		updgar();

	/* update the virtual screen to the physical screen */
	updupd(force);

	/* update the cursor and flush the buffers */
	movecursor(currow, curcol - lbound);
	TTflush();
	displaying = FALSE;
#if SIGWINCH
	while (chg_width || chg_height)
		newscreensize(chg_height, chg_width);
#endif
	return TRUE;
}
示例#13
0
文件: spawn.c 项目: ytoto/uemacs
/*
 * filter a buffer through an external DOS program
 * Bound to ^X #
 */
int filter_buffer(int f, int n)
{
	int s;		/* return status from CLI */
	struct buffer *bp;	/* pointer to buffer to zot */
	char line[NLINE];	/* command line send to shell */
	char tmpnam[NFILEN];	/* place to store real file name */
	static char bname1[] = "fltinp";

	static char filnam1[] = "fltinp";
	static char filnam2[] = "fltout";

	/* don't allow this command if restricted */
	if (restflag)
		return resterr();

	if (curbp->b_mode & MDVIEW)	/* don't allow this command if      */
		return rdonly();	/* we are in read only mode     */

#if     VMS
	mlwrite("Not available under VMS");
	return FALSE;
#endif

	/* get the filter name and its args */
	if ((s = mlreply("#", line, NLINE)) != TRUE)
		return s;

	/* setup the proper file names */
	bp = curbp;
	xstrcpy(tmpnam, bp->b_fname);	/* save the original name */
	xstrcpy(bp->b_fname, bname1);	/* set it to our new one */

	/* write it out, checking for errors */
	if (writeout(filnam1) != TRUE) {
		mlwrite("(Cannot write filter file)");
		xstrcpy(bp->b_fname, tmpnam);
		return FALSE;
	}
#if     MSDOS
	strcat(line, " <fltinp >fltout");
	movecursor(term.t_nrow - 1, 0);
	TTkclose();
	shellprog(line);
	TTkopen();
	sgarbf = TRUE;
	s = TRUE;
#endif

#if     V7 | USG | BSD
	TTputc('\n');		/* Already have '\r'    */
	TTflush();
	TTclose();		/* stty to old modes    */
	TTkclose();
	strcat(line, " <fltinp >fltout");
	system(line);
	TTopen();
	TTkopen();
	TTflush();
	sgarbf = TRUE;
	s = TRUE;
#endif

	/* on failure, escape gracefully */
	if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) {
		mlwrite("(Execution failed)");
		xstrcpy(bp->b_fname, tmpnam);
		unlink(filnam1);
		unlink(filnam2);
		return s;
	}

	/* reset file name */
	xstrcpy(bp->b_fname, tmpnam);	/* restore name */
	bp->b_flag |= BFCHG;	/* flag it as changed */

	/* and get rid of the temporary file */
	unlink(filnam1);
	unlink(filnam2);
	return TRUE;
}
示例#14
0
/* the #ifdefs have been totally separated, for readability */
static int
spawn1(int rerun, int pressret)
{
#if DISP_IBMPC
	int	closed;
#endif
#if COMMON_SH_PROMPT
	register int	s;
	char	line[NLINE];	/* command line send to shell */

	if ((s = ShellPrompt(&save_shell[0], line, rerun)) != TRUE)
		return s;
#endif	/* COMMON_SH_PROMPT */

	/* take care of autowrite */
	if (writeall(FALSE,1,FALSE,TRUE,TRUE) != TRUE)
		return FALSE;

#if SYS_UNIX
#if DISP_X11
	(void)system_SHELL(line);
#else
	ttclean(TRUE);
	(void)system_SHELL(line);
	TTflush();
	ttunclean();
	if (pressret)
		pressreturn();
	TTopen();
	TTkopen();
	TTflush();
	sgarbf = TRUE;
#endif /* DISP_X11 */
	return AfterShell();
#endif /* SYS_UNIX */

#if	SYS_VMS
	TTputc('\n');			/* Already have '\r'	*/
	TTflush();
	s = sys(line);			/* Run the command.	*/
	mlforce("\r\n\n[End]");		/* Pause.		*/
	TTflush();
	(void)keystroke();
	sgarbf = TRUE;
	return (s);
#endif
#if	SYS_WIN31
	mlforce("[Not in Windows 3.1]");
	return FALSE;
#endif
#if	SYS_MSDOS || SYS_OS2 || SYS_WINNT
	bottomleft();
	TTputc('\n');
	TTflush();
	TTkclose();
#if	DISP_IBMPC
	/* If we don't reset to 80x25, parts of the shell-output will go
	 * astray.
	 */
	closed = term.t_ncol != 80 || term.t_nrow != 25;
	if (closed)
		TTclose();
#endif
	system(line);
	TTkopen();
	/* if we are interactive, pause here */
	if (pressret) {
		pressreturn();
	}
#if	DISP_IBMPC
	/* Reopen the display _after_ the prompt, to keep the shell-output
	 * in the same type of screen as the prompt.
	 */
	if (closed)
		TTopen();
#endif
	sgarbf = TRUE;
	return AfterShell();
#endif
}
示例#15
0
文件: unix.c 项目: axelmuhr/Helios-NG
/*
 * Pipe a one line command into a window
 * Bound to ^X @
 */
pipecmd(f, n)
{
        register int    s;	/* return status from CLI */
	register WINDOW *wp;	/* pointer to new window */
	register BUFFER *bp;	/* pointer to buffer to zot */
        char	line[NLINE];	/* command line send to shell */
	static char bname[] = "command";

	static char filnam[NFILEN] = "command";

	/* don't allow this command if restricted */
	if (restflag)
		return(resterr());

	/* get the command to pipe in */
        if ((s=mlreply("@", line, NLINE)) != TRUE)
                return(s);

	/* get rid of the command output buffer if it exists */
        if ((bp=bfind(bname, FALSE, 0)) != FALSE) {
		/* try to make sure we are off screen */
		wp = wheadp;
		while (wp != NULL) {
			if (wp->w_bufp == bp) {
				onlywind(FALSE, 1);
				break;
			}
			wp = wp->w_wndp;
		}
		if (zotbuf(bp) != TRUE)

			return(FALSE);
	}

        TTputc('\n');                /* Already have '\r'    */
        TTflush();
        TTclose();                              /* stty to old modes    */
	strcat(line,">");
	strcat(line,filnam);
        system(line);
        TTopen();
        TTflush();
        sgarbf = TRUE;
        s = TRUE;

	if (s != TRUE)
		return(s);

	/* split the current window to make room for the command output */
	if (splitwind(FALSE, 1) == FALSE)
			return(FALSE);

	/* and read the stuff in */
	if (getfile(filnam, FALSE) == FALSE)
		return(FALSE);

	/* make this window in VIEW mode, update all mode lines */
	curwp->w_bufp->b_mode |= MDVIEW;
	wp = wheadp;
	while (wp != NULL) {
		wp->w_flag |= WFMODE;
		wp = wp->w_wndp;
	}

	/* and get rid of the temporary file */
	unlink(filnam);
	return(TRUE);
}
示例#16
0
文件: spawn.c 项目: ytoto/uemacs
/*
 * Create a subjob with a copy of the command intrepreter in it. When the
 * command interpreter exits, mark the screen as garbage so that you do a full
 * repaint. Bound to "^X C". The message at the start in VMS puts out a newline.
 * Under some (unknown) condition, you don't get one free when DCL starts up.
 */
int spawncli(int f, int n)
{
#if     V7 | USG | BSD
	char *cp;
#endif

	/* don't allow this command if restricted */
	if (restflag)
		return resterr();
#if WINNT
	mlwrite("(unsupported)");
	return FALSE;
#endif

#if     VMS
	movecursor(term.t_nrow, 0);	/* In last line.        */
	mlputs("(Starting DCL)\r\n");
	TTflush();		/* Ignore "ttcol".      */
	sgarbf = TRUE;
	sys(NULL);
	sleep(1);
	mlputs("\r\n(Returning from DCL)\r\n");
	TTflush();
	sleep(1);
	return TRUE;
#endif
#if     MSDOS & (MSC | TURBO)
	movecursor(term.t_nrow, 0);	/* Seek to last line.   */
	TTflush();
	TTkclose();
	shellprog("");
	TTkopen();
	sgarbf = TRUE;
	return TRUE;
#endif
#if     V7 | USG | BSD
	movecursor(term.t_nrow, 0);	/* Seek to last line.   */
	TTflush();
	TTclose();		/* stty to old settings */
	TTkclose();		/* Close "keyboard" */
	if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
		system(cp);
	else
#if	BSD
		system("exec /bin/csh");
#else
		system("exec /bin/sh");
#endif
	sgarbf = TRUE;
	sleep(2);
	TTopen();
	TTkopen();
#ifdef SIGWINCH
/*
 * This fools the update routines to force a full
 * redraw with complete window size checking.
 *		-lbt
 */
	chg_width = term.t_ncol;
	chg_height = term.t_nrow + 1;
	term.t_nrow = term.t_ncol = 0;
#endif
	return TRUE;
#endif
}
示例#17
0
// Restore cursor position.  Return status.
int restorecursor(void) {

	if(movecursor(oldrow,oldcol - lbound) == SUCCESS)
		(void) TTflush();
	return rc.status;
	}
示例#18
0
// Display a pop-up window and page it for the user.  If altmodeline is true, display buffer name and filename (only) on bottom
// mode line.  If endprompt is true, wait for user to press a key before returning (regardless of page size).  Current bindings
// (if any) for backPage, forwPage, backLine, and forwLine commands are recognized as well as 'b' (backward page), 'f' or space
// (forward page), 'u' (backward half page), 'd' (forward half page), 'g' (goto first page), 'G' (goto last page), ESC or 'q'
// (exit), and '?' (help).  Any non-navigation key gets pushed back into the input stream to be interpeted later as a command. 
// Return status.
int bpop(Buffer *bufp,bool altmodeline,bool endprompt) {
	Line *lnp1,*lnp,*lpmax;
	int crow;		// Current screen row number.
	int disprows;		// Total number of display rows.
	int halfpage;		// Rows in a half page.
	int n;			// Rows to move.
	ushort ek;		// Input extended key.
	char *strp,*strpz;	// Line text pointers.
	char *hprompt = NULL;	// Help prompt;
	bool firstpass = true;

	// Display special mode line if requested.
	if(altmodeline) {

		// Find last window on screen and rewrite its mode line.
		wupd_modeline(wnextis(NULL),bufp);
		}

	// Set up and display a pop-up "window".
	disprows = term.t_nrow - 2;

	// Check if buffer will fit on one page and if not, set lpmax to first line of last page.
	lpmax = NULL;
	n = 0;
	for(lnp = lforw(bufp->b_hdrlnp); lnp != bufp->b_hdrlnp; lnp = lforw(lnp)) {
		if(++n > disprows) {

			// Find beginning of last page.
			lpmax = bufp->b_hdrlnp;
			n = disprows;
			do {
				lpmax = lback(lpmax);
				} while(--n > 0);
			break;
			}
		}

	// Begin at the beginning.
	lnp1 = lforw(bufp->b_hdrlnp);
	halfpage = disprows / 2;
	n = 0;

	// Display a page (beginning at line lnp1 + n) and prompt for a naviagtion command.  Loop until exit key entered or
	// endprompt is false and buffer fits on one page (lpmax is NULL).
	for(;;) {
		lnp = lnp1;

		// Moving backward?
		if(n < 0) {
			do {
				// At beginning of buffer?
				if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp))
					break;

				// No, back up one line.
				lnp1 = lback(lnp1);
				} while(++n < 0);
			}

		// Moving forward?
		else if(n > 0) {
			do {
				// At end of buffer or max line?
				if(lpmax == NULL || lnp1 == bufp->b_hdrlnp || lnp1 == lpmax)
					break;

				// No, move forward one line.
				lnp1 = lforw(lnp1);
				} while(--n > 0);
			}

		// Illegal command?
		if(n != 0 && lnp1 == lnp)

			// Yes, ignore it.
			n = 0;
		else {
			// Found first row ... display page.
			lnp = lnp1;
			crow = 0;
			do {
				// At end of buffer?
				if(lnp == bufp->b_hdrlnp) {

					// Yes, erase remaining lines on physical screen.
					while(crow < disprows) {
						vtmove(crow,0);
						vteeol();
#if COLOR
						vscreen[crow]->v_rfcolor = gfcolor;
						vscreen[crow]->v_rbcolor = gbcolor;
#endif
						vscreen[crow]->v_left = FARRIGHT;
						vscreen[crow]->v_right = 0;
#if COLOR
						vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR;
#else
						vscreen[crow++]->v_flags |= VFCHGD;
#endif
						}
					break;
					}

				// Update the virtual screen image for this line.  Characters past right edge of screen won't be
				// displayed, so ignore those.
				vtmove(crow,0);
				strpz = (strp = ltext(lnp)) + (lused(lnp) <= (int) term.t_ncol ? lused(lnp) : term.t_ncol);
				while(strp < strpz)
					vtputc(*strp++);
				vteeol();
#if COLOR
				vscreen[crow]->v_rfcolor = gfcolor;
				vscreen[crow]->v_rbcolor = gbcolor;
#endif
				vscreen[crow]->v_left = FARRIGHT;
				vscreen[crow]->v_right = 0;
#if COLOR
				vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR;
#else
				vscreen[crow++]->v_flags |= VFCHGD;
#endif
				// On to the next line.
				lnp = lforw(lnp);
				} while(crow < disprows);

			// Screen is full.  Copy the virtual screen to the physical screen.
			if(pupd_all(false) != SUCCESS)
				return rc.status;

			// Bail out if called from terminp() and one-page buffer.
			if(firstpass && !endprompt && lpmax == NULL)
				goto uexit;
			firstpass = false;
			}

		// Display prompt.
		mlputs(MLHOME | MLFORCE,hprompt != NULL ? hprompt : lpmax == NULL || lnp1 == lpmax ? text201 : ": ");
													// "End: "
		if(TTflush() != SUCCESS)
			return rc.status;

		// Get response.
		for(;;) {
			// Get a keystroke and decode it.
			if(getkey(&ek) != SUCCESS)
				return rc.status;

			// Exit?
			if(ek == (CTRL | '[') || ek == 'q')
				goto uexit;

			// Forward whole page?
			if(ek == ' ' || ek == 'f' || iscmd(ek,forwPage)) {
				n = disprows - overlap;
				break;
				}

			// Forward half page?
			if(ek == 'd') {
				n = halfpage;
				break;
				}

			// Backward whole page?
			if(ek == 'b' || iscmd(ek,backPage)) {
				n = overlap - disprows;
				break;
				}

			// Backward half page?
			if(ek == 'u') {
				n = -halfpage;
				break;
				}

			// Forward a line?
			if(iscmd(ek,forwLine)) {
				n = 1;
				break;
				}

			// Backward a line?
			if(iscmd(ek,backLine)) {
				n = -1;
				break;
				}

			// First page?
			if(ek == 'g') {
				if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp))
					n = -1;			// Force beep.
				else {
					lnp1 = lforw(bufp->b_hdrlnp);
					n = 0;
					}
				break;
				}

			// Last page?
			if(ek == 'G') {
				if(lpmax == NULL || lnp1 == lpmax)
					n = 1;			// Force beep.
				else {
					lnp1 = lpmax;
					n = 0;
					}
				break;
				}

			// Help?
			if(ek == '?') {
				StrList msg;

				// Get string list...
				if(vopen(&msg,NULL,false) != 0)
					return vrcset();

				// build prompt...
				if(vputs(text202,&msg) != 0)
						// "(<SPC>,f"
					return vrcset();
				if(hkey(&msg,forwPage,0) != SUCCESS)
					return rc.status;
				if(vputs(text203,&msg) != 0)
						// ") +page (b"
					return vrcset();
				if(hkey(&msg,backPage,0) != SUCCESS)
					return rc.status;
				if(vputs(text204,&msg) != 0)
						// ") -page (d) +half (u) -half"
					return vrcset();
				if(hkey(&msg,forwLine,'+') != SUCCESS || hkey(&msg,backLine,'-') != SUCCESS)
					return rc.status;
				if(vputs(text206,&msg) != 0)
						// " (g) first (G) last (ESC,q) quit (?) help: "
					return vrcset();

				// and display it.
				if(vclose(&msg) != 0)
					return vrcset();
				mlputs(MLHOME | MLFORCE,msg.sl_vp->v_strp);
				}
			else {
				// Other key.  "Unget" the key for reprocessing and return.
				tungetc(ek);
				goto uexit;
				}
			}
		}
uexit:
	uphard();
	if(endprompt)
		mlerase(MLFORCE);

	return rc.status;
	}
示例#19
0
static int
xterm_button(int c)
{
	WINDOW	*wp;
	int	event;
	int	button;
	int	x;
	int	y;
	int	status;
#if OPT_XTERM >= 3
	int	save_row = ttrow;
	int	save_col = ttcol;
	int	firstrow, lastrow;
	int	startx, endx, mousex;
	int	starty, endy, mousey;
	MARK	save_dot;
	char	temp[NSTRING];
	static	const	char	*fmt = "\033[%d;%d;%d;%d;%dT";
#endif	/* OPT_XTERM >= 3 */

	if (insertmode)
		return ABORT;

	if ((status = (global_g_val(GMDXTERM_MOUSE))) != 0) {
		beginDisplay;
		switch(c) {
		case 'M':	/* button-event */
			event	= keystroke();
			x	= XtermPos() + x_origin;
			y	= XtermPos() + y_origin;

			button	= (event & 3) + 1;
			TRACE(("M-button event:%d x:%d y:%d\n", event, x, y))
			if (button > 3) {
				endofDisplay;
				return TRUE; /* button up */
			}
			wp = row2window(y-1);
#if OPT_XTERM >= 3
			/* Tell the xterm how to highlight the selection.
			 * It won't do anything else until we do this.
			 */
			if (wp != 0) {
				firstrow = wp->w_toprow + 1;
				lastrow  = mode_row(wp) + 1;
			} else {		/* from message-line */
				firstrow = term.t_nrow ;
				lastrow  = term.t_nrow + 1;
			}
			if (y >= lastrow)	/* don't select modeline */
				y = lastrow - 1;
			(void)lsprintf(temp, fmt, 1, x, y, firstrow, lastrow);
			putpad(temp);
			TTflush();
#endif	/* OPT_XTERM >= 3 */
			/* Set the dot-location if button 1 was pressed in a
			 * window.
			 */
			if (wp != 0
			 && button == 1
			 && !reading_msg_line
			 && setcursor(y-1, x-1)) {
				/*mlerase();*/
				(void)update(TRUE);
				status = TRUE;
			} else if (button <= 3) {
#if OPT_XTERM >= 3
				/* abort the selection */
				(void)lsprintf(temp, fmt, 0, x, y, firstrow, lastrow);
				putpad(temp);
				TTflush();
#endif	/* OPT_XTERM >= 3 */
				status = ABORT;
			} else {
				status = FALSE;
			}
			break;
#if OPT_XTERM >= 3
		case 't':	/* reports valid text-location */
			x = XtermPos();
			y = XtermPos();

			TRACE(("t: x:%d y:%d\n", x, y))
			setwmark(y-1, x-1);
			yankregion();

			movecursor(save_row, save_col);
			/*mlerase();*/
			(void)update(TRUE);
			break;
		case 'T':	/* reports invalid text-location */
			/*
			 * The starting-location returned is not the location
			 * at which the mouse was pressed.  Instead, it is the
			 * top-most location of the selection.  In turn, the
			 * ending-location is the bottom-most location of the
			 * selection.  The mouse-up location is not necessarily
			 * a pointer to valid text.
			 *
			 * This case handles multi-clicking events as well as
			 * selections whose start or end location was not
			 * pointing to text.
			 */
			save_dot = DOT;
			startx = XtermPos();	/* starting-location */
			starty = XtermPos();
			endx   = XtermPos();	/* ending-location */
			endy   = XtermPos();
			mousex = XtermPos();	/* location at mouse-up */
			mousey = XtermPos();

			TRACE(("T: start(%d,%d) end(%d,%d) mouse(%d,%d)\n",
				starty, startx,
				endy,   endx,
				mousey, mousex))
			setcursor(starty - 1, startx - 1);
			setwmark (endy   - 1, endx   - 1);
			if (MK.o != 0 && !is_at_end_of_line(MK))
				MK.o += 1;
			yankregion();

			DOT = save_dot;
			movecursor(save_row, save_col);
			/*mlerase();*/
			(void)update(TRUE);
			break;
#endif /* OPT_XTERM >= 3 */
		default:
			status = FALSE;
		}
		endofDisplay;
	}
示例#20
0
文件: spawn.c 项目: ytoto/uemacs
/*
 * Pipe a one line command into a window
 * Bound to ^X @
 */
int pipecmd(int f, int n)
{
	int s;		/* return status from CLI */
	struct window *wp;	/* pointer to new window */
	struct buffer *bp;	/* pointer to buffer to zot */
	char line[NLINE];	/* command line send to shell */
	static char bname[] = "command";

	static char filnam[NSTRING] = "command";

#if     MSDOS
	char *tmp;
	FILE *fp;
	int len;
#endif

	/* don't allow this command if restricted */
	if (restflag)
		return resterr();

#if	MSDOS
	if ((tmp = getenv("TMP")) == NULL
	    && (tmp = getenv("TEMP")) == NULL)
		xstrcpy(filnam, "command");
	else {
		xstrcpy(filnam, tmp);
		len = strlen(tmp);
		if (len <= 0 || filnam[len - 1] != '\\'
		    && filnam[len - 1] != '/')
			strcat(filnam, "\\");
		strcat(filnam, "command");
	}
#endif

#if     VMS
	mlwrite("Not available under VMS");
	return FALSE;
#endif

	/* get the command to pipe in */
	if ((s = mlreply("@", line, NLINE)) != TRUE)
		return s;

	/* get rid of the command output buffer if it exists */
	if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
		/* try to make sure we are off screen */
		wp = wheadp;
		while (wp != NULL) {
			if (wp->w_bufp == bp) {
#if	PKCODE
				if (wp == curwp)
					delwind(FALSE, 1);
				else
					onlywind(FALSE, 1);
				break;
#else
				onlywind(FALSE, 1);
				break;
#endif
			}
			wp = wp->w_wndp;
		}
		if (zotbuf(bp) != TRUE)

			return FALSE;
	}
#if     MSDOS
	strcat(line, " >>");
	strcat(line, filnam);
	movecursor(term.t_nrow, 0);
	TTkclose();
	shellprog(line);
	TTkopen();
	sgarbf = TRUE;
	if ((fp = fopen(filnam, "r")) == NULL) {
		s = FALSE;
	} else {
		fclose(fp);
		s = TRUE;
	}
#endif

#if     V7 | USG | BSD
	TTflush();
	TTclose();		/* stty to old modes    */
	TTkclose();
	strcat(line, ">");
	strcat(line, filnam);
	system(line);
	TTopen();
	TTkopen();
	TTflush();
	sgarbf = TRUE;
	s = TRUE;
#endif

	if (s != TRUE)
		return s;

	/* split the current window to make room for the command output */
	if (splitwind(FALSE, 1) == FALSE)
		return FALSE;

	/* and read the stuff in */
	if (getfile(filnam, FALSE) == FALSE)
		return FALSE;

	/* make this window in VIEW mode, update all mode lines */
	curwp->w_bufp->b_mode |= MDVIEW;
	wp = wheadp;
	while (wp != NULL) {
		wp->w_flag |= WFMODE;
		wp = wp->w_wndp;
	}

	/* and get rid of the temporary file */
	unlink(filnam);
	return TRUE;
}
示例#21
0
// Make sure that the display is right.  This is a four-part process.  First, resize the windows in the current screen to match
// the current terminal dimensions if needed.  Second, scan through all of the screen windows looking for dirty (flagged) ones.
// Check the framing and refresh the lines.  Third, make sure that "currow" and "curcol" are correct for the current window.
// And fourth, make the virtual and physical screens the same.  Return status.
int update(bool force) {
	EWindow *winp;
	int count;

#if TYPEAH || !VISMAC
	// If we are not forcing the update...
	if(!force) {
#if TYPEAH
		// If there are keystrokes waiting to be processed, skip the update.
		if(typahead(&count) != SUCCESS || count > 0)
			return rc.status;
#endif
#if !VISMAC
		// If we are replaying a keyboard macro, don't bother keeping updated.
		if(kmacro.km_state == KMPLAY)
			return rc.status;
#endif
		}
#endif
	// Current screen dimensions wrong?
	if(cursp->s_flags) {		// ESRESIZE set?
		EWindow *lastwp,*nextwp;
		int nrow;

		// Loop until vertical size of all windows matches terminal rows.
		do {
			// Does current screen need to grow vertically?
			if(term.t_nrow > cursp->s_nrow) {

				// Yes, go to the last window...
				winp = wnextis(NULL);

				// and enlarge it as needed.
				winp->w_nrows = (cursp->s_nrow = term.t_nrow) - winp->w_toprow - 2;
				winp->w_flags |= WFHARD | WFMODE;
				}

			// Does current screen need to shrink vertically?
			else if(term.t_nrow < cursp->s_nrow) {

				// Rebuild the window structure.
				nextwp = cursp->s_wheadp;
				lastwp = NULL;
				nrow = 0;
				do {
					winp = nextwp;
					nextwp = winp->w_nextp;

					// Get rid of window if it is too low.
					if(winp->w_toprow >= term.t_nrow - 2) {

						// Save the "face" parameters.
						--winp->w_bufp->b_nwind;
						wftobf(winp,winp->w_bufp);

						// Update curwp and lastwp if needed.
						if(winp == curwp)
							wswitch(wheadp);
						if(lastwp != NULL)
							lastwp->w_nextp = NULL;

						// Free the structure.
						free((void *) winp);
						winp = NULL;
						}
					else {
						// Need to change this window size?
						if(winp->w_toprow + winp->w_nrows - 1 >= term.t_nrow - 2) {
							winp->w_nrows = term.t_nrow - winp->w_toprow - 2;
							winp->w_flags |= WFHARD | WFMODE;
							}
						nrow += winp->w_nrows + 1;
						}

					lastwp = winp;
					} while(nextwp != NULL);
				cursp->s_nrow = nrow;
				}
			} while(cursp->s_nrow != term.t_nrow);

		// Update screen controls and mark screen for a redraw.
		cursp->s_ncol = term.t_ncol;
		cursp->s_flags = 0;
		opflags |= OPSCREDRAW;
		}

	// Check all windows and update any that need refreshing.
	winp = wheadp;
	do {
		if(winp->w_flags) {

			// The window has changed in some way: service it.
			if(wupd_reframe(winp) != SUCCESS)		// Check the framing.
				return rc.status;
			if((winp->w_flags & ~WFMODE) == WFEDIT)
				vupd_dotline(winp);			// Update EDITed line only.
			else if(winp->w_flags & ~WFMOVE)
				vupd_all(winp);				// Update all lines.
			if(winp->w_flags & WFMODE)
				wupd_modeline(winp,NULL);		// Update modeline.
			winp->w_flags = winp->w_force = 0;
			}

		// On to the next window.
		} while((winp = winp->w_nextp) != NULL);

	// Recalc the current hardware cursor location.
	wupd_cursor();

	// Check for lines to de-extend.
	supd_dex();

	// If screen is garbage, redraw it.
	if(opflags & OPSCREDRAW) {
		if(modetab[MDR_GLOBAL].flags & MDNOUPD)
			opflags &= ~OPSCREDRAW;
		else if(supd_redraw() != SUCCESS)
			return rc.status;
		}

	// Update the virtual screen to the physical screen.
	if(pupd_all(force) != SUCCESS)
		return rc.status;

	// Update the cursor position and flush the buffers.
	if(movecursor(currow,curcol - lbound) != SUCCESS || TTflush() != SUCCESS)
		return rc.status;

#if MMDEBUG & DEBUG_SCRDUMP
	dumpscreens("Exiting update()");
#endif
	return rc.status;
	}