source: main/trunk/greenstone2/runtime-src/src/recpt/maincfg.cpp@ 24959

Last change on this file since 24959 was 19820, checked in by mdewsnip, 15 years ago

Now also looks for collect/<collection>/custom/<collection>/etc/custom.cfg files too, to be consistent with src/colservr/colservrconfig.cpp.

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1/**********************************************************************
2 *
3 * maincfg.cpp --
4 * Copyright (C) 2008 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 "maincfg.h"
27#include "fileutil.h"
28
29
30#if defined(GSDL_USE_OBJECTSPACE)
31# include <ospace/std/iostream>
32# include <ospace/std/fstream>
33#elif defined(GSDL_USE_IOS_H)
34# include <iostream.h>
35# include <fstream.h>
36#else
37# include <iostream>
38# include <fstream>
39#endif
40
41
42bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
43 const text_t &collection)
44{
45
46 cerr << "Warning: Using version of main_cfg_read() that does not support 'collecthome'" << endl;
47
48 text_t collecthome = filename_cat(gsdlhome,"collect");
49
50 cerr << "Setting collecthome to be " << collecthome << endl;
51
52
53 return main_cfg_read(recpt,gsdlhome,collecthome,collection);
54}
55
56
57// main_cfg_read reads both main.cfg and collect.cfg. It attempts
58// to read main.cfg first so values in collect.cfg override those
59// set earlier by main.cfg
60bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
61 const text_t& collecthome, const text_t &collection) {
62
63 // read in the main configuration file
64 bool rv = false;
65
66 text_t key, filename;
67 text_tarray cfgline;
68 filename = filename_cat (gsdlhome, "etc", "main.cfg");
69 if (!collection.empty() && file_exists(filename)) {
70 rv = recpt.read_configfile(filename);
71 } else {
72 if (file_exists (filename)) {
73 rv = recpt.read_configfile(filename);
74 }
75 }
76
77 // Look for collect.cfg in <collecthome>/collection-name/etc directory
78 // (if this is for a particular collection), and then GSDLHOME/etc.
79 if (!collection.empty()) {
80 filename = filename_cat (collecthome, collection, "etc", "collect.cfg");
81 if (!file_exists (filename)) {
82 filename = filename_cat (gsdlhome, "etc", "collect.cfg");
83 if (!file_exists (filename)) filename.clear();
84 }
85
86 if (!filename.empty()) {
87 rv |= recpt.read_configfile(filename);
88 }
89
90 // Look for custom.cfg in <collecthome>/collection-name/custom/collection-name/etc too
91 filename = filename_cat (collecthome, collection, "custom", collection, "etc", "custom.cfg");
92 if (file_exists(filename))
93 {
94 rv |= recpt.read_configfile(filename);
95 }
96 }
97 return rv;
98}
Note: See TracBrowser for help on using the repository browser.