1 /*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Arthur David Olson of the National Cancer Institute. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)scheck.c 8.1 (Berkeley) 06/08/93"; 13 #endif /* not lint */ 14 15 #ifdef notdef 16 static char elsieid[] = "@(#)scheck.c 8.9"; 17 #endif 18 19 /*LINTLIBRARY*/ 20 21 #include <stdio.h> 22 #include <ctype.h> 23 #include <string.h> 24 #include <stdlib.h> 25 26 char * 27 scheck(string, format) 28 const char * const string; 29 const char * const format; 30 { 31 register char * fbuf; 32 register const char * fp; 33 register char * tp; 34 register int c; 35 register char * result; 36 char dummy; 37 38 result = ""; 39 if (string == NULL || format == NULL) 40 return result; 41 fbuf = malloc(2 * strlen(format) + 4); 42 if (fbuf == NULL) 43 return result; 44 fp = format; 45 tp = fbuf; 46 while ((*tp++ = c = *fp++) != '\0') { 47 if (c != '%') 48 continue; 49 if (*fp == '%') { 50 *tp++ = *fp++; 51 continue; 52 } 53 *tp++ = '*'; 54 if (*fp == '*') 55 ++fp; 56 while (isascii(*fp) && isdigit(*fp)) 57 *tp++ = *fp++; 58 if (*fp == 'l' || *fp == 'h') 59 *tp++ = *fp++; 60 else if (*fp == '[') 61 do *tp++ = *fp++; 62 while (*fp != '\0' && *fp != ']'); 63 if ((*tp++ = *fp++) == '\0') 64 break; 65 } 66 *(tp - 1) = '%'; 67 *tp++ = 'c'; 68 *tp = '\0'; 69 if (sscanf((char *)string, fbuf, &dummy) != 1) 70 result = (char *) format; 71 ifree(fbuf); 72 return result; 73 } 74