schroot-base-run.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  *********************************************************************/
00018 
00019 #ifndef SCHROOT_BASE_RUN_H
00020 #define SCHROOT_BASE_RUN_H
00021 
00022 #include <schroot-base/schroot-base-options.h>
00023 
00024 #include <sbuild/sbuild-config.h>
00025 
00026 #include <cstdlib>
00027 #include <iostream>
00028 #include <string>
00029 
00030 namespace schroot_base
00031 {
00032 
00042   template<class O, class M>
00043   static int
00044   run (int   argc,
00045        char *argv[])
00046   {
00047     typedef O options_type;
00048     typedef M main_type;
00049 
00050     try
00051       {
00052         // Set up locale.
00053         try
00054           {
00055             std::locale::global(std::locale(""));
00056           }
00057         catch (std::runtime_error const& e) // Invalid locale
00058           {
00059             std::locale::global(std::locale::classic());
00060           }
00061         std::cout.imbue(std::locale());
00062         std::cerr.imbue(std::locale());
00063 
00064         bindtextdomain (SBUILD_MESSAGE_CATALOGUE, LOCALEDIR);
00065         textdomain (SBUILD_MESSAGE_CATALOGUE);
00066 
00067         typename options_type::ptr opts(new options_type);
00068         main_type kit(opts);
00069         exit (kit.run(argc, argv));
00070       }
00071     catch (std::exception const& e)
00072       {
00073         sbuild::log_exception_error(e);
00074         exit(EXIT_FAILURE);
00075       }
00076     catch (...)
00077       {
00078         sbuild::log_unknown_exception_error();
00079         exit(EXIT_FAILURE);
00080       }
00081   }
00082 
00083 }
00084 
00085 #endif /* SCHROOT_BASE_RUN_H */
00086 
00087 /*
00088  * Local Variables:
00089  * mode:C++
00090  * End:
00091  */

Generated on Sat Jul 5 12:00:17 2008 for schroot by  doxygen 1.5.6