cprover
parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "parse_options.h"
10 
11 #include <iostream>
12 
13 #if defined (_WIN32)
14 #define EX_OK 0
15 #define EX_USAGE 1
16 #else
17 #include <sysexits.h>
18 #endif
19 
20 #include "cmdline.h"
21 #include "exception_utils.h"
22 #include "exit_codes.h"
23 #include "signal_catcher.h"
24 
26  const std::string &_optstring, int argc, const char **argv)
27 {
28  std::string optstring=std::string("?h(help)")+_optstring;
29  parse_result=cmdline.parse(argc, argv, optstring.c_str());
30 }
31 
33 {
34 }
35 
37 {
38  std::cerr << "Usage error!\n\n";
39  help();
40 }
41 
45 {
46  if(!cmdline.unknown_arg.empty())
47  std::cerr << "Unknown option: " << cmdline.unknown_arg << "\n";
48 }
49 
51 {
52  // catch all exceptions here so that this code is not duplicated
53  // for each tool
54  try
55  {
56  if(parse_result)
57  {
58  usage_error();
60  return EX_USAGE;
61  }
62 
63  if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help"))
64  {
65  help();
66  return EX_OK;
67  }
68 
69  // install signal catcher
71 
72  return doit();
73  }
75  {
76  std::cerr << e.what() << "\n";
78  }
79  catch(const cprover_exception_baset &e)
80  {
81  std::cerr << e.what() << '\n';
83  }
84 }
85 
86 std::string
87 banner_string(const std::string &front_end, const std::string &version)
88 {
89  const std::string version_str = front_end + " " + version + " " +
90  std::to_string(sizeof(void *) * 8) + "-bit";
91 
92  std::string::size_type left_padding = 0, right_padding = 0;
93  if(version_str.size() < 57)
94  {
95  left_padding = (57 - version_str.size() + 1) / 2;
96  right_padding = (57 - version_str.size()) / 2;
97  }
98 
99  return "* *" + std::string(left_padding, ' ') + version_str +
100  std::string(right_padding, ' ') + "* *";
101 }
virtual int doit()=0
virtual void help()
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
virtual int main()
unsignedbv_typet size_type()
Definition: c_types.cpp:58
virtual bool parse(int argc, const char **argv, const char *optstring)
Definition: cmdline.cpp:156
std::string what() const override
A human readable description of what went wrong.
void unknown_option_msg()
Print an error message mentioning the option that was not recognized when parsing the command line.
virtual bool isset(char option) const
Definition: cmdline.cpp:27
Base class for exceptions thrown in the cprover project.
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
void install_signal_catcher()
std::string banner_string(const std::string &front_end, const std::string &version)
#define CPROVER_EXIT_EXCEPTION
An (unanticipated) exception was thrown during computation.
Definition: exit_codes.h:41
Document and give macros for the exit codes of CPROVER binaries.
virtual std::string what() const =0
A human readable description of what went wrong.
virtual void usage_error()
std::string unknown_arg
Definition: cmdline.h:45
#define CPROVER_EXIT_USAGE_ERROR
A usage error is returned when the command line is invalid or conflicting.
Definition: exit_codes.h:33
parse_options_baset(const std::string &optstring, int argc, const char **argv)