Print this page
9083 replace regex implementation with tre

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/expr/compile.c
          +++ new/usr/src/cmd/expr/compile.c
↓ open down ↓ 33 lines elided ↑ open up ↑
  34   34   *      Goal is to work with vi and sed/ed.
  35   35   *      Returns expbuf in dhl format (encoding of first two bytes).
  36   36   *      Note also that this is profoundly single threaded.  You
  37   37   *      cannot call compile twice with two separate search strings
  38   38   *      because the second call will wipe out the earlier stored string.
  39   39   *      This must be fixed, plus a general cleanup should be performed
  40   40   *      if this is to be integrated into libc.
  41   41   *
  42   42   */
  43   43  
  44      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  45      -
  46   44  #include <stdio.h>
  47   45  #include <widec.h>
  48   46  #include <sys/types.h>
  49   47  #include <regex.h>
  50   48  #include <locale.h>
  51   49  #include <stdlib.h>
  52   50  #include <locale.h>
  53   51  #include <string.h>
  54   52  #include <unistd.h>
  55   53  #include <regexpr.h>
↓ open down ↓ 310 lines elided ↑ open up ↑
 366  364   *      Note REG_ESUB Can't happen- 9 is no longer max num of subexpressions
 367  365   *      To do your errors right use xregerr() to get the regcomp error
 368  366   *      string and print that.
 369  367   *
 370  368   * |    regcomp/regexec              |  Compile/step/advance                |
 371  369   * +---------------------------------+--------------------------------------+
 372  370   * 0 REG_OK       Pattern matched       1  - Pattern matched
 373  371   * 1 REG_NOMATCH  No match              0  - Pattern didn't match
 374  372   * 2 REG_ECOLLATE Bad collation elmnt.  67 - Returned by compile on mbtowc err
 375  373   * 3 REG_EESCAPE  trailing \ in patrn   45 - } expected after \.
 376      - * 4 REG_ENEWLINE \n before end pattrn  36 - Illegal or missing delimiter.
 377      - * 5 REG_ENSUB    Over 9 \( \) pairs    43 - Too many \(
 378  374   * 6 REG_ESUBREG  Bad number in \[0-9]  25 - ``\digit'' out of range.
 379  375   * 7 REG_EBRACK   [ ] inbalance         49 - [ ] imbalance.
 380  376   * 8 REG_EPAREN   ( ) inbalance         42 - \(~\) imbalance.
 381  377   * 9 REG_EBRACE   \{ \} inbalance       45 - } expected after \.
 382  378   * 10 REG_ERANGE  bad range endpoint    11 - Range endpoint too large.
 383  379   * 11 REG_ESPACE  no memory for pattern 50 - Regular expression overflow.
 384  380   * 12 REG_BADRPT  invalid repetition    36 - Illegal or missing delimiter.
 385  381   * 13 REG_ECTYPE  invalid char-class    67 - illegal byte sequence
 386  382   * 14 REG_BADPAT  syntax error          50 - Regular expression overflow.
 387  383   * 15 REG_BADBR   \{ \} contents bad    46 - First number exceeds 2nd in \{~\}
 388      - * 16 REG_EFATAL  internal error        50 - Regular expression overflow.
 389  384   * 17 REG_ECHAR   bad mulitbyte char    67 - illegal byte sequence
 390      - * 18 REG_STACK   stack overflow        50 - Regular expression overflow.
 391      - * 19 REG_ENOSYS  function not supported 50- Regular expression overflow.
 392  385   *
 393  386   *      For reference here's the compile/step errno's. We don't generate
 394  387   *      41 here - it's done earlier, nor 44 since we can't tell if from 46.
 395  388   *
 396  389   *      11 - Range endpoint too large.
 397  390   *      16 - Bad number.
 398  391   *      25 - ``\digit'' out of range.
 399  392   *      36 - Illegal or missing delimiter.
 400  393   *      41 - No remembered search string.
 401  394   *      42 - \(~\) imbalance.
↓ open down ↓ 8 lines elided ↑ open up ↑
 410  403  static int
 411  404  map_errnos(int Errno)
 412  405  {
 413  406          switch (Errno) {
 414  407          case REG_ECOLLATE:
 415  408                  regerrno = 67;
 416  409                  break;
 417  410          case REG_EESCAPE:
 418  411                  regerrno = 45;
 419  412                  break;
 420      -        case REG_ENEWLINE:
 421      -                regerrno = 36;
 422      -                break;
 423      -        case REG_ENSUB:
 424      -                regerrno = 43;
 425      -                break;
 426  413          case REG_ESUBREG:
 427  414                  regerrno = 25;
 428  415                  break;
 429  416          case REG_EBRACK:
 430  417                  regerrno = 49;
 431  418                  break;
 432  419          case REG_EPAREN:
 433  420                  regerrno = 42;
 434  421                  break;
 435  422          case REG_EBRACE:
↓ open down ↓ 10 lines elided ↑ open up ↑
 446  433                  break;
 447  434          case REG_ECTYPE:
 448  435                  regerrno = 67;
 449  436                  break;
 450  437          case REG_BADPAT:
 451  438                  regerrno = 50;
 452  439                  break;
 453  440          case REG_BADBR:
 454  441                  regerrno = 46;
 455  442                  break;
 456      -        case REG_EFATAL:
 457      -                regerrno = 50;
 458      -                break;
 459  443          case REG_ECHAR:
 460  444                  regerrno = 67;
 461  445                  break;
 462      -        case REG_STACK:
 463      -                regerrno = 50;
 464      -                break;
 465      -        case REG_ENOSYS:
 466      -                regerrno = 50;
 467      -                break;
 468  446          default:
 469  447                  regerrno = 50;
 470  448                  break;
 471  449          }
 472  450          return (regerrno);
 473  451  }
 474  452  
 475  453  /*
 476  454   *  This is a routine to clean up the subtle substructure of the struct
 477  455   *  regex_comp type for use by clients of this module.  Since the struct
↓ open down ↓ 19 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX