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

Diff for /src/usr.bin/sed/compile.c between version 1.21 and 1.22

version 1.21, 2005/04/11 07:11:44 version 1.22, 2006/10/09 00:23:56
Line 35 
Line 35 
   
 #ifndef lint  #ifndef lint
 /* from: static char sccsid[] = "@(#)compile.c  8.2 (Berkeley) 4/28/95"; */  /* from: static char sccsid[] = "@(#)compile.c  8.2 (Berkeley) 4/28/95"; */
 static char *rcsid = "$OpenBSD$";  static const char rcsid[] = "$OpenBSD$";
 #endif /* not lint */  #endif /* not lint */
   
 #include <sys/types.h>  #include <sys/types.h>
Line 183 
Line 183 
                                 cmd->a2 = xmalloc(sizeof(struct s_addr));                                  cmd->a2 = xmalloc(sizeof(struct s_addr));
                                 p = compile_addr(p, cmd->a2);                                  p = compile_addr(p, cmd->a2);
                                 EATSPACE();                                  EATSPACE();
                         } else                          } else {
                                 cmd->a2 = 0;                                  cmd->a2 = 0;
                 } else                          }
                   } else {
                         cmd->a1 = cmd->a2 = 0;                          cmd->a1 = cmd->a2 = 0;
                   }
   
 nonsel:         /* Now parse the command */  nonsel:         /* Now parse the command */
                 if (!*p)                  if (!*p)
Line 199 
Line 201 
                         err(COMPILE, "invalid command code %c", *p);                          err(COMPILE, "invalid command code %c", *p);
                 if (naddr > fp->naddr)                  if (naddr > fp->naddr)
                         err(COMPILE,                          err(COMPILE,
 "command %c expects up to %d address(es), found %d", *p, fp->naddr, naddr);                              "command %c expects up to %d address(es), found %d",
                               *p, fp->naddr, naddr);
                 switch (fp->args) {                  switch (fp->args) {
                 case NONSEL:                    /* ! */                  case NONSEL:                    /* ! */
                         p++;                          p++;
Line 243 
Line 246 
                         p++;                          p++;
                         EATSPACE();                          EATSPACE();
                         if (*p != '\\')                          if (*p != '\\')
                                 err(COMPILE,                                  err(COMPILE, "command %c expects \\ followed by"
 "command %c expects \\ followed by text", cmd->code);                                      " text", cmd->code);
                         p++;                          p++;
                         EATSPACE();                          EATSPACE();
                         if (*p)                          if (*p)
                                 err(COMPILE,                                  err(COMPILE, "extra characters after \\ at the"
 "extra characters after \\ at the end of %c command", cmd->code);                                      " end of %c command", cmd->code);
                         cmd->t = compile_text();                          cmd->t = compile_text();
                         break;                          break;
                 case COMMENT:                   /* \0 # */                  case COMMENT:                   /* \0 # */
Line 299 
Line 302 
                 case SUBST:                     /* s */                  case SUBST:                     /* s */
                         p++;                          p++;
                         if (*p == '\0' || *p == '\\')                          if (*p == '\0' || *p == '\\')
                                 err(COMPILE,                                  err(COMPILE, "substitute pattern can not be"
 "substitute pattern can not be delimited by newline or backslash");                                      " delimited by newline or backslash");
                         cmd->u.s = xmalloc(sizeof(struct s_subst));                          cmd->u.s = xmalloc(sizeof(struct s_subst));
                         p = compile_re(p, &cmd->u.s->re);                          p = compile_re(p, &cmd->u.s->re);
                         if (p == NULL)                          if (p == NULL)
Line 325 
Line 328 
                                 goto semicolon;                                  goto semicolon;
                         }                          }
                         if (*p)                          if (*p)
                                 err(COMPILE,                                  err(COMPILE, "extra text at the end of a"
 "extra text at the end of a transform command");                                      " transform command");
                         break;                          break;
                 }                  }
         }          }
Line 360 
Line 363 
                         continue;                          continue;
                 } else if (*p == '\\' && p[1] == '[') {                  } else if (*p == '\\' && p[1] == '[') {
                         *d++ = *p++;                          *d++ = *p++;
                 } else if (*p == '\\' && p[1] == c)                  } else if (*p == '\\' && p[1] == c) {
                         p++;                          p++;
                 else if (*p == '\\' && p[1] == 'n') {                  } else if (*p == '\\' && p[1] == 'n') {
                         *d++ = '\n';                          *d++ = '\n';
                         p += 2;                          p += 2;
                         continue;                          continue;
                 } else if (*p == '\\' && p[1] == '\\')                  } else if (*p == '\\' && p[1] == '\\') {
                         *d++ = *p++;                          *d++ = *p++;
                 else if (*p == c) {                  } else if (*p == c) {
                         *d = '\0';                          *d = '\0';
                         return (p + 1);                          return (p + 1);
                 }                  }
Line 396 
Line 399 
                         for (c = *s; (*t = *s) != ']' || c != d; s++, t++)                          for (c = *s; (*t = *s) != ']' || c != d; s++, t++)
                                 if ((c = *s) == '\0')                                  if ((c = *s) == '\0')
                                         return NULL;                                          return NULL;
                 } else if (*s == '\\' && s[1] == 'n')                  } else if (*s == '\\' && s[1] == 'n') {
                             *t = '\n', s++;                          *t = '\n';
         return (*s == ']') ? *sp = ++s, ++t : NULL;                          s++;
                   }
           if (*s == ']') {
                   *sp = ++s;
                   return (++t);
           } else {
                   return (NULL);
           }
 }  }
   
 /*  /*
Line 529 
Line 539 
                 switch (*p) {                  switch (*p) {
                 case 'g':                  case 'g':
                         if (gn)                          if (gn)
                                 err(COMPILE,                                  err(COMPILE, "more than one number or 'g' in"
 "more than one number or 'g' in substitute flags");                                      " substitute flags");
                         gn = 1;                          gn = 1;
                         s->n = 0;                          s->n = 0;
                         break;                          break;
Line 545 
Line 555 
                 case '4': case '5': case '6':                  case '4': case '5': case '6':
                 case '7': case '8': case '9':                  case '7': case '8': case '9':
                         if (gn)                          if (gn)
                                 err(COMPILE,                                  err(COMPILE, "more than one number or 'g' in"
 "more than one number or 'g' in substitute flags");                                      " substitute flags");
                         gn = 1;                          gn = 1;
                         l = strtol(p, &p, 10);                          l = strtol(p, &p, 10);
                         if (l <= 0 || l >= INT_MAX)                          if (l <= 0 || l >= INT_MAX)

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22