Fresco/Berlin/src Makefile.in,1.44,1.45 RCManager.cc,1.3,1.4
Neil John Pilgrim <[email protected]>
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Berlin/src
In directory purcel:/tmp/cvs-serv9791/Berlin/src
Modified Files:
Makefile.in RCManager.cc
Log Message:
Factor code from server.cc into RCManager, to enable use across all Berlin binaries. Modify pinyin demo to not use RCManager (for now) - its a Berlin library, not something that clients should use.
Index: Makefile.in
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/Makefile.in,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- Makefile.in 6 Apr 2003 16:15:47 -0000 1.44
+++ Makefile.in 14 Apr 2003 00:25:06 -0000 1.45
@@ -30,6 +30,7 @@
include $(cdir)/local.mk
+CPPFLAGS+= -DRC_PREFIX='"$(prefix)"' -DRC_SYSCONFDIR='"$(sysconfdir)"'
CXXFLAGS+= $(SO_CXXFLAGS)
LDFLAGS += $(SO_LDFLAGS)
LIBS += -lpng
Index: RCManager.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/RCManager.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- RCManager.cc 2 Jun 2002 04:44:18 -0000 1.3
+++ RCManager.cc 14 Apr 2003 00:25:06 -0000 1.4
@@ -19,35 +19,125 @@
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*/
-#include "Berlin/RCManager.hh"
+#include <Berlin/RCManager.hh>
+#include <Berlin/Logger.hh>
+#include <Prague/Sys/User.hh>
#include <fstream>
+#include <stdexcept>
+#include <map>
-using namespace Prague;
+#ifdef RC_SYSCONFDIR
+const std::string sysconfdir = RC_SYSCONFDIR;
+#else
+const std::string sysconfdir = "";
+#endif
-std::map<std::string, Path> RCManager::_paths;
+// -----------------------------------------------------------------------------
+// Internals
+// -----------------------------------------------------------------------------
+static std::map<std::string, Prague::Path> _paths;
-void RCManager::read(const std::string &file)
+namespace RCManager_internals
{
- std::ifstream ifs(file.c_str());
- if (!ifs) { throw std::runtime_error("RCManager: file not found.");}
- while (ifs)
- {
- std::string name;
- ifs >> name;
- ifs.ignore(1024, '=');
- std::string path;
- ifs >> path;
- _paths.insert(std::make_pair(name, path));
- }
+ void read_file(const std::string &file)
+ {
+ std::ifstream ifs(file.c_str());
+ if (!ifs) { throw std::runtime_error("RCManager: file not found.");}
+ while (ifs)
+ {
+ std::string name;
+ ifs >> name;
+ ifs.ignore(1024, '=');
+ std::string path;
+ ifs >> path;
+ _paths.insert(std::make_pair(name, path));
+ }
+ }
+
+ void add_to_path(const std::string &name, const std::string &value)
+ {
+ Prague::Path &path = _paths[name];
+ path.append(value);
+ }
}
-Path RCManager::get_path(const std::string &name)
+// -----------------------------------------------------------------------------
+// Public functions
+// -----------------------------------------------------------------------------
+Prague::Path RCManager::get_path(const std::string &name)
{
- return _paths[name];
+ // NOTE: default (empty) path is constructed if not present in _paths yet
+ return _paths[name];
}
-void RCManager::add_to_path(const std::string &name, const std::string &value)
+// Find our resource file:
+void RCManager::setup(Prague::GetOpt const &getopt)
{
- Path &path = _paths[name];
- path.append(value);
+ std::string value;
+ if (getopt.get("resource", &value))
+ {
+ // Load resourcefile given on the commandline:
+ try
+ {
+ value = Prague::Path::expand_user(value);
+ RCManager_internals::read_file(value);
+ Logger::log(Logger::loader) << "Resourcefile \""
+ << value << "\" read."
+ << std::endl;
+ }
+ catch (const std::runtime_error &e)
+ {
+ std::cerr << "ERROR: Resourcefile \"" << value
+ << "\" given on the commandline failed to load: "
+ << e.what() << std::endl;
+ exit (1);
+ }
+ }
+ else
+ {
+ // Search for berlinrc in default places:
+ value = sysconfdir + "/berlinrc";
+
+ bool is_configured = 0;
+ try
+ {
+ RCManager_internals::read_file(value);
+ is_configured = 1;
+ Logger::log(Logger::loader) << "Resourcefile \""
+ << value << "\" read."
+ << std::endl;
+ }
+ catch (const std::runtime_error &e)
+ {
+ std::cerr << "Warning: Default resourcefile \"" << value
+ << "\" failed to load: "
+ << e.what() << std::endl;
+ }
+
+ // FIXME: merge additional configuration:
+ if(getenv("BERLINRC")) value = std::string(getenv("BERLINRC"));
+ else value ="";
+
+ if (value.empty())
+ value = std::string(Prague::User().home()) + "/.berlin";
+
+ try
+ {
+ if (!is_configured)
+ {
+ RCManager_internals::read_file(value);
+ Logger::log(Logger::loader) << "Resourcefile \""
+ << value << "\" read."
+ << std::endl;
+ }
+ }
+ catch (const std::runtime_error &e)
+ {
+ std::cerr << "ERROR: System resourcefile is missing and "
+ << "user's resourcefile \"" << value
+ << "\" failed to load too: "
+ << e.what() << std::endl;
+ exit(1);
+ }
+ }
}