LocARNA-1.8.11
options.hh
1 #ifndef LOCARNA_OPTIONS_HH
2 #define LOCARNA_OPTIONS_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 
9 /*------------------------------------------------------------
10 
11  Copyright (C) 1999 by Sebastian Will.
12 
13  All Rights Reserved.
14 
15  ------------------------------------------------------------*/
16 
17 /************************************************************
18  *
19  * options -- an interface for getopt_long
20  *
21  ************************************************************/
22 
23 /************************************************************
24  *
25  * interface to getopt
26  *
27  * - easier to use
28  * - may be restricted to certain cases
29  * - hopefully useable for many cases
30  *
31  ************************************************************/
32 
33 #include <getopt.h>
34 #include <string>
35 
36 namespace LocARNA {
37 
38 #ifndef FALSE
39 # define FALSE 0
40 #endif
41 
42 #ifndef TRUE
43 # define TRUE 1
44 #endif
45 
46  /* argument types */
47 #define O_NO_ARG 0
48 #define O_ARG_STRING 1
49 #define O_ARG_INT 2
50 #define O_ARG_FLOAT 3
51 #define O_ARG_DOUBLE 4
52 #define O_ARG_BOOL 5
53 #define O_SECTION -1
54 #define O_SECTION_HIDE -2
55 
56 #define O_NODEFAULT std::string("__")
57 
61  typedef
62  struct {
63  std::string longname;
64  char shortname;
65  bool *flag;
66  int arg_type;
67  void *argument;
68  std::string deflt;
69  std::string argname;
70  std::string description;
71  } option_def;
72 
73  /* longname==0 and shortname==0 and arg_type<=O_SECTION is not allowed for regular options definition */
74 
75  /*
76  Example for option_def array
77 
78  bool opt_help;
79  .
80  .
81  .
82  int optVal_size;
83  int default_size=1000;
84 
85  struct option_def my_options[] = {
86  {"help",'h',&opt_help,O_NO_ARG,0,O_NODEFAULT,0,"This help"},
87  {"num",'n',&opt_num,O_ARG_INT,&optVal_num,O_NODEFAULT,0,"Some arbitrary number"},
88  {"output",'o',0,O_ARG_STRING,&outputfile,O_NODEFAULT,
89  "output-file", "File for output"}, // mandatory
90  {"size",'s',0,O_ARG_INT,&optVal_size,"100","size","Size of problem"},
91  {0,0,0,O_ARG_STRING,&inputfile,O_NODEFAULT,"input-file","File for input"},
92  {0,0,0,0,0,0,0,0}
93  };
94 
95  the last entry shows how to define non-option command line
96  arguments. If there is more than one such definition, the order of
97  those argument definitions is important. This is different to the
98  option argument definitions.
99 
100  */
101 
102  /* ***********************************************************/
103  /* error message */
104  extern char *O_error_msg;
105 
106  /* ***********************************************************/
107  /* prototypes */
108 
110  bool process_options(int argc, char *argv[], option_def options[]);
111 
112  /* print a usage string */
113  void print_usage(char *progname, option_def options[]);
114 
115  /* print a longer help */
116  void print_help(char *progname, option_def options[]);
117 
118  const char*
119  convert_arg_type(int arg_type);
120 
127  void
128  print_galaxy_xml(char *progname, option_def options[]);
129 
135  void print_options(option_def options[]);
136 
137 } // end namespace LocARNA
138 
139 #endif
std::string description
optional description (shown in help)
Definition: options.hh:70
bool * flag
pointer to flag that indicates if option given
Definition: options.hh:65
void print_galaxy_xml(char *progname, option_def options[])
prints a galaxy wrapper in xml format
Definition: options.cc:411
Definition structure of an option.
Definition: options.hh:61
void print_options(option_def options[])
Definition: options.cc:320
int arg_type
type of argument
Definition: options.hh:66
bool process_options(int argc, char *argv[], option_def *options)
process options
Definition: options.cc:130
Definition: aligner.cc:17
std::string argname
optional name for an argument (shown in usage string)
Definition: options.hh:69
std::string deflt
pointer to default argument, if arg optional. otherwise 0
Definition: options.hh:68
void print_usage(char *progname, option_def options[])
Definition: options.cc:388
char * O_error_msg
pointer to string buffer for error message
Definition: options.cc:50
void print_help(char *progname, option_def options[])
Definition: options.cc:596
char shortname
short option char
Definition: options.hh:64
std::string longname
long option name
Definition: options.hh:63
void * argument
pointer to variable that should hold argument, 0 indicates no arg
Definition: options.hh:67