Build Lunapaint from Contrib.
[AROS-Contrib.git] / libini / iniAppend.c
blob216cce32a0c2cf83124c4fcbee6b17d729be1dbd
1 /**********************************************************************************
2 * iniAppend
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
8 **************************************************
9 * This code was created by Peter Harvey @ CodeByDesign.
10 * Released under LGPL 28.JAN.99
12 * Contributions from...
13 * -----------------------------------------------
14 * Peter Harvey - pharvey@codebydesign.com
15 **************************************************/
17 #include "inifile_intern.h"
18 #include "ini.h"
19 #include <aros/libcall.h>
21 /*****************************************************************************
23 NAME */
24 AROS_LH2(int, iniAppend,
26 /* SYNOPSIS */
27 AROS_LHA(HINI, hIni, D0),
28 AROS_LHA(char *, pszFileName, A0),
30 /* LOCATION */
31 struct Library *, inifileBase, 9, inifile)
33 /* FUNCTION
35 INPUTS
37 RESULT
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 HISTORY
51 *****************************************************************************/
53 AROS_LIBFUNC_INIT
55 FILE *hFile;
56 char szLine[INI_MAX_LINE+1];
57 char szObjectName[INI_MAX_OBJECT_NAME+1];
58 char szPropertyName[INI_MAX_PROPERTY_NAME+1];
59 char szPropertyValue[INI_MAX_PROPERTY_VALUE+1];
61 /* SANITY CHECK */
62 if ( strlen( pszFileName ) > ODBC_FILENAME_MAX )
63 return INI_ERROR;
65 /* OPEN FILE */
66 hFile = fopen( pszFileName, "r" );
67 if ( !hFile )
68 return INI_ERROR;
70 iniObjectLast( hIni );
71 iniPropertyLast( hIni );
73 /* SCAN UNTIL WE GET TO AN OBJECT NAME OR EOF */
74 szLine[0] = '\0';
75 if ( _iniScanUntilObject( hIni, hFile, szLine ) == INI_SUCCESS )
79 if ( szLine[0] == hIni->cLeftBracket )
81 _iniObjectRead( hIni, szLine, szObjectName );
82 if ( iniObjectSeek( hIni, szObjectName ) == INI_SUCCESS )
84 iniObjectLast( hIni );
85 iniPropertyLast( hIni );
86 if ( _iniScanUntilNextObject( hIni, hFile, szLine ) != INI_SUCCESS)
87 break;
89 else
91 iniObjectInsert( hIni, szObjectName );
92 if ( fgets( szLine, INI_MAX_LINE, hFile ) == NULL )
93 break;
96 else if ( (szLine[0] != hIni->cComment) && isalnum(szLine[0]) )
98 _iniPropertyRead( hIni, szLine, szPropertyName, szPropertyValue );
99 iniPropertyInsert( hIni, szPropertyName, szPropertyValue );
100 if ( fgets( szLine, INI_MAX_LINE, hFile ) == NULL )
101 break;
103 else
105 if ( fgets( szLine, INI_MAX_LINE, hFile ) == NULL )
106 break;
108 } while( 1 );
111 /* WE ARE NOT GOING TO TRY TO BE SMART ENOUGH TO SAVE THIS STUFF */
112 hIni->bReadOnly = 1;
114 /* CLEANUP */
115 if ( hFile != NULL )
116 fclose( hFile );
118 return INI_SUCCESS;
120 AROS_LIBFUNC_EXIT
121 } /* iniAppend */