1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * conftools.cpp
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 | #include "text_t.h"
|
---|
27 | #include "conftools.h"
|
---|
28 |
|
---|
29 | int write_confline (ofstream &fileout, const text_t &key, const text_t value) {
|
---|
30 | if (key.empty() || value.empty()) return -1;
|
---|
31 | outconvertclass text_t2ascii;
|
---|
32 | fileout << text_t2ascii << key << "=" << value << "\n";
|
---|
33 | return 0;
|
---|
34 | }
|
---|
35 |
|
---|
36 | int get_confline (ifstream &filein, text_t &key, text_t &value) {
|
---|
37 | if (filein.eof()) return -1;
|
---|
38 |
|
---|
39 | key.clear();
|
---|
40 | value.clear();
|
---|
41 | char c;
|
---|
42 | filein.get(c);
|
---|
43 |
|
---|
44 | int foundeq = 0;
|
---|
45 | while (!filein.eof() && c != '\n') {
|
---|
46 | if (!foundeq && c == '=') {foundeq = 1; filein.get(c);}
|
---|
47 |
|
---|
48 | if (foundeq) value.push_back(c);
|
---|
49 | else key.push_back(c);
|
---|
50 | filein.get(c);
|
---|
51 | }
|
---|
52 | if (key.empty()) return -1;
|
---|
53 | return 0;
|
---|
54 | }
|
---|
55 |
|
---|