~ubuntu-branches/debian/sid/postgresql-9.3/sid

« back to all changes in this revision

Viewing changes to src/timezone/scheck.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 05:39:52 UTC
  • Revision ID: package-import@ubuntu.com-20130508053952-1j7uilp7mjtrvq8q
Tags: upstream-9.3~beta1
ImportĀ upstreamĀ versionĀ 9.3~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *        src/timezone/scheck.c
 
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
}