1 | /********************************************************************************** |
2 | * iniAppend |
3 | * |
4 | * - Appends Sections which do not exist in hIni. Ignores all else. |
5 | * - Does not try to append 'missing' Entries to existing Sections (does not try to merge). |
6 | * - hIni will become ReadOnly |
7 | * |
8 | ************************************************** |
9 | * This code was created by Peter Harvey @ CodeByDesign. |
10 | * Released under LGPL 28.JAN.99 |
11 | * |
12 | * Contributions from... |
13 | * ----------------------------------------------- |
14 | * Peter Harvey - pharvey@codebydesign.com |
15 | **************************************************/ |
16 | |
17 | #include <config.h> |
18 | #include "ini.h" |
19 | |
20 | int iniAppend( HINI hIni, char *pszFileName ) |
21 | { |
22 | FILE *hFile; |
23 | char szLine[INI_MAX_LINE+1]; |
24 | char szObjectName[INI_MAX_OBJECT_NAME+1]; |
25 | char szPropertyName[INI_MAX_PROPERTY_NAME+1]; |
26 | char szPropertyValue[INI_MAX_PROPERTY_VALUE+1]; |
27 | |
28 | /* SANITY CHECK */ |
29 | if ( strlen( pszFileName ) > ODBC_FILENAME_MAX ) |
30 | return INI_ERROR; |
31 | |
32 | /* OPEN FILE */ |
33 | hFile = uo_fopen( pszFileName, "r" ); |
34 | if ( !hFile ) |
35 | return INI_ERROR; |
36 | |
37 | iniObjectLast( hIni ); |
38 | iniPropertyLast( hIni ); |
39 | |
40 | /* SCAN UNTIL WE GET TO AN OBJECT NAME OR EOF */ |
41 | szLine[0] = '\0'; |
42 | if ( _iniScanUntilObject( hIni, hFile, szLine ) == INI_SUCCESS ) |
43 | { |
44 | do |
45 | { |
46 | if ( szLine[0] == hIni->cLeftBracket ) |
47 | { |
48 | _iniObjectRead( hIni, szLine, szObjectName ); |
49 | if ( iniObjectSeek( hIni, szObjectName ) == INI_SUCCESS ) |
50 | { |
51 | iniObjectLast( hIni ); |
52 | iniPropertyLast( hIni ); |
53 | if ( _iniScanUntilNextObject( hIni, hFile, szLine ) != INI_SUCCESS) |
54 | break; |
55 | } |
56 | else |
57 | { |
58 | iniObjectInsert( hIni, szObjectName ); |
59 | if ( uo_fgets( szLine, INI_MAX_LINE, hFile ) == NULL ) |
60 | break; |
61 | } |
62 | } |
63 | else if ( (strchr( hIni->cComment, szLine[0] ) == NULL ) && isalnum(szLine[0]) ) |
64 | { |
65 | _iniPropertyRead( hIni, szLine, szPropertyName, szPropertyValue ); |
66 | iniPropertyInsert( hIni, szPropertyName, szPropertyValue ); |
67 | if ( uo_fgets( szLine, INI_MAX_LINE, hFile ) == NULL ) |
68 | break; |
69 | } |
70 | else |
71 | { |
72 | if ( uo_fgets( szLine, INI_MAX_LINE, hFile ) == NULL ) |
73 | break; |
74 | } |
75 | } while( 1 ); |
76 | } |
77 | |
78 | /* WE ARE NOT GOING TO TRY TO BE SMART ENOUGH TO SAVE THIS STUFF */ |
79 | hIni->bReadOnly = 1; |
80 | |
81 | /* CLEANUP */ |
82 | if ( hFile != NULL ) |
83 | uo_fclose( hFile ); |
84 | |
85 | return INI_SUCCESS; |
86 | } |
87 | |
88 | |
89 | |