version 1.27, 2006/04/03 00:19:32 |
version 1.28, 2006/05/02 17:10:25 |
|
|
static int grep(int, int); |
static int grep(int, int); |
static int compile(int, int); |
static int compile(int, int); |
static int gid(int, int); |
static int gid(int, int); |
static struct buffer *compile_mode(const char *, const char *, const char *); |
static struct buffer *compile_mode(const char *, const char *); |
static int getbufcwd(char *, size_t); |
|
static int xlint(int, int); |
static int xlint(int, int); |
|
|
void grep_init(void); |
void grep_init(void); |
|
|
char cprompt[NFILEN], *bufp; |
char cprompt[NFILEN], *bufp; |
struct buffer *bp; |
struct buffer *bp; |
struct mgwin *wp; |
struct mgwin *wp; |
char path[NFILEN]; |
|
|
|
/* get buffer cwd */ |
|
if (getbufcwd(path, sizeof(path)) == FALSE) { |
|
ewprintf("Failed. " |
|
"Can't get working directory of current buffer."); |
|
return (FALSE); |
|
} |
|
|
|
(void)strlcpy(cprompt, "grep -n ", sizeof(cprompt)); |
(void)strlcpy(cprompt, "grep -n ", sizeof(cprompt)); |
if ((bufp = eread("Run grep: ", cprompt, NFILEN, |
if ((bufp = eread("Run grep: ", cprompt, NFILEN, |
EFDEF | EFNEW | EFCR)) == NULL) |
EFDEF | EFNEW | EFCR)) == NULL) |
|
|
return (FALSE); |
return (FALSE); |
(void)snprintf(command, sizeof(command), "%s /dev/null", bufp); |
(void)snprintf(command, sizeof(command), "%s /dev/null", bufp); |
|
|
if ((bp = compile_mode("*grep*", command, path)) == NULL) |
if ((bp = compile_mode("*grep*", command)) == NULL) |
return (FALSE); |
return (FALSE); |
if ((wp = popbuf(bp)) == NULL) |
if ((wp = popbuf(bp)) == NULL) |
return (FALSE); |
return (FALSE); |
|
|
char cprompt[NFILEN], *bufp; |
char cprompt[NFILEN], *bufp; |
struct buffer *bp; |
struct buffer *bp; |
struct mgwin *wp; |
struct mgwin *wp; |
char path[NFILEN]; |
|
|
|
/* get buffer cwd */ |
|
if (getbufcwd(path, sizeof(path)) == FALSE) { |
|
ewprintf("Failed. " |
|
"Can't get working directory of current buffer."); |
|
return (FALSE); |
|
} |
|
|
|
(void)strlcpy(cprompt, "make lint ", sizeof(cprompt)); |
(void)strlcpy(cprompt, "make lint ", sizeof(cprompt)); |
if ((bufp = eread("Run lint: ", cprompt, NFILEN, |
if ((bufp = eread("Run lint: ", cprompt, NFILEN, |
EFDEF | EFNEW | EFCR)) == NULL) |
EFDEF | EFNEW | EFCR)) == NULL) |
|
|
return (FALSE); |
return (FALSE); |
(void)snprintf(command, sizeof(command), "%s 2>&1", bufp); |
(void)snprintf(command, sizeof(command), "%s 2>&1", bufp); |
|
|
if ((bp = compile_mode("*lint*", command, path)) == NULL) |
if ((bp = compile_mode("*lint*", command)) == NULL) |
return (FALSE); |
return (FALSE); |
if ((wp = popbuf(bp)) == NULL) |
if ((wp = popbuf(bp)) == NULL) |
return (FALSE); |
return (FALSE); |
|
|
char cprompt[NFILEN], *bufp; |
char cprompt[NFILEN], *bufp; |
struct buffer *bp; |
struct buffer *bp; |
struct mgwin *wp; |
struct mgwin *wp; |
char path[NFILEN]; |
|
|
|
/* get buffer cwd */ |
|
if (getbufcwd(path, sizeof(path)) == FALSE) { |
|
ewprintf("Failed. " |
|
"Can't get working directory of current buffer."); |
|
return (FALSE); |
|
} |
|
|
|
(void)strlcpy(cprompt, compile_last_command, sizeof(cprompt)); |
(void)strlcpy(cprompt, compile_last_command, sizeof(cprompt)); |
if ((bufp = eread("Compile command: ", cprompt, NFILEN, |
if ((bufp = eread("Compile command: ", cprompt, NFILEN, |
EFDEF | EFNEW | EFCR)) == NULL) |
EFDEF | EFNEW | EFCR)) == NULL) |
|
|
|
|
(void)snprintf(command, sizeof(command), "%s 2>&1", bufp); |
(void)snprintf(command, sizeof(command), "%s 2>&1", bufp); |
|
|
if ((bp = compile_mode("*compile*", command, path)) == NULL) |
if ((bp = compile_mode("*compile*", command)) == NULL) |
return (FALSE); |
return (FALSE); |
if ((wp = popbuf(bp)) == NULL) |
if ((wp = popbuf(bp)) == NULL) |
return (FALSE); |
return (FALSE); |
|
|
struct buffer *bp; |
struct buffer *bp; |
struct mgwin *wp; |
struct mgwin *wp; |
int i, j; |
int i, j; |
char path[NFILEN]; |
|
|
|
/* get buffer cwd */ |
|
if (getbufcwd(path, sizeof(path)) == FALSE) { |
|
ewprintf("Failed. " |
|
"Can't get working directory of current buffer."); |
|
return (FALSE); |
|
} |
|
|
|
/* catch ([^\s(){}]+)[\s(){}]* */ |
/* catch ([^\s(){}]+)[\s(){}]* */ |
|
|
i = curwp->w_doto; |
i = curwp->w_doto; |
|
|
return (FALSE); |
return (FALSE); |
(void)snprintf(command, sizeof(command), "gid %s", cprompt); |
(void)snprintf(command, sizeof(command), "gid %s", cprompt); |
|
|
if ((bp = compile_mode("*gid*", command, path)) == NULL) |
if ((bp = compile_mode("*gid*", command)) == NULL) |
return (FALSE); |
return (FALSE); |
if ((wp = popbuf(bp)) == NULL) |
if ((wp = popbuf(bp)) == NULL) |
return (FALSE); |
return (FALSE); |
|
|
} |
} |
|
|
struct buffer * |
struct buffer * |
compile_mode(const char *name, const char *command, const char *path) |
compile_mode(const char *name, const char *command) |
{ |
{ |
struct buffer *bp; |
struct buffer *bp; |
FILE *fpipe; |
FILE *fpipe; |
|
|
if (bclear(bp) != TRUE) |
if (bclear(bp) != TRUE) |
return (NULL); |
return (NULL); |
|
|
addlinef(bp, "cd %s", path); |
if (getbufcwd(bp->b_cwd, sizeof(bp->b_cwd)) != TRUE) |
|
return (NULL); |
|
addlinef(bp, "cd %s", bp->b_cwd); |
addline(bp, command); |
addline(bp, command); |
addline(bp, ""); |
addline(bp, ""); |
|
|
if (getcwd(cwd, sizeof(cwd)) == NULL) |
if (getcwd(cwd, sizeof(cwd)) == NULL) |
panic("Can't get current directory!"); |
panic("Can't get current directory!"); |
if (chdir(path) == -1) { |
if (chdir(bp->b_cwd) == -1) { |
ewprintf("Can't change dir to %s", path); |
ewprintf("Can't change dir to %s", bp->b_cwd); |
return (NULL); |
return (NULL); |
} |
} |
if ((fpipe = popen(command, "r")) == NULL) { |
if ((fpipe = popen(command, "r")) == NULL) { |
|
|
struct mgwin *wp; |
struct mgwin *wp; |
char *fname, *line, *lp, *ln; |
char *fname, *line, *lp, *ln; |
int lineno, len; |
int lineno, len; |
char *adjf; |
char *adjf, path[NFILEN]; |
const char *errstr; |
const char *errstr; |
struct line *last; |
struct line *last; |
|
|
|
|
lineno = (int)strtonum(ln, INT_MIN, INT_MAX, &errstr); |
lineno = (int)strtonum(ln, INT_MIN, INT_MAX, &errstr); |
if (errstr) |
if (errstr) |
goto fail; |
goto fail; |
|
|
adjf = adjustname(fname); |
if (fname && fname[0] != '/') { |
|
(void)strlcpy(path, curbp->b_cwd, sizeof(path)); |
|
if (strlcat(path, fname, sizeof(path)) >= sizeof(path)) |
|
goto fail; |
|
adjf = path; |
|
} else { |
|
adjf = adjustname(fname); |
|
} |
free(line); |
free(line); |
|
|
if (adjf == NULL) |
if (adjf == NULL) |
|
|
curwp->w_flag |= WFMOVE; |
curwp->w_flag |= WFMOVE; |
|
|
return (compile_goto_error(f, n)); |
return (compile_goto_error(f, n)); |
} |
|
|
|
/* |
|
* Return the working directory for the current buffer, terminated |
|
* with a '/'. First, try to extract it from the current buffer's |
|
* filename. If that fails, use global cwd. |
|
*/ |
|
static int |
|
getbufcwd(char *path, size_t plen) |
|
{ |
|
char *dname, cwd[NFILEN]; |
|
if (plen == 0) |
|
goto error; |
|
|
|
if (curbp->b_fname && curbp->b_fname[0] != '\0' && |
|
(dname = dirname(curbp->b_fname)) != NULL) { |
|
if (strlcpy(path, dname, plen) >= plen) |
|
goto error; |
|
if (strlcat(path, "/", plen) >= plen) |
|
goto error; |
|
} else { |
|
if ((dname = getcwd(cwd, sizeof(cwd))) == NULL) |
|
goto error; |
|
if (strlcpy(path, dname, plen) >= plen) |
|
goto error; |
|
} |
|
return (TRUE); |
|
error: |
|
path = NULL; |
|
return (FALSE); |
|
} |
} |