Пример #1
0
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
}
Пример #2
0
/*
 * 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);
}
Пример #3
0
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);
}
Пример #4
0
PASCAL NEAR gotoline(	/* move to a particular line.
			   argument (n) must be a positive integer for
			   this to actually do anything		*/

  int f,
  int n )	/* prefix flag and argument */

{
	register int status;	/* status return */
	char arg[NSTRING];	/* buffer to hold argument */

	/* get an argument if one doesnt exist */
	if (f == FALSE) {
		if ((status = mlreply(TEXT7, arg, NSTRING)) != TRUE) {
/*                                    "Line to GOTO: " */
			mlwrite(TEXT8);
/*                              "[Aborted]" */
			return(status);
		}
		n = asc_int(arg);
	}

	if (n < 1)		/* if a bogus argument...then leave */
		return(FALSE);

	/* first, we go to the start of the buffer */
        curwp->w_dotp  = lforw(curbp->b_linep);
        curwp->w_doto  = 0;
	return(forwline(f,n-1,TRUE));
}
Пример #5
0
/*
 * storeproc:
 *	Set up a procedure buffer and flag to store all
 *	executed command lines there
 *
 * int f;		default flag
 * int n;		macro number to use
 */
int storeproc(int f, int n)
{
	struct buffer *bp;	/* pointer to macro buffer */
	int status;	/* return status */
	char bname[NBUFN];	/* name of buffer to use */

	/* a numeric argument means its a numbered macro */
	if (f == TRUE)
		return storemac(f, n);

	/* get the name of the procedure */
	if ((status =
	     mlreply("Procedure name: ", &bname[1], NBUFN - 2)) != TRUE)
		return status;

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

	/* set up the new macro buffer */
	if ((bp = bfind(bname, TRUE, BFINVS)) == NULL) {
		mlwrite("Can not create macro");
		return FALSE;
	}

	/* and make sure it is empty */
	bclear(bp);

	/* and set the macro store pointers to it */
	mstore = TRUE;
	bstore = bp;
	return TRUE;
}
Пример #6
0
/*
 * 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;
}
Пример #7
0
/*
 * execute a series of commands in a file
 *
 * int f, n;		default flag and numeric arg to pass on to file
 */
int execfile(int f, int n)
{
	int status;	/* return status of name query */
	char *fname;	/* name of file to execute */
	char *fspec;		/* full file spec */

        fname = alloca(NSTRING * sizeof(char));
	if ((status =
	     mlreply("File to execute: ", fname, NSTRING - 1)) != TRUE)
		return status;

#if	1
	/* look up the path for the file */
	fspec = flook(fname, FALSE);	/* used to by TRUE, P.K. */

	/* if it isn't around */
	if (fspec == NULL)
		return FALSE;

#endif
	/* otherwise, execute it */
	while (n-- > 0)
		if ((status = dofile(fspec)) != TRUE)
			return status;

	return TRUE;
}
Пример #8
0
/*
 * Rename the current buffer
 *
 * int f, n;		default Flag & Numeric arg
 */
int namebuffer(int f, int n)
{
	struct buffer *bp;	/* pointer to scan through all buffers */
	char bufn[NBUFN];	/* buffer to hold buffer name */

	/* prompt for and get the new buffer name */
      ask:if (mlreply("Change buffer name to: ", bufn, NBUFN) !=
	    TRUE)
		return FALSE;

	/* and check for duplicates */
	bp = bheadp;
	while (bp != NULL) {
		if (bp != curbp) {
			/* if the names the same */
			if (strcmp(bufn, bp->b_bname) == 0)
				goto ask;	/* try again */
		}
		bp = bp->b_bufp;	/* onward */
	}

	strcpy(curbp->b_bname, bufn);	/* copy buffer name to structure */
	curwp->w_flag |= WFMODE;	/* make mode line replot */
	mlerase();
	return TRUE;
}
Пример #9
0
int getfile(char fname[])
{
  BUFFER *bp;
  LINE *lp;
  char bname[NBUFN];		/* buffer name to put file */
  int i, s;

  for (bp = bheadp; bp != (BUFFER*)0; bp = bp->b_bufp)
    {
      if ((bp->b_flag & BFTEMP) == 0 && strcmp(bp->b_fname, fname) == 0)
	{
	  if (--curbp->b_nwnd == 0)
	    {
	      curbp->b_dotp = curwp->w_dotp;
	      curbp->b_doto = curwp->w_doto;
	      curbp->b_markp = curwp->w_markp;
	      curbp->b_marko = curwp->w_marko;
	    }
	  swbuffer(bp);
	  lp = curwp->w_dotp;
	  i = curwp->w_ntrows / 2;
	  while (i-- && lback(lp) != curbp->b_linep)
	    lp = lback(lp);
	  curwp->w_linep = lp;
	  curwp->w_flag |= WFMODE | WFHARD;
	  mlwrite("[Old buffer]");
	  return (TRUE);
	}
    }
  makename(bname, fname);	/* New buffer name */
  while ((bp = bfind(bname, FALSE, 0)) != (BUFFER*)0)
    {
      s = mlreply("Buffer name: ", bname, NBUFN);
      if (s == ABORT)		/* ^G to just quit */
	return (s);
      if (s == FALSE)
	{			/* CR to clobber it */
	  makename(bname, fname);
	  break;
	}
    }
  if (bp == (BUFFER*)0 && (bp = bfind(bname, TRUE, 0)) == (BUFFER*)0)
    {
      mlwrite("Cannot create buffer");
      return (FALSE);
    }
  if (--curbp->b_nwnd == 0)
    {				/* Undisplay */
      curbp->b_dotp = curwp->w_dotp;
      curbp->b_doto = curwp->w_doto;
      curbp->b_markp = curwp->w_markp;
      curbp->b_marko = curwp->w_marko;
    }
  curbp = bp;			/* Switch to it */
  curwp->w_bufp = bp;
  curbp->b_nwnd++;
  return (readin(fname));	/* Read it in */
}
Пример #10
0
/*
 * Select a file for editing.
 * Look around to see if you can find the
 * file in another buffer; if you can find it
 * just switch to the buffer. If you cannot find
 * the file, create a new buffer, read in the
 * text, and switch to the new buffer.
 * Bound to GOLD E.
 */
filevisit(f, n)
{
        char            fname[NFILEN];

	fname[0] = 0;
        return	mlreply("Visit file: ", fname, NFILEN) &&
		window_split(f,n) &&
		file_readin(fname);
}
Пример #11
0
Файл: file.c Проект: aksr/esnc
/*
 * Select a file for editing. Look around to see if you can find the fine in
 * another buffer; if you can find it just switch to the buffer. If you cannot
 * find the file, create a new buffer, read in the text, and switch to the new
 * buffer. Bound to C-X C-F.
 */
int filefind (int f, int n)
{
  char fname[NFILEN];		/* file user wishes to find */
  int s;			/* status return */

  if ((s = mlreply ("Find file: ", fname, NFILEN)) != TRUE)
    return (s);
  return (getfile (fname));
}
Пример #12
0
/*
 * Insert a file into the current buffer. This is really easy; all you do it
 * find the name of the file, and call the standard "insert a file into the
 * current buffer" code. Bound to "C-X C-I".
 */
int insfile(int f, int n)
{
  int s;
  char fname[NFILEN];

  if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE)
    return (s);
  return (ifile(fname));
}
Пример #13
0
/*
 * Read a file into the current buffer. This is really easy; all you do it
 * find the name of the file, and call the standard "read a file into the
 * current buffer" code. Bound to "C-X C-R"
 */
int fileread(int f, int n)
{
  int s;
  char fname[NFILEN];

  if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE)
    return (s);
  return (readin(fname));
}
Пример #14
0
/*
 * Read a file into the current
 * buffer. This is really easy; all you do it
 * find the name of the file, and call the standard
 * "read a file into the current buffer" code.
 * Bound to "C-X C-R".
 */
fileread(f, n)
{
        register int    s;
        char            fname[NFILEN];

	fname[0] = 0;
        if ((s=mlreply("Read file: ", fname, NFILEN)) != TRUE)
                return (s);
        return (readin(fname));
}
Пример #15
0
/*
 * getfile()
 *
 * char fname[];	file name to find
 * int lockfl;		check the file for locks?
 */
int getfile(char *fname, int lockfl)
{
	struct buffer *bp;
	struct line *lp;
	int i;
	int s;
	char bname[NBUFN];	/* buffer name to put file */

#if	MSDOS
	mklower(fname);		/* msdos isn't case sensitive */
#endif
	for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
		if ((bp->b_flag & BFINVS) == 0
		    && strcmp(bp->b_fname, fname) == 0) {
			swbuffer(bp);
			lp = curwp->w_dotp;
			i = curwp->w_ntrows / 2;
			while (i-- && lback(lp) != curbp->b_linep)
				lp = lback(lp);
			curwp->w_linep = lp;
			curwp->w_flag |= WFMODE | WFHARD;
			cknewwindow();
			mlwrite("(Old buffer)");
			return TRUE;
		}
	}
	makename(bname, fname);	/* New buffer name.     */
	while ((bp = bfind(bname, FALSE, 0)) != NULL) {
		/* old buffer name conflict code */
		s = mlreply("Buffer name: ", bname, NBUFN);
		if (s == ABORT)	/* ^G to just quit      */
			return s;
		if (s == FALSE) {	/* CR to clobber it     */
			makename(bname, fname);
			break;
		}
	}
	if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
		mlwrite("Cannot create buffer");
		return FALSE;
	}
	if (--curbp->b_nwnd == 0) {	/* Undisplay.           */
		curbp->b_dotp = curwp->w_dotp;
		curbp->b_doto = curwp->w_doto;
		curbp->b_markp = curwp->w_markp;
		curbp->b_marko = curwp->w_marko;
	}
	curbp = bp;		/* Switch to it.        */
	curwp->w_bufp = bp;
	curbp->b_nwnd++;
	s = readin(fname, lockfl);	/* Read it in.          */
	cknewwindow();
	return s;
}
Пример #16
0
/*
 * Read a file into the current
 * buffer. This is really easy; all you do it
 * find the name of the file, and call the standard
 * "read a file into the current buffer" code.
 * Bound to "C-X C-R".
 */
fileread(f, n)
{
        register int    s;
        char fname[NFILEN];

	if (restflag)		/* don't allow this command if restricted */
		return(resterr());
        if ((s=mlreply("Read file: ", fname, NFILEN)) != TRUE)
                return(s);
        return(readin(fname, TRUE));
}
Пример #17
0
/*
 * Select a file for editing.
 * Look around to see if you can find the
 * fine in another buffer; if you can find it
 * just switch to the buffer. If you cannot find
 * the file, create a new buffer, read in the
 * text, and switch to the new buffer.
 * Bound to C-X C-F.
 */
int filefind(int f, int n)
{
	char fname[NFILEN];	/* file user wishes to find */
	int s;		/* status return */

	if (restflag)		/* don't allow this command if restricted */
		return resterr();
	if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE)
		return s;
	return getfile(fname, TRUE);
}
Пример #18
0
/*
 * Read a file into the current
 * buffer. This is really easy; all you do it
 * find the name of the file, and call the standard
 * "read a file into the current buffer" code.
 * Bound to "C-X C-R".
 */
int fileread(int f, int n)
{
	int s;
	char fname[NFILEN];

	if (restflag)		/* don't allow this command if restricted */
		return resterr();
	if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE)
		return s;
	return readin(fname, TRUE);
}
Пример #19
0
/*
 * Attach a buffer to a window. The
 * values of dot and mark come from the buffer
 * if the use count is 0. Otherwise, they come
 * from some other window.
 */
int usebuffer(int f, int n)
{
	struct buffer *bp;
	int s;
	char bufn[NBUFN];

	if ((s = mlreply("Use buffer: ", bufn, NBUFN)) != TRUE)
		return s;
	if ((bp = bfind(bufn, TRUE, 0)) == NULL)
		return FALSE;
	return swbuffer(bp);
}
Пример #20
0
/* ARGSUSED0 */
int killbuffer (int f, int n)
{
  BUFFER *bp;
  char bufn[NBUFN];
  int s;

  if ((s = mlreply ("Kill buffer: ", bufn, NBUFN)) != TRUE)
    return (s);
  if ((bp = bfind (bufn, FALSE, 0)) == NULL) /* Easy if unknown */
    return (TRUE);
  return (zotbuf (bp));
}
Пример #21
0
/* ARGSUSED0 */
int usebuffer (int f, int n)
{
  BUFFER *bp;
  char bufn[NBUFN];
  int s;

  if ((s = mlreply ("Use buffer: ", bufn, NBUFN)) != TRUE)
    return (s);
  if ((bp = bfind (bufn, TRUE, 0)) == NULL)
    return (FALSE);
  return (swbuffer (bp));
}
Пример #22
0
/*
 * Insert a file into the current
 * buffer. This is really easy; all you do it
 * find the name of the file, and call the standard
 * "insert a file into the current buffer" code.
 * Bound to "C-X C-I".
 */
insfile(f, n)
{
        register int    s;
        char fname[NFILEN];

	if (restflag)		/* don't allow this command if restricted */
		return(resterr());
	if (curbp->b_mode&MDVIEW)	/* don't allow this command if	*/
		return(rdonly());	/* we are in read only mode	*/
        if ((s=mlreply("Insert file: ", fname, NFILEN)) != TRUE)
                return(s);
        return(ifile(fname));
}
Пример #23
0
/*
 * execcmd:
 *	Execute a command line command to be typed in
 *	by the user
 *
 * int f, n;		default Flag and Numeric argument
 */
int execcmd(int f, int n)
{
	int status;	/* status return */
	char *cmdstr;	/* string holding command to execute */

        cmdstr = alloca(NSTRING * sizeof(char));
	/* get the line wanted */
	if ((status = mlreply(": ", cmdstr, NSTRING)) != TRUE)
		return status;

	execlevel = 0;
	return docmd(cmdstr);
}
Пример #24
0
/* ARGSUSED0 */
int killbuffer (int f, int n)
{
  BUFFER *bp;
  BUFFER *bp_alt;
  char bufn[NBUFN];
  char prompt[NFILEN];
  int s;

  sprintf(prompt, "Kill Buffer: (default %s) ", curbp->b_bname);
  s = mlreply (prompt, bufn, NBUFN);

  if (s == ABORT)
	return ABORT;
  else if (s == FALSE) {
	bp = curbp;
  } else {
	/* return if cant find named buffer */
	if ((bp = bfind (bufn, FALSE, 0)) == NULL)
	  return FALSE;
  }

  /* beep if attempt to kill buffer list */
  if (bp == blistp) {
	(*term.t_beep) ();
	mlerase();
	return FALSE;
  }

  /* find a buffer to switch to, not this one and not an internal buffer */
  bp_alt = bheadp;
  while (bp_alt != NULL)
	{
	  if (bp_alt != bp && (bp_alt->b_flag & BFTEMP) != BFTEMP)
		break;
	  bp_alt = bp_alt->b_bufp;
	}

  /* no alternate buffer, try for scratch or create it */
  if (bp_alt == NULL) {
	bp_alt = get_scratch();
  }

  if (bp_alt == NULL) {
	  return (FALSE);
  }

  swbuffer(bp_alt);
  s = zotbuf(bp);
  mlerase();
  return s;
}
Пример #25
0
/*
 * Dispose of a buffer, by name.
 * Ask for the name. Look it up (don't get too
 * upset if it isn't there at all!). Get quite upset
 * if the buffer is being displayed. Clear the buffer (ask
 * if the buffer has been changed). Then free the header
 * line and the buffer header. Bound to "C-X K".
 */
int killbuffer(int f, int n)
{
	struct buffer *bp;
	int s;
	char bufn[NBUFN];

	if ((s = mlreply("Kill buffer: ", bufn, NBUFN)) != TRUE)
		return s;
	if ((bp = bfind(bufn, FALSE, 0)) == NULL)	/* Easy if unknown.     */
		return TRUE;
	if (bp->b_flag & BFINVS)	/* Deal with special buffers        */
		return TRUE;	/* by doing nothing.    */
	return zotbuf(bp);
}
Пример #26
0
/*
 * Insert a file into the current
 * buffer. This is really easy; all you do it
 * find the name of the file, and call the standard
 * "insert a file into the current buffer" code.
 * Bound to "C-X C-I".
 */
int insfile(int f, int n)
{
	int s;
	char fname[NFILEN];

	if (restflag)		/* don't allow this command if restricted */
		return resterr();
	if (curbp->b_mode & MDVIEW)	/* don't allow this command if      */
		return rdonly();	/* we are in read only mode     */
	if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE)
		return s;
	if ((s = ifile(fname)) != TRUE)
		return s;
	return reposition(TRUE, -1);
}
Пример #27
0
int Dinsertfile(f,n)
{
	int s,nline,nbytes;
	WINDOW *wp;
	char fname[NFILEN],*line;

	fname[0] = 0;
	if (mlreply("Insert file: ",fname,NFILEN) == FALSE)
		return FALSE;

	s = ffropen(fname);		/* open file for reading	*/
	switch (s)
	{
	    case FIOFNF:
		mlwrite("File not found");
	    case FIOERR:
		return FALSE;
	}
	mlwrite("[Reading file]");
	nline = 0;
	while ((s = ffgetline(&line,&nbytes)) == FIOSUC)
	{	register char *p;

		for (p = line; nbytes; p++,nbytes--)
		{
			if (line_insert(1,*p) == FALSE)
				return FALSE;
		}
		if (random_newline(FALSE,1) == FALSE)
			return FALSE;
		++nline;
	}
	ffclose();
        if (s == FIOEOF) {                      /* Don't zap message!   */
                if (nline == 1)
                        mlwrite("[Read 1 line]");
                else
                        mlwrite("[Read %d lines]", nline);
        }
        for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) {
                if (wp->w_bufp == curbp) {
                        wp->w_flag |= WFMODE|WFHARD;
                }
        }
	return s != FIOERR;
}
Пример #28
0
/*
 * Get the string to use as an encryption string.
 */
static int
get_encryption_key(char *key,	/* where to write key */
		   size_t len)
{
    int status;			/* return status */
    int save_vl_echo = vl_echo;
    char temp[NKEYLEN];

    /* turn command input echo off */
    vl_echo = FALSE;

    temp[0] = EOS;
    status = mlreply("-Encryption String: ", temp, (UINT) (len - 1));
    vl_echo = save_vl_echo;

    if (status == TRUE)
	vl_make_encrypt_key(key, temp);

    mlerase();
    return (status);
}
Пример #29
0
/*
 * The command allows the user to modify the file name associated with the
 * current buffer. It is like the "f" command in UNIX "ed". The operation is
 * simple; just zap the name in the BUFFER structure, and mark the windows as
 * needing an update. You can type a blank line at the prompt if you wish.
 */
int filename(int f, int n)
{
  WINDOW *wp;
  char fname[NFILEN];
  int s;

  if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT)
    return (s);
  if (s == FALSE)
    strncpy(curbp->b_fname, "", 1);
  else
    strncpy(curbp->b_fname, fname, NFILEN);
  wp = wheadp;			/* update mode lines */
  while (wp != NULL)
    {
      if (wp->w_bufp == curbp)
	wp->w_flag |= WFMODE;
      wp = wp->w_wndp;
    }
  return (TRUE);
}
Пример #30
0
/*
 * Ask for a file name, and write the contents of the current buffer to that
 * file. Update the remembered file name and clear the buffer changed flag.
 * This handling of file names is different from the earlier versions, and is
 * more compatable with Gosling EMACS than with ITS EMACS. Bound to "C-X C-W".
 */
int filewrite(int f, int n)
{
  WINDOW *wp;
  char fname[NFILEN];
  int s;

  if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE)
    return (s);
  if ((s = writeout(fname)) == TRUE)
    {
      strncpy(curbp->b_fname, fname, NFILEN);
      curbp->b_flag &= ~BFCHG;
      wp = wheadp;		/* Update mode lines */
      while (wp != NULL)
	{
	  if (wp->w_bufp == curbp)
	    wp->w_flag |= WFMODE;
	  wp = wp->w_wndp;
	}
    }
  return (s);
}