Header And Logo

PostgreSQL
| The world's most advanced open source database.

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  * IDENTIFICATION
00006  *    src/timezone/scheck.c
00007  */
00008 
00009 #include "postgres_fe.h"
00010 
00011 #include "private.h"
00012 
00013 
00014 const char *
00015 scheck(const char *string, const char *format)
00016 {
00017     char       *fbuf;
00018     const char *fp;
00019     char       *tp;
00020     int         c;
00021     const char *result;
00022     char        dummy;
00023 
00024     result = "";
00025     if (string == NULL || format == NULL)
00026         return result;
00027     fbuf = imalloc((int) (2 * strlen(format) + 4));
00028     if (fbuf == NULL)
00029         return result;
00030     fp = format;
00031     tp = fbuf;
00032     while ((*tp++ = c = *fp++) != '\0')
00033     {
00034         if (c != '%')
00035             continue;
00036         if (*fp == '%')
00037         {
00038             *tp++ = *fp++;
00039             continue;
00040         }
00041         *tp++ = '*';
00042         if (*fp == '*')
00043             ++fp;
00044         while (is_digit(*fp))
00045             *tp++ = *fp++;
00046         if (*fp == 'l' || *fp == 'h')
00047             *tp++ = *fp++;
00048         else if (*fp == '[')
00049             do
00050                 *tp++ = *fp++;
00051             while (*fp != '\0' && *fp != ']');
00052         if ((*tp++ = *fp++) == '\0')
00053             break;
00054     }
00055     *(tp - 1) = '%';
00056     *tp++ = 'c';
00057     *tp = '\0';
00058     if (sscanf(string, fbuf, &dummy) != 1)
00059         result = (char *) format;
00060     ifree(fbuf);
00061     return result;
00062 }