]> granicus.if.org Git - postgresql/blob - src/timezone/scheck.c
In a non-hashed Agg node, reset the "aggcontext" at group boundaries, instead
[postgresql] / src / timezone / scheck.c
1 /*
2  * This file is in the public domain, so clarified as of
3  * 2006-07-17 by Arthur David Olson.
4  *
5  * IDENTIFICATION
6  *        $PostgreSQL: pgsql/src/timezone/scheck.c,v 1.9 2008/02/16 21:16:04 tgl Exp $
7  */
8
9 #include "postgres_fe.h"
10
11 #include "private.h"
12
13
14 const char *
15 scheck(const char *string, const char *format)
16 {
17         char       *fbuf;
18         const char *fp;
19         char       *tp;
20         int                     c;
21         const char *result;
22         char            dummy;
23
24         result = "";
25         if (string == NULL || format == NULL)
26                 return result;
27         fbuf = imalloc((int) (2 * strlen(format) + 4));
28         if (fbuf == NULL)
29                 return result;
30         fp = format;
31         tp = fbuf;
32         while ((*tp++ = c = *fp++) != '\0')
33         {
34                 if (c != '%')
35                         continue;
36                 if (*fp == '%')
37                 {
38                         *tp++ = *fp++;
39                         continue;
40                 }
41                 *tp++ = '*';
42                 if (*fp == '*')
43                         ++fp;
44                 while (is_digit(*fp))
45                         *tp++ = *fp++;
46                 if (*fp == 'l' || *fp == 'h')
47                         *tp++ = *fp++;
48                 else if (*fp == '[')
49                         do
50                                 *tp++ = *fp++;
51                         while (*fp != '\0' && *fp != ']');
52                 if ((*tp++ = *fp++) == '\0')
53                         break;
54         }
55         *(tp - 1) = '%';
56         *tp++ = 'c';
57         *tp = '\0';
58         if (sscanf(string, fbuf, &dummy) != 1)
59                 result = (char *) format;
60         ifree(fbuf);
61         return result;
62 }