#include #include #include "tools.h" #include "Time.h" #include "StateMachineDim.h" #include "MessageDim.h" #include "Shell.h" #include "ServiceList.h" #include "Configuration.h" using namespace std; #include "RemoteControl.h" template void RunShell(Configuration &conf) { // A normal kill will call its destructor! (Very nice feature ;) ) static T shell(conf.GetName().c_str(), conf.Get("console")!=1); WindowLog &win = shell.GetStreamIn(); WindowLog &wout = shell.GetStreamOut(); if (conf.Has("log")) if (!wout.OpenLogFile(conf.Get("log"))) win << kRed << "ERROR - Couldn't open log-file " << conf.Get("log") << ": " << strerror(errno) << endl; shell.Run(); } // ======================================================================== void SetupConfiguration(Configuration &conf) { const string n = conf.GetName()+".log"; po::options_description config("Program options"); config.add_options() ("dns", var("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)") ("log,l", var(n), "Write log-file") ("console,c", var(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") ; conf.AddEnv("dns", "DIM_DNS_NODE"); conf.AddOptions(config); } /* Extract usage clause(s) [if any] for SYNOPSIS. Translators: "Usage" and "or" here are patterns (regular expressions) which are used to match the usage synopsis in program output. An example from cp (GNU coreutils) which contains both strings: Usage: cp [OPTION]... [-T] SOURCE DEST or: cp [OPTION]... SOURCE... DIRECTORY or: cp [OPTION]... -t DIRECTORY SOURCE... */ void PrintUsage() { cout << "The console connects to all available Dim Servers and allows to " "easily access all of their commands.\n" "\n" "Usage: test3 [-c type] [OPTIONS]\n" " or: test3 [OPTIONS]\n" "\n" "Options:\n" "The following describes the available commandline options. " "For further details on how command line option are parsed " "and in which order which configuration sources are accessed " "please refer to the class reference of the Configuration class."; cout << endl; } void PrintHelp() { /* cout << "bla bla bla" << endl << endl; cout << endl; cout << "Environment:" << endl; cout << "environment" << endl; cout << endl; cout << "Examples:" << endl; cout << "test exam" << endl; cout << endl; cout << "Files:" << endl; cout << "files" << endl; cout << endl; */ } /* The first line of the --version information is assumed to be in one of the following formats: {GNU,Free} ({GNU,Free} ) - {GNU,Free} and separated from any copyright/author details by a blank line. Handle multi-line bug reporting sections of the form: Report bugs to GNU home page: ... */ void PrintVersion(const char *name) { cout << name << " - FACT++ 1.0\n" "\n" "Written by Thomas Bretz et al.\n" "\n" "Report bugs to Thomas Bretz \n" "FACT++ home page: http://www.xxx.com\n" "\n" "Copyright (C) 2011 by the FACT Collaboration.\n" "This is free software; see the source for copying conditions.\n" << endl; } int main(int argc, char *argv[]) { Configuration conf(argv[0]); conf.SetPrintUsage(PrintUsage); SetupConfiguration(conf); po::variables_map vm; try { vm = conf.Parse(argc, argv); } catch (std::exception &e) { #if BOOST_VERSION > 104000 po::multiple_occurrences *MO = dynamic_cast(&e); if (MO) cout << "Error: " << e.what() << " of '" << MO->get_option_name() << "' option." << endl; else #endif cout << "Error: " << e.what() << endl; cout << endl; return -1; } if (conf.HasPrint()) return -1; if (conf.HasVersion()) { PrintVersion(argv[0]); return -1; } if (conf.HasHelp()) { PrintHelp(); return -1; } // To allow overwriting of DIM_DNS_NODE set 0 to 1 setenv("DIM_DNS_NODE", conf.Get("dns").c_str(), 1); if (conf.Get("console")==0) RunShell(conf); else RunShell(conf); return 0; }