96 |
96 |
#include <unistd.h>
|
97 |
97 |
#include <wchar.h>
|
98 |
98 |
|
99 |
|
#include "charclass.h"
|
100 |
|
|
101 |
99 |
#define DOLLAR '$'
|
102 |
100 |
#define DOT '.'
|
103 |
101 |
#define EOS '\0'
|
... | ... | |
466 |
464 |
const Char *pattern = *patternp + 1;
|
467 |
465 |
Char *bufnext = *bufnextp;
|
468 |
466 |
const Char *colon;
|
469 |
|
struct cclass *cc;
|
|
467 |
char cbuf[MB_LEN_MAX + 32];
|
|
468 |
wctype_t cc;
|
470 |
469 |
size_t len;
|
471 |
470 |
|
472 |
471 |
if ((colon = g_strchr(pattern, COLON)) == NULL ||
|
... | ... | |
474 |
473 |
return (1); /* not a character class */
|
475 |
474 |
|
476 |
475 |
len = (size_t)(colon - pattern);
|
477 |
|
for (cc = cclasses; cc->name != NULL; cc++) {
|
|
476 |
if (len + MB_LEN_MAX + 1 > sizeof (cbuf))
|
|
477 |
return (-1); /* invalid character class */
|
|
478 |
{
|
478 |
479 |
wchar_t w;
|
479 |
480 |
const Char *s1 = pattern;
|
480 |
|
const char *s2 = cc->name;
|
|
481 |
char *s2 = cbuf;
|
481 |
482 |
size_t n = len;
|
482 |
483 |
|
483 |
|
/* Are the strings the same? */
|
484 |
|
while (n > 0 && (w = (s1++)->wc) == *s2 && w != EOS) {
|
485 |
|
n--;
|
486 |
|
s2++;
|
|
484 |
/* Copy the string. */
|
|
485 |
while (n > 0) {
|
|
486 |
w = (s1++)->wc;
|
|
487 |
/* Only single byte characters. */
|
|
488 |
if (wctomb(s2, w) == 1) {
|
|
489 |
n--;
|
|
490 |
s2++;
|
|
491 |
} else {
|
|
492 |
return (-1); /* invalid character class */
|
|
493 |
}
|
487 |
494 |
}
|
488 |
|
if (n == 0 && *s2 == EOS)
|
489 |
|
break;
|
|
495 |
*s2 = EOS;
|
490 |
496 |
}
|
491 |
|
if (cc->name == NULL)
|
|
497 |
if ((cc = wctype(cbuf)) == 0)
|
492 |
498 |
return (-1); /* invalid character class */
|
493 |
499 |
bufnext->at = M_QUOTE;
|
494 |
500 |
(bufnext++)->wc = M_CLASS;
|
495 |
|
bufnext->at = (cc - &cclasses[0]);
|
496 |
|
(bufnext++)->wc = COLON;
|
|
501 |
bufnext->at = 0;
|
|
502 |
(bufnext++)->wc = cc;
|
497 |
503 |
*bufnextp = bufnext;
|
498 |
504 |
*patternp += len + 3;
|
499 |
505 |
|
... | ... | |
1080 |
1086 |
++pat;
|
1081 |
1087 |
while (((c = *pat++).at != M_QUOTE) || c.wc != M_END) {
|
1082 |
1088 |
if (c.at == M_QUOTE && c.wc == M_CLASS) {
|
1083 |
|
Char idx;
|
|
1089 |
Char cc;
|
1084 |
1090 |
|
1085 |
|
idx.at = pat->at;
|
1086 |
|
idx.wc = pat->wc;
|
1087 |
|
if (idx.at < NCCLASSES &&
|
1088 |
|
cclasses[idx.at].isctype(k.wc))
|
|
1091 |
cc.at = pat->at;
|
|
1092 |
cc.wc = pat->wc;
|
|
1093 |
if (iswctype(k.wc, cc.wc))
|
1089 |
1094 |
ok = 1;
|
1090 |
1095 |
++pat;
|
1091 |
1096 |
}
|