Last change
on this file since 120 was 112, checked in by rjmcnab, 25 years ago |
Standard header.
|
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.3 KB
|
Rev | Line | |
---|
[100] | 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 112 1999-01-12 01:51:06Z rjmcnab $
|
---|
| 9 | *
|
---|
| 10 | *********************************************************************/
|
---|
| 11 |
|
---|
| 12 | /*
|
---|
| 13 | $Log$
|
---|
[112] | 14 | Revision 1.3 1999/01/12 01:50:57 rjmcnab
|
---|
| 15 |
|
---|
| 16 | Standard header.
|
---|
| 17 |
|
---|
[100] | 18 | Revision 1.2 1999/01/08 02:33:13 rjmcnab
|
---|
| 19 |
|
---|
| 20 | Added standard header to source files.
|
---|
| 21 |
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 |
|
---|
[57] | 25 | #include "cfgread.h"
|
---|
| 26 |
|
---|
[100] | 27 |
|
---|
[57] | 28 | // returns 0 on success, -1 on failure
|
---|
| 29 | int read_cfg_line (ifstream &filein, text_tarray &values) {
|
---|
| 30 | values.erase(values.begin(), values.end());
|
---|
| 31 |
|
---|
| 32 | if (!filein.good()) return -1;
|
---|
| 33 |
|
---|
| 34 | text_t curvalue;
|
---|
| 35 | char c;
|
---|
| 36 |
|
---|
| 37 | int firstchar = 1;
|
---|
| 38 | filein.get(c);
|
---|
| 39 | while (!filein.eof()) {
|
---|
| 40 | if (c == '#' && firstchar) {
|
---|
| 41 | // found a comment, ignore the rest of the line
|
---|
| 42 | while (!filein.eof() && c != '\n') {
|
---|
| 43 | filein.get(c);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | } else if (firstchar && (c == '\n' || c == ' ' || c == '\t')) {
|
---|
| 47 | // found initial white space, ignore it
|
---|
| 48 |
|
---|
| 49 | } else if (c == '\n') {
|
---|
| 50 | // found the end of an entry
|
---|
| 51 | break;
|
---|
| 52 |
|
---|
| 53 | } else if (c == '\t') {
|
---|
| 54 | // found a record separator
|
---|
| 55 | values.push_back(curvalue);
|
---|
| 56 | curvalue.clear();
|
---|
| 57 |
|
---|
| 58 | } else {
|
---|
| 59 | curvalue.push_back(c);
|
---|
| 60 | firstchar = 0;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | filein.get(c);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | values.push_back(curvalue);
|
---|
| 67 |
|
---|
| 68 | return 0;
|
---|
| 69 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.