From: Michael Meskes <meskes@topsystem.de>
Cleanups for ecpg, as well as a missing patch so that its configured in
This commit is contained in:
parent
72aa1dabb9
commit
df10360d8e
|
@ -5,11 +5,11 @@ all clean::
|
||||||
@echo Nothing to be done.
|
@echo Nothing to be done.
|
||||||
|
|
||||||
install::
|
install::
|
||||||
install ecpglib.h $(HEADERDIR)
|
install ecpglib.h $(DESTDIR)$(HEADERDIR)
|
||||||
install ecpgtype.h $(HEADERDIR)
|
install ecpgtype.h $(DESTDIR)$(HEADERDIR)
|
||||||
install sqlca.h $(HEADERDIR)
|
install sqlca.h $(DESTDIR)$(HEADERDIR)
|
||||||
|
|
||||||
uninstall::
|
uninstall::
|
||||||
rm -f $(HEADERDIR)/ecpglib.h
|
rm -f $(DESTDIR)$(HEADERDIR)/ecpglib.h
|
||||||
rm -f $(HEADERDIR)/ecpgtype.h
|
rm -f $(DESTDIR)$(HEADERDIR)/ecpgtype.h
|
||||||
rm -f $(HEADERDIR)/sqlca.h
|
rm -f $(DESTDIR)$(HEADERDIR)/sqlca.h
|
||||||
|
|
|
@ -3,18 +3,57 @@ include $(SRCDIR)/Makefile.global
|
||||||
|
|
||||||
PQ_INCLUDE=-I$(SRCDIR)/include -I$(SRCDIR)/interfaces/libpq
|
PQ_INCLUDE=-I$(SRCDIR)/include -I$(SRCDIR)/interfaces/libpq
|
||||||
|
|
||||||
all: lib
|
SO_MAJOR_VERSION=0
|
||||||
|
SO_MINOR_VERSION=5
|
||||||
|
|
||||||
lib: libecpg.a
|
PORTNAME=@PORTNAME@
|
||||||
|
|
||||||
|
# Shared library stuff
|
||||||
|
shlib :=
|
||||||
|
install-shlib-dep :=
|
||||||
|
ifeq ($(PORTNAME), linux)
|
||||||
|
ifdef LINUX_ELF
|
||||||
|
install-shlib-dep := install-shlib
|
||||||
|
shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
|
||||||
|
LDFLAGS_SL = -shared
|
||||||
|
CFLAGS += $(CFLAGS_SL)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(PORTNAME), bsd)
|
||||||
|
install-shlib-dep := install-shlib
|
||||||
|
shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
|
||||||
|
LDFLAGS_SL = -x -Bshareable -Bforcearchive
|
||||||
|
CFLAGS += $(CFLAGS_SL)
|
||||||
|
endif
|
||||||
|
ifeq ($(PORTNAME), i386_solaris)
|
||||||
|
install-shlib-dep := install-shlib
|
||||||
|
shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
|
||||||
|
LDFLAGS_SL = -G -z text
|
||||||
|
CFLAGS += $(CFLAGS_SL)
|
||||||
|
endif
|
||||||
|
ifeq ($(PORTNAME), univel)
|
||||||
|
install-shlib-dep := install-shlib
|
||||||
|
shlib := libecpg.so.1
|
||||||
|
LDFLAGS_SL = -G -z text
|
||||||
|
CFLAGS += $(CFLAGS_SL)
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: libecpg.a $(shlib)
|
||||||
|
|
||||||
|
$(shlib): ecpglib.o typename.o
|
||||||
|
$(LD) $(LDFLAGS_SL) -o $@ ecpglib.o typename.o
|
||||||
|
ln -sf $@ libecpg.so
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.a core a.out *~
|
rm -f *.o *.a core a.out *~ $(shlib) libecpg.so
|
||||||
|
|
||||||
install: libecpg.a
|
install: libecpg.a
|
||||||
install -m 644 libecpg.a $(LIBDIR)
|
install -m 644 libecpg.a $(DESTDIR)$(LIBDIR)
|
||||||
|
install -m 644 $(shlib) $(DESTDIR)$(LIBDIR)
|
||||||
|
ln -sf $(shlib) $(DESTDIR)$(LIBDIR)/libecpg.so
|
||||||
|
|
||||||
uninstall::
|
uninstall::
|
||||||
rm -f $(LIBDIR)/libecpg.a
|
rm -f $(DESTDIR)$(LIBDIR)/libecpg.a $(DESTDIR)$(LIBDIR)/$(shlib)
|
||||||
|
|
||||||
# Rules that do something
|
# Rules that do something
|
||||||
libecpg.a : libecpg.a(ecpglib.o) libecpg.a(typename.o)
|
libecpg.a : libecpg.a(ecpglib.o) libecpg.a(typename.o)
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
SRCDIR= ../../..
|
SRCDIR= ../../..
|
||||||
include $(SRCDIR)/Makefile.global
|
include $(SRCDIR)/Makefile.global
|
||||||
|
|
||||||
|
MAJOR_VERSION=0
|
||||||
|
MINOR_VERSION=5
|
||||||
|
PATCHLEVEL=1
|
||||||
|
|
||||||
CC=@CC@
|
CC=@CC@
|
||||||
LEX=@LEX@
|
LEX=@LEX@
|
||||||
LEXLIB=@LEXLIB@
|
LEXLIB=@LEXLIB@
|
||||||
YACC=@YACC@
|
YACC=@YACC@
|
||||||
YFLAGS=@YFLAGS@
|
YFLAGS=@YFLAGS@
|
||||||
|
|
||||||
CFLAGS=-I../include -O2 -g -Wall
|
CFLAGS=-I../include -O2 -g -Wall -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)
|
||||||
|
|
||||||
all:: ecpg
|
all:: ecpg
|
||||||
|
|
||||||
|
@ -15,14 +19,14 @@ clean:
|
||||||
rm -f *.o core a.out ecpg preproc.tab.h y.tab.c *~
|
rm -f *.o core a.out ecpg preproc.tab.h y.tab.c *~
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install -c -m 755 ecpg $(BINDIR)
|
install -c -m 755 ecpg $(DESTDIR)$(BINDIR)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(BINDIR)/ecpg
|
rm -f $(DESTDIR)$(BINDIR)/ecpg
|
||||||
|
|
||||||
# Rule that really do something.
|
# Rule that really do something.
|
||||||
ecpg: y.tab.o pgc.o type.o ecpg.o
|
ecpg: y.tab.o pgc.o type.o ecpg.o ../lib/typename.o
|
||||||
$(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o -L../lib -lecpg $(LEXLIB)
|
$(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o ../lib/typename.o $(LEXLIB)
|
||||||
|
|
||||||
y.tab.h y.tab.c: preproc.y
|
y.tab.h y.tab.c: preproc.y
|
||||||
$(YACC) $(YFLAGS) $<
|
$(YACC) $(YFLAGS) $<
|
||||||
|
|
|
@ -7,25 +7,22 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
extern void lex_init(void);
|
#include "extern.h"
|
||||||
extern FILE *yyin, *yyout;
|
|
||||||
extern char * input_filename;
|
|
||||||
extern int yyparse(void);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(char *progname)
|
usage(char *progname)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s: [ -o outout file name] file1 [file2] ...\n", progname);
|
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
||||||
|
fprintf(stderr, "Usage: %s: [-v] [-d] [ -o outout file name] file1 [file2] ...\n", progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *const argv[])
|
main(int argc, char *const argv[])
|
||||||
{
|
{
|
||||||
char c,
|
char c, out_option = 0;
|
||||||
out_option = 0;
|
|
||||||
int fnr;
|
int fnr;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "o:")) != EOF)
|
while ((c = getopt(argc, argv, "vdo:")) != EOF)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
@ -36,71 +33,77 @@ main(int argc, char *const argv[])
|
||||||
else
|
else
|
||||||
out_option = 1;
|
out_option = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
debugging = 1;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* after the options there must not be anything but filenames */
|
if (optind >= argc) /* no files specified */
|
||||||
for (fnr = optind; fnr < argc; fnr++)
|
usage(argv[0]);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
char *filename,
|
/* after the options there must not be anything but filenames */
|
||||||
*ptr2ext;
|
for (fnr = optind; fnr < argc; fnr++)
|
||||||
|
|
||||||
filename = malloc(strlen(argv[fnr]) + 2);
|
|
||||||
if (filename == NULL)
|
|
||||||
{
|
{
|
||||||
perror("malloc");
|
char *filename, *ptr2ext;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(filename, argv[fnr]);
|
filename = malloc(strlen(argv[fnr]) + 2);
|
||||||
|
if (filename == NULL)
|
||||||
ptr2ext = strrchr(filename, '.');
|
|
||||||
/* no extension or extension not equal .pgc */
|
|
||||||
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
|
|
||||||
{
|
|
||||||
ptr2ext = filename + strlen(filename);
|
|
||||||
ptr2ext[0] = '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* make extension = .c */
|
|
||||||
ptr2ext[1] = 'c';
|
|
||||||
ptr2ext[2] = '\0';
|
|
||||||
|
|
||||||
if (out_option == 0) /* calculate the output name */
|
|
||||||
{
|
|
||||||
yyout = fopen(filename, "w");
|
|
||||||
if (yyout == NULL)
|
|
||||||
{
|
{
|
||||||
perror(filename);
|
perror("malloc");
|
||||||
free(filename);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strcpy(filename, argv[fnr]);
|
||||||
|
|
||||||
|
ptr2ext = strrchr(filename, '.');
|
||||||
|
/* no extension or extension not equal .pgc */
|
||||||
|
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
|
||||||
|
{
|
||||||
|
ptr2ext = filename + strlen(filename);
|
||||||
|
ptr2ext[0] = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* make extension = .c */
|
||||||
|
ptr2ext[1] = 'c';
|
||||||
|
ptr2ext[2] = '\0';
|
||||||
|
|
||||||
|
if (out_option == 0) /* calculate the output name */
|
||||||
|
{
|
||||||
|
yyout = fopen(filename, "w");
|
||||||
|
if (yyout == NULL)
|
||||||
|
{
|
||||||
|
perror(filename);
|
||||||
|
free(filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yyin = fopen(input_filename = argv[fnr], "r");
|
||||||
|
if (yyin == NULL)
|
||||||
|
perror(argv[fnr]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* initialize lex */
|
||||||
|
lex_init();
|
||||||
|
|
||||||
|
/* we need two includes */
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* and parse the source */
|
||||||
|
yyparse();
|
||||||
|
|
||||||
|
fclose(yyin);
|
||||||
|
if (out_option == 0)
|
||||||
|
fclose(yyout);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
yyin = fopen(input_filename = argv[fnr], "r");
|
|
||||||
if (yyin == NULL)
|
|
||||||
{
|
|
||||||
perror(argv[fnr]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* initialize lex */
|
|
||||||
lex_init();
|
|
||||||
|
|
||||||
/* we need two includes everytime */
|
|
||||||
fprintf(yyout, "/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n");
|
|
||||||
|
|
||||||
/* and parse the source */
|
|
||||||
yyparse();
|
|
||||||
|
|
||||||
fclose(yyin);
|
|
||||||
if (out_option == 0)
|
|
||||||
fclose(yyout);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(filename);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "type.h"
|
|
||||||
|
|
||||||
void yyerror(char *);
|
#include "type.h"
|
||||||
extern FILE * yyout;
|
#include "extern.h"
|
||||||
extern char * yytext;
|
|
||||||
extern int yylineno;
|
static void yyerror(char *);
|
||||||
extern int yyleng;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables containing simple states.
|
* Variables containing simple states.
|
||||||
|
@ -65,7 +63,7 @@ find_variable(char * name)
|
||||||
{
|
{
|
||||||
char * errorstring = (char *) malloc(strlen(name) + 100);
|
char * errorstring = (char *) malloc(strlen(name) + 100);
|
||||||
|
|
||||||
sprintf(errorstring, "The variabel :%s is not declared.", name);
|
sprintf(errorstring, "The variable :%s is not declared.", name);
|
||||||
|
|
||||||
yyerror(errorstring);
|
yyerror(errorstring);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +85,7 @@ new_variable(const char * name, struct ECPGtype * type)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here is the variables that need to be handled on every request.
|
* Here are the variables that need to be handled on every request.
|
||||||
* These are of two kinds: input and output.
|
* These are of two kinds: input and output.
|
||||||
* I will make two lists for them.
|
* I will make two lists for them.
|
||||||
*/
|
*/
|
||||||
|
@ -359,7 +357,7 @@ both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2
|
||||||
| S_ANYTHING;
|
| S_ANYTHING;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
void yyerror(char * error)
|
static void yyerror(char * error)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s\n", error);
|
fprintf(stderr, "%s\n", error);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
all: test2 perftest
|
all: test2 perftest
|
||||||
|
|
||||||
test2: test2.c
|
test2: test2.c
|
||||||
gcc -g -I ../include -I ../../../libpq -o test2 test2.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
|
gcc -g -I ../include -I ../../libpq -o test2 test2.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
|
||||||
test2.c: test2.pgc
|
test2.c: test2.pgc
|
||||||
../preproc/ecpg test2.pgc
|
ecpg test2.pgc
|
||||||
|
|
||||||
perftest: perftest.c
|
perftest: perftest.c
|
||||||
gcc -g -I ../include -I ../../../libpq -o perftest perftest.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
|
gcc -g -I ../include -I ../../libpq -o perftest perftest.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
|
||||||
perftest.c: perftest.pgc
|
perftest.c: perftest.pgc
|
||||||
../preproc/ecpg perftest.pgc
|
ecpg perftest.pgc
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
/bin/rm test2 test2.c perftest perftest.c
|
/bin/rm test2 test2.c perftest perftest.c log
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
exec sql include sqlca;
|
exec sql include sqlca;
|
||||||
|
|
||||||
#define SQLCODE sqlca.sqlcode
|
#define SQLCODE sqlca.sqlcode
|
||||||
|
|
||||||
|
extern void ECPGdebug(int n, FILE *dbgs);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_error (char *msg)
|
db_error (char *msg)
|
||||||
{
|
{
|
||||||
|
@ -14,17 +18,20 @@ int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
exec sql begin declare section;
|
exec sql begin declare section;
|
||||||
varchar text[8];
|
varchar name[8];
|
||||||
int count;
|
long born;
|
||||||
double control;
|
|
||||||
exec sql end declare section;
|
exec sql end declare section;
|
||||||
|
FILE *dbgs;
|
||||||
|
|
||||||
|
if ((dbgs = fopen("log", "w")) != NULL)
|
||||||
|
ECPGdebug(1, dbgs);
|
||||||
|
|
||||||
exec sql connect 'mm';
|
exec sql connect 'mm';
|
||||||
if (SQLCODE)
|
if (SQLCODE)
|
||||||
db_error ("connect");
|
db_error ("connect");
|
||||||
|
|
||||||
exec sql declare cur cursor for
|
exec sql declare cur cursor for
|
||||||
select text, control, count from test;
|
select name, born from meskes;
|
||||||
if (SQLCODE) db_error ("declare");
|
if (SQLCODE) db_error ("declare");
|
||||||
|
|
||||||
exec sql open cur;
|
exec sql open cur;
|
||||||
|
@ -32,10 +39,10 @@ exec sql end declare section;
|
||||||
db_error ("open");
|
db_error ("open");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
exec sql fetch in cur into :text, :control, :count;
|
exec sql fetch in cur into :name, :born;
|
||||||
if (SQLCODE)
|
if (SQLCODE)
|
||||||
break;
|
break;
|
||||||
printf ("%8.8s %d %f\n", text.arr, count, control);
|
printf ("%8.8s was born %d\n", name.arr, born);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SQLCODE < 0)
|
if (SQLCODE < 0)
|
||||||
|
@ -46,5 +53,8 @@ exec sql end declare section;
|
||||||
exec sql commit;
|
exec sql commit;
|
||||||
if (SQLCODE) db_error ("commit");
|
if (SQLCODE) db_error ("commit");
|
||||||
|
|
||||||
|
if (dbgs != NULL)
|
||||||
|
fclose(dbgs);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue