Exemple #1
0
/* ARGSUSED */
int
filevisitalt(int f, int n)
{
	struct buffer	*bp;
	char	 fname[NFILEN], *bufp, *adjf;
	int	 status;

	if (getbufcwd(fname, sizeof(fname)) != TRUE)
		fname[0] = '\0';
	bufp = eread("Find alternate file: ", fname, NFILEN,
	    EFNEW | EFCR | EFFILE | EFDEF);
	if (bufp == NULL)
		return (ABORT);
	else if (bufp[0] == '\0')
		return (FALSE);

	status = killbuffer(curbp);
	if (status == ABORT || status == FALSE)
		return (ABORT);

	adjf = adjustname(fname, TRUE);
	if (adjf == NULL)
		return (FALSE);
	if ((bp = findbuffer(adjf)) == NULL)
		return (FALSE);
	curbp = bp;
	if (showbuffer(bp, curwp, WFFULL) != TRUE)
		return (FALSE);
	if (bp->b_fname[0] == '\0') {
		if ((status = readin(adjf)) != TRUE)
			killbuffer(bp);
		return (status);
	}
	return (TRUE);
}
Exemple #2
0
/* ARGSUSED */
int
poptofile(int f, int n)
{
	struct buffer	*bp;
	struct mgwin	*wp;
	char	 fname[NFILEN], *adjf, *bufp;
	int	 status;

	if (getbufcwd(fname, sizeof(fname)) != TRUE)
		fname[0] = '\0';
	if ((bufp = eread("Find file in other window: ", fname, NFILEN,
	    EFNEW | EFCR | EFFILE | EFDEF)) == NULL)
		return (ABORT);
	else if (bufp[0] == '\0')
		return (FALSE);
	adjf = adjustname(fname, TRUE);
	if (adjf == NULL)
		return (FALSE);
	if ((bp = findbuffer(adjf)) == NULL)
		return (FALSE);
	if (bp == curbp)
		return (splitwind(f, n));
	if ((wp = popbuf(bp)) == NULL)
		return (FALSE);
	curbp = bp;
	curwp = wp;
	if (bp->b_fname[0] == '\0') {
		if ((status = readin(adjf)) != TRUE)
			killbuffer(bp);
		return (status);
	}
	return (TRUE);
}
Exemple #3
0
/* ARGSUSED */
int
filewrite(int f, int n)
{
	struct stat     statbuf;
	int	 s;
	char	 fname[NFILEN], bn[NBUFN], tmp[NFILEN + 25];
	char	*adjfname, *bufp;
        FILE    *ffp;

	if (getbufcwd(fname, sizeof(fname)) != TRUE)
		fname[0] = '\0';
	if ((bufp = eread("Write file: ", fname, NFILEN,
	    EFDEF | EFNEW | EFCR | EFFILE)) == NULL)
		return (ABORT);
	else if (bufp[0] == '\0')
		return (FALSE);

	adjfname = adjustname(fname, TRUE);
	if (adjfname == NULL)
		return (FALSE);

        /* Check if file exists; write checks done later */
        if (stat(adjfname, &statbuf) == 0) {
		snprintf(tmp, sizeof(tmp), "File `%s' exists; overwrite",
		    adjfname);
		if ((s = eyorn(tmp)) != TRUE)
                        return (s);
        }

	/* old attributes are no longer current */
	bzero(&curbp->b_fi, sizeof(curbp->b_fi));
	if ((s = writeout(&ffp, curbp, adjfname)) == TRUE) {
		(void)strlcpy(curbp->b_fname, adjfname, sizeof(curbp->b_fname));
		if (getbufcwd(curbp->b_cwd, sizeof(curbp->b_cwd)) != TRUE)
			(void)strlcpy(curbp->b_cwd, "/", sizeof(curbp->b_cwd));
		if (augbname(bn, curbp->b_fname, sizeof(bn))
		    == FALSE)
			return (FALSE);
		free(curbp->b_bname);
		if ((curbp->b_bname = strdup(bn)) == NULL)
			return (FALSE);
		(void)fupdstat(curbp);
		curbp->b_flag &= ~(BFBAK | BFCHG);
		upmodes(curbp);
	}
	return (s);
}
Exemple #4
0
/* ARGSUSED */
int
filevisitalt(int f, int n)
{
	char	 fname[NFILEN], *bufp;

	if (getbufcwd(fname, sizeof(fname)) != TRUE)
		fname[0] = '\0';
	bufp = eread("Find alternate file: ", fname, NFILEN,
	    EFNEW | EFCR | EFFILE | EFDEF);
	if (bufp == NULL)
		return (ABORT);
	else if (bufp[0] == '\0')
		return (FALSE);

	return (do_filevisitalt(fname));
}
Exemple #5
0
Fichier : dir.c Projet : ibara/mg
int
ask_makedir(void)
{

	char		 bufc[NFILEN];
	char		*path;

	if (getbufcwd(bufc, sizeof(bufc)) != TRUE)
		return (ABORT);
	if ((path = eread("Make directory: ", bufc, NFILEN,
	    EFDEF | EFNEW | EFCR | EFFILE)) == NULL)
		return (ABORT);
	else if (path[0] == '\0')
		return (FALSE);

	return (do_makedir(path));
}
Exemple #6
0
/* ARGSUSED */
int
fileinsert(int f, int n)
{
	char	 fname[NFILEN], *bufp, *adjf;

	if (getbufcwd(fname, sizeof(fname)) != TRUE)
		fname[0] = '\0';
	bufp = eread("Insert file: ", fname, NFILEN,
	    EFNEW | EFCR | EFFILE | EFDEF);
	if (bufp == NULL)
		return (ABORT);
	else if (bufp[0] == '\0')
		return (FALSE);
	adjf = adjustname(bufp, TRUE);
	if (adjf == NULL)
		return (FALSE);
	return (insertfile(adjf, NULL, FALSE));
}
Exemple #7
0
/* ARGSUSED */
int
tagsvisit(int f, int n)
{
	char fname[NFILEN], *bufp, *temp;
	struct stat sb;
	
	if (getbufcwd(fname, sizeof(fname)) == FALSE)
		fname[0] = '\0';
	
	if (strlcat(fname, DEFAULTFN, sizeof(fname)) >= sizeof(fname)) {
		dobeep();
		ewprintf("Filename too long");
		return (FALSE);
	}
	
	bufp = eread("visit tags table (default %s): ", fname,
	    NFILEN, EFFILE | EFCR | EFNEW | EFDEF, DEFAULTFN);

	if (stat(bufp, &sb) == -1) {
		dobeep();
		ewprintf("stat: %s", strerror(errno));
		return (FALSE);
	} else if (S_ISREG(sb.st_mode) == 0) {
		dobeep();
		ewprintf("Not a regular file");
		return (FALSE);
	} else if (access(bufp, R_OK) == -1) {
		dobeep();
		ewprintf("Cannot access file %s", bufp);
		return (FALSE);
	}
	
	if (tagsfn == NULL) {
		if (bufp == NULL)
			return (ABORT);
		else if (bufp[0] == '\0') {
			if ((tagsfn = strdup(fname)) == NULL) {
				dobeep();
				ewprintf("Out of memory");
				return (FALSE);
			}
		} else {
			/* bufp points to local variable, so duplicate. */
			if ((tagsfn = strdup(bufp)) == NULL) {
				dobeep();
				ewprintf("Out of memory");
				return (FALSE);
			}
		}
	} else {
		if ((temp = strdup(bufp)) == NULL) {
			dobeep();
			ewprintf("Out of memory");
			return (FALSE);
		}
		free(tagsfn);
		tagsfn = temp;
		if (eyorn("Keep current list of tags table also") == FALSE) {
			ewprintf("Starting a new list of tags table");
			unloadtags();
		}
		loaded = FALSE;
	}
	return (TRUE);
}
Exemple #8
0
/* ARGSUSED */
static int
compile_goto_error(int f, int n)
{
	struct buffer	*bp;
	struct mgwin	*wp;
	char	*fname, *line, *lp, *ln;
	int	 lineno;
	char	*adjf, path[NFILEN];
	const char *errstr;
	struct line	*last;

	compile_win = curwp;
	compile_buffer = curbp;
	last = blastlp(compile_buffer);

 retry:
	/* last line is compilation result */
	if (curwp->w_dotp == last)
		return (FALSE);

	if ((line = linetostr(curwp->w_dotp)) == NULL)
		return (FALSE);
	lp = line;
	if ((fname = strsep(&lp, ":")) == NULL || *fname == '\0')
		goto fail;
	if ((ln = strsep(&lp, ":")) == NULL || *ln == '\0')
		goto fail;
	lineno = (int)strtonum(ln, INT_MIN, INT_MAX, &errstr);
	if (errstr)
		goto fail;

	if (fname && fname[0] != '/') {
		if (getbufcwd(path, sizeof(path)) == FALSE)
			goto fail;
		if (strlcat(path, fname, sizeof(path)) >= sizeof(path))
			goto fail;
		adjf = path;
	} else {
		adjf = adjustname(fname, TRUE);
	}
	free(line);

	if (adjf == NULL)
		return (FALSE);

	if ((bp = findbuffer(adjf)) == NULL)
		return (FALSE);
	if ((wp = popbuf(bp, WNONE)) == NULL)
		return (FALSE);
	curbp = bp;
	curwp = wp;
	if (bp->b_fname[0] == '\0')
		readin(adjf);
	gotoline(FFARG, lineno);
	return (TRUE);
fail:
	free(line);
	if (curwp->w_dotp != blastlp(curbp)) {
		curwp->w_dotp = lforw(curwp->w_dotp);
		curwp->w_rflag |= WFMOVE;
		goto retry;
	}
	dobeep();
	ewprintf("No more hits");
	return (FALSE);
}
Exemple #9
0
struct buffer *
compile_mode(const char *name, const char *command)
{
	struct buffer	*bp;
	FILE	*fpipe;
	char	*buf;
	size_t	 len;
	int	 ret, n;
	char	 cwd[NFILEN], qcmd[NFILEN];
	char	 timestr[NTIME];
	time_t	 t;

	n = snprintf(qcmd, sizeof(qcmd), "%s 2>&1", command);
	if (n < 0 || n >= sizeof(qcmd))
		return (NULL);

	bp = bfind(name, TRUE);
	if (bclear(bp) != TRUE)
		return (NULL);

	if (getbufcwd(bp->b_cwd, sizeof(bp->b_cwd)) != TRUE)
		return (NULL);
	addlinef(bp, "cd %s", bp->b_cwd);
	addline(bp, qcmd);
	addline(bp, "");

	if (getcwd(cwd, sizeof(cwd)) == NULL)
		panic("Can't get current directory!");
	if (chdir(bp->b_cwd) == -1) {
		dobeep();
		ewprintf("Can't change dir to %s", bp->b_cwd);
		return (NULL);
	}
	if ((fpipe = popen(qcmd, "r")) == NULL) {
		dobeep();
		ewprintf("Problem opening pipe");
		return (NULL);
	}
	/*
	 * We know that our commands are nice and the last line will end with
	 * a \n, so we don't need to try to deal with the last line problem
	 * in fgetln.
	 */
	while ((buf = fgetln(fpipe, &len)) != NULL) {
		buf[len - 1] = '\0';
		addline(bp, buf);
	}
	ret = pclose(fpipe);
	t = time(NULL);
	strftime(timestr, sizeof(timestr), "%a %b %e %T %Y", localtime(&t));
	addline(bp, "");
	if (ret != 0)
		addlinef(bp, "Command exited abnormally with code %d"
		    " at %s", ret, timestr);
	else
		addlinef(bp, "Command finished at %s", timestr);

	bp->b_dotp = bfirstlp(bp);
	bp->b_modes[0] = name_mode("fundamental");
	bp->b_modes[1] = name_mode("compile");
	bp->b_nmodes = 1;

	compile_buffer = bp;

	if (chdir(cwd) == -1) {
		dobeep();
		ewprintf("Can't change dir back to %s", cwd);
		return (NULL);
	}
	return (bp);
}