- regexec - match a regexp against a string */
| 794 | - regexec - match a regexp against a string |
| 795 | */ |
| 796 | int32_t |
| 797 | regexec( |
| 798 | regexp *prog, |
| 799 | const char *string ) |
| 800 | { |
| 801 | char *s; |
| 802 | |
| 803 | /* Be paranoid... */ |
| 804 | if (prog == NULL || string == NULL) { |
| 805 | regerror("NULL parameter"); |
| 806 | return(0); |
| 807 | } |
| 808 | |
| 809 | /* Check validity of program. */ |
| 810 | if (UCHARAT(prog->program) != MAGIC) { |
| 811 | regerror("corrupted program"); |
| 812 | return(0); |
| 813 | } |
| 814 | |
| 815 | /* If there is a "must appear" string, look for it. */ |
| 816 | if ( prog->regmust != NULL ) |
| 817 | { |
| 818 | s = (char *)string; |
| 819 | while ( ( s = strchr( s, prog->regmust[ 0 ] ) ) != NULL ) |
| 820 | { |
| 821 | if ( !strncmp( s, prog->regmust, prog->regmlen ) ) |
| 822 | break; /* Found it. */ |
| 823 | ++s; |
| 824 | } |
| 825 | if ( s == NULL ) /* Not present. */ |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | /* Mark beginning of line for ^ . */ |
| 830 | regbol = (char *)string; |
| 831 | |
| 832 | /* Simplest case: anchored match need be tried only once. */ |
| 833 | if ( prog->reganch ) |
| 834 | return regtry( prog, string ); |
| 835 | |
| 836 | /* Messy cases: unanchored match. */ |
| 837 | s = (char *)string; |
| 838 | if (prog->regstart != '\0') |
| 839 | /* We know what char it must start with. */ |
| 840 | while ((s = strchr(s, prog->regstart)) != NULL) { |
| 841 | if (regtry(prog, s)) |
| 842 | return(1); |
| 843 | s++; |
| 844 | } |
| 845 | else |
| 846 | /* We do not -- general case. */ |
| 847 | do { |
| 848 | if ( regtry( prog, s ) ) |
| 849 | return( 1 ); |
| 850 | } while ( *s++ != '\0' ); |
| 851 | |
| 852 | /* Failure. */ |
| 853 | return 0; |
no test coverage detected