Deleted Added
full compact
regex.c (228072) regex.c (250125)
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;
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=0;
58 char *errbuf, *rxerr;
59
59
60 errbuf = (char*)flex_alloc(errbuf_sz *sizeof(char));
61 regerror (err, preg, errbuf, errbuf_sz);
62 snprintf (errbuf, errbuf_sz, "regcomp failed: %s\n", errbuf);
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);
63
64 flexfatal (errbuf);
65 free(errbuf);
68
69 flexfatal (errbuf);
70 free(errbuf);
71 free(rxerr);
66 }
67}
68
69/** Extract a copy of the match, or NULL if no match.
70 * @param m A match as returned by regexec().
71 * @param src The source string that was passed to regexec().
72 * @return The allocated string.
73 */
74char *regmatch_dup (regmatch_t * m, const char *src)
75{
76 char *str;
77 int len;
78
79 if (m == NULL || m->rm_so < 0)
80 return NULL;
81 len = m->rm_eo - m->rm_so;
82 str = (char *) flex_alloc ((len + 1) * sizeof (char));
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"));
83 strncpy (str, src + m->rm_so, len);
84 str[len] = 0;
85 return str;
86}
87
88/** Copy the match.
89 * @param m A match as returned by regexec().
90 * @param dest The destination buffer.

--- 74 unchanged lines hidden ---
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 ---