]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/misc.c
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.
16 #include <../iodbc/iodbc.h>
18 #include <../iodbc/isql.h>
19 #include <../iodbc/isqlext.h>
37 if( c1
>= 'a' && c1
<= 'z' )
46 if( c2
>= 'a' && c2
<= 'z' )
55 if( (c1
- c2
) || !c1
|| !c2
)
61 return (int)!(c1
- c2
);
64 static char* /* return new position in input str */
66 char* istr
, /* old position in input buf */
67 char* obuf
) /* token string ( if "\0", then finished ) */
69 for(; *istr
&& *istr
!= '\n' ; istr
++ )
75 if( c
== ' ' || c
== '\t' )
85 if( c
== ';' || c
== '=' )
91 if( nx
== ' ' || nx
== '\t' || nx
== ';' || nx
== '=' )
103 #if !defined(WINDOWS) && !defined(WIN32) && !defined(OS2)
109 getinitfile(char* buf
, int size
)
114 j
= STRLEN("/odbc.ini") + 1;
121 #if !defined(UNIX_PWD)
123 i
= GetWindowsDirectory((LPSTR
)buf
, size
);
125 if( i
== 0 || i
> size
- j
)
130 sprintf( buf
+ i
, "/odbc.ini");
134 ptr
= (char*)getpwuid(getuid());
141 ptr
= ((struct passwd
*)ptr
)->pw_dir
;
143 if( ptr
== NULL
|| *ptr
== '\0' )
148 if( size
< STRLEN(ptr
) + j
)
153 sprintf( buf
, "%s%s", ptr
, "/.odbc.ini");
154 /* i.e. searching ~/.odbc.ini */
160 char* _iodbcdm_getkeyvalbydsn(
166 /* read odbc init file to resolve the value of specified
167 * key from named or defaulted dsn section
171 char dsntk
[SQL_MAX_DSN_LENGTH
+ 3] = { '[', '\0' };
172 char token
[1024]; /* large enough */
177 #define DSN_NOMATCH 0
179 #define DSN_DEFAULT 2
181 int dsnid
= DSN_NOMATCH
;
182 int defaultdsn
= DSN_NOMATCH
;
184 if( dsn
== NULL
|| *dsn
== 0 )
187 dsnlen
= STRLEN(dsn
);
190 if( dsnlen
== SQL_NTS
)
192 dsnlen
= STRLEN(dsn
);
195 if( dsnlen
<= 0 || keywd
== NULL
|| buf
== 0 || size
<= 0 )
200 if( dsnlen
> sizeof(dsntk
) - 2 )
207 STRNCAT( dsntk
, dsn
, dsnlen
);
208 STRCAT( dsntk
, "]" );
212 path
= getinitfile(pathbuf
, sizeof(pathbuf
));
219 file
= (FILE*)fopen(path
, "r");
230 str
= fgets(buf
, sizeof(buf
), file
);
239 if( upper_strneq(str
, "[default]", STRLEN("[default]")) )
241 /* we only read first dsn default dsn
242 * section (as well as named dsn).
244 if( defaultdsn
== DSN_NOMATCH
)
247 defaultdsn
= DSN_DEFAULT
;
256 else if( upper_strneq( str
, dsntk
, dsnlen
) )
267 else if( dsnid
== DSN_NOMATCH
)
272 str
= readtoken(str
, token
);
274 if( upper_strneq( keywd
, token
, STRLEN(keywd
)) )
276 str
= readtoken(str
, token
);
278 if( ! STREQ( token
, "=") )
279 /* something other than = */
284 str
= readtoken(str
, token
);
286 if( STRLEN(token
) > size
- 1)
291 STRNCPY(value
, token
, size
);
292 /* copy the value(i.e. next token) to buf */
294 if( dsnid
!= DSN_DEFAULT
)
303 return (*value
)? value
:NULL
;
306 char* _iodbcdm_getkeyvalinstr(
313 char token
[1024] = { '\0' };
316 if( cnstr
== NULL
|| value
== NULL
317 || keywd
== NULL
|| size
< 1 )
322 if( cnlen
== SQL_NTS
)
324 cnlen
= STRLEN (cnstr
);
334 cnstr
= readtoken(cnstr
, token
);
341 if( STREQ( token
, ";" ) )
350 if( upper_strneq(token
, keywd
, strlen(keywd
)) )
357 if( STREQ( token
, "=" ) )
364 if( size
< strlen(token
) + 1 )
369 STRNCPY( value
, token
, size
);