source: trunk/gsdl/lib/cfgread.cpp@ 413

Last change on this file since 413 was 131, checked in by rjmcnab, 25 years ago

Changed the configuration file reader so that any space can be used to
seperate items and so that quotes can be used to contain items. I also
allowed a '\' to indicate that the line continues on the next line.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1/**********************************************************************
2 *
3 * cfgread.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: cfgread.cpp 131 1999-02-02 09:54:26Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.4 1999/02/02 09:54:26 rjmcnab
15
16 Changed the configuration file reader so that any space can be used to
17 seperate items and so that quotes can be used to contain items. I also
18 allowed a '\' to indicate that the line continues on the next line.
19
20 Revision 1.3 1999/01/12 01:50:57 rjmcnab
21
22 Standard header.
23
24 Revision 1.2 1999/01/08 02:33:13 rjmcnab
25
26 Added standard header to source files.
27
28 */
29
30
31#include "cfgread.h"
32
33
34// returns 0 on success, -1 on failure
35int read_cfg_line (ifstream &filein, text_tarray &values) {
36 // outconvertclass text_t2ascii;
37
38 values.erase(values.begin(), values.end());
39
40 if (!filein.good()) return -1;
41
42 text_t curvalue;
43 char c, quote;
44
45 bool linecontinues = true;
46 filein.get(c);
47 while (!filein.eof() && linecontinues) {
48 // eat up all return characters
49 while (!filein.eof() && (c=='\n' || c=='\r')) { filein.get(c); }
50
51 // ignore comments
52 if (c == '#') {
53 while (!filein.eof() && c!='\n' && c!='\r') { filein.get(c); }
54 }
55
56 // deal with all the records on this line
57 while (!filein.eof() && c!='\n' && c!='\r') {
58 // ignore white space
59 while (!filein.eof() && (c==' ' || c=='\t')) { filein.get(c); }
60
61 // get the next record
62 if (c!='\n' && c!='\r') {
63 curvalue.clear();
64 quote = 0;
65
66 // see if this is a quoted record
67 if (c=='\'' || c=='\"') {
68 quote = c;
69 filein.get(c);
70 }
71
72 // get the value
73 while (!filein.eof() && c!='\n' && c!='\r') {
74 if (quote != 0 && c == quote) { // end of quote
75 filein.get(c);
76 break;
77 } else if (quote == 0 && (c == ' ' || c == '\t')) {
78 break; // space seperator
79 }
80 curvalue.push_back(c);
81 filein.get(c);
82 }
83
84 // see if the record continues on the next line
85 if ((c=='\n' || c=='\r') && curvalue=="\\") {
86 linecontinues = true;
87 } else {
88 // cerr << text_t2ascii << "\"" << curvalue << "\" ";
89
90 values.push_back(curvalue);
91 curvalue.clear();
92 linecontinues = false;
93 }
94 }
95 }
96 }
97
98 // cerr << "\n";
99
100 return 0;
101}
Note: See TracBrowser for help on using the repository browser.