| 1 | /********************************************************************************** |
| 2 | * . |
| 3 | * totally untested |
| 4 | * |
| 5 | * see iniElement instead |
| 6 | **********************************************************************************/ |
| 7 | |
| 8 | #include <config.h> |
| 9 | #include "ini.h" |
| 10 | |
| 11 | int iniPropertyValue( char *pszString, char *pszProperty, char *pszValue, char cEqual, char cPropertySep ) |
| 12 | { |
| 13 | char szBuffer[INI_MAX_LINE+1]; |
| 14 | char szEqual[2]; |
| 15 | char szPropertySep[2]; |
| 16 | char *pProperty; |
| 17 | char *pValue; |
| 18 | char *pValueLastChar; |
| 19 | |
| 20 | szEqual[0] = cEqual; |
| 21 | szEqual[1] = '\0'; |
| 22 | szPropertySep[0] = cPropertySep; |
| 23 | szPropertySep[1] = '\0'; |
| 24 | |
| 25 | strcpy( pszValue, "" ); |
| 26 | strncpy( szBuffer, pszString, INI_MAX_LINE ); |
| 27 | |
| 28 | /* find pszProperty */ |
| 29 | while ( 1 ) |
| 30 | { |
| 31 | pProperty = (char *)strtok( szBuffer, (const char *)szPropertySep ); |
| 32 | if ( pProperty == NULL ) |
| 33 | break; |
| 34 | else |
| 35 | { |
| 36 | /* extract pszValue */ |
| 37 | if ( strncmp( pProperty, pszProperty, strlen(pszProperty) ) == 0 ) |
| 38 | { |
| 39 | pValue = (char *)strtok( szBuffer, (const char *)szEqual ); |
| 40 | if ( pValue ) |
| 41 | { |
| 42 | /* truncate any other data */ |
| 43 | pValueLastChar = (char *)strchr( pValue, szPropertySep[ 0 ] ); |
| 44 | if ( pValueLastChar ) |
| 45 | pValueLastChar[0] = '\0'; |
| 46 | |
| 47 | strncpy( pszValue, pValue, INI_MAX_PROPERTY_VALUE ); |
| 48 | iniAllTrim( pszValue ); |
| 49 | } |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return INI_SUCCESS; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | |