]>
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>
38 if( c1
>= 'a' && c1
<= 'z' )
47 if( c2
>= 'a' && c2
<= 'z' )
56 if( (c1
- c2
) || !c1
|| !c2
)
62 return (int)!(c1
- c2
);
65 static char* /* return new position in input str */
67 char* istr
, /* old position in input buf */
68 char* obuf
) /* token string ( if "\0", then finished ) */
70 for(; *istr
&& *istr
!= '\n' ; istr
++ )
76 if( c
== ' ' || c
== '\t' )
86 if( c
== ';' || c
== '=' )
92 if( nx
== ' ' || nx
== '\t' || nx
== ';' || nx
== '=' )
104 #if !defined(WINDOWS) && !defined(WIN32) && !defined(OS2)
110 getinitfile(char* buf
, int size
)
115 j
= STRLEN("/odbc.ini") + 1;
122 #if !defined(UNIX_PWD)
124 i
= GetWindowsDirectory((LPSTR
)buf
, size
);
126 if( i
== 0 || i
> size
- j
)
131 sprintf( buf
+ i
, "/odbc.ini");
135 ptr
= (char*)getpwuid(getuid());
142 ptr
= ((struct passwd
*)ptr
)->pw_dir
;
144 if( ptr
== NULL
|| *ptr
== '\0' )
149 if( size
< STRLEN(ptr
) + j
)
154 sprintf( buf
, "%s%s", ptr
, "/.odbc.ini");
155 /* i.e. searching ~/.odbc.ini */
161 char* _iodbcdm_getkeyvalbydsn(
167 /* read odbc init file to resolve the value of specified
168 * key from named or defaulted dsn section
172 char dsntk
[SQL_MAX_DSN_LENGTH
+ 3] = { '[', '\0' };
173 char token
[1024]; /* large enough */
178 #define DSN_NOMATCH 0
180 #define DSN_DEFAULT 2
182 int dsnid
= DSN_NOMATCH
;
183 int defaultdsn
= DSN_NOMATCH
;
185 if( dsn
== NULL
|| *dsn
== 0 )
188 dsnlen
= STRLEN(dsn
);
191 if( dsnlen
== SQL_NTS
)
193 dsnlen
= STRLEN(dsn
);
196 if( dsnlen
<= 0 || keywd
== NULL
|| buf
== 0 || size
<= 0 )
201 if( dsnlen
> sizeof(dsntk
) - 2 )
208 STRNCAT( dsntk
, dsn
, dsnlen
);
209 STRCAT( dsntk
, "]" );
213 path
= getinitfile(pathbuf
, sizeof(pathbuf
));
220 file
= (FILE*)fopen(path
, "r");
231 str
= fgets(buf
, sizeof(buf
), file
);
240 if( upper_strneq(str
, "[default]", STRLEN("[default]")) )
242 /* we only read first dsn default dsn
243 * section (as well as named dsn).
245 if( defaultdsn
== DSN_NOMATCH
)
248 defaultdsn
= DSN_DEFAULT
;
257 else if( upper_strneq( str
, dsntk
, dsnlen
) )
268 else if( dsnid
== DSN_NOMATCH
)
273 str
= readtoken(str
, token
);
275 if( upper_strneq( keywd
, token
, STRLEN(keywd
)) )
277 str
= readtoken(str
, token
);
279 if( ! STREQ( token
, "=") )
280 /* something other than = */
285 str
= readtoken(str
, token
);
287 if( STRLEN(token
) > size
- 1)
292 STRNCPY(value
, token
, size
);
293 /* copy the value(i.e. next token) to buf */
295 if( dsnid
!= DSN_DEFAULT
)
304 return (*value
)? value
:NULL
;
307 char* _iodbcdm_getkeyvalinstr(
314 char token
[1024] = { '\0' };
317 if( cnstr
== NULL
|| value
== NULL
318 || keywd
== NULL
|| size
< 1 )
323 if( cnlen
== SQL_NTS
)
325 cnlen
= STRLEN (cnstr
);
335 cnstr
= readtoken(cnstr
, token
);
342 if( STREQ( token
, ";" ) )
351 if( upper_strneq(token
, keywd
, strlen(keywd
)) )
358 if( STREQ( token
, "=" ) )
365 if( size
< strlen(token
) + 1 )
370 STRNCPY( value
, token
, size
);