14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*8462SApril.Chin@Sun.COM * Copyright (c) 1985-2008 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 7*8462SApril.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 * return the tab table index that matches s ignoring case and .'s 364887Schin * tm_data.format checked if tminfo.format!=tm_data.format 374887Schin * 384887Schin * ntab and nsuf are the number of elements in tab and suf, 394887Schin * -1 for 0 sentinel 404887Schin * 414887Schin * all isalpha() chars in str must match 424887Schin * suf is a table of nsuf valid str suffixes 434887Schin * if e is non-null then it will point to first unmatched char in str 444887Schin * which will always be non-isalpha() 454887Schin */ 464887Schin 474887Schin int 484887Schin tmlex(register const char* s, char** e, char** tab, int ntab, char** suf, int nsuf) 494887Schin { 504887Schin register char** p; 514887Schin register char* x; 524887Schin register int n; 534887Schin 544887Schin for (p = tab, n = ntab; n-- && (x = *p); p++) 554887Schin if (*x && *x != '%' && tmword(s, e, x, suf, nsuf)) 564887Schin return p - tab; 574887Schin if (tm_info.format != tm_data.format && tab >= tm_info.format && tab < tm_info.format + TM_NFORM) 584887Schin { 594887Schin tab = tm_data.format + (tab - tm_info.format); 604887Schin if (suf && tab >= tm_info.format && tab < tm_info.format + TM_NFORM) 614887Schin suf = tm_data.format + (suf - tm_info.format); 624887Schin for (p = tab, n = ntab; n-- && (x = *p); p++) 634887Schin if (*x && *x != '%' && tmword(s, e, x, suf, nsuf)) 644887Schin return p - tab; 654887Schin } 664887Schin return -1; 674887Schin } 68