[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.50 and 1.51

version 1.50, 2024/01/25 16:40:51 version 1.51, 2024/04/25 18:33:53
Line 613 
Line 613 
         size_t orig_size = f->gototab[state].allocated;         // 2nd half of new mem is this size          size_t orig_size = f->gototab[state].allocated;         // 2nd half of new mem is this size
         memset(p + orig_size, 0, orig_size * sizeof(gtte));     // clean it out          memset(p + orig_size, 0, orig_size * sizeof(gtte));     // clean it out
   
         f->gototab[state].allocated = new_size;                 // update gotottab info          f->gototab[state].allocated = new_size;                 // update gototab info
         f->gototab[state].entries = p;          f->gototab[state].entries = p;
 }  }
   
 static int get_gototab(fa *f, int state, int ch) /* hide gototab inplementation */  static int get_gototab(fa *f, int state, int ch) /* hide gototab implementation */
 {  {
         gtte key;          gtte key;
         gtte *item;          gtte *item;
Line 644 
Line 644 
         return left->ch - right->ch;          return left->ch - right->ch;
 }  }
   
 static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplementation */  static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab implementation */
 {  {
         if (f->gototab[state].inuse == 0) {          if (f->gototab[state].inuse == 0) {
                 f->gototab[state].entries[0].ch = ch;                  f->gototab[state].entries[0].ch = ch;
Line 657 
Line 657 
                 if (tab->inuse + 1 >= tab->allocated)                  if (tab->inuse + 1 >= tab->allocated)
                         resize_gototab(f, state);                          resize_gototab(f, state);
   
                 f->gototab[state].entries[f->gototab[state].inuse-1].ch = ch;                  f->gototab[state].entries[f->gototab[state].inuse].ch = ch;
                 f->gototab[state].entries[f->gototab[state].inuse-1].state = val;                  f->gototab[state].entries[f->gototab[state].inuse].state = val;
                 f->gototab[state].inuse++;                  f->gototab[state].inuse++;
                 return val;                  return val;
         } else {          } else {
Line 683 
Line 683 
         gtt *tab = & f->gototab[state];          gtt *tab = & f->gototab[state];
         if (tab->inuse + 1 >= tab->allocated)          if (tab->inuse + 1 >= tab->allocated)
                 resize_gototab(f, state);                  resize_gototab(f, state);
         ++tab->inuse;  
         f->gototab[state].entries[tab->inuse].ch = ch;          f->gototab[state].entries[tab->inuse].ch = ch;
         f->gototab[state].entries[tab->inuse].state = val;          f->gototab[state].entries[tab->inuse].state = val;
           ++tab->inuse;
   
         qsort(f->gototab[state].entries,          qsort(f->gototab[state].entries,
                 f->gototab[state].inuse, sizeof(gtte), entry_cmp);                  f->gototab[state].inuse, sizeof(gtte), entry_cmp);
Line 836 
Line 836 
 }  }
   
   
 #define MAX_UTF_BYTES   4       // UTF-8 is up to 4 bytes long  
   
 /*  /*
  * NAME   * NAME
  *     fnematch   *     fnematch
Line 874 
Line 872 
   
         do {          do {
                 /*                  /*
                  * Call u8_rune with at least MAX_UTF_BYTES ahead in                   * Call u8_rune with at least awk_mb_cur_max ahead in
                  * the buffer until EOF interferes.                   * the buffer until EOF interferes.
                  */                   */
                 if (k - j < MAX_UTF_BYTES) {                  if (k - j < awk_mb_cur_max) {
                         if (k + MAX_UTF_BYTES > buf + bufsize) {                          if (k + awk_mb_cur_max > buf + bufsize) {
                                   char *obuf = buf;
                                 adjbuf(&buf, &bufsize,                                  adjbuf(&buf, &bufsize,
                                     bufsize + MAX_UTF_BYTES,                                      bufsize + awk_mb_cur_max,
                                     quantum, 0, "fnematch");                                      quantum, 0, "fnematch");
   
                                   /* buf resized, maybe moved. update pointers */
                                   *pbufsize = bufsize;
                                   if (obuf != buf) {
                                           i = buf + (i - obuf);
                                           j = buf + (j - obuf);
                                           k = buf + (k - obuf);
                                           *pbuf = buf;
                                           if (patlen)
                                                   patbeg = buf + (patbeg - obuf);
                                   }
                         }                          }
                         for (n = MAX_UTF_BYTES ; n > 0; n--) {                          for (n = awk_mb_cur_max ; n > 0; n--) {
                                 *k++ = (c = getc(f)) != EOF ? c : 0;                                  *k++ = (c = getc(f)) != EOF ? c : 0;
                                 if (c == EOF) {                                  if (c == EOF) {
                                         if (ferror(f))                                          if (ferror(f))
Line 919 
Line 929 
                 j = i;                  j = i;
                 s = 2;                  s = 2;
         } while (1);          } while (1);
   
         /* adjbuf() may have relocated a resized buffer. Inform the world. */  
         *pbuf = buf;  
         *pbufsize = bufsize;  
   
         if (patlen) {          if (patlen) {
                 /*                  /*

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51