1 /* 2 ** This file is in the public domain, so clarified as of 3 ** 2006-07-17 by Arthur David Olson. 4 */ 5 6 #ifndef lint 7 #ifndef NOID 8 static const char elsieid[] = "@(#)scheck.c 8.19"; 9 #endif /* !defined lint */ 10 #endif /* !defined NOID */ 11 12 #ifndef lint 13 static const char rcsid[] = 14 "$FreeBSD: stable/9/contrib/tzcode/zic/scheck.c 192625 2009-05-23 06:31:50Z edwin $"; 15 #endif /* not lint */ 16 17 /*LINTLIBRARY*/ 18 19 #include "private.h" 20 21 const char * scheck(string,format)22scheck(string, format) 23 const char * const string; 24 const char * const format; 25 { 26 register char * fbuf; 27 register const char * fp; 28 register char * tp; 29 register int c; 30 register const char * result; 31 char dummy; 32 33 result = ""; 34 if (string == NULL || format == NULL) 35 return result; 36 fbuf = imalloc((int) (2 * strlen(format) + 4)); 37 if (fbuf == NULL) 38 return result; 39 fp = format; 40 tp = fbuf; 41 while ((*tp++ = c = *fp++) != '\0') { 42 if (c != '%') 43 continue; 44 if (*fp == '%') { 45 *tp++ = *fp++; 46 continue; 47 } 48 *tp++ = '*'; 49 if (*fp == '*') 50 ++fp; 51 while (is_digit(*fp)) 52 *tp++ = *fp++; 53 if (*fp == 'l' || *fp == 'h') 54 *tp++ = *fp++; 55 else if (*fp == '[') 56 do *tp++ = *fp++; 57 while (*fp != '\0' && *fp != ']'); 58 if ((*tp++ = *fp++) == '\0') 59 break; 60 } 61 *(tp - 1) = '%'; 62 *tp++ = 'c'; 63 *tp = '\0'; 64 if (sscanf(string, fbuf, &dummy) != 1) 65 result = (char *) format; 66 ifree(fbuf); 67 return result; 68 } 69