Skip to content

Commit

Permalink
start different way to produce export functions
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy77 committed Feb 26, 2012
1 parent 9d05db5 commit a546e54
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 119 deletions.
7 changes: 6 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Sun Feb 26 23:09:04 CET 2012 Frediano Ziglio <freddy77_A_gmail_D_com>
* src/odbc/Makefile.am src/odbc/error.c src/odbc/odbc.c:
* src/odbc/odbc_export.pl src/odbc/sqlwparams.h:
- start different way to produce export functions

Mon Jan 23 13:23:51 EST 2012 JK Lowden <jklowden@freetds.org>
* src/apps/tsql.c

Expand Down Expand Up @@ -1018,4 +1023,4 @@ Sat Apr 9 16:15:00 EDT 2011 JK Lowden <jklowden@freetds.org>
* ChangeLog-0.91 added because of release

$FreeTDS$
$Id: ChangeLog,v 1.3445 2012-01-23 18:25:04 jklowden Exp $
$Id: ChangeLog,v 1.3446 2012-02-26 22:09:20 freddy77 Exp $
20 changes: 18 additions & 2 deletions src/odbc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.51 2011-06-08 09:25:53 freddy77 Exp $
# $Id: Makefile.am,v 1.52 2012-02-26 22:09:20 freddy77 Exp $
SUBDIRS = unittests
AM_CPPFLAGS = -I$(top_srcdir)/include $(ODBC_INC)

Expand All @@ -11,7 +11,8 @@ MINGW_SOURCES =
endif
libtdsodbc_la_SOURCES= odbc.c connectparams.c convert_tds2sql.c \
descriptor.c prepare_query.c odbc_util.c \
native.c sql2tds.c error.c odbc_checks.c sqlwchar.c sqlwparams.h $(MINGW_SOURCES)
native.c sql2tds.c error.c odbc_checks.c sqlwchar.c sqlwparams.h \
odbc_export.h error_export.h $(MINGW_SOURCES)
if MINGW32
libtdsodbc_la_LIBADD= ../../win32/setup.res ../tds/libtds.la ../replacements/libreplacements.la $(ODBCINSTLIB) \
$(NETWORK_LIBS) $(LTLIBICONV) $(FREETDS_LIBGCC)
Expand All @@ -34,3 +35,18 @@ endif
odbc: $(EXTRA_LTLIBRARIES)
@echo ''

if HAVE_PERL_SOURCES
BUILT_SOURCES = odbc_export.h error_export.h

clean-local:
cd $(srcdir) && rm -f $(BUILT_SOURCES)

odbc_export.h: odbc_export.pl Makefile odbc.c
perl $(srcdir)/odbc_export.pl $(srcdir)/odbc.c > $@.tmp
mv $@.tmp $@

error_export.h: odbc_export.pl Makefile error.c
perl $(srcdir)/odbc_export.pl $(srcdir)/error.c > $@.tmp
mv $@.tmp $@

endif
6 changes: 4 additions & 2 deletions src/odbc/error.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
* Copyright (C) 1998-1999 Brian Bruns
* Copyright (C) 2003-2010 Frediano Ziglio
* Copyright (C) 2003-2012 Frediano Ziglio
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -42,7 +42,7 @@
#include <dmalloc.h>
#endif

TDS_RCSID(var, "$Id: error.c,v 1.68 2011-08-16 07:04:22 freddy77 Exp $");
TDS_RCSID(var, "$Id: error.c,v 1.69 2012-02-26 22:09:20 freddy77 Exp $");

static void odbc_errs_pop(struct _sql_errors *errs);
static const char *odbc_get_msg(const char *sqlstate);
Expand Down Expand Up @@ -794,3 +794,5 @@ sqlstate2to3(char *state)
return result;
}

#include "error_export.h"

6 changes: 4 additions & 2 deletions src/odbc/odbc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
* Copyright (C) 1998, 1999, 2000, 2001 Brian Bruns
* Copyright (C) 2002-2011 Frediano Ziglio
* Copyright (C) 2002-2012 Frediano Ziglio
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -59,7 +59,7 @@
#include <dmalloc.h>
#endif

TDS_RCSID(var, "$Id: odbc.c,v 1.588 2012-01-17 03:43:56 jklowden Exp $");
TDS_RCSID(var, "$Id: odbc.c,v 1.589 2012-02-26 22:09:20 freddy77 Exp $");

static SQLRETURN _SQLAllocConnect(SQLHENV henv, SQLHDBC FAR * phdbc);
static SQLRETURN _SQLAllocEnv(SQLHENV FAR * phenv, SQLINTEGER odbc_version);
Expand Down Expand Up @@ -7228,3 +7228,5 @@ SQLSetScrollOptions(SQLHSTMT hstmt, SQLUSMALLINT fConcurrency, SQLLEN crowKeyset
ODBC_EXIT_(stmt);
}

#include "odbc_export.h"

98 changes: 98 additions & 0 deletions src/odbc/odbc_export.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/perl

use strict;
open(IN, $ARGV[0]) or die;

my @types = split(',', 'SQLHANDLE,SQLHENV,SQLHDBC,SQLHSTMT,SQLHDESC,SQLHWND,SQLSMALLINT,SQLUSMALLINT,SQLINTEGER,SQLSMALLINT *,SQLLEN *,SQLULEN *,SQLINTEGER *,SQLPOINTER');

while(<IN>) {
chomp;
while ($_ =~ m/\\$/) {
$_ =~ s/\\$//;
$_ .= <IN>;
chomp;
}
s/\s+/ /g;
s/ $//;
s/^ //;
if (/define FUNC NAME\(([^\)]+)\) \((.*)\)$/) {
my $func = $1;
my $args = $2;
my $wide = 0;
my $params_all = '';
my $params_w = '';
my $params_a = '';
my $pass_all = '';
my $pass_aw = '';
my $sep = '';
$wide = 1 if $args =~ / WIDE ?$/;
$args =~ s/ WIDE ?$//;
# print "$1 - $2\n";
while ($args =~ /(P.*?)\(([^\,)]+),?([^\,)]+)\)/g) {
my ($type, $a, $b) = ($1,$2,$3);
# print "--- $1 -- $2 -- $3\n";
if ($type eq 'P') {
$a =~ s/ FAR \*$/ */;
die $a if !grep { $_ eq $a } @types;
$params_all .= "$sep$a $b";
$params_a .= "$sep$a $b";
$params_w .= "$sep$a $b";
$pass_all .= "$sep$b";
$pass_aw .= "$sep$b";
} elsif ($type eq 'PCHARIN' || $type eq 'PCHAROUT') {
die $b if $b ne 'SQLSMALLINT' && $b ne 'SQLINTEGER';
if ($type eq 'PCHARIN') {
$params_all .= "${sep}ODBC_CHAR * sz$a, $b cb$a";
$params_a .= "${sep}SQLCHAR * sz$a, $b cb$a";
$params_w .= "${sep}SQLWCHAR * sz$a, $b cb$a";
$pass_all .= "${sep}sz$a, cb$a";
$pass_aw .= "$sep(ODBC_CHAR*) sz$a, cb$a";
} else {
$params_all .= "${sep}ODBC_CHAR * sz$a, $b cb${a}Max, $b FAR* pcb$a";
$params_a .= "${sep}SQLCHAR * sz$a, $b cb${a}Max, $b FAR* pcb$a";
$params_w .= "${sep}SQLWCHAR * sz$a, $b cb${a}Max, $b FAR* pcb$a";
$pass_all .= "${sep}sz$a, cb${a}Max, pcb$a";
$pass_aw .= "${sep}(ODBC_CHAR*) sz$a, cb${a}Max, pcb$a";
}
} elsif ($type eq 'PCHAR') {
$params_all .= "${sep}ODBC_CHAR * $a";
$params_a .= "${sep}SQLCHAR * $a";
$params_w .= "${sep}SQLWCHAR * $a";
$pass_all .= "${sep}$a";
$pass_aw .= "$sep(ODBC_CHAR*) $a";
} else {
die $type;
}
$sep = ', ';
}
print "#ifdef ENABLE_ODBC_WIDE
static SQLRETURN _$func($params_all, int wide);
SQLRETURN ODBC_API $func($params_a) {
return _$func($pass_aw, 0);
}
SQLRETURN ODBC_API ${func}W($params_w) {
return _$func($pass_aw, 1);
}
#else
SQLRETURN ODBC_API $func($params_a) {
return _$func($pass_all);
}
#endif
";
}
}
close(IN);

exit 0;

__END__
static SQLRETURN _SQLPrepare (SQLHSTMT hstmt, ODBC_CHAR* szSqlStr, SQLINTEGER cbSqlStr , int wide);
SQLRETURN __attribute__((externally_visible)) SQLPrepare (SQLHSTMT hstmt, SQLCHAR* szSqlStr, SQLINTEGER cbSqlStr ) {
return _SQLPrepare (hstmt, (ODBC_CHAR*) szSqlStr, cbSqlStr ,0);
}
SQLRETURN __attribute__((externally_visible)) SQLPrepareW (SQLHSTMT hstmt, SQLWCHAR * szSqlStr, SQLINTEGER cbSqlStr ) {
return _SQLPrepare (hstmt, (ODBC_CHAR*) szSqlStr, cbSqlStr ,1);
}
static SQLRETURN _SQLPrepare (SQLHSTMT hstmt, ODBC_CHAR* szSqlStr, SQLINTEGER cbSqlStr , int wide)
118 changes: 6 additions & 112 deletions src/odbc/sqlwparams.h
Original file line number Diff line number Diff line change
@@ -1,131 +1,25 @@
//#define FUNC NAME(SQLTest) (P(SQLSMALLINT, x), PCHAR(y) WIDE)

#ifdef ENABLE_ODBC_WIDE

#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#undef PCHARIN
#undef PCHAROUT
#define NAME(a) _ ## a
#define WIDE , int wide
#define P(a,b) a b
#define PCHAR(a) ODBC_CHAR* a
#define PCHARIN(n,t) PCHAR(sz ## n), P(t, cb ## n)
#define PCHAROUT(n,t) PCHAR(sz ## n), P(t, cb ## n ## Max), P(t FAR*, pcb ## n)
static SQLRETURN FUNC;



#undef NAME
#undef WIDE
#undef PCHAR
#define NAME(a) a
#define WIDE
#define PCHAR(a) SQLCHAR* a
SQLRETURN ODBC_PUBLIC ODBC_API FUNC {

#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#define NAME(a) _ ## a
#define WIDE ,0
#define P(a,b) b
#define PCHAR(a) (ODBC_CHAR*) a
return FUNC;
}



#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#define NAME(a) a ## W
#define WIDE
#define P(a,b) a b
#define PCHAR(a) SQLWCHAR * a
SQLRETURN ODBC_PUBLIC ODBC_API FUNC {

#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#define NAME(a) _ ## a
#define WIDE ,1
#define P(a,b) b
#define PCHAR(a) (ODBC_CHAR*) a
return FUNC;
}



#undef WIDE
#undef P
#undef PCHAR
#define WIDE , int wide
#define P(a,b) a b
#define PCHAR(a) ODBC_CHAR* a
static SQLRETURN FUNC



#ifdef ENABLE_ODBC_WIDE
# define WIDE , int wide
# define PCHAR(a) ODBC_CHAR* a
#else
# define WIDE
# define PCHAR(a) SQLCHAR* a
#endif



#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#undef PCHARIN
#undef PCHAROUT
#define NAME(a) _ ## a
#define WIDE
#define P(a,b) a b
#define PCHAR(a) SQLCHAR* a
#define PCHARIN(n,t) PCHAR(sz ## n), P(t, cb ## n)
#define PCHAROUT(n,t) PCHAR(sz ## n), P(t, cb ## n ## Max), P(t FAR*, pcb ## n)
static SQLRETURN FUNC;



#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#define NAME(a) a
#define WIDE
#define P(a,b) a b
#define PCHAR(a) SQLCHAR* a
SQLRETURN ODBC_API FUNC {

#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#define NAME(a) _ ## a
#define WIDE
#define P(a,b) b
#define PCHAR(a) a
return FUNC;
}


#undef NAME
#undef WIDE
#undef P
#undef PCHAR
#define NAME(a) _ ## a
#define WIDE
#define P(a,b) a b
#define PCHAR(a) SQLCHAR* a
static SQLRETURN FUNC

#endif


#undef FUNC

0 comments on commit a546e54

Please sign in to comment.