Exemple #1
0
/*
 * 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;
}
Exemple #2
0
void
popup_msgs(void)
{
    BUFFER *savebp = curbp;
    WINDOW *savewp = curwp;
    MARK savemk;
    register BUFFER *bp;
    WINDOW *wp;

    if ((bp = create_msgs()) == 0)
	return;

    savemk = DOT;
    if (!is_empty_buf(bp)) {
	if ((curwp == 0) || sgarbf || global_g_val(GMDPOPUP_MSGS) == -TRUE) {
	    return;		/* CAN'T popup yet */
	}
	if (popupbuff(bp) == FALSE) {
	    (void) zotbuf(bp);
	    return;
	}

	if ((wp = bp2any_wp(bp)) != NULL) {
	    make_local_w_val(wp, WMDNUMBER);
	    set_w_val(wp, WMDNUMBER, FALSE);
	}
	set_rdonly(bp, non_filename(), MDVIEW);
	curbp = savebp;
	curwp = savewp;
	if (savewp)
	    DOT = savemk;
    }
}
Exemple #3
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));
}
Exemple #4
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;
}
Exemple #5
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);
}
Exemple #6
0
/*
 * If no warning messages were encountered during startup, and the popup-msgs
 * mode wasn't enabled, discard the informational messages that are there
 * already.
 */
void
purge_msgs(void)
{
    TRACE(("purge_msgs mode:%d, warnings:%d\n",
	   global_g_val(GMDPOPUP_MSGS), warnings));

    if ((global_g_val(GMDPOPUP_MSGS) == -TRUE)
	&& (warnings == 0)) {
	BUFFER *bp = find_b_name(MESSAGES_BufName);
	if (valid_buffer(bp)
	    && bp->b_nwnd == 0) {
	    (void) zotbuf(bp);
	}
	set_global_g_val(GMDPOPUP_MSGS, FALSE);
    }
}
/*
 * Pipe a one line command into a window
 */
int
pipecmd(int f, int n)
{
	register int	s;	/* return status from CLI */
	register WINDOW *wp;	/* pointer to new window */
	register BUFFER *bp;	/* pointer to buffer to zot */
	static char oline[NLINE];	/* command line send to shell */
	char	line[NLINE];	/* command line send to shell */
	WINDOW *ocurwp;		/* save the current window during delete */

	static char filnam[NSTRING] = "command";

	/* get the command to pipe in */
	if ((s=mlreply("cmd: <", oline, NLINE)) != TRUE)
		return(s);

	(void)strcpy(line,oline);

	/* get rid of the command output buffer if it exists */
	if ((bp=find_b_name(OUTPUT_BufName)) != NULL) {
		/* try to make sure we are off screen */
		ocurwp = NULL;
		for_each_window(wp) {
			if (wp->w_bufp == bp) {
				if (curwp != wp) {
					ocurwp = curwp;
					curwp = wp;
				}
				delwind(FALSE, 1);
				if (ocurwp != NULL)
					curwp = ocurwp;
				break;
			}
		}
		if (zotbuf(bp) != TRUE)
			return(FALSE);
	}
Exemple #8
0
/*
 * Pipe a one line command into a window
 * Bound to ^X @
 * We use a unique temporary file name so that multiple instances of
 * MicroEMACS don't try to use the same file.
 */
pipecmd(f, n)
{
	register WINDOW *wp;	/* pointer to new window */
	register BUFFER *bp;	/* pointer to buffer to zot */
	register char *tmp;	/* ptr to TMP DOS environment variable */
	char line[NLINE];	/* command line send to shell */
	static char bname[] = "command";
	static char filnam[NSTRING];
	char *getenv();

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

	/* 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;
		}
		/* get rid of the existing command buffer */
		if (zotbuf(bp) != TRUE)
			return(FALSE);
	}

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

	/* Call mktemp() to get a unique filename in the tmp directory. */
	if ((tmp = getenv("TMP")) == NULL)
		filnam[0] = 0;
	else {
		strcpy(filnam, tmp);
		if (filnam[strlen(filnam) - 1] != '\\')
			strcat(filnam, "\\");
        }
	strcat(filnam,"eXXXXXX");
	mktemp(filnam);

	/* redirect the command output to the output file */
	strcat(line, " >>");
	strcat(line, filnam);
	movecursor(term.t_nrow - 1, 0);

	/* execute the command */
	TTkclose();
	system(line);
	TTkopen();
        sgarbf = TRUE;

	/* did the output file get generated? */
	if (access( filnam, 0) != 0)
		return(FALSE);
		
	/* 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);

	/* rename the buffer */
	strcpy( curwp->w_bufp->b_bname, "command");
	/* 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);
}
Exemple #9
0
int buffermenu(int f, int n)
{
  BUFFER *bp;
  BUFFER *org_bp = curbp;
  int c,k;
  int bufptr;
  int bufcount = 0;

  bufptr = 1;

 start:
  listbuffers(f,n);
  swbuffer(blistp);
  onlywind(0,0);
  bufcount = count_buffers();

  if (bufptr > bufcount)
	bufptr = bufcount;

  if (bufcount > 0)
	forwline(0, bufptr + 1);
  else
	forwline(0, 2);

  for (;;) {
	mlwrite("Buffer Menu: 1,2,s,v,k,q ");
	update();
	c = ttgetc();

	/* if no buffers, only allow exit */
	if (bufcount == 0) {
	  switch (c) {
	  case 'q': case 'Q': case 'x': case 'X':
		break;
	  default:
		(*term.t_beep) ();
		continue;
	  }
	}

	/*
	 * pre process escape sequence to get up/down arrows
	 * convert to CTRL+N, CTRL+P 
	 */
	if (c == ESC) {
	  k = getctl();
	  if (k == '[') {
		k = getctl();
		switch(k) {
		case 'A': c = CTRL_P; break;
		case 'B': c = CTRL_N; break;
		default: 
		  (*term.t_beep)();
		  continue;
		}
	  } else {
		k = getctl();
		(*term.t_beep) ();
		continue;
	  }
	}  /* if ESC */

	switch (c) {
	case 'n':
	case 'N':
	case CTRL_N:
	  if (bufcount == bufptr) {
		(*term.t_beep) ();
		break;
	  }
	  forwline(0,1);
	  bufptr++;
	  break;

	case 'p':
	case 'P':
	case CTRL_P:
	  if (bufptr == 1) {
		(*term.t_beep) ();
		break;
	  }
	  backline(0,1);
	  bufptr--;
	  break;

	case '1':
	  bp = get_buffer(bufptr);
	  swbuffer(bp);
	  onlywind(0,0);
	  mlerase();
	  return TRUE;

	case '2':
	  bp = get_buffer(bufptr);
	  swbuffer(bp);
	  onlywind(0,0);
	  /* need to check or is still valid */
	  if (valid_buf(org_bp) == TRUE && bufcount > 1)
		{
		  splitwind(0,0);
		  swbuffer(org_bp);
		  nextwind(0,0);
		}
	  mlerase();
	  return TRUE;

	  /* save file */
	case 's':
	case 'S':
	  bp = get_buffer(bufptr);
	  if (bp != NULL) {
		curbp = bp;
		(void)filesave(0,0);
		curbp = blistp;
		goto start;
	  }
	  break;

	  /* toggle read only */
	case 'v':
	case 'V':
	case '%':
	  bp = get_buffer(bufptr);
	  if (bp != NULL)  /* be defensive */
		bp->b_flag ^= BFRO;
	  goto start;
	  break;

	  /* kill buffer */
	case 'k':
	case 'K':
	  bp = get_buffer(bufptr);
	  if (bp != NULL)
		zotbuf(bp);
	  goto start;
	  break;

	  /* exit buffer menu */
	case 'q':
	case 'Q':
	case 'x':
	case 'X':
	  if (bufcount == 0) {
		bp = get_scratch();
		swbuffer(bp);
		onlywind(0,0);
		mlerase();
		return TRUE;
	  }

	  if (valid_buf(org_bp) == TRUE)
		swbuffer(org_bp);
	  else
		swbuffer(bheadp);
	  onlywind(0,0);
	  mlerase();
	  return TRUE;

	  /* any other key */
	default:
	  (*term.t_beep) ();
	  break;
	}
  }

  mlerase();
  return TRUE;
}
Exemple #10
0
int main(int argc, char **argv)
{
	int c = -1;	/* command character */
	int f;		/* default flag */
	int n;		/* numeric repeat count */
	int mflag;	/* negative flag on repeat */
	struct buffer *bp;	/* temp buffer pointer */
	int firstfile;	/* first file flag */
	int carg;	/* current arg to scan */
	int startflag;	/* startup executed flag */
	struct buffer *firstbp = NULL;	/* ptr to first buffer in cmd line */
	int basec;		/* c stripped of meta character */
	int viewflag;		/* are we starting in view mode? */
	int gotoflag;		/* do we need to goto a line at start? */
	int gline = 0;		/* if so, what line? */
	int searchflag;		/* Do we need to search at start? */
	int saveflag;		/* temp store for lastflag */
	int errflag;		/* C error processing? */
	char bname[NBUFN];	/* buffer name of file to read */
#if	CRYPT
	int cryptflag;		/* encrypting on the way in? */
	char ekey[NPAT];	/* startup encryption key */
#endif
	int newc;

#if	PKCODE & VMS
	(void) umask(-1); /* Use old protection (this is at wrong place). */
#endif

#if	PKCODE & BSD
	sleep(1); /* Time for window manager. */
#endif

#if	UNIX
#ifdef SIGWINCH
	signal(SIGWINCH, sizesignal);
#endif
#endif
	if (argc == 2) {
		if (strcmp(argv[1], "--help") == 0) {
			usage(EXIT_FAILURE);
		}
		if (strcmp(argv[1], "--version") == 0) {
			version();
			exit(EXIT_SUCCESS);
		}
	}

	/* Initialize the editor. */
	vtinit();		/* Display */
	edinit("main");		/* Buffers, windows */
	varinit();		/* user variables */

	viewflag = FALSE;	/* view mode defaults off in command line */
	gotoflag = FALSE;	/* set to off to begin with */
	searchflag = FALSE;	/* set to off to begin with */
	firstfile = TRUE;	/* no file to edit yet */
	startflag = FALSE;	/* startup file not executed yet */
	errflag = FALSE;	/* not doing C error parsing */
#if	CRYPT
	cryptflag = FALSE;	/* no encryption by default */
#endif

	/* Parse the command line */
	for (carg = 1; carg < argc; ++carg) {
		/* Process Switches */
#if	PKCODE
		if (argv[carg][0] == '+') {
			gotoflag = TRUE;
			gline = atoi(&argv[carg][1]);
		} else
#endif
		if (argv[carg][0] == '-') {
			switch (argv[carg][1]) {
				/* Process Startup macroes */
			case 'a':	/* process error file */
			case 'A':
				errflag = TRUE;
				break;
			case 'e':	/* -e for Edit file */
			case 'E':
				viewflag = FALSE;
				break;
			case 'g':	/* -g for initial goto */
			case 'G':
				gotoflag = TRUE;
				gline = atoi(&argv[carg][2]);
				break;
#if	CRYPT
			case 'k':	/* -k<key> for code key */
			case 'K':
				cryptflag = TRUE;
				strcpy(ekey, &argv[carg][2]);
				break;
#endif
#if	PKCODE
			case 'n':	/* -n accept null chars */
			case 'N':
				nullflag = TRUE;
				break;
#endif
			case 'r':	/* -r restrictive use */
			case 'R':
				restflag = TRUE;
				break;
			case 's':	/* -s for initial search string */
			case 'S':
				searchflag = TRUE;
				strncpy(pat, &argv[carg][2], NPAT);
				break;
			case 'v':	/* -v for View File */
			case 'V':
				viewflag = TRUE;
				break;
			default:	/* unknown switch */
				/* ignore this for now */
				break;
			}

		} else if (argv[carg][0] == '@') {

			/* Process Startup macroes */
			if (startup(&argv[carg][1]) == TRUE)
				/* don't execute emacs.rc */
				startflag = TRUE;

		} else {

			/* Process an input file */

			/* set up a buffer for this file */
			makename(bname, argv[carg]);
			unqname(bname);

			/* set this to inactive */
			bp = bfind(bname, TRUE, 0);
			strcpy(bp->b_fname, argv[carg]);
			bp->b_active = FALSE;
			if (firstfile) {
				firstbp = bp;
				firstfile = FALSE;
			}

			/* set the modes appropriatly */
			if (viewflag)
				bp->b_mode |= MDVIEW;
#if	CRYPT
			if (cryptflag) {
				bp->b_mode |= MDCRYPT;
				myencrypt((char *) NULL, 0);
				myencrypt(ekey, strlen(ekey));
				strncpy(bp->b_key, ekey, NPAT);
			}
#endif
		}
	}

#if	UNIX
	signal(SIGHUP, emergencyexit);
	signal(SIGTERM, emergencyexit);
#endif

	/* if we are C error parsing... run it! */
	if (errflag) {
		if (startup("error.cmd") == TRUE)
			startflag = TRUE;
	}

	/* if invoked with no other startup files,
	   run the system startup file here */
	if (startflag == FALSE) {
		startup("");
		startflag = TRUE;
	}
	discmd = TRUE;		/* P.K. */

	/* if there are any files to read, read the first one! */
	bp = bfind("main", FALSE, 0);
	if (firstfile == FALSE && (gflags & GFREAD)) {
		swbuffer(firstbp);
		zotbuf(bp);
	} else
		bp->b_mode |= gmode;

	/* Deal with startup gotos and searches */
	if (gotoflag && searchflag) {
		update(FALSE);
		mlwrite("(Can not search and goto at the same time!)");
	} else if (gotoflag) {
		if (gotoline(TRUE, gline) == FALSE) {
			update(FALSE);
			mlwrite("(Bogus goto argument)");
		}
	} else if (searchflag) {
		if (forwhunt(FALSE, 0) == FALSE)
			update(FALSE);
	}

	/* Setup to process commands. */
	lastflag = 0;  /* Fake last flags. */

      loop:
	/* Execute the "command" macro...normally null. */
	saveflag = lastflag;  /* Preserve lastflag through this. */
	execute(META | SPEC | 'C', FALSE, 1);
	lastflag = saveflag;

#if TYPEAH && PKCODE
	if (typahead()) {
		newc = getcmd();
		update(FALSE);
		do {
			fn_t execfunc;

			if (c == newc && (execfunc = getbind(c)) != NULL
			    && execfunc != insert_newline
			    && execfunc != insert_tab)
				newc = getcmd();
			else
				break;
		} while (typahead());
		c = newc;
	} else {
		update(FALSE);
		c = getcmd();
	}
#else
	/* Fix up the screen    */
	update(FALSE);

	/* get the next command from the keyboard */
	c = getcmd();
#endif
	/* if there is something on the command line, clear it */
	if (mpresf != FALSE) {
		mlerase();
		update(FALSE);
#if	CLRMSG
		if (c == ' ')	/* ITS EMACS does this  */
			goto loop;
#endif
	}
	f = FALSE;
	n = 1;

	/* do META-# processing if needed */

	basec = c & ~META;	/* strip meta char off if there */
	if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
		f = TRUE;	/* there is a # arg */
		n = 0;		/* start with a zero default */
		mflag = 1;	/* current minus flag */
		c = basec;	/* strip the META */
		while ((c >= '0' && c <= '9') || (c == '-')) {
			if (c == '-') {
				/* already hit a minus or digit? */
				if ((mflag == -1) || (n != 0))
					break;
				mflag = -1;
			} else {
				n = n * 10 + (c - '0');
			}
			if ((n == 0) && (mflag == -1))	/* lonely - */
				mlwrite("Arg:");
			else
				mlwrite("Arg: %d", n * mflag);

			c = getcmd();	/* get the next key */
		}
		n = n * mflag;	/* figure in the sign */
	}

	/* do ^U repeat argument processing */

	if (c == reptc) {	/* ^U, start argument   */
		f = TRUE;
		n = 4;		/* with argument of 4 */
		mflag = 0;	/* that can be discarded. */
		mlwrite("Arg: 4");
		while (((c = getcmd()) >= '0' && c <= '9') || c == reptc
		       || c == '-') {
			if (c == reptc)
				if ((n > 0) == ((n * 4) > 0))
					n = n * 4;
				else
					n = 1;
			/*
			 * If dash, and start of argument string, set arg.
			 * to -1.  Otherwise, insert it.
			 */
			else if (c == '-') {
				if (mflag)
					break;
				n = 0;
				mflag = -1;
			}
			/*
			 * If first digit entered, replace previous argument
			 * with digit and set sign.  Otherwise, append to arg.
			 */
			else {
				if (!mflag) {
					n = 0;
					mflag = 1;
				}
				n = 10 * n + c - '0';
			}
			mlwrite("Arg: %d",
				(mflag >= 0) ? n : (n ? -n : -1));
		}
		/*
		 * Make arguments preceded by a minus sign negative and change
		 * the special argument "^U -" to an effective "^U -1".
		 */
		if (mflag == -1) {
			if (n == 0)
				n++;
			n = -n;
		}
	}

	/* and execute the command */
	execute(c, f, n);
	goto loop;
}
Exemple #11
0
/*
 * 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);
}
Exemple #12
0
static BUFFER *
gettagsfile(int n, int *endofpathflagp, int *did_read)
{
#ifdef MDCHK_MODTIME
    time_t current;
#endif
    char *tagsfile;
    BUFFER *tagbp;
    char tagbufname[NBUFN];
    char tagfilename[NFILEN];

    *endofpathflagp = FALSE;
    *did_read = FALSE;

    (void) lsprintf(tagbufname, TAGFILE_BufName, n + 1);

    /* is the buffer around? */
    if ((tagbp = find_b_name(tagbufname)) == NULL) {
	char *tagf = global_b_val_ptr(VAL_TAGS);

	nth_name(tagfilename, tagf, n);
	if (!doglob(tagfilename)
	    || tagfilename[0] == EOS) {
	    *endofpathflagp = TRUE;
	    return NULL;
	}

	/* look up the tags file */
	tagsfile = cfg_locate(tagfilename, LOCATE_TAGS);

	/* if it isn't around, don't sweat it */
	if (tagsfile == NULL) {
	    return NULL;
	}

	/* find the pointer to that buffer */
	if ((tagbp = bfind(tagbufname, BFINVS)) == NULL) {
	    mlforce("[Can't create tags buffer]");
	    return NULL;
	}

	if (readin(tagsfile, FALSE, tagbp, FALSE) != TRUE) {
	    zotbuf(tagbp);
	    return NULL;
	}
	*did_read = TRUE;
    }
#ifdef MDCHK_MODTIME
    /*
     * Re-read the tags buffer if we are checking modification-times and
     * find that the tags file's been changed. We check the global mode
     * value because it's too awkward to set the local mode value for a
     * scratch buffer.
     */
    if (global_b_val(MDCHK_MODTIME)
	&& get_modtime(tagbp, &current)
	&& tagbp->b_modtime != current) {
	if (!*did_read
	    && readin(tagbp->b_fname, FALSE, tagbp, FALSE) != TRUE) {
	    zotbuf(tagbp);
	    return NULL;
	}
	set_modtime(tagbp, tagbp->b_fname);
	*did_read = TRUE;
    }
#endif
    b_set_invisible(tagbp);
    return tagbp;
}
Exemple #13
0
/*
 * 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;
}