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

Diff for /src/usr.bin/awk/b.c between version 1.4 and 1.5

version 1.4, 1997/04/07 15:59:55 version 1.5, 1997/08/25 16:17:10
Line 1 
Line 1 
   /*      $OpenBSD$       */
 /****************************************************************  /****************************************************************
 Copyright (C) AT&T and Lucent Technologies 1996  Copyright (C) Lucent Technologies 1997
 All Rights Reserved  All Rights Reserved
   
 Permission to use, copy, modify, and distribute this software and  Permission to use, copy, modify, and distribute this software and
Line 7 
Line 8 
 granted, provided that the above copyright notice appear in all  granted, provided that the above copyright notice appear in all
 copies and that both that the copyright notice and this  copies and that both that the copyright notice and this
 permission notice and warranty disclaimer appear in supporting  permission notice and warranty disclaimer appear in supporting
 documentation, and that the names of AT&T or Lucent Technologies  documentation, and that the name Lucent Technologies or any of
 or any of their entities not be used in advertising or publicity  its entities not be used in advertising or publicity pertaining
 pertaining to distribution of the software without specific,  to distribution of the software without specific, written prior
 written prior permission.  permission.
   
 AT&T AND LUCENT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS  LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
 FITNESS. IN NO EVENT SHALL AT&T OR LUCENT OR ANY OF THEIR  IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
 ENTITIES BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
 USE OR PERFORMANCE OF THIS SOFTWARE.  THIS SOFTWARE.
 ****************************************************************/  ****************************************************************/
   
 /* lasciate ogne speranza, voi ch'entrate. */  /* lasciate ogne speranza, voi ch'entrate. */
Line 31 
Line 32 
 #include <string.h>  #include <string.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include "awk.h"  #include "awk.h"
 #include "awkgram.h"  #include "ytab.h"
   
 #define HAT     (NCHARS-1)      /* matches ^ in regular expr */  #define HAT     (NCHARS-1)      /* matches ^ in regular expr */
                                 /* NCHARS is 2**n */                                  /* NCHARS is 2**n */
Line 283 
Line 284 
 char *cclenter(char *p) /* add a character class */  char *cclenter(char *p) /* add a character class */
 {  {
         int i, c, c2;          int i, c, c2;
         char *op;          char *op, *bp;
         static Gstring *cgp = 0;          static char *buf = 0;
           static int bufsz = 100;
   
         op = p;          op = p;
         if (cgp == 0)          if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
                 cgp = newGstring();                  ERROR "out of space for character class [%.10s...] 1", p FATAL;
         caddreset(cgp);          bp = buf;
         i = 0;          for (i = 0; (c = *p++) != 0; ) {
         while ((c = *p++) != 0) {  
                 if (c == '\\') {                  if (c == '\\') {
                         c = quoted(&p);                          c = quoted(&p);
                 } else if (c == '-' && i > 0 && cgp->cbuf[i-1] != 0) {                  } else if (c == '-' && i > 0 && bp[-1] != 0) {
                         if (*p != 0) {                          if (*p != 0) {
                                 c = cgp->cbuf[i-1];                                  c = bp[-1];
                                 c2 = *p++;                                  c2 = *p++;
                                 if (c2 == '\\')                                  if (c2 == '\\')
                                         c2 = quoted(&p);                                          c2 = quoted(&p);
                                 if (c > c2) {   /* empty; ignore */                                  if (c > c2) {   /* empty; ignore */
                                         cunadd(cgp);                                          bp--;
                                         i--;                                          i--;
                                         continue;                                          continue;
                                 }                                  }
                                 while (c < c2) {                                  while (c < c2) {
                                         cadd(cgp, ++c);                                          if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, 0))
                                                   ERROR "out of space for character class [%.10s...] 2", p FATAL;
                                           *bp++ = ++c;
                                         i++;                                          i++;
                                 }                                  }
                                 continue;                                  continue;
                         }                          }
                 }                  }
                 cadd(cgp, c);                  if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, 0))
                           ERROR "out of space for character class [%.10s...] 3", p FATAL;
                   *bp++ = c;
                 i++;                  i++;
         }          }
         cadd(cgp, 0);          *bp = 0;
         dprintf( ("cclenter: in = |%s|, out = |%s|\n", op, cgp->cbuf) );          dprintf( ("cclenter: in = |%s|, out = |%s|\n", op, buf) );
         xfree(op);          xfree(op);
         return(tostring(cgp->cbuf));          return(tostring(buf));
 }  }
   
 void overflo(char *s)  void overflo(char *s)
Line 339 
Line 344 
                         maxsetvec *= 4;                          maxsetvec *= 4;
                         setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));                          setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
                         tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));                          tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
                         if (setvec == 0 || tmpset == 0) { abort();                          if (setvec == 0 || tmpset == 0)
                                 overflo("out of space in cfoll()");                                  overflo("out of space in cfoll()");
 }  
                 }                  }
                 for (i = 0; i <= f->accept; i++)                  for (i = 0; i <= f->accept; i++)
                         setvec[i] = 0;                          setvec[i] = 0;
Line 676 
Line 680 
   
 int relex(void)         /* lexical analyzer for reparse */  int relex(void)         /* lexical analyzer for reparse */
 {  {
         int c;          int c, n;
         int cflag;          int cflag;
         static Gstring *gp = 0;          static char *buf = 0;
           static int bufsz = 100;
           char *bp;
   
         switch (c = *prestr++) {          switch (c = *prestr++) {
         case '|': return OR;          case '|': return OR;
Line 699 
Line 705 
                 rlxval = c;                  rlxval = c;
                 return CHAR;                  return CHAR;
         case '[':          case '[':
                 if (gp == 0)                  if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
                         gp = newGstring();                          ERROR "out of space in reg expr %.10s..", lastre FATAL;
                 caddreset(gp);                  bp = buf;
                 if (*prestr == '^') {                  if (*prestr == '^') {
                         cflag = 1;                          cflag = 1;
                         prestr++;                          prestr++;
                 }                  }
                 else                  else
                         cflag = 0;                          cflag = 0;
                   n = 2 * strlen(prestr)+1;
                   if (!adjbuf(&buf, &bufsz, n, n, &bp, 0))
                           ERROR "out of space for reg expr %.10s...", lastre FATAL;
                 for (; ; ) {                  for (; ; ) {
                         if ((c = *prestr++) == '\\') {                          if ((c = *prestr++) == '\\') {
                                 cadd(gp, '\\');                                  *bp++ = '\\';
                                 if ((c = *prestr++) == '\0')                                  if ((c = *prestr++) == '\0')
                                         ERROR "nonterminated character class %.20s...", lastre FATAL;                                          ERROR "nonterminated character class %.20s...", lastre FATAL;
                                 cadd(gp, c);                                  *bp++ = c;
                         } else if (c == '\n') {                          } else if (c == '\n') {
                                 ERROR "newline in character class %.20s...", lastre FATAL;                                  ERROR "newline in character class %.20s...", lastre FATAL;
                         } else if (c == '\0') {                          } else if (c == '\0') {
                                 ERROR "nonterminated character class %.20s", lastre FATAL;                                  ERROR "nonterminated character class %.20s", lastre FATAL;
                         } else if (gp->clen == 0) {     /* 1st char is special */                          } else if (bp == buf) { /* 1st char is special */
                                 cadd(gp, c);                                  *bp++ = c;
                         } else if (c == ']') {                          } else if (c == ']') {
                                 cadd(gp, 0);                                  *bp++ = 0;
                                 rlxstr = tostring(gp->cbuf);                                  rlxstr = tostring(buf);
                                 if (cflag == 0)                                  if (cflag == 0)
                                         return CCL;                                          return CCL;
                                 else                                  else
                                         return NCCL;                                          return NCCL;
                         } else                          } else
                                 cadd(gp, c);                                  *bp++ = c;
                 }                  }
         }          }
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5