1 /**********************************************************************************
5 **************************************************
6 * This code was created by Peter Harvey @ CodeByDesign.
7 * Released under LGPL 28.JAN.99
9 * Contributions from...
10 * -----------------------------------------------
11 * PAH = Peter Harvey - pharvey@codebydesign.com
12 * -----------------------------------------------
14 * PAH 06.MAR.99 Can now create file-less INI. Pass NULL for
15 * pszFileName. Then copy a file name into hIni->szFileName
16 * before calling iniCommit.
17 **************************************************/
19 #include "inifile_intern.h"
21 #include <aros/libcall.h>
23 /*****************************************************************************
25 AROS_LH7(int, iniOpen
,
28 AROS_LHA(HINI
*, hIni
, A0
),
29 AROS_LHA(char, *pszFileName
, A1
),
30 AROS_LHA(char, cComment
, D0
),
31 AROS_LHA(char, cLeftBracket
, D1
),
32 AROS_LHA(char, cRightBracket
, D2
),
33 AROS_LHA(char, cEqual
, D3
),
34 AROS_LHA(int, bCreate
, D4
),
37 struct Library
*, inifileBase
, 29, inifile
)
57 *****************************************************************************/
62 char szLine
[INI_MAX_LINE
+1];
63 char szObjectName
[INI_MAX_OBJECT_NAME
+1];
64 char szPropertyName
[INI_MAX_PROPERTY_NAME
+1];
65 char szPropertyValue
[INI_MAX_PROPERTY_VALUE
+1];
69 *hIni
= malloc( sizeof(INI
) );
71 strncpy( (*hIni
)->szFileName
, pszFileName
, ODBC_FILENAME_MAX
);
73 strncpy( (*hIni
)->szFileName
, "", ODBC_FILENAME_MAX
);
74 (*hIni
)->cComment
= cComment
;
75 (*hIni
)->cLeftBracket
= cLeftBracket
;
76 (*hIni
)->cRightBracket
= cRightBracket
;
77 (*hIni
)->cEqual
= cEqual
;
78 (*hIni
)->bChanged
= FALSE
;
79 (*hIni
)->hCurObject
= NULL
;
80 (*hIni
)->hFirstObject
= NULL
;
81 (*hIni
)->hLastObject
= NULL
;
82 (*hIni
)->nObjects
= 0;
83 (*hIni
)->bReadOnly
= 0;
88 hFile
= fopen( pszFileName
, "r" );
91 if ( bCreate
== TRUE
)
93 hFile
= fopen( pszFileName
, "w" );
104 nValidFile
= _iniScanUntilObject( *hIni
, hFile
, szLine
);
105 if ( nValidFile
== INI_SUCCESS
)
110 if ( szLine
[0] == cLeftBracket
)
112 _iniObjectRead( (*hIni
), szLine
, szObjectName
);
113 iniObjectInsert( (*hIni
), szObjectName
);
115 else if ( (szLine
[0] != cComment
) && !isspace(szLine
[0]) )
117 _iniPropertyRead( (*hIni
), szLine
, szPropertyName
, szPropertyValue
);
118 iniPropertyInsert( (*hIni
), szPropertyName
, szPropertyValue
);
121 } while ( (ptr
= fgets( szLine
, INI_MAX_LINE
, hFile
)) != NULL
);
123 else if ( nValidFile
== INI_ERROR
)
137 iniObjectFirst( *hIni
);
139 } /* if file given */