139984Sbostic #ifndef lint 239984Sbostic #ifndef NOID 339984Sbostic static char elsieid[] = "@(#)scheck.c 8.9"; 439984Sbostic #endif /* !defined lint */ 539984Sbostic #endif /* !defined NOID */ 639984Sbostic 739984Sbostic /*LINTLIBRARY*/ 839984Sbostic 9*46793Sbostic #include <stdio.h> 10*46793Sbostic #include <ctype.h> 11*46793Sbostic #include <string.h> 12*46793Sbostic #include <stdlib.h> 1339984Sbostic 1439984Sbostic char * 1539984Sbostic scheck(string, format) 1639984Sbostic const char * const string; 1739984Sbostic const char * const format; 1839984Sbostic { 1939984Sbostic register char * fbuf; 2039984Sbostic register const char * fp; 2139984Sbostic register char * tp; 2239984Sbostic register int c; 2339984Sbostic register char * result; 2439984Sbostic char dummy; 2539984Sbostic 2639984Sbostic result = ""; 2739984Sbostic if (string == NULL || format == NULL) 2839984Sbostic return result; 29*46793Sbostic fbuf = malloc(2 * strlen(format) + 4); 3039984Sbostic if (fbuf == NULL) 3139984Sbostic return result; 3239984Sbostic fp = format; 3339984Sbostic tp = fbuf; 3439984Sbostic while ((*tp++ = c = *fp++) != '\0') { 3539984Sbostic if (c != '%') 3639984Sbostic continue; 3739984Sbostic if (*fp == '%') { 3839984Sbostic *tp++ = *fp++; 3939984Sbostic continue; 4039984Sbostic } 4139984Sbostic *tp++ = '*'; 4239984Sbostic if (*fp == '*') 4339984Sbostic ++fp; 4439984Sbostic while (isascii(*fp) && isdigit(*fp)) 4539984Sbostic *tp++ = *fp++; 4639984Sbostic if (*fp == 'l' || *fp == 'h') 4739984Sbostic *tp++ = *fp++; 4839984Sbostic else if (*fp == '[') 4939984Sbostic do *tp++ = *fp++; 5039984Sbostic while (*fp != '\0' && *fp != ']'); 5139984Sbostic if ((*tp++ = *fp++) == '\0') 5239984Sbostic break; 5339984Sbostic } 5439984Sbostic *(tp - 1) = '%'; 5539984Sbostic *tp++ = 'c'; 5639984Sbostic *tp = '\0'; 57*46793Sbostic if (sscanf((char *)string, fbuf, &dummy) != 1) 5839984Sbostic result = (char *) format; 5939984Sbostic ifree(fbuf); 6039984Sbostic return result; 6139984Sbostic } 62