1 /* 2 * $FreeBSD: src/usr.sbin/zic/scheck.c,v 1.4 1999/08/28 01:21:19 peter Exp $ 3 */ 4 /*LINTLIBRARY*/ 5 6 #include "private.h" 7 8 const char * 9 scheck(const char * const string, const char * const format) 10 { 11 char *fbuf; 12 const char *fp; 13 char *tp; 14 int c; 15 const char *result; 16 char dummy; 17 18 result = ""; 19 if (string == NULL || format == NULL) 20 return result; 21 fbuf = imalloc((int) (2 * strlen(format) + 4)); 22 if (fbuf == NULL) 23 return result; 24 fp = format; 25 tp = fbuf; 26 while ((*tp++ = c = *fp++) != '\0') { 27 if (c != '%') 28 continue; 29 if (*fp == '%') { 30 *tp++ = *fp++; 31 continue; 32 } 33 *tp++ = '*'; 34 if (*fp == '*') 35 ++fp; 36 while (is_digit(*fp)) 37 *tp++ = *fp++; 38 if (*fp == 'l' || *fp == 'h') 39 *tp++ = *fp++; 40 else if (*fp == '[') 41 do *tp++ = *fp++; 42 while (*fp != '\0' && *fp != ']'); 43 if ((*tp++ = *fp++) == '\0') 44 break; 45 } 46 *(tp - 1) = '%'; 47 *tp++ = 'c'; 48 *tp = '\0'; 49 if (sscanf(string, fbuf, &dummy) != 1) 50 result = (char *) format; 51 ifree(fbuf); 52 return result; 53 } 54