⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proc.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE * * is provided to you without charge, and with no warranty.  You may give  * * away copies of JOVE, including sources, provided that this notice is    * * included in all the files.                                              * ***************************************************************************/#include "jove.h"#include "ctype.h"#include "fp.h"#include "re.h"#include "termcap.h"#include "disp.h"#include "rec.h"#include <signal.h>#ifdef	STDARGS# include <stdarg.h>#else# include <varargs.h>#endif#ifdef	MSDOS# include <io.h># include <process.h># include <sys/stat.h>#endifprivate void	DoShell proto((char *, char *)),	com_finish proto((int, char *));long	SigMask = 0;/* This disgusting RE search string parses output from the GREP   family, from the pdp11 compiler, pcc, and lint.  Jay (HACK)   Fenlasen changed this to work for the lint errors. */char	ErrFmtStr[256] = "^\\{\",\\}\\([^:\"( \t]*\\)\\{\"\\, line ,:,(\\} *\\([0-9][0-9]*\\)[:)]\\\|::  *\\([^(]*\\)(\\([0-9]*\\))$\\\|( \\([^(]*\\)(\\([0-9]*\\)) ),";struct error {	Buffer		*er_buf;	/* Buffer error is in */	Line		*er_mess,	/* Actual error message */			*er_text;	/* Actual error */	int		er_char;	/* char pos of error */	struct error	*er_prev,	/* List of errors */			*er_next;};private struct error	*cur_error = NULL,		*errorlist = NULL;Buffer		*perr_buf = NULL;	/* Buffer with error messages */bool	WtOnMk = ON;		/* Write the modified files when we make *//* Eliminate any error records that contain dangling references to Lines. * We only eliminate error structs when either referent is recycled. * If it deleted, we keep it (dormant) in case it will be pasted back * into the same buffer. */voidChkErrorLines(){	register struct error	*e;	struct error	*prev = NULL;	for (e = errorlist; e != NULL; ) {		struct error	*next = e->er_next;		if (e->er_mess->l_dline == NULL_DADDR		|| e->er_text->l_dline == NULL_DADDR)		{			/* dangling reference: delete */			if (prev == NULL)				errorlist = next;			else				prev->er_next = next;			if (next != NULL)				next->er_prev = prev;			if (cur_error == e)				cur_error = next;			free((UnivPtr)e);		} else {			prev = e;		}		e = next;	}}/* Add an error to the end of the list of errors.  This is used for   parse-{C,LINT}-errors and for the spell-buffer command */private struct error *AddError(laste, errline, buf, line, charpos)struct error	*laste;Line	*errline,	*line;Buffer	*buf;int	charpos;{	struct error	*new = (struct error *) emalloc(sizeof *new);	new->er_prev = laste;	if (laste)		laste->er_next = new;	else {		if (errorlist)		/* Free up old errors */			ErrFree();		cur_error = errorlist = new;	}	laste = new;	new->er_next = NULL;	new->er_buf = buf;	new->er_text = line;	new->er_char = charpos;	new->er_mess = errline;	return new;}voidget_FL_info(fname, lineno)char	*fname,	*lineno;{	putmatch(1, fname, (size_t)FILESIZE);	putmatch(2, lineno, (size_t)FILESIZE);	/* error had lineno followed fname, so switch the two */	if (!jisdigit(lineno[0])) {		char	tmp[FILESIZE];		strcpy(tmp, lineno);		strcpy(lineno, fname);		strcpy(fname, tmp);	}}/* Free up all the errors */voidErrFree(){	register struct error	*ep;	for (ep = errorlist; ep != NULL; ep = ep->er_next)		free((UnivPtr) ep);	errorlist = cur_error = NULL;}/* Parse errors of the form specified in ErrFmtStr in the current   buffer.  Do a show error of the first error.  This is neat because this   will work for any kind of output that prints a file name and a line   number on the same line. */voidErrParse(){	struct RE_block	re_blk;	Bufpos	*bp;	char	fname[FILESIZE],		lineno[FILESIZE];	int	lnum,		last_lnum = -1;	struct error	*ep = NULL;	Buffer	*buf,		*lastb = NULL;	Line	*err_line;	ErrFree();		/* This is important! */	ToFirst();	perr_buf = curbuf;	REcompile(ErrFmtStr, YES, &re_blk);	/* Find a line with a number on it. */	while ((bp = docompiled(FORWARD, &re_blk)) != NULL) {		SetDot(bp);		get_FL_info(fname, lineno);		buf = do_find((Window *)NULL, fname, YES);		if (buf != lastb) {			lastb = buf;			last_lnum = -1;		/* signals new file */			err_line = buf->b_first;		}		(void) chr_to_int(lineno, 10, NO, &lnum);		if (lnum == last_lnum)	/* one error per line is nicer */			continue;		if (last_lnum == -1)			last_lnum = 1;	/* that's where we really are */		err_line = next_line(err_line, lnum - last_lnum);		ep = AddError(ep, curline, buf, err_line, 0);		last_lnum = lnum;	}	if (cur_error != NULL)		ShowErr();}private voidNeedErrors(){	if (cur_error == NULL)		complain("No errors!");}private boolErrorHasReferents(){	return inlist(cur_error->er_buf->b_first, cur_error->er_text)		&& inlist(perr_buf->b_first, cur_error->er_mess);}/* Go the the next error, if there is one.  Put the error buffer in   one window and the buffer with the error in another window.   It checks to make sure that the error actually exists. */private voidToError(forward)bool	forward;{	register struct error	*e = cur_error;	int	num = arg_value();	NeedErrors();	if ((forward? e->er_next : e->er_prev) == NULL)		complain("You're at the %s error.", forward ? "last" : "first");	while (--num >= 0 || !ErrorHasReferents()) {		e = forward ? e->er_next : e->er_prev;		if (e == NULL)			break;		cur_error = e;	}	ShowErr();}voidNextError(){	ToError(TRUE);}voidPrevError(){	ToError(FALSE);}int	EWSize = 20;	/* percentage of screen the error window			   should be */private voidset_wsize(wsize)int	wsize;{	wsize = (LI * wsize) / 100;	if (wsize >= 1 && !one_windp())		WindSize(curwind, wsize - (curwind->w_height - 1));}/* Show the current error, i.e. put the line containing the error message   in one window, and the buffer containing the actual error in another   window. */voidShowErr(){	Window	*err_wind,		*buf_wind;	NeedErrors();	if (!ErrorHasReferents()) {		rbell();		return;	}	err_wind = windbp(perr_buf);	buf_wind = windbp(cur_error->er_buf);	if (err_wind && !buf_wind) {		SetWind(err_wind);		pop_wind(cur_error->er_buf->b_name, NO, -1);		buf_wind = curwind;	} else if (!err_wind && buf_wind) {		SetWind(buf_wind);		pop_wind(perr_buf->b_name, NO, -1);		err_wind = curwind;	} else if (!err_wind && !buf_wind) {		pop_wind(perr_buf->b_name, NO, -1);		err_wind = curwind;		pop_wind(cur_error->er_buf->b_name, NO, -1);		buf_wind = curwind;	}	/* Put the current error message at the top of its Window */	SetWind(err_wind);	SetLine(cur_error->er_mess);	SetTop(curwind, (curwind->w_line = cur_error->er_mess));	set_wsize(EWSize);	/* now go to the the line with the error in the other window */	SetWind(buf_wind);	DotTo(cur_error->er_text, cur_error->er_char);}char	ShcomBuf[LBSIZE];/* Make a buffer name given the command `command', i.e. "fgrep -n foo *.c"   will return the buffer name "fgrep".  */char *MakeName(command)char	*command;{	static char	bnm[50];	register char	*cp = bnm,			c;	do ; while ((c = *command++) != '\0' && (c == ' ' || c == '\t'));	do {		*cp++ = c;	} while ((c = *command++) != '\0' && (c != ' ' && c != '\t'));	*cp = '\0';	strcpy(bnm, basename(bnm));	return bnm;}/* Run make, first writing all the modified buffers (if the WtOnMk flag is   on), parse the errors, and go the first error. */private char	make_cmd[LBSIZE] = "make";voidMakeErrors(){	Window	*old = curwind;	int	status;	bool	compilation;	if (WtOnMk)		put_bufs(FALSE);	/* When we're not doing make or cc (i.e., the last command	   was probably a grep or something) and the user just types	   C-X C-E, he probably (possibly, hopefully, usually (in my	   case)) doesn't want to do the grep again but rather wants	   to do a make again; so we ring the bell and insert the	   default command and let the person decide. */	compilation = (sindex("make", make_cmd) || sindex("cc", make_cmd));	if (is_an_arg() || !compilation) {		if (!compilation) {			rbell();			Inputp = make_cmd;	/* insert the default for the user */		}		null_ncpy(make_cmd, ask(make_cmd, "Compilation command: "),				sizeof (make_cmd) - 1);	}	status = UnixToBuf(MakeName(make_cmd), (char *)NULL, YES, EWSize, YES,		Shell, ShFlags, make_cmd, (char *)NULL);	com_finish(status, make_cmd);	ErrParse();	if (!cur_error)		SetWind(old);}#ifdef	SPELLprivate voidSpelParse(bname)char	*bname;{	Buffer	*buftospel,		*wordsb;	char	wordspel[100];	Bufpos	*bp;	struct error	*ep = NULL;	ErrFree();		/* This is important! */	buftospel = curbuf;	wordsb = buf_exists(bname);	perr_buf = wordsb;	/* This is important (buffer containing				   error messages) */	SetBuf(wordsb);	ToFirst();	f_mess("Finding misspelled words ... ");	while (!lastp(curline)) {		swritef(wordspel, sizeof(wordspel), "\\<%s\\>", linebuf);		SetBuf(buftospel);		ToFirst();		while ((bp = dosearch(wordspel, FORWARD, NO)) != NULL) {			SetDot(bp);			ep = AddError(ep, wordsb->b_dot, buftospel,					  curline, curchar);		}		SetBuf(wordsb);		line_move(FORWARD, 1, NO);	}	add_mess("Done.");	SetBuf(buftospel);	ShowErr();}voidSpelBuffer(){	char	*Spell = "Spell",		com[100];	Window	*savewp = curwind;	if (curbuf->b_fname == NULL)		complain("no file name");	if (IsModified(curbuf))		SaveFile();	swritef(com, sizeof(com), "spell %s", curbuf->b_fname);	(void) UnixToBuf(Spell, (char *)NULL, YES, EWSize, YES,		Shell, ShFlags, com, (char *) NULL);	message("[Delete the irrelevant words and then type C-X C-C]");	ToFirst();	Recur();	SetWind(savewp);	SpelParse(Spell);}voidSpelWords(){	char	*buftospel;	Buffer	*wordsb = curbuf;	if ((buftospel = ask_buf((Buffer *)NULL)) == NULL)		return;	SetBuf(do_select(curwind, buftospel));	SpelParse(wordsb->b_name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -