/[emacs]/emacs/src/regex.c
ViewVC logotype

Diff of /emacs/src/regex.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.176.2.3 by miles, Tue Jul 6 09:14:37 2004 UTC revision 1.176.2.4 by miles, Tue Jul 6 09:24:07 2004 UTC
# Line 2  Line 2 
2     0.12.  (Implements POSIX draft P1003.2/D11.2, except for some of the     0.12.  (Implements POSIX draft P1003.2/D11.2, except for some of the
3     internationalization features.)     internationalization features.)
4    
5     Copyright (C) 1993,94,95,96,97,98,99,2000 Free Software Foundation, Inc.     Copyright (C) 1993,94,95,96,97,98,99,2000,04  Free Software Foundation, Inc.
6    
7     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 217  char *realloc (); Line 217  char *realloc ();
217  /* Define the syntax stuff for \<, \>, etc.  */  /* Define the syntax stuff for \<, \>, etc.  */
218    
219  /* Sword must be nonzero for the wordchar pattern commands in re_match_2.  */  /* Sword must be nonzero for the wordchar pattern commands in re_match_2.  */
220  enum syntaxcode { Swhitespace = 0, Sword = 1 };  enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 };
221    
222  # ifdef SWITCH_ENUM_BUG  # ifdef SWITCH_ENUM_BUG
223  #  define SWITCH_ENUM_CAST(x) ((int)(x))  #  define SWITCH_ENUM_CAST(x) ((int)(x))
# Line 398  init_syntax_once () Line 398  init_syntax_once ()
398       if (ISALNUM (c))       if (ISALNUM (c))
399          re_syntax_table[c] = Sword;          re_syntax_table[c] = Sword;
400    
401     re_syntax_table['_'] = Sword;     re_syntax_table['_'] = Ssymbol;
402    
403     done = 1;     done = 1;
404  }  }
# Line 655  typedef enum Line 655  typedef enum
655    wordbound,    /* Succeeds if at a word boundary.  */    wordbound,    /* Succeeds if at a word boundary.  */
656    notwordbound, /* Succeeds if not at a word boundary.  */    notwordbound, /* Succeeds if not at a word boundary.  */
657    
658      symbeg,       /* Succeeds if at symbol beginning.  */
659      symend,       /* Succeeds if at symbol end.  */
660    
661          /* Matches any character whose syntax is specified.  Followed by          /* Matches any character whose syntax is specified.  Followed by
662             a byte which contains a syntax code, e.g., Sword.  */             a byte which contains a syntax code, e.g., Sword.  */
663    syntaxspec,    syntaxspec,
# Line 1094  print_partial_compiled_pattern (start, e Line 1097  print_partial_compiled_pattern (start, e
1097          case wordend:          case wordend:
1098            fprintf (stderr, "/wordend");            fprintf (stderr, "/wordend");
1099    
1100            case symbeg:
1101              printf ("/symbeg");
1102              break;
1103    
1104            case symend:
1105              printf ("/symend");
1106              break;
1107    
1108          case syntaxspec:          case syntaxspec:
1109            fprintf (stderr, "/syntaxspec");            fprintf (stderr, "/syntaxspec");
1110            mcnt = *p++;            mcnt = *p++;
# Line 3398  regex_compile (pattern, size, syntax, bu Line 3409  regex_compile (pattern, size, syntax, bu
3409                BUF_PUSH (wordend);                BUF_PUSH (wordend);
3410                break;                break;
3411    
3412                case '_':
3413                  if (syntax & RE_NO_GNU_OPS)
3414                    goto normal_char;
3415                  laststart = b;
3416                  PATFETCH (c);
3417                  if (c == '<')
3418                    BUF_PUSH (symbeg);
3419                  else if (c == '>')
3420                    BUF_PUSH (symend);
3421                  else
3422                    FREE_STACK_RETURN (REG_BADPAT);
3423                  break;
3424    
3425              case 'b':              case 'b':
3426                if (syntax & RE_NO_GNU_OPS)                if (syntax & RE_NO_GNU_OPS)
3427                  goto normal_char;                  goto normal_char;
# Line 3890  analyse_first (p, pend, fastmap, multiby Line 3914  analyse_first (p, pend, fastmap, multiby
3914          case notwordbound:          case notwordbound:
3915          case wordbeg:          case wordbeg:
3916          case wordend:          case wordend:
3917            case symbeg:
3918            case symend:
3919            continue;            continue;
3920    
3921    
# Line 4654  mutually_exclusive_p (bufp, p1, p2) Line 4680  mutually_exclusive_p (bufp, p1, p2)
4680        break;        break;
4681    
4682      case wordend:      case wordend:
4683      case notsyntaxspec:        return ((re_opcode_t) *p1 == syntaxspec && p1[1] == Sword);
4684        case symend:
4685        return ((re_opcode_t) *p1 == syntaxspec        return ((re_opcode_t) *p1 == syntaxspec
4686                && p1[1] == (op2 == wordend ? Sword : p2[1]));                && (p1[1] == Ssymbol || p1[1] == Sword));
4687        case notsyntaxspec:
4688          return ((re_opcode_t) *p1 == syntaxspec && p1[1] == p2[1]);
4689    
4690      case wordbeg:      case wordbeg:
4691      case syntaxspec:        return ((re_opcode_t) *p1 == notsyntaxspec && p1[1] == Sword);
4692        case symbeg:
4693        return ((re_opcode_t) *p1 == notsyntaxspec        return ((re_opcode_t) *p1 == notsyntaxspec
4694                && p1[1] == (op2 == wordbeg ? Sword : p2[1]));                && (p1[1] == Ssymbol || p1[1] == Sword));
4695        case syntaxspec:
4696          return ((re_opcode_t) *p1 == notsyntaxspec && p1[1] == p2[1]);
4697    
4698      case wordbound:      case wordbound:
4699        return (((re_opcode_t) *p1 == notsyntaxspec        return (((re_opcode_t) *p1 == notsyntaxspec
# Line 5802  re_match_2_internal (bufp, string1, size Line 5834  re_match_2_internal (bufp, string1, size
5834                  }                  }
5835              }              }
5836            break;            break;
5837    
5838            case symbeg:
5839              DEBUG_PRINT1 ("EXECUTING symbeg.\n");
5840    
5841              /* We FAIL in one of the following cases: */
5842    
5843              /* Case 1: D is at the end of string.  */
5844              if (AT_STRINGS_END (d))
5845                goto fail;
5846              else
5847                {
5848                  /* C1 is the character before D, S1 is the syntax of C1, C2
5849                     is the character at D, and S2 is the syntax of C2.  */
5850                  re_wchar_t c1, c2;
5851                  int s1, s2;
5852    #ifdef emacs
5853                  int offset = PTR_TO_OFFSET (d);
5854                  int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
5855                  UPDATE_SYNTAX_TABLE (charpos);
5856    #endif
5857                  PREFETCH ();
5858                  c2 = RE_STRING_CHAR (d, dend - d);
5859                  s2 = SYNTAX (c2);
5860            
5861                  /* Case 2: S2 is neither Sword nor Ssymbol. */
5862                  if (s2 != Sword && s2 != Ssymbol)
5863                    goto fail;
5864    
5865                  /* Case 3: D is not at the beginning of string ... */
5866                  if (!AT_STRINGS_BEG (d))
5867                    {
5868                      GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
5869    #ifdef emacs
5870                      UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1);
5871    #endif
5872                      s1 = SYNTAX (c1);
5873    
5874                      /* ... and S1 is Sword or Ssymbol.  */
5875                      if (s1 == Sword || s1 == Ssymbol)
5876                        goto fail;
5877                    }
5878                }
5879              break;
5880    
5881            case symend:
5882              DEBUG_PRINT1 ("EXECUTING symend.\n");
5883    
5884              /* We FAIL in one of the following cases: */
5885    
5886              /* Case 1: D is at the beginning of string.  */
5887              if (AT_STRINGS_BEG (d))
5888                goto fail;
5889              else
5890                {
5891                  /* C1 is the character before D, S1 is the syntax of C1, C2
5892                     is the character at D, and S2 is the syntax of C2.  */
5893                  re_wchar_t c1, c2;
5894                  int s1, s2;
5895    #ifdef emacs
5896                  int offset = PTR_TO_OFFSET (d) - 1;
5897                  int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
5898                  UPDATE_SYNTAX_TABLE (charpos);
5899    #endif
5900                  GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
5901                  s1 = SYNTAX (c1);
5902    
5903                  /* Case 2: S1 is neither Ssymbol nor Sword.  */
5904                  if (s1 != Sword && s1 != Ssymbol)
5905                    goto fail;
5906    
5907                  /* Case 3: D is not at the end of string ... */
5908                  if (!AT_STRINGS_END (d))
5909                    {
5910                      PREFETCH_NOLIMIT ();
5911                      c2 = RE_STRING_CHAR (d, dend - d);
5912    #ifdef emacs
5913                      UPDATE_SYNTAX_TABLE_FORWARD (charpos);
5914    #endif
5915                      s2 = SYNTAX (c2);
5916    
5917                      /* ... and S2 is Sword or Ssymbol.  */
5918                      if (s2 == Sword || s2 == Ssymbol)
5919                        goto fail;
5920                    }
5921                }
5922              break;
5923    
5924          case syntaxspec:          case syntaxspec:
5925          case notsyntaxspec:          case notsyntaxspec:

Legend:
Removed from v.1.176.2.3  
changed lines
  Added in v.1.176.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26