1*39984Sbostic #ifndef lint 2*39984Sbostic #ifndef NOID 3*39984Sbostic static char elsieid[] = "@(#)scheck.c 8.9"; 4*39984Sbostic #endif /* !defined lint */ 5*39984Sbostic #endif /* !defined NOID */ 6*39984Sbostic 7*39984Sbostic /*LINTLIBRARY*/ 8*39984Sbostic 9*39984Sbostic #include "stdio.h" 10*39984Sbostic #include "ctype.h" 11*39984Sbostic #include "string.h" 12*39984Sbostic #include "stdlib.h" 13*39984Sbostic #include "nonstd.h" 14*39984Sbostic 15*39984Sbostic extern char * imalloc P((int n)); 16*39984Sbostic extern void ifree P((char * p)); 17*39984Sbostic 18*39984Sbostic char * 19*39984Sbostic scheck(string, format) 20*39984Sbostic const char * const string; 21*39984Sbostic const char * const format; 22*39984Sbostic { 23*39984Sbostic register char * fbuf; 24*39984Sbostic register const char * fp; 25*39984Sbostic register char * tp; 26*39984Sbostic register int c; 27*39984Sbostic register char * result; 28*39984Sbostic char dummy; 29*39984Sbostic 30*39984Sbostic result = ""; 31*39984Sbostic if (string == NULL || format == NULL) 32*39984Sbostic return result; 33*39984Sbostic fbuf = imalloc(2 * strlen(format) + 4); 34*39984Sbostic if (fbuf == NULL) 35*39984Sbostic return result; 36*39984Sbostic fp = format; 37*39984Sbostic tp = fbuf; 38*39984Sbostic while ((*tp++ = c = *fp++) != '\0') { 39*39984Sbostic if (c != '%') 40*39984Sbostic continue; 41*39984Sbostic if (*fp == '%') { 42*39984Sbostic *tp++ = *fp++; 43*39984Sbostic continue; 44*39984Sbostic } 45*39984Sbostic *tp++ = '*'; 46*39984Sbostic if (*fp == '*') 47*39984Sbostic ++fp; 48*39984Sbostic while (isascii(*fp) && isdigit(*fp)) 49*39984Sbostic *tp++ = *fp++; 50*39984Sbostic if (*fp == 'l' || *fp == 'h') 51*39984Sbostic *tp++ = *fp++; 52*39984Sbostic else if (*fp == '[') 53*39984Sbostic do *tp++ = *fp++; 54*39984Sbostic while (*fp != '\0' && *fp != ']'); 55*39984Sbostic if ((*tp++ = *fp++) == '\0') 56*39984Sbostic break; 57*39984Sbostic } 58*39984Sbostic *(tp - 1) = '%'; 59*39984Sbostic *tp++ = 'c'; 60*39984Sbostic *tp = '\0'; 61*39984Sbostic if (sscanf(string, fbuf, &dummy) != 1) 62*39984Sbostic result = (char *) format; 63*39984Sbostic ifree(fbuf); 64*39984Sbostic return result; 65*39984Sbostic } 66