/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Bell Laboratories25*26* time conversion support27*/2829#include <ast.h>30#include <tm.h>31#include <ctype.h>3233/*34* return the tab table index that matches s ignoring case and .'s35* tm_data.format checked if tminfo.format!=tm_data.format36*37* ntab and nsuf are the number of elements in tab and suf,38* -1 for 0 sentinel39*40* all isalpha() chars in str must match41* suf is a table of nsuf valid str suffixes42* if e is non-null then it will point to first unmatched char in str43* which will always be non-isalpha()44*/4546int47tmlex(register const char* s, char** e, char** tab, int ntab, char** suf, int nsuf)48{49register char** p;50register char* x;51register int n;5253for (p = tab, n = ntab; n-- && (x = *p); p++)54if (*x && *x != '%' && tmword(s, e, x, suf, nsuf))55return p - tab;56if (tm_info.format != tm_data.format && tab >= tm_info.format && tab < tm_info.format + TM_NFORM)57{58tab = tm_data.format + (tab - tm_info.format);59if (suf && tab >= tm_info.format && tab < tm_info.format + TM_NFORM)60suf = tm_data.format + (suf - tm_info.format);61for (p = tab, n = ntab; n-- && (x = *p); p++)62if (*x && *x != '%' && tmword(s, e, x, suf, nsuf))63return p - tab;64}65return -1;66}676869