Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit df10360

Browse files
committed
From: Michael Meskes <meskes@topsystem.de>
Cleanups for ecpg, as well as a missing patch so that its configured in
1 parent 72aa1da commit df10360

File tree

7 files changed

+144
-90
lines changed

7 files changed

+144
-90
lines changed

src/interfaces/ecpg/include/Makefile.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ all clean::
55
@echo Nothing to be done.
66

77
install::
8-
install ecpglib.h $(HEADERDIR)
9-
install ecpgtype.h $(HEADERDIR)
10-
install sqlca.h $(HEADERDIR)
8+
install ecpglib.h $(DESTDIR)$(HEADERDIR)
9+
install ecpgtype.h $(DESTDIR)$(HEADERDIR)
10+
install sqlca.h $(DESTDIR)$(HEADERDIR)
1111

1212
uninstall::
13-
rm -f $(HEADERDIR)/ecpglib.h
14-
rm -f $(HEADERDIR)/ecpgtype.h
15-
rm -f $(HEADERDIR)/sqlca.h
13+
rm -f $(DESTDIR)$(HEADERDIR)/ecpglib.h
14+
rm -f $(DESTDIR)$(HEADERDIR)/ecpgtype.h
15+
rm -f $(DESTDIR)$(HEADERDIR)/sqlca.h

src/interfaces/ecpg/lib/Makefile.in

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,57 @@ include $(SRCDIR)/Makefile.global
33

44
PQ_INCLUDE=-I$(SRCDIR)/include -I$(SRCDIR)/interfaces/libpq
55

6-
all: lib
6+
SO_MAJOR_VERSION=0
7+
SO_MINOR_VERSION=5
78

8-
lib: libecpg.a
9+
PORTNAME=@PORTNAME@
10+
11+
# Shared library stuff
12+
shlib :=
13+
install-shlib-dep :=
14+
ifeq ($(PORTNAME), linux)
15+
ifdef LINUX_ELF
16+
install-shlib-dep := install-shlib
17+
shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
18+
LDFLAGS_SL = -shared
19+
CFLAGS += $(CFLAGS_SL)
20+
endif
21+
endif
22+
ifeq ($(PORTNAME), bsd)
23+
install-shlib-dep := install-shlib
24+
shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
25+
LDFLAGS_SL = -x -Bshareable -Bforcearchive
26+
CFLAGS += $(CFLAGS_SL)
27+
endif
28+
ifeq ($(PORTNAME), i386_solaris)
29+
install-shlib-dep := install-shlib
30+
shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
31+
LDFLAGS_SL = -G -z text
32+
CFLAGS += $(CFLAGS_SL)
33+
endif
34+
ifeq ($(PORTNAME), univel)
35+
install-shlib-dep := install-shlib
36+
shlib := libecpg.so.1
37+
LDFLAGS_SL = -G -z text
38+
CFLAGS += $(CFLAGS_SL)
39+
endif
40+
41+
all: libecpg.a $(shlib)
42+
43+
$(shlib): ecpglib.o typename.o
44+
$(LD) $(LDFLAGS_SL) -o $@ ecpglib.o typename.o
45+
ln -sf $@ libecpg.so
946

1047
clean:
11-
rm -f *.o *.a core a.out *~
48+
rm -f *.o *.a core a.out *~ $(shlib) libecpg.so
1249

1350
install: libecpg.a
14-
install -m 644 libecpg.a $(LIBDIR)
51+
install -m 644 libecpg.a $(DESTDIR)$(LIBDIR)
52+
install -m 644 $(shlib) $(DESTDIR)$(LIBDIR)
53+
ln -sf $(shlib) $(DESTDIR)$(LIBDIR)/libecpg.so
1554

1655
uninstall::
17-
rm -f $(LIBDIR)/libecpg.a
56+
rm -f $(DESTDIR)$(LIBDIR)/libecpg.a $(DESTDIR)$(LIBDIR)/$(shlib)
1857

1958
# Rules that do something
2059
libecpg.a : libecpg.a(ecpglib.o) libecpg.a(typename.o)

src/interfaces/ecpg/preproc/Makefile.in

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
SRCDIR= ../../..
22
include $(SRCDIR)/Makefile.global
33

4+
MAJOR_VERSION=0
5+
MINOR_VERSION=5
6+
PATCHLEVEL=1
7+
48
CC=@CC@
59
LEX=@LEX@
610
LEXLIB=@LEXLIB@
711
YACC=@YACC@
812
YFLAGS=@YFLAGS@
913

10-
CFLAGS=-I../include -O2 -g -Wall
14+
CFLAGS=-I../include -O2 -g -Wall -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)
1115

1216
all:: ecpg
1317

1418
clean:
1519
rm -f *.o core a.out ecpg preproc.tab.h y.tab.c *~
1620

1721
install: all
18-
install -c -m 755 ecpg $(BINDIR)
22+
install -c -m 755 ecpg $(DESTDIR)$(BINDIR)
1923

2024
uninstall:
21-
rm -f $(BINDIR)/ecpg
25+
rm -f $(DESTDIR)$(BINDIR)/ecpg
2226

2327
# Rule that really do something.
24-
ecpg: y.tab.o pgc.o type.o ecpg.o
25-
$(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o -L../lib -lecpg $(LEXLIB)
28+
ecpg: y.tab.o pgc.o type.o ecpg.o ../lib/typename.o
29+
$(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o ../lib/typename.o $(LEXLIB)
2630

2731
y.tab.h y.tab.c: preproc.y
2832
$(YACC) $(YFLAGS) $<

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,22 @@
77
#include <stdlib.h>
88
#include <strings.h>
99

10-
extern void lex_init(void);
11-
extern FILE *yyin, *yyout;
12-
extern char * input_filename;
13-
extern int yyparse(void);
10+
#include "extern.h"
1411

1512
static void
1613
usage(char *progname)
1714
{
18-
fprintf(stderr, "Usage: %s: [ -o outout file name] file1 [file2] ...\n", progname);
15+
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
16+
fprintf(stderr, "Usage: %s: [-v] [-d] [ -o outout file name] file1 [file2] ...\n", progname);
1917
}
2018

2119
int
2220
main(int argc, char *const argv[])
2321
{
24-
char c,
25-
out_option = 0;
22+
char c, out_option = 0;
2623
int fnr;
2724

28-
while ((c = getopt(argc, argv, "o:")) != EOF)
25+
while ((c = getopt(argc, argv, "vdo:")) != EOF)
2926
{
3027
switch (c)
3128
{
@@ -36,71 +33,77 @@ main(int argc, char *const argv[])
3633
else
3734
out_option = 1;
3835
break;
36+
case 'd':
37+
debugging = 1;
38+
break;
39+
case 'v':
3940
default:
4041
usage(argv[0]);
4142
}
4243
}
4344

44-
/* after the options there must not be anything but filenames */
45-
for (fnr = optind; fnr < argc; fnr++)
45+
if (optind >= argc) /* no files specified */
46+
usage(argv[0]);
47+
else
4648
{
47-
char *filename,
48-
*ptr2ext;
49-
50-
filename = malloc(strlen(argv[fnr]) + 2);
51-
if (filename == NULL)
49+
/* after the options there must not be anything but filenames */
50+
for (fnr = optind; fnr < argc; fnr++)
5251
{
53-
perror("malloc");
54-
continue;
55-
}
52+
char *filename, *ptr2ext;
5653

57-
strcpy(filename, argv[fnr]);
54+
filename = malloc(strlen(argv[fnr]) + 2);
55+
if (filename == NULL)
56+
{
57+
perror("malloc");
58+
continue;
59+
}
5860

59-
ptr2ext = strrchr(filename, '.');
60-
/* no extension or extension not equal .pgc */
61-
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
62-
{
63-
ptr2ext = filename + strlen(filename);
64-
ptr2ext[0] = '.';
65-
}
61+
strcpy(filename, argv[fnr]);
6662

67-
/* make extension = .c */
68-
ptr2ext[1] = 'c';
69-
ptr2ext[2] = '\0';
63+
ptr2ext = strrchr(filename, '.');
64+
/* no extension or extension not equal .pgc */
65+
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
66+
{
67+
ptr2ext = filename + strlen(filename);
68+
ptr2ext[0] = '.';
69+
}
7070

71-
if (out_option == 0) /* calculate the output name */
72-
{
73-
yyout = fopen(filename, "w");
74-
if (yyout == NULL)
71+
/* make extension = .c */
72+
ptr2ext[1] = 'c';
73+
ptr2ext[2] = '\0';
74+
75+
if (out_option == 0) /* calculate the output name */
7576
{
76-
perror(filename);
77-
free(filename);
78-
continue;
77+
yyout = fopen(filename, "w");
78+
if (yyout == NULL)
79+
{
80+
perror(filename);
81+
free(filename);
82+
continue;
83+
}
7984
}
80-
}
8185

82-
yyin = fopen(input_filename = argv[fnr], "r");
83-
if (yyin == NULL)
84-
{
85-
perror(argv[fnr]);
86-
}
87-
else
88-
{
89-
/* initialize lex */
90-
lex_init();
86+
yyin = fopen(input_filename = argv[fnr], "r");
87+
if (yyin == NULL)
88+
perror(argv[fnr]);
89+
else
90+
{
91+
/* initialize lex */
92+
lex_init();
9193

92-
/* we need two includes everytime */
93-
fprintf(yyout, "/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n");
94+
/* we need two includes */
95+
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
9496

95-
/* and parse the source */
96-
yyparse();
97+
/* and parse the source */
98+
yyparse();
9799

98-
fclose(yyin);
99-
if (out_option == 0)
100-
fclose(yyout);
101-
}
100+
fclose(yyin);
101+
if (out_option == 0)
102+
fclose(yyout);
103+
}
102104

103-
free(filename);
105+
free(filename);
106+
}
104107
}
105108
return (0);
106109
}

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
#include <stdio.h>
44
#include <string.h>
55
#include <stdlib.h>
6+
67
#include "type.h"
8+
#include "extern.h"
79

8-
void yyerror(char *);
9-
extern FILE * yyout;
10-
extern char * yytext;
11-
extern int yylineno;
12-
extern int yyleng;
10+
static void yyerror(char *);
1311

1412
/*
1513
* Variables containing simple states.
@@ -65,7 +63,7 @@ find_variable(char * name)
6563
{
6664
char * errorstring = (char *) malloc(strlen(name) + 100);
6765

68-
sprintf(errorstring, "The variabel :%s is not declared.", name);
66+
sprintf(errorstring, "The variable :%s is not declared.", name);
6967

7068
yyerror(errorstring);
7169
}
@@ -87,7 +85,7 @@ new_variable(const char * name, struct ECPGtype * type)
8785

8886

8987
/*
90-
* Here is the variables that need to be handled on every request.
88+
* Here are the variables that need to be handled on every request.
9189
* These are of two kinds: input and output.
9290
* I will make two lists for them.
9391
*/
@@ -359,7 +357,7 @@ both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2
359357
| S_ANYTHING;
360358

361359
%%
362-
void yyerror(char * error)
360+
static void yyerror(char * error)
363361
{
364362
fprintf(stderr, "%s\n", error);
365363
exit(1);

src/interfaces/ecpg/test/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
all: test2 perftest
22

33
test2: test2.c
4-
gcc -g -I ../include -I ../../../libpq -o test2 test2.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
4+
gcc -g -I ../include -I ../../libpq -o test2 test2.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
55
test2.c: test2.pgc
6-
../preproc/ecpg test2.pgc
6+
ecpg test2.pgc
77

88
perftest: perftest.c
9-
gcc -g -I ../include -I ../../../libpq -o perftest perftest.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
9+
gcc -g -I ../include -I ../../libpq -o perftest perftest.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
1010
perftest.c: perftest.pgc
11-
../preproc/ecpg perftest.pgc
11+
ecpg perftest.pgc
1212

1313
clean:
14-
/bin/rm test2 test2.c perftest perftest.c
14+
/bin/rm test2 test2.c perftest perftest.c log

src/interfaces/ecpg/test/test2.pgc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
#include <stdio.h>
2+
13
exec sql include sqlca;
24

35
#define SQLCODE sqlca.sqlcode
46

7+
extern void ECPGdebug(int n, FILE *dbgs);
8+
59
void
610
db_error (char *msg)
711
{
@@ -14,28 +18,31 @@ int
1418
main ()
1519
{
1620
exec sql begin declare section;
17-
varchar text[8];
18-
int count;
19-
double control;
21+
varchar name[8];
22+
long born;
2023
exec sql end declare section;
24+
FILE *dbgs;
25+
26+
if ((dbgs = fopen("log", "w")) != NULL)
27+
ECPGdebug(1, dbgs);
2128

2229
exec sql connect 'mm';
2330
if (SQLCODE)
2431
db_error ("connect");
2532

2633
exec sql declare cur cursor for
27-
select text, control, count from test;
34+
select name, born from meskes;
2835
if (SQLCODE) db_error ("declare");
2936

3037
exec sql open cur;
3138
if (SQLCODE)
3239
db_error ("open");
3340

3441
while (1) {
35-
exec sql fetch in cur into :text, :control, :count;
42+
exec sql fetch in cur into :name, :born;
3643
if (SQLCODE)
3744
break;
38-
printf ("%8.8s %d %f\n", text.arr, count, control);
45+
printf ("%8.8s was born %d\n", name.arr, born);
3946
}
4047

4148
if (SQLCODE < 0)
@@ -46,5 +53,8 @@ exec sql end declare section;
4653
exec sql commit;
4754
if (SQLCODE) db_error ("commit");
4855

56+
if (dbgs != NULL)
57+
fclose(dbgs);
58+
4959
return (0);
5060
}

0 commit comments

Comments
 (0)