source: gsdl/trunk/src/recpt/maincfg.cpp@ 16312

Last change on this file since 16312 was 16310, checked in by davidb, 16 years ago

Introduction of 'collecthome' which parallels 'gsdlhome' to allow the toplevel collect folder to be outside of the gsdlhome area

  • Property svn:executable set to *
File size: 3.0 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 return main_cfg_read(recpt,gsdlhome,collecthome,collection);
50}
51
52
53// main_cfg_read reads both main.cfg and collect.cfg. It attempts
54// to read main.cfg first so values in collect.cfg override those
55// set earlier by main.cfg
56bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
57 const text_t& collecthome, const text_t &collection) {
58
59 // read in the main configuration file
60 bool rv = false;
61
62 text_t key, filename;
63 text_tarray cfgline;
64 filename = filename_cat (gsdlhome, "etc");
65 filename = filename_cat (filename, "main.cfg");
66 if (!collection.empty() && file_exists(filename)) {
67 rv = recpt.read_configfile(filename);
68 } else {
69 filename_cat (filename, gsdlhome, "etc", "main.cfg");
70 if (file_exists (filename)) {
71 rv = recpt.read_configfile(filename);
72 }
73 }
74
75 // Look for collect.cfg in <collecthome>/collection-name/etc directory
76 // (if this is for a particular collection), and then GSDLHOME/etc.
77 if (!collection.empty()) {
78 filename = filename_cat (collecthome, collection);
79 filename = filename_cat (filename, "etc");
80 filename = filename_cat (filename, "collect.cfg");
81 if (!file_exists (filename)) {
82 filename = filename_cat (gsdlhome, "etc");
83 filename = filename_cat (filename, "collect.cfg");
84 if (!file_exists (filename)) filename.clear();
85 }
86
87 if (!filename.empty()) {
88 rv |= recpt.read_configfile(filename);
89 }
90 }
91 return rv;
92}
Note: See TracBrowser for help on using the repository browser.