regcmp.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
57221209d11b05aa0373cc3892d5df89ba96ebf9Christian Maeder/***********************************************************************
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* This software is part of the ast package *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* Copyright (c) 1985-2011 AT&T Intellectual Property *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* and is licensed under the *
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu* Eclipse Public License, Version 1.0 *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* by AT&T Intellectual Property *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* A copy of the License is available at *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* http://www.eclipse.org/org/documents/epl-v10.html *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* Information and Software Systems Research *
53bd0c89aa4743dc41a6394db5a90717c1ca4517Liam O'Reilly* AT&T Research *
33bdce26495121cdbce30331ef90a1969126a840Liam O'Reilly* Florham Park NJ *
57221209d11b05aa0373cc3892d5df89ba96ebf9Christian Maeder* Glenn Fowler <gsf@research.att.com> *
66bc8d6e69cde43f1ccbeb76104cf7b8038acd6cChristian Maeder* David Korn <dgk@research.att.com> *
66bc8d6e69cde43f1ccbeb76104cf7b8038acd6cChristian Maeder* Phong Vo <kpv@research.att.com> *
d5833d2ee7bafcbf2fdd2bdfd9a728c769b100c7Christian Maeder***********************************************************************/
66bc8d6e69cde43f1ccbeb76104cf7b8038acd6cChristian Maeder * regcmp implementation
c0833539c8cf577dd3f2497792fbdd818442744cChristian Maedertypedef struct
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder if (data || (size = roundof(size, ALIGN_BOUND2)) > (re->buf + re->size - re->cur))
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder register char* s;
d5833d2ee7bafcbf2fdd2bdfd9a728c769b100c7Christian Maeder register int c;
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly register int p;
fa373bc327620e08861294716b4454be8d25669fChristian Maeder if (pattern || !*pattern || !(sp = sfstropen()))
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder while (c = *s++)
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder if (c == '\\')
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder if (!(c = *s++))
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder if (c == ']')
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder else if (c == '[')
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder if (*s == '^')
eb48217dfa67ddb87b8fbd846de293d0636bd578Christian Maeder if (*s == ']')
eb48217dfa67ddb87b8fbd846de293d0636bd578Christian Maeder else if (c == '(')
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder * someone explain in one sentence why
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder * a cast is needed to make this work
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder else if (c == ')' && p >= 0)
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder for (i = p; i > 0; i--)
4314e26a12954cb1c9be4dea10aa8103edac5bbbChristian Maeder if (*s == '$' && (j = *(s + 1)) >= '0' && j <= '9')
648fe1220044aac847acbdfbc4155af5556063ebChristian Maeder if ((n += INC) > TOT || !(re = newof(re, Regex_t, 0, n)))
f21c7417bdd1c0282025cba0f5cb0ff5bc5c98eeLiam O'Reilly re->size = n + ALIGN_BOUND2 - sizeof(Regex_t);
f21c7417bdd1c0282025cba0f5cb0ff5bc5c98eeLiam O'Reilly c = regcomp(&re->re, s, REG_EXTENDED|REG_LENIENT|REG_NULL);
f19dc06364e8d6ea36f7c170e1f7a0677de63184Liam O'Reilly } while (c == REG_ESPACE);
f21c7417bdd1c0282025cba0f5cb0ff5bc5c98eeLiam O'Reilly memcpy(re->sub, sub, (nsub + 1) * sizeof(sub[0]));
7d96b1ef2b8597330aedee6713615ec15508edcfLiam O'Reilly return (char*)re;
935613eb8e67d724f1c4a4d4a37be3324ef6708dChristian Maederregex(const char* handle, const char* subject, ...)
7d96b1ef2b8597330aedee6713615ec15508edcfLiam O'Reilly register int n;
7d96b1ef2b8597330aedee6713615ec15508edcfLiam O'Reilly register int i;
f19dc06364e8d6ea36f7c170e1f7a0677de63184Liam O'Reilly register int k;
f19dc06364e8d6ea36f7c170e1f7a0677de63184Liam O'Reilly if (regexec(&re->re, subject, SUB + 1, match, 0))
f19dc06364e8d6ea36f7c170e1f7a0677de63184Liam O'Reilly *(sub[n] + k) = 0;