(preg, string, nmatch, pmatch, eflags)
| 4805 | We return 0 if we find a match and REG_NOMATCH if not. */ |
| 4806 | |
| 4807 | int |
| 4808 | regexec (preg, string, nmatch, pmatch, eflags) |
| 4809 | const regex_t *preg; |
| 4810 | const char *string; |
| 4811 | size_t nmatch; |
| 4812 | regmatch_t pmatch[]; |
| 4813 | int eflags; |
| 4814 | { |
| 4815 | int ret; |
| 4816 | struct re_registers regs; |
| 4817 | regex_t private_preg; |
| 4818 | int len = strlen (string); |
| 4819 | boolean want_reg_info = !preg->no_sub && nmatch > 0; |
| 4820 | |
| 4821 | private_preg = *preg; |
| 4822 | |
| 4823 | private_preg.not_bol = !!(eflags & REG_NOTBOL); |
| 4824 | private_preg.not_eol = !!(eflags & REG_NOTEOL); |
| 4825 | |
| 4826 | /* The user has told us exactly how many registers to return |
| 4827 | information about, via `nmatch'. We have to pass that on to the |
| 4828 | matching routines. */ |
| 4829 | private_preg.regs_allocated = REGS_FIXED; |
| 4830 | |
| 4831 | if (want_reg_info) |
| 4832 | { |
| 4833 | regs.num_regs = nmatch; |
| 4834 | regs.start = TALLOC (nmatch, regoff_t); |
| 4835 | regs.end = TALLOC (nmatch, regoff_t); |
| 4836 | if (regs.start == NULL || regs.end == NULL) |
| 4837 | return (int) REG_NOMATCH; |
| 4838 | } |
| 4839 | |
| 4840 | /* Perform the searching operation. */ |
| 4841 | ret = re_search (&private_preg, string, len, |
| 4842 | /* start: */ 0, /* range: */ len, |
| 4843 | want_reg_info ? ®s : (struct re_registers *) 0); |
| 4844 | |
| 4845 | /* Copy the register information to the POSIX structure. */ |
| 4846 | if (want_reg_info) |
| 4847 | { |
| 4848 | if (ret >= 0) |
| 4849 | { |
| 4850 | unsigned r; |
| 4851 | |
| 4852 | for (r = 0; r < nmatch; r++) |
| 4853 | { |
| 4854 | pmatch[r].rm_so = regs.start[r]; |
| 4855 | pmatch[r].rm_eo = regs.end[r]; |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | /* If we needed the temporary register info, free the space now. */ |
| 4860 | free (regs.start); |
| 4861 | free (regs.end); |
| 4862 | } |
| 4863 | |
| 4864 | /* We want zero return to mean success, unlike `re_search'. */ |
no test coverage detected