libdballe  5.18
cmdline.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Author: Enrico Zini <enrico@enricozini.com>
18  */
19 
20 #ifndef DBA_CMDLINE_H
21 #define DBA_CMDLINE_H
22 
28 #include <wreport/error.h>
29 #include <dballe/core/rawmsg.h>
30 #include <popt.h>
31 #include <list>
32 #include <string>
33 
34 namespace dballe {
35 struct Record;
36 
37 namespace cmdline {
38 
40 {
41  int (*func)(poptContext);
42  const char* aliases[3];
43  const char* usage;
44  const char* desc;
45  const char* longdesc;
46  struct poptOption* optable;
47 };
48 
49 #define ODT_END { NULL, NULL, NULL, NULL, NULL, NULL }
50 
51 struct tool_desc
52 {
53  const char* desc;
54  const char* longdesc;
55  struct op_dispatch_table* ops;
56 };
57 
59 {
60  const char* name;
61  const char* manpage_examples_section;
62  const char* manpage_files_section;
63  const char* manpage_seealso_section;
64 };
65 
67 struct error_cmdline : public std::exception
68 {
69  std::string msg;
70 
72  error_cmdline(const std::string& msg) : msg(msg) {}
73  ~error_cmdline() throw () {}
74 
75  virtual const char* what() const throw () { return msg.c_str(); }
76 
78  static void throwf(const char* fmt, ...) WREPORT_THROWF_ATTRS(1, 2);
79 };
80 
81 
85 void dba_cmdline_print_dba_error();
86 
91 void dba_cmdline_error(poptContext optCon, const char* fmt, ...) __attribute__ ((noreturn));
92 
96 Encoding dba_cmdline_stringToMsgType(const char* type);
97 
101 int dba_cmdline_dispatch_main(const struct program_info* pinfo, const struct tool_desc* desc, int argc, const char* argv[]);
102 
108 unsigned dba_cmdline_get_query(poptContext optCon, Record& query);
109 
113 void list_templates();
114 
116 std::list<std::string> get_filenames(poptContext optCon);
117 
118 } // namespace cmdline
119 } // namespace dballe
120 
121 /* vim:set ts=4 sw=4: */
122 #endif