! \brief Match pattern against string and store result in pmatch */
| 82 | |
| 83 | /*! \brief Match pattern against string and store result in pmatch */ |
| 84 | int reg_match(char *pattern, char *string, regmatch_t *pmatch) |
| 85 | { |
| 86 | regex_t preg; |
| 87 | |
| 88 | if (regcomp(&preg, pattern, REG_EXTENDED | REG_NEWLINE)) { |
| 89 | return -1; |
| 90 | } |
| 91 | if (preg.re_nsub > MAX_MATCH) { |
| 92 | regfree(&preg); |
| 93 | return -2; |
| 94 | } |
| 95 | if (regexec(&preg, string, MAX_MATCH, pmatch, 0)) { |
| 96 | regfree(&preg); |
| 97 | return -3; |
| 98 | } |
| 99 | regfree(&preg); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /*! \brief Match pattern against string and, if match succeeds, and replace string |