Skip to content

Commit fefe703

Browse files
author
Michael Meskes
committed
More cleaning up and removed some duplicates.
1 parent 34dc9ab commit fefe703

File tree

13 files changed

+164
-456
lines changed

13 files changed

+164
-456
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,5 +2225,9 @@ Tue, 14 Aug 2007 11:46:51 +0200
22252225
- Use '$n' for positional variables, '?' is still possible via ecpg
22262226
option.
22272227
- Cleaned up the sources a little bit.
2228+
2229+
Wed, 22 Aug 2007 08:41:33 +0200
2230+
2231+
- More cleaning up and removed some duplicates.
22282232
- Set ecpg library version to 6.0.
22292233
- Set ecpg version to 4.4.

src/interfaces/ecpg/pgtypeslib/dt.h

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.37 2007/08/14 10:01:53 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.38 2007/08/22 08:20:58 meskes Exp $ */
22

33
#ifndef DT_H
44
#define DT_H
@@ -310,31 +310,24 @@ do { \
310310
#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND)
311311
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
312312

313-
int DecodeTimeOnly(char **field, int *ftype,
314-
int nf, int *dtype,
315-
struct tm * tm, fsec_t *fsec, int *tzp);
316-
317-
int DecodeInterval(char **field, int *ftype,
318-
int nf, int *dtype,
319-
struct tm * tm, fsec_t *fsec);
320-
321-
int EncodeTimeOnly(struct tm * tm, fsec_t fsec, int *tzp, int style, char *str);
322-
int EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str, bool);
323-
int EncodeInterval(struct tm * tm, fsec_t fsec, int style, char *str);
324-
325-
int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
326-
327-
int DecodeUnits(int field, char *lowtoken, int *val);
328-
329-
bool CheckDateTokenTables(void);
330-
331-
int EncodeDateOnly(struct tm *, int, char *, bool);
332-
void GetEpochTime(struct tm *);
333-
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
334-
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
335-
void j2date(int, int *, int *, int *);
336-
void GetCurrentDateTime(struct tm *);
337-
int date2j(int, int, int);
313+
int DecodeTimeOnly(char **, int *, int, int *, struct tm *, fsec_t *, int *);
314+
int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *);
315+
int DecodeTime(char *, int, int *, struct tm *, fsec_t *);
316+
int EncodeTimeOnly(struct tm *, fsec_t, int *, int, char *);
317+
int EncodeDateTime(struct tm *, fsec_t, int *, char **, int, char *, bool);
318+
int EncodeInterval(struct tm *, fsec_t, int, char *);
319+
int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
320+
int DecodeUnits(int field, char *lowtoken, int *val);
321+
bool CheckDateTokenTables(void);
322+
int EncodeDateOnly(struct tm *, int, char *, bool);
323+
void GetEpochTime(struct tm *);
324+
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
325+
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
326+
void j2date(int, int *, int *, int *);
327+
void GetCurrentDateTime(struct tm *);
328+
int date2j(int, int, int);
329+
void TrimTrailingZeros(char *);
330+
void dt2time(double, int *, int *, int *, fsec_t *);
338331

339332
extern char *pgtypes_date_weekdays_short[];
340333
extern char *pgtypes_date_months[];

src/interfaces/ecpg/pgtypeslib/dt_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.41 2007/08/14 10:01:53 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.42 2007/08/22 08:20:58 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -743,7 +743,7 @@ EncodeDateOnly(struct tm * tm, int style, char *str, bool EuroDates)
743743
return TRUE;
744744
} /* EncodeDateOnly() */
745745

746-
static void
746+
void
747747
TrimTrailingZeros(char *str)
748748
{
749749
int len = strlen(str);
@@ -1090,7 +1090,7 @@ GetCurrentDateTime(struct tm * tm)
10901090
abstime2tm(time(NULL), &tz, tm, NULL);
10911091
}
10921092

1093-
static void
1093+
void
10941094
dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
10951095
{
10961096
#ifdef HAVE_INT64_TIMESTAMP
@@ -1469,7 +1469,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm, bool EuroDates)
14691469
* Only check the lower limit on hours, since this same code
14701470
* can be used to represent time spans.
14711471
*/
1472-
static int
1472+
int
14731473
DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
14741474
{
14751475
char *cp;

src/interfaces/ecpg/pgtypeslib/interval.c

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/interval.c,v 1.36 2006/10/04 00:30:11 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/interval.c,v 1.37 2007/08/22 08:20:58 meskes Exp $ */
22

33
#include "postgres_fe.h"
44
#include <time.h>
@@ -13,90 +13,6 @@
1313
#include "pgtypes_error.h"
1414
#include "pgtypes_interval.h"
1515

16-
/* TrimTrailingZeros()
17-
* ... resulting from printing numbers with full precision.
18-
*/
19-
static void
20-
TrimTrailingZeros(char *str)
21-
{
22-
int len = strlen(str);
23-
24-
/* chop off trailing zeros... but leave at least 2 fractional digits */
25-
while (*(str + len - 1) == '0' && *(str + len - 3) != '.')
26-
{
27-
len--;
28-
*(str + len) = '\0';
29-
}
30-
}
31-
32-
/* DecodeTime()
33-
* Decode time string which includes delimiters.
34-
* Only check the lower limit on hours, since this same code
35-
* can be used to represent time spans.
36-
*/
37-
static int
38-
DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
39-
{
40-
char *cp;
41-
42-
*tmask = DTK_TIME_M;
43-
44-
tm->tm_hour = strtol(str, &cp, 10);
45-
if (*cp != ':')
46-
return -1;
47-
str = cp + 1;
48-
tm->tm_min = strtol(str, &cp, 10);
49-
if (*cp == '\0')
50-
{
51-
tm->tm_sec = 0;
52-
*fsec = 0;
53-
}
54-
else if (*cp != ':')
55-
return -1;
56-
else
57-
{
58-
str = cp + 1;
59-
tm->tm_sec = strtol(str, &cp, 10);
60-
if (*cp == '\0')
61-
*fsec = 0;
62-
else if (*cp == '.')
63-
{
64-
#ifdef HAVE_INT64_TIMESTAMP
65-
char fstr[MAXDATELEN + 1];
66-
67-
/*
68-
* OK, we have at most six digits to work with. Let's construct a
69-
* string and then do the conversion to an integer.
70-
*/
71-
strncpy(fstr, (cp + 1), 7);
72-
strcpy(fstr + strlen(fstr), "000000");
73-
*(fstr + 6) = '\0';
74-
*fsec = strtol(fstr, &cp, 10);
75-
#else
76-
str = cp;
77-
*fsec = strtod(str, &cp);
78-
#endif
79-
if (*cp != '\0')
80-
return -1;
81-
}
82-
else
83-
return -1;
84-
}
85-
86-
/* do a sanity check */
87-
#ifdef HAVE_INT64_TIMESTAMP
88-
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
89-
tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= USECS_PER_SEC)
90-
return -1;
91-
#else
92-
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
93-
tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= 1)
94-
return -1;
95-
#endif
96-
97-
return 0;
98-
} /* DecodeTime() */
99-
10016
/* DecodeInterval()
10117
* Interpret previously parsed fields for general time interval.
10218
* Return 0 if decoded and -1 if problems.

src/interfaces/ecpg/pgtypeslib/timestamp.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -97,36 +97,6 @@ SetEpochTimestamp(void)
9797
return dt;
9898
} /* SetEpochTimestamp() */
9999

100-
static void
101-
dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
102-
{
103-
#ifdef HAVE_INT64_TIMESTAMP
104-
int64 time;
105-
#else
106-
double time;
107-
#endif
108-
109-
time = jd;
110-
111-
#ifdef HAVE_INT64_TIMESTAMP
112-
*hour = time / USECS_PER_HOUR;
113-
time -= (*hour) * USECS_PER_HOUR;
114-
*min = time / USECS_PER_MINUTE;
115-
time -= (*min) * USECS_PER_MINUTE;
116-
*sec = time / USECS_PER_SEC;
117-
*fsec = time - *sec * USECS_PER_SEC;
118-
*sec = time / USECS_PER_SEC;
119-
*fsec = time - *sec * USECS_PER_SEC;
120-
#else
121-
*hour = time / SECS_PER_HOUR;
122-
time -= (*hour) * SECS_PER_HOUR;
123-
*min = time / SECS_PER_MINUTE;
124-
time -= (*min) * SECS_PER_MINUTE;
125-
*sec = time;
126-
*fsec = time - *sec;
127-
#endif
128-
} /* dt2time() */
129-
130100
/* timestamp2tm()
131101
* Convert timestamp data type to POSIX time structure.
132102
* Note that year is _not_ 1900-based, but is an explicit full value.

src/interfaces/ecpg/preproc/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1998-2007, PostgreSQL Global Development Group
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.127 2007/08/14 10:01:53 meskes Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.128 2007/08/22 08:20:58 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -27,7 +27,7 @@ override CFLAGS += -Wno-error
2727
endif
2828
override CFLAGS += $(PTHREAD_CFLAGS)
2929

30-
OBJS= preproc.o type.o ecpg.o ecpg_keywords.o output.o parser.o \
30+
OBJS= preproc.o type.o ecpg.o output.o parser.o \
3131
keywords.o c_keywords.o ../ecpglib/typename.o descriptor.o variable.o \
3232
$(WIN32RES)
3333

@@ -57,7 +57,7 @@ else
5757
@$(missing) flex $< $@
5858
endif
5959

60-
c_keywords.o ecpg_keywords.o keywords.o preproc.o parser.o: preproc.h
60+
c_keywords.o keywords.o preproc.o parser.o: preproc.h
6161

6262
parser.c: $(top_srcdir)/src/backend/parser/parser.c
6363
rm -f $@ && $(LN_S) $< .

src/interfaces/ecpg/preproc/c_keywords.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* keywords.c
44
* lexical token lookup for reserved words in postgres embedded SQL
55
*
6-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/c_keywords.c,v 1.20 2007/05/10 09:53:16 meskes Exp $
6+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/c_keywords.c,v 1.21 2007/08/22 08:20:58 meskes Exp $
77
* §
88
*-------------------------------------------------------------------------
99
*/
@@ -20,7 +20,7 @@
2020
* !!WARNING!!: This list must be sorted, because binary
2121
* search is used to locate entries.
2222
*/
23-
static ScanKeyword ScanKeywords[] = {
23+
static const ScanKeyword ScanCKeywords[] = {
2424
/* name value */
2525
{"VARCHAR", VARCHAR},
2626
{"auto", S_AUTO},
@@ -50,25 +50,8 @@ static ScanKeyword ScanKeywords[] = {
5050
{"year", YEAR_P},
5151
};
5252

53-
ScanKeyword *
53+
const ScanKeyword *
5454
ScanCKeywordLookup(char *text)
5555
{
56-
ScanKeyword *low = &ScanKeywords[0];
57-
ScanKeyword *high = endof(ScanKeywords) - 1;
58-
ScanKeyword *middle;
59-
int difference;
60-
61-
while (low <= high)
62-
{
63-
middle = low + (high - low) / 2;
64-
difference = strcmp(middle->name, text);
65-
if (difference == 0)
66-
return middle;
67-
else if (difference < 0)
68-
low = middle + 1;
69-
else
70-
high = middle - 1;
71-
}
72-
73-
return NULL;
56+
return DoLookup(text, &ScanCKeywords[0], endof(ScanCKeywords) - 1);
7457
}

0 commit comments

Comments
 (0)