Changeset: b3a44e89509c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b3a44e89509c
Branch: extract_types
Log Message:

Merge with default.


diffs (truncated from 1098 to 300 lines):

diff --git a/clients/mapiclient/dotmonetdb.c b/clients/mapiclient/dotmonetdb.c
--- a/clients/mapiclient/dotmonetdb.c
+++ b/clients/mapiclient/dotmonetdb.c
@@ -15,7 +15,6 @@
 void
 parse_dotmonetdb(DotMonetdb *dotfile)
 {
-       char *cfile;
        FILE *config = NULL;
        char buf[FILENAME_MAX];
 
@@ -29,10 +28,43 @@ parse_dotmonetdb(DotMonetdb *dotfile)
         * (3 is standard shell syntax: use XDG_CONFIG_HOME if set, else use
         * $HOME/.config in its place)
         */
+#ifdef NATIVE_WIN32
+       wchar_t *cfile;
+       wchar_t wbuf[FILENAME_MAX];
+#define CF     "%ls"                           /* format to print cfile */
+
+       if ((cfile = _wgetenv(L"DOTMONETDBFILE")) == NULL) {
+               /* no environment variable: use a default */
+               cfile = L".monetdb";
+               if ((config = _wfopen(cfile, L"r")) == NULL) {
+                       const wchar_t *xdg = _wgetenv(L"XDG_CONFIG_HOME");
+                       const wchar_t *home = _wgetenv(L"HOME");
+                       int len = -1;
+                       cfile = wbuf;
+                       if (xdg != NULL)
+                               len = _snwprintf(wbuf, sizeof(wbuf), 
L"%ls%lcmonetdb", xdg, DIR_SEP);
+                       else if (home != NULL)
+                               len = _snwprintf(wbuf, sizeof(wbuf), 
L"%ls%lc.config%lcmonetdb", home, DIR_SEP, DIR_SEP);
+                       if (len == -1 || len >= FILENAME_MAX || (config = 
_wfopen(wbuf, L"r")) == NULL) {
+                               if (home) {
+                                       len = _snwprintf(wbuf, sizeof(wbuf), 
L"%ls%lc.monetdb", home, DIR_SEP);
+                                       if (len >= 0 && len < FILENAME_MAX)
+                                               config = _wfopen(wbuf, L"r");
+                               }
+                       }
+               }
+       } else if (*cfile != 0 && (config = _wfopen(cfile, L"r")) == NULL) {
+               fprintf(stderr, "failed to open file '%ls': %s\n",
+                       cfile, strerror(errno));
+       }
+#else
+       char *cfile;
+#define CF     "%s"                            /* format to print cfile */
+
        if ((cfile = getenv("DOTMONETDBFILE")) == NULL) {
                /* no environment variable: use a default */
                cfile = ".monetdb";
-               if ((config = MT_fopen(cfile, "r")) == NULL) {
+               if ((config = fopen(cfile, "r")) == NULL) {
                        const char *xdg = getenv("XDG_CONFIG_HOME");
                        const char *home = getenv("HOME");
                        int len = -1;
@@ -41,18 +73,19 @@ parse_dotmonetdb(DotMonetdb *dotfile)
                                len = snprintf(buf, sizeof(buf), "%s%cmonetdb", 
xdg, DIR_SEP);
                        else if (home != NULL)
                                len = snprintf(buf, sizeof(buf), 
"%s%c.config%cmonetdb", home, DIR_SEP, DIR_SEP);
-                       if (len == -1 || len >= FILENAME_MAX || (config = 
MT_fopen(buf, "r")) == NULL) {
+                       if (len == -1 || len >= FILENAME_MAX || (config = 
fopen(buf, "r")) == NULL) {
                                if (home) {
                                        len = snprintf(buf, sizeof(buf), 
"%s%c.monetdb", home, DIR_SEP);
                                        if (len >= 0 && len < FILENAME_MAX)
-                                               config = MT_fopen(buf, "r");
+                                               config = fopen(buf, "r");
                                }
                        }
                }
-       } else if (*cfile != 0 && (config = MT_fopen(cfile, "r")) == NULL) {
+       } else if (*cfile != 0 && (config = fopen(cfile, "r")) == NULL) {
                fprintf(stderr, "failed to open file '%s': %s\n",
                        cfile, strerror(errno));
        }
+#endif
 
        *dotfile = (DotMonetdb) {0};
 
@@ -67,7 +100,7 @@ parse_dotmonetdb(DotMonetdb *dotfile)
                        if (buf[0] == '\0' || buf[0] == '#')
                                continue;
                        if ((q = strchr(buf, '=')) == NULL) {
-                               fprintf(stderr, "%s:%d: syntax error: %s\n",
+                               fprintf(stderr, CF ":%d: syntax error: %s\n",
                                        cfile, line, buf);
                                continue;
                        }
@@ -91,7 +124,7 @@ parse_dotmonetdb(DotMonetdb *dotfile)
                                /* make sure we don't set garbage */
                                if (strcmp(q, "sql") != 0 &&
                                    strcmp(q, "mal") != 0) {
-                                       fprintf(stderr, "%s:%d: unsupported "
+                                       fprintf(stderr, CF ":%d: unsupported "
                                                "language: %s\n",
                                                cfile, line, q);
                                }
@@ -118,7 +151,7 @@ parse_dotmonetdb(DotMonetdb *dotfile)
                                q = NULL;
                        }
                        if (q != NULL)
-                               fprintf(stderr, "%s:%d: unknown property: %s\n",
+                               fprintf(stderr, CF ":%d: unknown property: 
%s\n",
                                        cfile, line, buf);
                }
                fclose(config);
diff --git a/clients/odbc/driver/ODBCGlobal.h b/clients/odbc/driver/ODBCGlobal.h
--- a/clients/odbc/driver/ODBCGlobal.h
+++ b/clients/odbc/driver/ODBCGlobal.h
@@ -91,9 +91,33 @@ SQLRETURN MNDBFreeHandle(SQLSMALLINT han
 SQLRETURN MNDBGetDiagRec(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT 
recNumber, SQLCHAR *sqlState, SQLINTEGER *nativeErrorPtr, SQLCHAR *messageText, 
SQLSMALLINT bufferLength, SQLSMALLINT *textLengthPtr);
 
 #ifdef ODBCDEBUG
+#ifdef NATIVE_WIN32
+extern const wchar_t *ODBCdebug;
+#else
 extern const char *ODBCdebug;
+#endif
 
 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
+#ifdef NATIVE_WIN32
+#define ODBCLOG(...)                                                   \
+       do {                                                            \
+               if (ODBCdebug == NULL) {                                \
+                       if ((ODBCdebug = _wgetenv(L"ODBCDEBUG")) == NULL) \
+                               ODBCdebug = _wcsdup(L"");               \
+                       else                                            \
+                               ODBCdebug = _wcsdup(ODBCdebug);         \
+               }                                                       \
+               if (ODBCdebug != NULL && *ODBCdebug != 0) {             \
+                       FILE *_f;                                       \
+                       _f = _wfopen(ODBCdebug, L"a");                  \
+                       if (_f == NULL)                                 \
+                               _f = stderr;                            \
+                       fprintf(_f, __VA_ARGS__);                       \
+                       if (_f != stderr)                               \
+                               fclose(_f);                             \
+               }                                                       \
+       } while (0)
+#else
 #define ODBCLOG(...)                                                   \
        do {                                                            \
                if (ODBCdebug == NULL) {                                \
@@ -112,6 +136,7 @@ extern const char *ODBCdebug;
                                fclose(_f);                             \
                }                                                       \
        } while (0)
+#endif
 #else
 extern void ODBCLOG(_In_z_ _Printf_format_string_ const char *fmt, ...)
        __attribute__((__format__(__printf__, 1, 2)));
diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c
--- a/clients/odbc/driver/ODBCUtil.c
+++ b/clients/odbc/driver/ODBCUtil.c
@@ -2140,7 +2140,11 @@ struct sql_types ODBC_c_types[] = {
 
 #ifdef ODBCDEBUG
 
+#ifdef NATIVE_WIN32
+const wchar_t *ODBCdebug;
+#else
 const char *ODBCdebug;
+#endif
 static char unknown[32];
 
 char *
@@ -2711,15 +2715,26 @@ ODBCLOG(const char *fmt, ...)
 
        va_start(ap, fmt);
        if (ODBCdebug == NULL) {
+#ifdef NATIVE_WIN32
+               if ((ODBCdebug = _wgetenv(L"ODBCDEBUG")) == NULL)
+                       ODBCdebug = _wcsdup(L"");
+               else
+                       ODBCdebug = _wcsdup(ODBCdebug);
+#else
                if ((ODBCdebug = getenv("ODBCDEBUG")) == NULL)
                        ODBCdebug = strdup("");
                else
                        ODBCdebug = strdup(ODBCdebug);
+#endif
        }
        if (ODBCdebug != NULL && *ODBCdebug != 0) {
                FILE *f;
 
+#ifdef NATIVE_WIN32
+               f = _wfopen(ODBCdebug, L"a");
+#else
                f = fopen(ODBCdebug, "a");
+#endif
                if (f) {
                        vfprintf(f, fmt, ap);
                        fclose(f);
diff --git a/clients/odbc/driver/SQLBrowseConnect.c 
b/clients/odbc/driver/SQLBrowseConnect.c
--- a/clients/odbc/driver/SQLBrowseConnect.c
+++ b/clients/odbc/driver/SQLBrowseConnect.c
@@ -57,7 +57,7 @@ MNDBBrowseConnect(ODBCDbc *dbc,
        int n;
        SQLRETURN rc;
 #ifdef ODBCDEBUG
-       int allocated = 0;
+       bool allocated = false;
 #endif
 
        fixODBCstring(InConnectionString, StringLength1, SQLSMALLINT, 
addDbcError, dbc, return SQL_ERROR);
@@ -106,12 +106,33 @@ MNDBBrowseConnect(ODBCDbc *dbc,
                        dbname = attr;
 #ifdef ODBCDEBUG
                } else if (strcasecmp(key, "logfile") == 0 &&
-                          getenv("ODBCDEBUG") == NULL) {
+#ifdef NATIVE_WIN32
+                          _wgetenv(L"ODBCDEBUG")
+#else
+                          getenv("ODBCDEBUG")
+#endif
+                          == NULL) {
                        /* environment trumps everything */
                        if (ODBCdebug)
                                free((void *) ODBCdebug); /* discard const */
+#ifdef NATIVE_WIN32
+                       size_t attrlen = strlen(attr);
+                       SQLWCHAR *wattr = malloc((attrlen + 1) * 
sizeof(SQLWCHAR));
+                       if (ODBCutf82wchar(attr,
+                                          (SQLINTEGER) attrlen,
+                                          wattr,
+                                          (SQLLEN) ((attrlen + 1) * 
sizeof(SQLWCHAR)),
+                                          NULL,
+                                          NULL)) {
+                               free(wattr);
+                               wattr = NULL;
+                       }
+                       ODBCdebug = wattr;
+                       free(attr);
+#else
                        ODBCdebug = attr;
-                       allocated = 1;
+#endif
+                       allocated = true;
 #endif
                } else
                        free(attr);
@@ -160,14 +181,35 @@ MNDBBrowseConnect(ODBCDbc *dbc,
                        }
                }
 #ifdef ODBCDEBUG
-               if (!allocated && getenv("ODBCDEBUG") == NULL) {
+               if (!allocated &&
+#ifdef NATIVE_WIN32
+                   _wgetenv(L"ODBCDEBUG")
+#else
+                   getenv("ODBCDEBUG")
+#endif
+                   == NULL) {
                        /* if not set from InConnectionString argument
                         * or environment, look in profile */
                        n = SQLGetPrivateProfileString(dsn, "logfile", "", buf, 
sizeof(buf), "odbc.ini");
                        if (n > 0 && buf[0]) {
                                if (ODBCdebug)
                                        free((void *) ODBCdebug); /* discard 
const */
+#ifdef NATIVE_WIN32
+                               size_t attrlen = strlen(buf);
+                               SQLWCHAR *wattr = malloc((attrlen + 1) * 
sizeof(SQLWCHAR));
+                               if (ODBCutf82wchar(buf,
+                                                  (SQLINTEGER) attrlen,
+                                                  wattr,
+                                                  (SQLLEN) ((attrlen + 1) * 
sizeof(SQLWCHAR)),
+                                                  NULL,
+                                                  NULL)) {
+                                       free(wattr);
+                                       wattr = NULL;
+                               }
+                               ODBCdebug = wattr;
+#else
                                ODBCdebug = strdup(buf);
+#endif
                        }
                }
 #endif
diff --git a/clients/odbc/driver/SQLConnect.c b/clients/odbc/driver/SQLConnect.c
--- a/clients/odbc/driver/SQLConnect.c
+++ b/clients/odbc/driver/SQLConnect.c
@@ -121,7 +121,6 @@ MNDBConnect(ODBCDbc *dbc,
        char pwd[32];
        char buf[256];
        char db[32];
-       char *s;
        int n;
        Mapi mid;
 
@@ -151,9 +150,23 @@ MNDBConnect(ODBCDbc *dbc,
                                               logfile, sizeof(logfile),
                                               "odbc.ini");
                if (n > 0) {
-                       if (ODBCdebug)
-                               free((void *) ODBCdebug); /* discard const */
+                       free((void *) ODBCdebug); /* discard const */
+#ifdef NATIVE_WIN32
+                       size_t attrlen = strlen(logfile);
+                       SQLWCHAR *wattr = malloc((attrlen + 1) * 
sizeof(SQLWCHAR));
+                       if (ODBCutf82wchar(logfile,
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to