michael@0: /* michael@0: ** This file is in the public domain, so clarified as of michael@0: ** 2006-07-17 by Arthur David Olson. michael@0: */ michael@0: michael@0: #ifndef lint michael@0: #ifndef NOID michael@0: static char elsieid[] = "@(#)scheck.c 8.19"; michael@0: #endif /* !defined lint */ michael@0: #endif /* !defined NOID */ michael@0: michael@0: /*LINTLIBRARY*/ michael@0: michael@0: #include "private.h" michael@0: michael@0: const char * michael@0: scheck(string, format) michael@0: const char * const string; michael@0: const char * const format; michael@0: { michael@0: register char * fbuf; michael@0: register const char * fp; michael@0: register char * tp; michael@0: register int c; michael@0: register const char * result; michael@0: char dummy; michael@0: michael@0: result = ""; michael@0: if (string == NULL || format == NULL) michael@0: return result; michael@0: fbuf = imalloc((int) (2 * strlen(format) + 4)); michael@0: if (fbuf == NULL) michael@0: return result; michael@0: fp = format; michael@0: tp = fbuf; michael@0: while ((*tp++ = c = *fp++) != '\0') { michael@0: if (c != '%') michael@0: continue; michael@0: if (*fp == '%') { michael@0: *tp++ = *fp++; michael@0: continue; michael@0: } michael@0: *tp++ = '*'; michael@0: if (*fp == '*') michael@0: ++fp; michael@0: while (is_digit(*fp)) michael@0: *tp++ = *fp++; michael@0: if (*fp == 'l' || *fp == 'h') michael@0: *tp++ = *fp++; michael@0: else if (*fp == '[') michael@0: do *tp++ = *fp++; michael@0: while (*fp != '\0' && *fp != ']'); michael@0: if ((*tp++ = *fp++) == '\0') michael@0: break; michael@0: } michael@0: *(tp - 1) = '%'; michael@0: *tp++ = 'c'; michael@0: *tp = '\0'; michael@0: if (sscanf(string, fbuf, &dummy) != 1) michael@0: result = (char *) format; michael@0: ifree(fbuf); michael@0: return result; michael@0: }