Back to index

glibc  2.9
scheck.c
Go to the documentation of this file.
00001 /*
00002 ** This file is in the public domain, so clarified as of
00003 ** 2006-07-17 by Arthur David Olson.
00004 */
00005 
00006 #ifndef lint
00007 #ifndef NOID
00008 static char   elsieid[] = "@(#)scheck.c   8.19";
00009 #endif /* !defined lint */
00010 #endif /* !defined NOID */
00011 
00012 /*LINTLIBRARY*/
00013 
00014 #include "private.h"
00015 
00016 const char *
00017 scheck(string, format)
00018 const char * const   string;
00019 const char * const   format;
00020 {
00021        register char *             fbuf;
00022        register const char *       fp;
00023        register char *             tp;
00024        register int         c;
00025        register const char *       result;
00026        char                 dummy;
00027 
00028        result = "";
00029        if (string == NULL || format == NULL)
00030               return result;
00031        fbuf = imalloc((int) (2 * strlen(format) + 4));
00032        if (fbuf == NULL)
00033               return result;
00034        fp = format;
00035        tp = fbuf;
00036        while ((*tp++ = c = *fp++) != '\0') {
00037               if (c != '%')
00038                      continue;
00039               if (*fp == '%') {
00040                      *tp++ = *fp++;
00041                      continue;
00042               }
00043               *tp++ = '*';
00044               if (*fp == '*')
00045                      ++fp;
00046               while (is_digit(*fp))
00047                      *tp++ = *fp++;
00048               if (*fp == 'l' || *fp == 'h')
00049                      *tp++ = *fp++;
00050               else if (*fp == '[')
00051                      do *tp++ = *fp++;
00052                             while (*fp != '\0' && *fp != ']');
00053               if ((*tp++ = *fp++) == '\0')
00054                      break;
00055        }
00056        *(tp - 1) = '%';
00057        *tp++ = 'c';
00058        *tp = '\0';
00059        if (sscanf(string, fbuf, &dummy) != 1)
00060               result = (char *) format;
00061        ifree(fbuf);
00062        return result;
00063 }