| 1 |
/* |
| 2 |
* This file is part of MPSolve 3.2.2 |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa. |
| 5 |
* License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher |
| 6 |
* |
| 7 |
* Authors: |
| 8 |
* Leonardo Robol <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef MPS_OPTIONS_H_ |
| 12 |
#define MPS_OPTIONS_H_ |
| 13 |
|
| 14 |
/** |
| 15 |
* @file |
| 16 |
* @brief Implementation of option parsing for MPSolve. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <mps/mps.h> |
| 20 |
|
| 21 |
MPS_BEGIN_DECLS |
| 22 |
|
| 23 |
/** |
| 24 |
* @brief This struct holds a configuration for a command line option. |
| 25 |
* This is a step towards a more flexible implementation of the option parser, |
| 26 |
* compared to the traditional getopts() call. |
| 27 |
*/ |
| 28 |
struct mps_command_line_option { |
| 29 |
/** |
| 30 |
* @brief This is the character that is recognized as starting the |
| 31 |
* option specification on the command line. |
| 32 |
* |
| 33 |
* This value may be '\0' if only the long format is provided for this |
| 34 |
* option. |
| 35 |
*/ |
| 36 |
char format; |
| 37 |
|
| 38 |
/** |
| 39 |
* @brief This value is true if an argument may be specified for the option. |
| 40 |
* |
| 41 |
* The argument may or may not be mandatory, according to the mandatory field |
| 42 |
* of this struct. |
| 43 |
*/ |
| 44 |
mps_boolean argument; |
| 45 |
|
| 46 |
/** |
| 47 |
* @brief If this value is true then the argument for the option is mandatory. |
| 48 |
* Note that this value should be true only if argument is true. |
| 49 |
*/ |
| 50 |
mps_boolean mandatory; |
| 51 |
|
| 52 |
/** |
| 53 |
* @brief An optional long format for the option, or NULL if no long format is |
| 54 |
* specified. |
| 55 |
*/ |
| 56 |
char * long_format; |
| 57 |
}; |
| 58 |
|
| 59 |
/** |
| 60 |
* @brief Configuration for a command line parser. |
| 61 |
* |
| 62 |
* This struct essentialy holds a list of mps_command_line_option structs |
| 63 |
* that describe the options that should be parsed at command line. |
| 64 |
*/ |
| 65 |
struct mps_command_line_option_configuration { |
| 66 |
/** |
| 67 |
* @brief A list of mps_command_option instances that have been provided |
| 68 |
* for this parser configuration. |
| 69 |
*/ |
| 70 |
mps_list * command_options; |
| 71 |
}; |
| 72 |
|
| 73 |
/** |
| 74 |
* @brief Struct holding the options passed on the command |
| 75 |
* line. |
| 76 |
* |
| 77 |
* Typical usage is something like this: |
| 78 |
* @code |
| 79 |
* mps_opt* opt; |
| 80 |
* while (opt = mps_getopt(&argc, &argv, format)) |
| 81 |
* { |
| 82 |
* switch(opt->optchar) |
| 83 |
* { |
| 84 |
* case 'a': |
| 85 |
* [...] |
| 86 |
* break; |
| 87 |
* case 'n': |
| 88 |
* n = atoi(opt->opvalue); |
| 89 |
* break; |
| 90 |
* } |
| 91 |
* free(opt); |
| 92 |
* } |
| 93 |
* @endcode |
| 94 |
* |
| 95 |
* @see mps_getopts() |
| 96 |
*/ |
| 97 |
struct mps_opt { |
| 98 |
char optchar; |
| 99 |
char *optvalue; |
| 100 |
}; |
| 101 |
|
| 102 |
|
| 103 |
/** |
| 104 |
* @brief This struct holds a key and the value associated |
| 105 |
* with it. It's used for options that require a value associated. |
| 106 |
* |
| 107 |
* For example the option Degree needs a numeric value associated to |
| 108 |
* it. The values are always saved as the string that are read. |
| 109 |
*/ |
| 110 |
struct mps_input_option { |
| 111 |
/** |
| 112 |
* @brief Key associated with the option. |
| 113 |
*/ |
| 114 |
mps_option_key flag; |
| 115 |
|
| 116 |
/** |
| 117 |
* @brief Value of the flag, or NULL if no value |
| 118 |
* is provided. |
| 119 |
*/ |
| 120 |
char *value; |
| 121 |
}; |
| 122 |
|
| 123 |
/* STRUCTURES truth tables */ |
| 124 |
const static short int mps_rational_structures[] = { 0, 1, 0, 0, 0, 1, 0, 0, 0 }; |
| 125 |
const static short int mps_integer_structures[] = { 1, 0, 0, 0, 1, 0, 0, 0, 0 }; |
| 126 |
const static short int mps_fp_structures[] = { 0, 0, 1, 0, 0, 0, 1, 0, 0 }; |
| 127 |
const static short int mps_real_structures[] = { 1, 1, 1, 1, 0, 0, 0, 0, 0 }; |
| 128 |
const static short int mps_complex_structures[] = { 0, 0, 0, 0, 1, 1, 1, 1, 0 }; |
| 129 |
const static short int mps_bigfloat_structures[] = { 0, 0, 0, 1, 0, 0, 0, 1, 0 }; |
| 130 |
|
| 131 |
/* STRUCTURE related macros */ |
| 132 |
#define MPS_STRUCTURE_IS_RATIONAL(x) (mps_rational_structures[(x)]) |
| 133 |
#define MPS_STRUCTURE_IS_INTEGER(x) (mps_integer_structures[(x)]) |
| 134 |
#define MPS_STRUCTURE_IS_FP(x) (mps_fp_structures[(x)]) |
| 135 |
#define MPS_STRUCTURE_IS_REAL(x) (mps_real_structures[(x)]) |
| 136 |
#define MPS_STRUCTURE_IS_COMPLEX(x) (mps_complex_structures[(x)]) |
| 137 |
|
| 138 |
|
| 139 |
const static short int mps_user_representations[] = { 0, 0, 1 }; |
| 140 |
const static short int mps_sparse_representations[] = { 0, 1, 0 }; |
| 141 |
const static short int mps_dense_representations[] = { 1, 0, 0 }; |
| 142 |
|
| 143 |
#define MPS_DENSITY_IS_SPARSE(x) (mps_sparse_representations[(x)]) |
| 144 |
#define MPS_DENSITY_IS_DENSE(x) (mps_dense_representations[(x)]) |
| 145 |
|
| 146 |
/** |
| 147 |
* @brief Configuration for an input stream; this struct |
| 148 |
* contains the information on how the input stream should |
| 149 |
* be parsed. |
| 150 |
*/ |
| 151 |
struct mps_input_configuration { |
| 152 |
/** |
| 153 |
* @brief Selet the starting phase for the computation. |
| 154 |
* |
| 155 |
* Should be <code>float_phase</code> in the majority of |
| 156 |
* cases, and <code>dpe_phase</code> if the computation |
| 157 |
* is not manageable with the usual IEEE1354 limits. |
| 158 |
*/ |
| 159 |
mps_phase starting_phase; |
| 160 |
}; |
| 161 |
|
| 162 |
/** |
| 163 |
* @brief Configuration for the output. |
| 164 |
* |
| 165 |
* This struct holds the information on what has to be |
| 166 |
* computed by MPSolve, such as the desired output precision |
| 167 |
* and the search set for the roots, etc. |
| 168 |
*/ |
| 169 |
struct mps_output_configuration { |
| 170 |
/** |
| 171 |
* @brief Digits of required output precision |
| 172 |
*/ |
| 173 |
long int prec; |
| 174 |
|
| 175 |
/** |
| 176 |
* @brief Condition to be reached to return the computed |
| 177 |
* approximations. |
| 178 |
*/ |
| 179 |
mps_output_goal goal; |
| 180 |
|
| 181 |
/** |
| 182 |
* @brief True if the mulitplicity check is enabled in |
| 183 |
* MPSolve. |
| 184 |
*/ |
| 185 |
mps_boolean multiplicity; |
| 186 |
|
| 187 |
/** |
| 188 |
* @brief The set in which the roots must be searched. |
| 189 |
*/ |
| 190 |
mps_search_set search_set; |
| 191 |
|
| 192 |
/** |
| 193 |
* @brief These flags are used to determined which properties |
| 194 |
* of the roots must be determined by MPSolve. |
| 195 |
* |
| 196 |
* Possible values are: |
| 197 |
* -# MPS_OUTPUT_PROPERTY_REAL |
| 198 |
* -# MPS_OUTPUT_PROPERTY_IMAGINARY |
| 199 |
*/ |
| 200 |
char root_properties; |
| 201 |
|
| 202 |
/** |
| 203 |
* @brief Desired output format. |
| 204 |
* |
| 205 |
* Can be one of: |
| 206 |
* @code |
| 207 |
* MPS_OUTPUT_FORMAT_BARE |
| 208 |
* MPS_OUTPUT_FORMAT_GNUPLOT |
| 209 |
* MPS_OUTPUT_FORMAT_GNUPLOT_FULL |
| 210 |
* MPS_OUTPUT_FORMAT_COMPACT |
| 211 |
* MPS_OUTPUT_FORMAT_VERBOSE |
| 212 |
* MPS_OUTPUT_FORMAT_FULL |
| 213 |
* @endcode |
| 214 |
*/ |
| 215 |
mps_output_format format; |
| 216 |
}; |
| 217 |
|
| 218 |
/* Function in getopts.c */ |
| 219 |
void mps_parse_opts (mps_context * s, int argc, char *argv[]); |
| 220 |
mps_boolean mps_getopts (mps_opt ** opt, int *argc_ptr, char ***argv_ptr, |
| 221 |
const char *opt_format); |
| 222 |
|
| 223 |
|
| 224 |
mps_command_line_option_configuration * mps_command_line_option_configuration_new (void); |
| 225 |
|
| 226 |
MPS_END_DECLS |
| 227 |
|
| 228 |
#endif /* Header end */ |