6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews//
6fb9b25791778f69002eb72be6235e20d98ec452Tinderbox User// Automated Testing Framework (atf)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews//
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews// Copyright (c) 2007 The NetBSD Foundation, Inc.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews// All rights reserved.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews//
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// Redistribution and use in source and binary forms, with or without
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// modification, are permitted provided that the following conditions
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews// are met:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// 1. Redistributions of source code must retain the above copyright
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// notice, this list of conditions and the following disclaimer.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// 2. Redistributions in binary form must reproduce the above copyright
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// notice, this list of conditions and the following disclaimer in the
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// documentation and/or other materials provided with the distribution.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews//
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
8462dfb880040cde3a60f047ec18808737fd7e85Mark Andrews// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
420a43c8d8028992a4e9c170022f97bfac689025Evan Hunt// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
8d31dd9ab62d91b5f23ac687657c966d44074a3fMark Andrews// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews//
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
ad127d839d2e7aa542939a8a336691407e23397eMark Andrews#if !defined(TOOLS_APPLICATION_HPP)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#define TOOLS_APPLICATION_HPP
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <ostream>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <set>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <stdexcept>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <string>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsnamespace tools {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsnamespace application {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// ------------------------------------------------------------------------
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// The "usage_error" class.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// ------------------------------------------------------------------------
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsclass usage_error : public std::runtime_error {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char m_text[4096];
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewspublic:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews usage_error(const char*, ...) throw();
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ~usage_error(void) throw();
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews const char* what(void) const throw();
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews};
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// ------------------------------------------------------------------------
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// The "option" class.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// ------------------------------------------------------------------------
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsclass option {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char m_character;
ad127d839d2e7aa542939a8a336691407e23397eMark Andrews std::string m_argument;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews std::string m_description;
554d22d2deb8889bb16434176b5716ab79d15c50Mark Andrews
554d22d2deb8889bb16434176b5716ab79d15c50Mark Andrews friend class app;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewspublic:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews option(char, const std::string&, const std::string&);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews bool operator<(const option&) const;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews};
dd14c953a8a42b60ea86a2a630529014fc3d14ddMark Andrews
dd14c953a8a42b60ea86a2a630529014fc3d14ddMark Andrews// ------------------------------------------------------------------------
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// The "app" class.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews// ------------------------------------------------------------------------
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsclass app {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews bool m_hflag;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
3398334b3acda24b086957286288ca9852662b12Automatic Updater void process_options(void);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews void usage(std::ostream&);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews bool inited(void);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsprotected:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews typedef std::set< option > options_set;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews int m_argc;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char* const* m_argv;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews const char* m_argv0;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews const char* m_prog_name;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews std::string m_description;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews std::string m_manpage, m_global_manpage;
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews options_set options(void);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews // To be redefined.
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt virtual std::string specific_args(void) const;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews virtual options_set specific_options(void) const;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews virtual void process_option(int, const char*);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews virtual int main(void) = 0;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewspublic:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews app(const std::string&, const std::string&, const std::string&);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews virtual ~app(void);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews int run(int, char* const*);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews};
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews} // namespace application
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews} // namespace tools
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#endif // !defined(TOOLS_APPLICATION_HPP)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews