[BACK]Return to grep.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Diff for /src/usr.bin/mg/grep.c between version 1.28 and 1.29

version 1.28, 2006/05/02 17:10:25 version 1.29, 2006/05/27 21:22:45
Line 83 
Line 83 
 static int  static int
 grep(int f, int n)  grep(int f, int n)
 {  {
         char     command[NFILEN + 21];  
         char     cprompt[NFILEN], *bufp;          char     cprompt[NFILEN], *bufp;
         struct buffer   *bp;          struct buffer   *bp;
         struct mgwin    *wp;          struct mgwin    *wp;
Line 94 
Line 93 
                 return (ABORT);                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return (FALSE);                  return (FALSE);
         (void)snprintf(command, sizeof(command), "%s /dev/null", bufp);          if (strlcat(cprompt, " /dev/null", sizeof(cprompt)) >= sizeof(cprompt))
                   return (FALSE);
   
         if ((bp = compile_mode("*grep*", command)) == NULL)          if ((bp = compile_mode("*grep*", cprompt)) == NULL)
                 return (FALSE);                  return (FALSE);
         if ((wp = popbuf(bp)) == NULL)          if ((wp = popbuf(bp)) == NULL)
                 return (FALSE);                  return (FALSE);
Line 109 
Line 109 
 static int  static int
 xlint(int f, int n)  xlint(int f, int n)
 {  {
         char     command[NFILEN + 16];  
         char     cprompt[NFILEN], *bufp;          char     cprompt[NFILEN], *bufp;
         struct buffer   *bp;          struct buffer   *bp;
         struct mgwin    *wp;          struct mgwin    *wp;
Line 120 
Line 119 
                 return (ABORT);                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return (FALSE);                  return (FALSE);
         (void)snprintf(command, sizeof(command), "%s 2>&1", bufp);  
   
         if ((bp = compile_mode("*lint*", command)) == NULL)          if ((bp = compile_mode("*lint*", cprompt)) == NULL)
                 return (FALSE);                  return (FALSE);
         if ((wp = popbuf(bp)) == NULL)          if ((wp = popbuf(bp)) == NULL)
                 return (FALSE);                  return (FALSE);
Line 135 
Line 133 
 static int  static int
 compile(int f, int n)  compile(int f, int n)
 {  {
         char     command[NFILEN + 20];  
         char     cprompt[NFILEN], *bufp;          char     cprompt[NFILEN], *bufp;
         struct buffer   *bp;          struct buffer   *bp;
         struct mgwin    *wp;          struct mgwin    *wp;
Line 150 
Line 147 
                 return (ABORT);                  return (ABORT);
         (void)strlcpy(compile_last_command, bufp, sizeof(compile_last_command));          (void)strlcpy(compile_last_command, bufp, sizeof(compile_last_command));
   
         (void)snprintf(command, sizeof(command), "%s 2>&1", bufp);          if ((bp = compile_mode("*compile*", cprompt)) == 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);
Line 167 
Line 162 
 static int  static int
 gid(int f, int n)  gid(int f, int n)
 {  {
         char     command[NFILEN + 20];          char     command[NFILEN];
         char     cprompt[NFILEN], c, *bufp;          char     cprompt[NFILEN], c, *bufp;
         struct buffer   *bp;          struct buffer   *bp;
         struct mgwin    *wp;          struct mgwin    *wp;
         int      i, j;          int      i, j, len;
   
         /* catch ([^\s(){}]+)[\s(){}]* */          /* catch ([^\s(){}]+)[\s(){}]* */
   
Line 206 
Line 201 
                 return (ABORT);                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return (FALSE);                  return (FALSE);
         (void)snprintf(command, sizeof(command), "gid %s", cprompt);          len = snprintf(command, sizeof(command), "gid %s", cprompt);
           if (len < 0 || len >= sizeof(command))
                   return (FALSE);
   
         if ((bp = compile_mode("*gid*", command)) == NULL)          if ((bp = compile_mode("*gid*", command)) == NULL)
                 return (FALSE);                  return (FALSE);
Line 224 
Line 221 
         FILE    *fpipe;          FILE    *fpipe;
         char    *buf;          char    *buf;
         size_t   len;          size_t   len;
         int      ret;          int      ret, n;
         char     cwd[NFILEN];          char     cwd[NFILEN], qcmd[NFILEN];
         char     timestr[NTIME];          char     timestr[NTIME];
         time_t   t;          time_t   t;
   
           n = snprintf(qcmd, sizeof(qcmd), "%s 2>&1", command);
           if (n < 0 || n >= sizeof(qcmd))
                   return (NULL);
   
         bp = bfind(name, TRUE);          bp = bfind(name, TRUE);
         if (bclear(bp) != TRUE)          if (bclear(bp) != TRUE)
                 return (NULL);                  return (NULL);
Line 236 
Line 237 
         if (getbufcwd(bp->b_cwd, sizeof(bp->b_cwd)) != TRUE)          if (getbufcwd(bp->b_cwd, sizeof(bp->b_cwd)) != TRUE)
                 return (NULL);                  return (NULL);
         addlinef(bp, "cd %s", bp->b_cwd);          addlinef(bp, "cd %s", bp->b_cwd);
         addline(bp, command);          addline(bp, qcmd);
         addline(bp, "");          addline(bp, "");
   
         if (getcwd(cwd, sizeof(cwd)) == NULL)          if (getcwd(cwd, sizeof(cwd)) == NULL)
Line 245 
Line 246 
                 ewprintf("Can't change dir to %s", bp->b_cwd);                  ewprintf("Can't change dir to %s", bp->b_cwd);
                 return (NULL);                  return (NULL);
         }          }
         if ((fpipe = popen(command, "r")) == NULL) {          if ((fpipe = popen(qcmd, "r")) == NULL) {
                 ewprintf("Problem opening pipe");                  ewprintf("Problem opening pipe");
                 return (NULL);                  return (NULL);
         }          }
Line 289 
Line 290 
         struct buffer   *bp;          struct buffer   *bp;
         struct mgwin    *wp;          struct mgwin    *wp;
         char    *fname, *line, *lp, *ln;          char    *fname, *line, *lp, *ln;
         int      lineno, len;          int      lineno;
         char    *adjf, path[NFILEN];          char    *adjf, path[NFILEN];
         const char *errstr;          const char *errstr;
         struct line     *last;          struct line     *last;
Line 302 
Line 303 
         /* last line is compilation result */          /* last line is compilation result */
         if (curwp->w_dotp == last)          if (curwp->w_dotp == last)
                 return (FALSE);                  return (FALSE);
   
         len = llength(curwp->w_dotp);          if ((line = linetostr(curwp->w_dotp)) == NULL)
   
         if ((line = malloc(len + 1)) == NULL)  
                 return (FALSE);                  return (FALSE);
   
         (void)memcpy(line, curwp->w_dotp->l_text, len);  
         line[len] = '\0';  
   
         lp = line;          lp = line;
         if ((fname = strsep(&lp, ":")) == NULL || *fname == '\0')          if ((fname = strsep(&lp, ":")) == NULL || *fname == '\0')
                 goto fail;                  goto fail;

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29