=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/grep.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- src/usr.bin/mg/grep.c 2004/07/22 01:25:25 1.12 +++ src/usr.bin/mg/grep.c 2005/04/03 02:09:28 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.12 2004/07/22 01:25:25 vincent Exp $ */ +/* $OpenBSD: grep.c,v 1.13 2005/04/03 02:09:28 db Exp $ */ /* * Copyright (c) 2001 Artur Grabowski . All rights reserved. * @@ -29,11 +29,11 @@ #include -static int compile_goto_error(int, int); -static int next_error(int, int); -static int grep(int, int); -static int compile(int, int); -static int gid(int, int); +static int compile_goto_error(int, int); +static int next_error(int, int); +static int grep(int, int); +static int compile(int, int); +static int gid(int, int); static BUFFER *compile_mode(char *, char *); @@ -46,11 +46,11 @@ * * XXX - need some kind of callback to find out when those get killed. */ -MGWIN *compile_win; -BUFFER *compile_buffer; +MGWIN *compile_win; +BUFFER *compile_buffer; static PF compile_pf[] = { - compile_goto_error, + compile_goto_error }; static struct KEYMAPE (1 + IMAPEXT) compilemap = { @@ -58,7 +58,7 @@ 1 + IMAPEXT, rescan, { - { CCHR('M'), CCHR('M'), compile_pf, NULL }, + { CCHR('M'), CCHR('M'), compile_pf, NULL } } }; @@ -76,60 +76,60 @@ static int grep(int f, int n) { - char command[NFILEN + 20]; - char prompt[NFILEN], *bufp; - BUFFER *bp; - MGWIN *wp; + char command[NFILEN + 20]; + char prompt[NFILEN], *bufp; + BUFFER *bp; + MGWIN *wp; - (void)strlcpy(prompt, "grep -n ", sizeof prompt); + (void)strlcpy(prompt, "grep -n ", sizeof(prompt)); if ((bufp = eread("Run grep: ", prompt, NFILEN, EFDEF|EFNEW|EFCR)) == NULL) - return ABORT; + return (ABORT); - (void)snprintf(command, sizeof command, "%s /dev/null", bufp); + (void)snprintf(command, sizeof(command), "%s /dev/null", bufp); if ((bp = compile_mode("*grep*", command)) == NULL) - return FALSE; + return (FALSE); if ((wp = popbuf(bp)) == NULL) - return FALSE; + return (FALSE); curbp = bp; compile_win = curwp = wp; - return TRUE; + return (TRUE); } static int compile(int f, int n) { - char command[NFILEN + 20]; - char prompt[NFILEN], *bufp; - BUFFER *bp; - MGWIN *wp; + char command[NFILEN + 20]; + char prompt[NFILEN], *bufp; + BUFFER *bp; + MGWIN *wp; - (void)strlcpy(prompt, compile_last_command, sizeof prompt); + (void)strlcpy(prompt, compile_last_command, sizeof(prompt)); if ((bufp = eread("Compile command: ", prompt, NFILEN, EFDEF|EFNEW|EFCR)) == NULL) - return ABORT; - (void)strlcpy(compile_last_command, bufp, sizeof compile_last_command); + return (ABORT); + (void)strlcpy(compile_last_command, bufp, sizeof(compile_last_command)); - (void)snprintf(command, sizeof command, "%s 2>&1", bufp); + (void)snprintf(command, sizeof(command), "%s 2>&1", bufp); if ((bp = compile_mode("*compile*", command)) == NULL) - return FALSE; + return (FALSE); if ((wp = popbuf(bp)) == NULL) - return FALSE; + return (FALSE); curbp = bp; compile_win = curwp = wp; - return TRUE; + return (TRUE); } /* id-utils foo. */ static int gid(int f, int n) { - char command[NFILEN + 20]; - char prompt[NFILEN], c, *bufp; - BUFFER *bp; - MGWIN *wp; - int i, j; + char command[NFILEN + 20]; + char prompt[NFILEN], c, *bufp; + BUFFER *bp; + MGWIN *wp; + int i, j; /* catch ([^\s(){}]+)[\s(){}]* */ @@ -158,37 +158,37 @@ if ((bufp = eread("Run gid (with args): ", prompt, NFILEN, (j ? EFDEF : 0)|EFNEW|EFCR)) == NULL) - return ABORT; - (void)snprintf(command, sizeof command, "gid %s", prompt); + return (ABORT); + (void)snprintf(command, sizeof(command), "gid %s", prompt); if ((bp = compile_mode("*gid*", command)) == NULL) - return FALSE; + return (FALSE); if ((wp = popbuf(bp)) == NULL) - return FALSE; + return (FALSE); curbp = bp; compile_win = curwp = wp; - return TRUE; + return (TRUE); } BUFFER * compile_mode(char *name, char *command) { - BUFFER *bp; - FILE *pipe; - char *buf; - size_t len; - int ret; + BUFFER *bp; + FILE *pipe; + char *buf; + size_t len; + int ret; bp = bfind(name, TRUE); if (bclear(bp) != TRUE) - return NULL; + return (NULL); addlinef(bp, "Running (%s).", command); addline(bp, ""); if ((pipe = popen(command, "r")) == NULL) { ewprintf("Problem opening pipe"); - return NULL; + return (NULL); } /* * We know that our commands are nice and the last line will end with @@ -210,17 +210,17 @@ compile_buffer = bp; - return bp; + return (bp); } static int compile_goto_error(int f, int n) { - BUFFER *bp; - MGWIN *wp; - char *fname, *line, *lp, *ln, *lp1; - int lineno, len; - char *adjf; + BUFFER *bp; + MGWIN *wp; + char *fname, *line, *lp, *ln, *lp1; + int lineno, len; + char *adjf; compile_win = curwp; compile_buffer = curbp; @@ -229,7 +229,7 @@ len = llength(curwp->w_dotp); if ((line = malloc(len + 1)) == NULL) - return FALSE; + return (FALSE); (void)memcpy(line, curwp->w_dotp->l_text, len); line[len] = '\0'; @@ -250,15 +250,15 @@ return (FALSE); if ((bp = findbuffer(adjf)) == NULL) - return FALSE; + return (FALSE); if ((wp = popbuf(bp)) == NULL) - return FALSE; + return (FALSE); curbp = bp; curwp = wp; if (bp->b_fname[0] == 0) readin(adjf); gotoline(FFARG, lineno); - return TRUE; + return (TRUE); fail: free(line); if (curwp->w_dotp != lback(curbp->b_linep)) { @@ -267,7 +267,7 @@ goto retry; } ewprintf("No more hits"); - return FALSE; + return (FALSE); } static int @@ -275,16 +275,16 @@ { if (compile_win == NULL || compile_buffer == NULL) { ewprintf("No compilation active"); - return FALSE; + return (FALSE); } curwp = compile_win; curbp = compile_buffer; if (curwp->w_dotp == lback(curbp->b_linep)) { ewprintf("No more hits"); - return FALSE; + return (FALSE); } curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_flag |= WFMOVE; - return compile_goto_error(f, n); + return (compile_goto_error(f, n)); }