1/** regex - regular expression functions related to POSIX regex lib. */ 2 3/* This file is part of flex. */ 4 5/* Redistribution and use in source and binary forms, with or without */ 6/* modification, are permitted provided that the following conditions */ 7/* are met: */ 8 --- 41 unchanged lines hidden (view full) --- 50void flex_regcomp(regex_t *preg, const char *regex, int cflags) 51{ 52 int err; 53 54 memset (preg, 0, sizeof (regex_t)); 55 56 if ((err = regcomp (preg, regex, cflags)) != 0) { 57 const int errbuf_sz = 200; |
58 char *errbuf, *rxerr; |
59 |
60 errbuf = (char*)flex_alloc(errbuf_sz *sizeof(char)); 61 if (!errbuf) 62 flexfatal(_("Unable to allocate buffer to report regcomp")); 63 rxerr = (char*)flex_alloc(errbuf_sz *sizeof(char)); 64 if (!rxerr) 65 flexfatal(_("Unable to allocate buffer for regerror")); 66 regerror (err, preg, rxerr, errbuf_sz); 67 snprintf (errbuf, errbuf_sz, "regcomp for \"%s\" failed: %s", regex, rxerr); |
68 69 flexfatal (errbuf); 70 free(errbuf); |
71 free(rxerr); |
72 } 73} 74 75/** Extract a copy of the match, or NULL if no match. 76 * @param m A match as returned by regexec(). 77 * @param src The source string that was passed to regexec(). 78 * @return The allocated string. 79 */ 80char *regmatch_dup (regmatch_t * m, const char *src) 81{ 82 char *str; 83 int len; 84 85 if (m == NULL || m->rm_so < 0) 86 return NULL; 87 len = m->rm_eo - m->rm_so; 88 str = (char *) flex_alloc ((len + 1) * sizeof (char)); |
89 if (!str) 90 flexfatal(_("Unable to allocate a copy of the match")); |
91 strncpy (str, src + m->rm_so, len); 92 str[len] = 0; 93 return str; 94} 95 96/** Copy the match. 97 * @param m A match as returned by regexec(). 98 * @param dest The destination buffer. --- 74 unchanged lines hidden --- |