1: /* 2: * @(#)scheck.c 1.1 scheck.c 3/4/87 3: */ 4: 5: /*LINTLIBRARY*/ 6: 7: #include "stdio.h" 8: #include "ctype.h" 9: 10: extern char * imalloc(); 11: 12: char * 13: scheck(string, format) 14: char * string; 15: char * format; 16: { 17: register char * fbuf; 18: register char * fp; 19: register char * tp; 20: register int c; 21: register char * result; 22: char dummy; 23: 24: result = ""; 25: if (string == NULL || format == NULL) 26: return result; 27: fbuf = imalloc(2 * strlen(format) + 4); 28: if (fbuf == NULL) 29: return result; 30: fp = format; 31: tp = fbuf; 32: while ((*tp++ = c = *fp++) != '\0') { 33: if (c != '%') 34: continue; 35: if (*fp == '%') { 36: *tp++ = *fp++; 37: continue; 38: } 39: *tp++ = '*'; 40: if (*fp == '*') 41: ++fp; 42: while (isascii(*fp) && isdigit(*fp)) 43: *tp++ = *fp++; 44: if (*fp == 'l' || *fp == 'h') 45: *tp++ = *fp++; 46: else if (*fp == '[') 47: do *tp++ = *fp++; 48: while (*fp != '\0' && *fp != ']'); 49: if ((*tp++ = *fp++) == '\0') 50: break; 51: } 52: *(tp - 1) = '%'; 53: *tp++ = 'c'; 54: *tp = '\0'; 55: if (sscanf(string, fbuf, &dummy) != 1) 56: result = format; 57: free(fbuf); 58: return result; 59: }