Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "MNSINIParser.hxx"
21 : #include <rtl/byteseq.hxx>
22 :
23 9 : IniParser::IniParser(OUString const & rIniName) throw(com::sun::star::io::IOException )
24 : {
25 9 : OUString iniUrl;
26 : oslFileError fileError = osl_getFileURLFromSystemPath(
27 9 : rIniName.pData, &iniUrl.pData);
28 9 : if (fileError != osl_File_E_None)
29 : {
30 : SAL_WARN(
31 : "connectivity.mork",
32 : "InitParser, getFileURLFromSystemPath(" << rIniName << "): "
33 : << +fileError);
34 9 : return;
35 : }
36 :
37 : SAL_INFO("connectivity.mork", "IniParser: " << iniUrl);
38 9 : oslFileHandle handle=NULL;
39 9 : fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read);
40 :
41 9 : if (osl_File_E_None == fileError)
42 : {
43 6 : rtl::ByteSequence seq;
44 6 : sal_uInt64 nSize = 0;
45 :
46 6 : osl_getFileSize(handle, &nSize);
47 12 : OUString sectionName( "no name section" );
48 : while (true)
49 : {
50 : sal_uInt64 nPos;
51 72 : if (osl_File_E_None != osl_getFilePos(handle, &nPos) || nPos >= nSize)
52 12 : break;
53 66 : if (osl_File_E_None != osl_readLine(handle , reinterpret_cast<sal_Sequence **>(&seq)))
54 0 : break;
55 66 : OString line( reinterpret_cast<const char *>(seq.getConstArray()), seq.getLength() );
56 66 : sal_Int32 nIndex = line.indexOf('=');
57 66 : if (nIndex >= 1)
58 : {
59 36 : ini_Section *aSection = &mAllSection[sectionName];
60 36 : struct ini_NameValue nameValue;
61 72 : nameValue.sName = OStringToOUString(
62 36 : line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US );
63 72 : nameValue.sValue = OStringToOUString(
64 36 : line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 );
65 :
66 36 : aSection->lList.push_back(nameValue);
67 :
68 : }
69 : else
70 : {
71 30 : sal_Int32 nIndexStart = line.indexOf('[');
72 30 : sal_Int32 nIndexEnd = line.indexOf(']');
73 30 : if ( nIndexEnd > nIndexStart && nIndexStart >=0)
74 : {
75 30 : sectionName = OStringToOUString(
76 30 : line.copy(nIndexStart + 1,nIndexEnd - nIndexStart -1).trim(), RTL_TEXTENCODING_ASCII_US );
77 15 : if (sectionName.isEmpty())
78 0 : sectionName = "no name section";
79 :
80 15 : ini_Section *aSection = &mAllSection[sectionName];
81 15 : aSection->sName = sectionName;
82 : }
83 : }
84 66 : }
85 12 : osl_closeFile(handle);
86 : }
87 : else
88 : {
89 : SAL_INFO(
90 : "connectivity.mork",
91 : "IniParser couldn't open file " << iniUrl << ": " << +fileError);
92 9 : }
93 : }
94 :
95 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|