14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * David Korn <dgk@research.att.com> *
194887Schin * Phong Vo <kpv@research.att.com> *
204887Schin * *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin * Glenn Fowler
254887Schin * AT&T Bell Laboratories
264887Schin *
274887Schin * time conversion support
284887Schin */
294887Schin
304887Schin #include <ast.h>
314887Schin #include <tm.h>
324887Schin #include <ctype.h>
334887Schin
344887Schin /*
354887Schin * match s against t ignoring case and .'s
364887Schin *
374887Schin * suf is an n element table of suffixes that may trail s
384887Schin * if all isalpha() chars in s match then 1 is returned
394887Schin * and if e is non-null it will point to the first unmatched
404887Schin * char in s, otherwise 0 is returned
414887Schin */
424887Schin
434887Schin int
tmword(register const char * s,char ** e,register const char * t,char ** suf,int n)444887Schin tmword(register const char* s, char** e, register const char* t, char** suf, int n)
454887Schin {
464887Schin register int c;
474887Schin const char* b;
484887Schin
494887Schin if (*s && *t)
504887Schin {
514887Schin b = s;
524887Schin while (c = *s++)
534887Schin {
544887Schin if (c != '.')
554887Schin {
564887Schin if (!isalpha(c) || c != *t && (islower(c) ? toupper(c) : tolower(c)) != *t)
574887Schin break;
584887Schin t++;
594887Schin }
604887Schin }
614887Schin s--;
624887Schin if (!isalpha(c))
634887Schin {
644887Schin if (c == '_')
654887Schin s++;
664887Schin if (e)
674887Schin *e = (char*)s;
684887Schin return s > b;
694887Schin }
704887Schin if (!*t && s > (b + 1))
714887Schin {
724887Schin b = s;
734887Schin while (n-- && (t = *suf++))
744887Schin {
754887Schin s = b;
764887Schin while (isalpha(c = *s++) && (c == *t || (islower(c) ? toupper(c) : tolower(c)) == *t)) t++;
774887Schin if (!*t && !isalpha(c))
784887Schin {
794887Schin if (c != '_')
804887Schin s--;
814887Schin if (e)
824887Schin *e = (char*)s;
834887Schin return 1;
844887Schin }
854887Schin }
864887Schin }
874887Schin }
884887Schin return 0;
894887Schin }
90