Index: /trunk/FACT++/src/Main.h
===================================================================
--- /trunk/FACT++/src/Main.h	(revision 11574)
+++ /trunk/FACT++/src/Main.h	(revision 11575)
@@ -7,140 +7,140 @@
 
 #include "LocalControl.h"
+#include "Configuration.h"
 
-void MainThread(StateMachineImp *io_service, bool dummy)
+namespace Main
 {
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run(dummy);
-    Readline::Stop();
-}
+    void SetupConfiguration(Configuration &conf)
+    {
+        const string n = conf.GetName()+".log";
 
-/*
-template<class S>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
+        po::options_description config("Program options");
+        config.add_options()
+            ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
+            ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
+            ("log,l",     var<string>(n), "Write log-file")
+            ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
+            ("cmd",       vars<string>(), "Execute one or more commands at startup")
+            ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
+            ("quit",      po_switch(),    "Quit after startup");
+        ;
 
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
+        conf.AddEnv("dns",  "DIM_DNS_NODE");
+        conf.AddEnv("host", "DIM_HOST_NODE");
 
-    //log.SetWindow(stdscr);
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
+        conf.AddOptions(config);
+    }
 
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    AutoScheduler<S> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
+    void Thread(StateMachineImp *io_service, bool dummy)
+    {
+        // This is necessary so that the StateMachien Thread can signal the
+        // Readline to exit
+        io_service->Run(dummy);
+        Readline::Stop();
+    }
 
-    io_service.Run();
-
-    return 0;
-}
-*/
-
-template<class T, class S>
-int Main(Configuration &conf, bool dummy=false)
-{
-    static T shell(conf.GetName().c_str(),
+    template<class T, class S>
+    int execute(Configuration &conf, bool dummy=false)
+    {
+        static T shell(conf.GetName().c_str(),
                    conf.Has("console") ? conf.Get<int>("console")!=1 : 0);
 
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
+        WindowLog &win  = shell.GetStreamIn();
+        WindowLog &wout = shell.GetStreamOut();
 
-    const bool backlog = wout.GetBacklog();
-    const bool null    = wout.GetNullOutput();
-    wout.SetBacklog(false);
-    wout.SetNullOutput(false);
-    wout.Display(true);
+        const bool backlog = wout.GetBacklog();
+        const bool null    = wout.GetNullOutput();
+        wout.SetBacklog(false);
+        wout.SetNullOutput(false);
+        wout.Display(true);
 
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
+        if (conf.Has("log"))
+            if (!wout.OpenLogFile(conf.Get<string>("log")))
+                win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
 
-    S io_service(wout);
+        S io_service(wout);
 
-    const boost::filesystem::path path(conf.GetName());
+        const boost::filesystem::path path(conf.GetName());
 
-    const string pname = path.parent_path().string();
-    const string fname = path.filename();
+        const string pname = path.parent_path().string();
+        const string fname = path.filename();
 
-    const Time now;
-    io_service.Write(now, "/----------------------- Program ------------------------");
-    io_service.Write(now, "| Program:  "PACKAGE_STRING" ("+fname+")");
-    io_service.Write(now, "| CallPath: "+pname);
-    io_service.Write(now, "| Compiled: "__DATE__" "__TIME__);
-    io_service.Write(now, "| Revision: "REVISION);
-    io_service.Write(now, "| Contact:  "PACKAGE_BUGREPORT);
-    io_service.Write(now, "| URL:      "PACKAGE_URL);
-    io_service.Write(now, "| Start:    "+now.GetAsStr("%c"));
-    io_service.Write(now, "\\----------------------- Options ------------------------");
-    const multimap<string,string> mmap = conf.GetOptions();
-    for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++)
-        io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second);
-    io_service.Write(now, "\\------------------- Evaluating options -----------------");
-    const int rc = io_service.EvalOptions(conf);
-    if (rc>=0)
-    {
-        ostringstream str;
-        str << "Exit triggered by EvalOptions with rc=" << rc;
-        io_service.Write(now, str.str(), MessageImp::kError);
-        return rc;
-    }
-
-    const map<string,string> &wco = conf.GetWildcardOptions();
-    if (wco.size()>0)
-    {
-        io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn);
-
-        size_t max = 0;
-        for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
-            if (it->second.length()>max)
-                max = it->second.length();
-
-        for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
+        const Time now;
+        io_service.Write(now, "/----------------------- Program ------------------------");
+        io_service.Write(now, "| Program:  "PACKAGE_STRING" ("+fname+")");
+        io_service.Write(now, "| CallPath: "+pname);
+        io_service.Write(now, "| Compiled: "__DATE__" "__TIME__);
+        io_service.Write(now, "| Revision: "REVISION);
+        io_service.Write(now, "| Contact:  "PACKAGE_BUGREPORT);
+        io_service.Write(now, "| URL:      "PACKAGE_URL);
+        io_service.Write(now, "| Start:    "+now.GetAsStr("%c"));
+        io_service.Write(now, "\\----------------------- Options ------------------------");
+        const multimap<string,string> mmap = conf.GetOptions();
+        for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++)
+            io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second);
+        io_service.Write(now, "\\------------------- Evaluating options -----------------");
+        const int rc = io_service.EvalOptions(conf);
+        if (rc>=0)
         {
             ostringstream str;
-            str.setf(ios_base::left);
-            str << setw(max+1) << it->second << " : " << it->first;
-            io_service.Write(now, str.str(), MessageImp::kWarn);
+            str << "Exit triggered by EvalOptions with rc=" << rc;
+            io_service.Write(now, str.str(), MessageImp::kError);
+            return rc;
         }
-        io_service.Write(now, "Unrecognized options found, will exit with rc=127", MessageImp::kError);
-        return 127;
+
+        const map<string,string> &wco = conf.GetWildcardOptions();
+        if (wco.size()>0)
+        {
+            io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn);
+
+            size_t max = 0;
+            for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
+                if (it->second.length()>max)
+                    max = it->second.length();
+
+            for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
+            {
+                ostringstream str;
+                str.setf(ios_base::left);
+                str << setw(max+1) << it->second << " : " << it->first;
+                io_service.Write(now, str.str(), MessageImp::kWarn);
+            }
+            io_service.Write(now, "Unrecognized options found, will exit with rc=127", MessageImp::kError);
+            return 127;
+        }
+
+        io_service.Message("==================== Starting main loop =================");
+
+        wout.SetNullOutput(null);
+        wout.SetBacklog(backlog);
+
+        shell.SetReceiver(io_service);
+
+        //    boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));
+        thread t(bind(Main::Thread, &io_service, dummy));
+
+        const vector<string> v1 = conf.Vec<string>("cmd");
+        for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
+            shell.ProcessLine(*it);
+
+        const vector<string> v2 = conf.Vec<string>("exec");
+        for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
+            shell.Execute(*it);
+
+        if (conf.Get<bool>("quit"))
+            shell.Stop();
+
+        shell.Run();                 // Run the shell
+        io_service.Stop();           // Signal Loop-thread to stop
+        // io_service.Close();       // Obsolete, done by the destructor
+        // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;
+
+        // Wait until the StateMachine has finished its thread
+        // before returning and destroying the dim objects which might
+        // still be in use.
+        t.join();
+
+        return 0;
     }
-
-    io_service.Message("==================== Starting main loop =================");
-
-    wout.SetNullOutput(null);
-    wout.SetBacklog(backlog);
-
-    shell.SetReceiver(io_service);
-
-//    boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));
-    thread t(bind(MainThread, &io_service, dummy));
-
-    const vector<string> v1 = conf.Vec<string>("cmd");
-    for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
-        shell.ProcessLine(*it);
-
-    const vector<string> v2 = conf.Vec<string>("exec");
-    for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
-        shell.Execute(*it);
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-    // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
 }
 
Index: /trunk/FACT++/src/biasctrl.cc
===================================================================
--- /trunk/FACT++/src/biasctrl.cc	(revision 11574)
+++ /trunk/FACT++/src/biasctrl.cc	(revision 11575)
@@ -551,37 +551,4 @@
 // ------------------------------------------------------------------------
 
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-
-/*
-template<class S, class T>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    StateMachineBias<S, T> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
-
 #include "Main.h"
 
@@ -589,79 +556,16 @@
 int RunShell(Configuration &conf)
 {
-    return Main<T, StateMachineBias<S, R>>(conf);
-/*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    StateMachineBias<S, R> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-    boost::thread t(bind(RunThread, &io_service));
-    // boost::thread t(bind(&StateMachineBias<S>::Run, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;*/
+    return Main::execute<T, StateMachineBias<S, R>>(conf);
 }
 
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-        ("no-dim,d",  po_bool(),      "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-        ;
-
-    po::options_description control("FTM control options");
+    po::options_description control("BIAS control options");
     control.add_options()
+        ("no-dim,d",      po_bool(),  "Disable dim services")
         ("addr,a",        var<string>("ttysS0"),  "Device address of USB port to bias-power supply")
         ("quiet,q",       po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
         ;
 
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
     conf.AddOptions(control);
 }
@@ -715,4 +619,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 11574)
+++ /trunk/FACT++/src/datalogger.cc	(revision 11575)
@@ -2394,5 +2394,5 @@
 int RunShell(Configuration &conf)
 {
-    return Main<T, DataLogger>(conf, true);
+    return Main::execute<T, DataLogger>(conf, true);
 }
 
@@ -2445,17 +2445,4 @@
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    po::options_description configp("Program options");
-    configp.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-        ;
-
     po::options_description configs("DataLogger options");
     configs.add_options()
@@ -2471,8 +2458,4 @@
         ;
 
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(configp);
     conf.AddOptions(configs);
 }
@@ -2482,4 +2465,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
Index: /trunk/FACT++/src/dimctrl.cc
===================================================================
--- /trunk/FACT++/src/dimctrl.cc	(revision 11574)
+++ /trunk/FACT++/src/dimctrl.cc	(revision 11575)
@@ -34,24 +34,4 @@
 
 // ========================================================================
-void SetupConfiguration(Configuration &conf)
-{
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-        ("console,c", var<int>(0),    "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-        ;
-
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
-}
 
 /*
@@ -82,9 +62,11 @@
 }
 
+#include "Main.h"
+
 int main(int argc, const char *argv[])
 {
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
-    SetupConfiguration(conf);
+    Main::SetupConfiguration(conf);
 
     po::variables_map vm;
Index: /trunk/FACT++/src/drivectrl.cc
===================================================================
--- /trunk/FACT++/src/drivectrl.cc	(revision 11574)
+++ /trunk/FACT++/src/drivectrl.cc	(revision 11575)
@@ -938,28 +938,11 @@
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-        ("no-dim,d",  po_switch(),    "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-        ;
-
     po::options_description control("FTM control options");
     control.add_options()
+        ("no-dim,d",  po_switch(),    "Disable dim services")
         ("addr,a",  var<string>("localhost:7404"),  "Network address of FTM")
         ("quiet,q", po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
         ;
 
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
     conf.AddOptions(control);
 }
@@ -1013,4 +996,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
Index: /trunk/FACT++/src/fadctrl.cc
===================================================================
--- /trunk/FACT++/src/fadctrl.cc	(revision 11574)
+++ /trunk/FACT++/src/fadctrl.cc	(revision 11575)
@@ -1974,105 +1974,12 @@
 #include "Main.h"
 
-/*
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-*/
-/*
-template<class S>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    StateMachineFAD<S> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
-
 template<class T, class S>
 int RunShell(Configuration &conf)
 {
-    return Main<T, StateMachineFAD<S>>(conf);
-/*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    StateMachineFAD<S> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-    boost::thread t(bind(RunThread, &io_service));
-    //boost::thread t(bind(&StateMachineFAD<S>::Run, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
-    */
+    return Main::execute<T, StateMachineFAD<S>>(conf);
 }
 
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-//        ("no-dim,d",  po_switch(),    "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-        ;
-
     po::options_description control("FAD control options");
     control.add_options()
@@ -2128,5 +2035,4 @@
     conf.AddEnv("host", "DIM_HOST_NODE");
 
-    conf.AddOptions(config);
     conf.AddOptions(control);
     conf.AddOptions(connect);
@@ -2160,4 +2066,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
Index: /trunk/FACT++/src/fscctrl.cc
===================================================================
--- /trunk/FACT++/src/fscctrl.cc	(revision 11574)
+++ /trunk/FACT++/src/fscctrl.cc	(revision 11575)
@@ -520,107 +520,12 @@
 #include "Main.h"
 
-/*
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-*/
-/*
-template<class S, class T>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    StateMachineFSC<S, T> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
-
 template<class T, class S, class R>
 int RunShell(Configuration &conf)
 {
-    return Main<T, StateMachineFSC<S, R>>(conf);
-/*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    StateMachineFSC<S, R> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-    boost::thread t(boost::bind(RunThread, &io_service));
-    // boost::thread t(boost::bind(&StateMachineFSC<S>::Run, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
-*/
+    return Main::execute<T, StateMachineFSC<S, R>>(conf);
 }
 
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-        ("no-dim,d",  po_bool(),      "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit,q",    po_switch(),    "Quit after startup");
-        ;
-
     po::options_description control("FTM control options");
     control.add_options()
@@ -629,8 +534,4 @@
         ;
 
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
     conf.AddOptions(control);
 }
@@ -684,4 +585,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
Index: /trunk/FACT++/src/ftmctrl.cc
===================================================================
--- /trunk/FACT++/src/ftmctrl.cc	(revision 11574)
+++ /trunk/FACT++/src/ftmctrl.cc	(revision 11575)
@@ -2331,107 +2331,15 @@
 #include "Main.h"
 
-/*
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-*/
-/*
-template<class S, class T>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    StateMachineFTM<S, T> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
-
 template<class T, class S, class R>
 int RunShell(Configuration &conf)
 {
-    return Main<T, StateMachineFTM<S, R>>(conf);
-/*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    StateMachineFTM<S, R> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-    boost::thread t(bind(RunThread, &io_service));
-    // boost::thread t(bind(&StateMachineFTM<S>::Run, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
-    */
+    return Main::execute<T, StateMachineFTM<S, R>>(conf);
 }
 
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("no-dim,d",  po_bool(),      "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-        ;
-
     po::options_description control("Control options");
     control.add_options()
+        ("no-dim",        po_bool(),  "Disable dim services")
         ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
         ("quiet,q",       po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
@@ -2481,8 +2389,4 @@
         ;
 
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
     conf.AddOptions(control);
     conf.AddOptions(runtype);
@@ -2537,4 +2441,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
Index: /trunk/FACT++/src/mcp.cc
===================================================================
--- /trunk/FACT++/src/mcp.cc	(revision 11574)
+++ /trunk/FACT++/src/mcp.cc	(revision 11575)
@@ -422,118 +422,8 @@
 #include "Main.h"
 
-/*
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-*/
-/*
-template<class S, class T>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    StateMachineMCP<S, T> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
-
 template<class T>
 int RunShell(Configuration &conf)
 {
-    return Main<T, StateMachineMCP>(conf);
-/*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    StateMachineMCP<S, R> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-    boost::thread t(bind(RunThread, &io_service));
-    // boost::thread t(bind(&StateMachineMCP<S>::Run, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
-*/
-}
-
-void SetupConfiguration(Configuration &conf)
-{
-    const string n = conf.GetName()+".log";
-
-    po::options_description config("Program options");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-//        ("no-dim,d",  po_bool(),      "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit,q",    po_switch(),    "Quit after startup");
-        ;
-/*
-    po::options_description control("FTM control options");
-    control.add_options()
-        ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
-        ("quiet,q",       po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
-        ;
-*/
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
-//    conf.AddOptions(control);
+    return Main::execute<T, StateMachineMCP>(conf);
 }
 
@@ -586,5 +476,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
-    SetupConfiguration(conf);
+    Main::SetupConfiguration(conf);
 
     po::variables_map vm;
Index: /trunk/FACT++/src/scheduler.cc
===================================================================
--- /trunk/FACT++/src/scheduler.cc	(revision 11574)
+++ /trunk/FACT++/src/scheduler.cc	(revision 11575)
@@ -710,110 +710,16 @@
 // ------------------------------------------------------------------------
 #include "Main.h"
-/*
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-*/
-/*
-template<class S>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-    //log.SetWindow(stdscr);
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    AutoScheduler<S> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
 
 template<class T, class S>
 int RunShell(Configuration &conf)
 {
-    return Main<T, AutoScheduler<S>>(conf);
-    /*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    AutoScheduler<S> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-//    boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));
-    boost::thread t(boost::bind(RunThread, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-    // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
-*/
+    return Main::execute<T, AutoScheduler<S>>(conf);
 }
 
 void SetupConfiguration(Configuration &conf)
 {
-    const string n = conf.GetName()+".log";
-
-    //po::options_description config("Program options");
-    po::options_description config("Configuration");
-    config.add_options()
-        ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
-        ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
-        ("log,l",     var<string>(n), "Write log-file")
-        ("no-dim,d",  po_switch(),    "Disable dim services")
-        ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("cmd",       vars<string>(), "Execute one or more commands at startup")
-        ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
-        ("quit",      po_switch(),    "Quit after startup");
-
     po::options_description control("Scheduler options");
     control.add_options()
+        ("no-dim",    po_switch(),    "Disable dim services")
         ("schedule-database", var<string>()
 #if BOOST_VERSION >= 104200
@@ -843,8 +749,4 @@
     p.add("schedule", 1); // The first positional options
 
-    conf.AddEnv("dns",  "DIM_DNS_NODE");
-    conf.AddEnv("host", "DIM_HOST_NODE");
-
-    conf.AddOptions(config);
     conf.AddOptions(control);
     conf.SetArgumentPositions(p);
@@ -876,4 +778,5 @@
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintUsage);
+    Main::SetupConfiguration(conf);
     SetupConfiguration(conf);
 
