]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/misc.c
42b26a62b92a1b7fea43cafaa9eccaba190f8df7
1 /** miscellaneous functions
3 Copyright (C) 1995 by Ke Jin <kejin@empress.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
17 # define INCL_DOSMODULEMGR /* Module Manager values */
18 # define INCL_DOSERRORS /* Error values */
23 #include <../iodbc/iodbc.h>
25 #include <../iodbc/isql.h>
26 #include <../iodbc/isqlext.h>
48 if( c1
>= 'a' && c1
<= 'z' )
57 if( c2
>= 'a' && c2
<= 'z' )
66 if( (c1
- c2
) || !c1
|| !c2
)
72 return (int)!(c1
- c2
);
75 static char* /* return new position in input str */
77 char* istr
, /* old position in input buf */
78 char* obuf
) /* token string ( if "\0", then finished ) */
80 for(; *istr
&& *istr
!= '\n' ; istr
++ )
86 if( c
== ' ' || c
== '\t' )
96 if( c
== ';' || c
== '=' )
102 if( nx
== ' ' || nx
== '\t' || nx
== ';' || nx
== '=' )
114 #if !defined(WINDOWS) && !defined(WIN32) && !defined(OS2)
120 getinitfile(char* buf
, int size
)
125 j
= STRLEN("/iodbc.ini") + 1;
133 sprintf( buf
, "%s/iodbc.ini", DIR_INI_FILE
);
137 if( NULL
!= getenv("IODBC_INI") )
139 strcpy( buf
, getenv("IODBC_INI") );
145 if( NO_ERROR
== DosQueryModuleHandle(DLL_NAME
, &hModule
) &&
146 NO_ERROR
== DosQueryModuleName(hModule
, 256L, buf
) )
148 if( NULL
!= strrchr(buf
, '.') )
149 *(strchr(buf
, '.')) = '\0';
150 strcat( buf
, ".ini" );
154 strcpy( buf
, "iodbc.ini" );
160 # if !defined(UNIX_PWD)
162 i
= GetWindowsDirectory((LPSTR
)buf
, size
);
164 if( i
== 0 || i
> size
- j
)
169 sprintf( buf
+ i
, "/iodbc.ini");
173 ptr
= (char*)getpwuid(getuid());
180 ptr
= ((struct passwd
*)ptr
)->pw_dir
;
182 if( ptr
== NULL
|| *ptr
== '\0' )
187 if( size
< STRLEN(ptr
) + j
)
192 sprintf( buf
, "%s%s", ptr
, "/.iodbc.ini");
193 /* i.e. searching ~/.iodbc.ini */
201 char* _iodbcdm_getkeyvalbydsn(
207 /* read odbc init file to resolve the value of specified
208 * key from named or defaulted dsn section
212 char dsntk
[SQL_MAX_DSN_LENGTH
+ 3] = { '[', '\0' };
213 char token
[1024]; /* large enough */
218 #define DSN_NOMATCH 0
220 #define DSN_DEFAULT 2
222 int dsnid
= DSN_NOMATCH
;
223 int defaultdsn
= DSN_NOMATCH
;
225 if( dsn
== NULL
|| *dsn
== 0 )
228 dsnlen
= STRLEN(dsn
);
231 if( dsnlen
== SQL_NTS
)
233 dsnlen
= STRLEN(dsn
);
236 if( dsnlen
<= 0 || keywd
== NULL
|| buf
== 0 || size
<= 0 )
241 if( dsnlen
> sizeof(dsntk
) - 2 )
248 STRNCAT( dsntk
, dsn
, dsnlen
);
249 STRCAT( dsntk
, "]" );
253 path
= getinitfile(pathbuf
, sizeof(pathbuf
));
260 file
= (FILE*)fopen(path
, "r");
271 str
= fgets(buf
, sizeof(buf
), file
);
278 strtok( str
, "\n\r" );
282 if( upper_strneq(str
, "[default]", STRLEN("[default]")) )
284 /* we only read first dsn default dsn
285 * section (as well as named dsn).
287 if( defaultdsn
== DSN_NOMATCH
)
290 defaultdsn
= DSN_DEFAULT
;
299 else if( upper_strneq( str
, dsntk
, dsnlen
) )
310 else if( dsnid
== DSN_NOMATCH
)
315 str
= readtoken(str
, token
);
317 if( upper_strneq( keywd
, token
, STRLEN(keywd
)) )
319 str
= readtoken(str
, token
);
321 if( ! STREQ( token
, "=") )
322 /* something other than = */
327 str
= readtoken(str
, token
);
329 if( STRLEN(token
) > size
- 1)
334 STRNCPY(value
, token
, size
);
335 /* copy the value(i.e. next token) to buf */
337 if( dsnid
!= DSN_DEFAULT
)
346 return (*value
)? value
:NULL
;
349 char* _iodbcdm_getkeyvalinstr(
356 char token
[1024] = { '\0' };
359 if( cnstr
== NULL
|| value
== NULL
360 || keywd
== NULL
|| size
< 1 )
365 if( cnlen
== SQL_NTS
)
367 cnlen
= STRLEN (cnstr
);
377 cnstr
= readtoken(cnstr
, token
);
384 if( STREQ( token
, ";" ) )
393 if( upper_strneq(token
, keywd
, strlen(keywd
)) )
400 if( STREQ( token
, "=" ) )
407 if( size
< strlen(token
) + 1 )
412 STRNCPY( value
, token
, size
);