regcoll.c revision 3e14f97f673e8a630f076077de35afdd43dc1587
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1985-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* http://www.opensource.org/licenses/cpl1.0.txt *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#pragma prototyped
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * regex collation symbol support
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "reglib.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <ccode.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef UCS_BYTE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define UCS_BYTE 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "ucs_names.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct Ucs_map_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ucs_attr_t attr[3];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ucs_code_t code;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* name;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Dtlink_t link;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct Ucs_map_s* next;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin} Ucs_map_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define setattr(a,i) ((a)[(i)>>5]|=(1<<((i)&((1<<5)-1))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define tstattr(a,i) ((a)[(i)>>5]&(1<<((i)&((1<<5)-1))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define clrattr(a,i) ((a)[(i)>>5]&=~(1<<((i)&((1<<5)-1))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic struct Local_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int fatal;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Dt_t* attrs;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Dt_t* names;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Dtdisc_t dtdisc;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if CC_NATIVE != CC_ASCII
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin unsigned char* a2n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin} local;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * initialize the writeable tables from the readonly data
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the tables are big enough to be concerned about text vs. data vs. bss
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * UCS_BYTE==0 100K
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * UCS_BYTE==1 20K
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic int
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chininitialize(void)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int i;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Ucs_map_t* a;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Ucs_map_t* w;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (local.fatal)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.dtdisc.link = offsetof(Ucs_map_t, link);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.dtdisc.key = offsetof(Ucs_map_t, name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.dtdisc.size = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(w = (Ucs_map_t*)malloc(sizeof(Ucs_map_t) * (elementsof(ucs_attrs) + elementsof(ucs_names)))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.fatal = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(local.attrs = dtopen(&local.dtdisc, Dttree)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin free(w);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.fatal = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(local.names = dtopen(&local.dtdisc, Dttree)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin free(w);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dtclose(local.attrs);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.fatal = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (i = 0; i < elementsof(ucs_attrs); i++, w++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin memcpy(w, &ucs_attrs[i], offsetof(Ucs_dat_t, table));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin w->name = ucs_strings[ucs_attrs[i].table] + ucs_attrs[i].index;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin w->next = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dtinsert(local.attrs, w);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (i = 0; i < elementsof(ucs_names); i++, w++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin memcpy(w, &ucs_names[i], offsetof(Ucs_dat_t, table));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin w->name = ucs_strings[ucs_names[i].table] + ucs_names[i].index;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin w->next = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (a = (Ucs_map_t*)dtsearch(local.names, w))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (a->next)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin a = a->next;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin a->next = w;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dtinsert(local.names, w);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if CC_NATIVE != CC_ASCII
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin local.a2n = ccmap(CC_ASCII, CC_NATIVE);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return the collating symbol delimited by [c c], where c is either '=' or '.'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * s points to the first char after the initial [
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if e!=0 it is set to point to the next char in s on return
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the collating symbol is converted to multibyte in <buf,size>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the return value is:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * -1 syntax error or buf not large enough
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * >=0 size with 0-terminated mb collation element
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * or ligature value in buf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinint
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinregcollate(register const char* s, char** e, char* buf, int size)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* u;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* b;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* x;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Ucs_map_t* a;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ucs_map_t* z;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* v;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int r;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int ul;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int term;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin wchar_t w[2];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ucs_attr_t attr[3];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (size < 2)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if ((term = *s++) != '.' && term != '=')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s--;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (*s == term && *(s + 1) == ']')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin t = s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mbchar(s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((n = (s - t)) == 1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*s == term && *(s + 1) == ']')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s += 2;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!local.attrs && initialize())
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin attr[0] = attr[1] = attr[2] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b = buf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin x = buf + size - 2;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin do
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin v = s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin u = b;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (;;)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(c = *s++))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (c == term)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(c = *s++))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (c != term)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (c != ']')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (c == ' ' || c == '-' && u > b && *s != ' ' && *s != '-')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (isupper(c))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin c = tolower(c);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (u > x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *u++ = c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *u = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (a = (Ucs_map_t*)dtmatch(local.attrs, b))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin setattr(attr, a->code);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (u < x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *u++ = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (b == buf)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (isupper(*v))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = UCS_UC;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (islower(*v))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = UCS_LC;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b = u;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } while (r > 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (b > buf && *(b - 1) == ' ')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b--;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *b = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin attr[0] &= ~((Ucs_attr_t)1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (ul)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tstattr(attr, UCS_UC) || tstattr(attr, UCS_LC))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin setattr(attr, ul);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (z = (Ucs_map_t*)dtmatch(local.names, buf))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for(;;)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (a = z; a; a = a->next)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((attr[0] & a->attr[0]) == attr[0] && (attr[1] & a->attr[1]) == attr[1] && (attr[2] & a->attr[2]) == attr[2])
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#if 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (a->code <= 0xff)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if CC_NATIVE != CC_ASCII
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin buf[0] = local.a2n[a->code];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin buf[0] = a->code;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin buf[r = 1] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin w[0] = a->code;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin w[1] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((r = wcstombs(buf, w, size)) > 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!ul)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin clrattr(attr, ul);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ul = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (r < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if ((n = s - t - 2) > (size - 1))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy(buf, t, n);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin buf[n] = 0;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (n == 1)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin r = n;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin for (t = buf; isalnum(*t); t++);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (!*t)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin r = n;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (*s++ != term || *s++ != ']')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s--;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (n > (size - 1))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin memcpy(buf, t, n);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin buf[r = n] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (e)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *e = (char*)s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return r;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}