libdballe
5.18
|
00001 /* 00002 * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU 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, write to the Free Software 00015 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00016 * 00017 * Author: Enrico Zini <enrico@enricozini.com> 00018 */ 00019 00020 #ifndef DBA_CMDLINE_H 00021 #define DBA_CMDLINE_H 00022 00028 #include <wreport/error.h> 00029 #include <dballe/core/rawmsg.h> 00030 #include <popt.h> 00031 #include <list> 00032 #include <string> 00033 00034 namespace dballe { 00035 struct Record; 00036 00037 namespace cmdline { 00038 00039 struct op_dispatch_table 00040 { 00041 int (*func)(poptContext); 00042 const char* aliases[3]; 00043 const char* usage; 00044 const char* desc; 00045 const char* longdesc; 00046 struct poptOption* optable; 00047 }; 00048 00049 #define ODT_END { NULL, NULL, NULL, NULL, NULL, NULL } 00050 00051 struct tool_desc 00052 { 00053 const char* desc; 00054 const char* longdesc; 00055 struct op_dispatch_table* ops; 00056 }; 00057 00058 struct program_info 00059 { 00060 const char* name; 00061 const char* manpage_examples_section; 00062 const char* manpage_files_section; 00063 const char* manpage_seealso_section; 00064 }; 00065 00067 struct error_cmdline : public std::exception 00068 { 00069 std::string msg; 00070 00072 error_cmdline(const std::string& msg) : msg(msg) {} 00073 ~error_cmdline() throw () {} 00074 00075 virtual const char* what() const throw () { return msg.c_str(); } 00076 00078 static void throwf(const char* fmt, ...) WREPORT_THROWF_ATTRS(1, 2); 00079 }; 00080 00081 00085 void dba_cmdline_print_dba_error(); 00086 00091 void dba_cmdline_error(poptContext optCon, const char* fmt, ...) __attribute__ ((noreturn)); 00092 00096 Encoding dba_cmdline_stringToMsgType(const char* type); 00097 00101 int dba_cmdline_dispatch_main(const struct program_info* pinfo, const struct tool_desc* desc, int argc, const char* argv[]); 00102 00108 unsigned dba_cmdline_get_query(poptContext optCon, Record& query); 00109 00113 void list_templates(); 00114 00116 std::list<std::string> get_filenames(poptContext optCon); 00117 00118 } // namespace cmdline 00119 } // namespace dballe 00120 00121 /* vim:set ts=4 sw=4: */ 00122 #endif