Debian Codegraph @

src/opts.h

raw
1 /* -*- buffer-read-only: t -*- vi: set ro:
2 *
3 * DO NOT EDIT THIS FILE (opts.h)
4 *
5 * It has been AutoGen-ed
6 * From the definitions opts.def
7 * and the template file options
8 *
9 * Generated from AutoOpts 42:2:17 templates.
10 *
11 * AutoOpts is a copyrighted work. This header file is not encumbered
12 * by AutoOpts licensing, but is provided under the licensing terms chosen
13 * by the complexity author or copyright holder. AutoOpts is
14 * licensed under the terms of the LGPL. The redistributable library
15 * (``libopts'') is licensed under the terms of either the LGPL or, at the
16 * users discretion, the BSD license. See the AutoOpts and/or libopts sources
17 * for details.
18 *
19 * The complexity program is copyrighted and licensed
20 * under the following terms:
21 *
22 * Copyright (C) 2011-2020 Bruce Korb, all rights reserved.
23 * This is free software. It is licensed for use, modification and
24 * redistribution under the terms of the GNU General Public License,
25 * version 3 or later <http://gnu.org/licenses/gpl.html>
26 *
27 * complexity is free software: you can redistribute it and/or modify it
28 * under the terms of the GNU General Public License as published by the
29 * Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
31 *
32 * complexity is distributed in the hope that it will be useful, but
33 * WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 * See the GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License along
38 * with this program. If not, see <http://www.gnu.org/licenses/>.
39 */
40 /**
41 * This file contains the programmatic interface to the Automated
42 * Options generated for the complexity program.
43 * These macros are documented in the AutoGen info file in the
44 * "AutoOpts" chapter. Please refer to that doc for usage help.
45 */
46 #ifndef AUTOOPTS_OPTS_H_GUARD
47 #define AUTOOPTS_OPTS_H_GUARD 1
48 #include <autoopts/options.h>
49 #include <stdarg.h>
50 #include <stdnoreturn.h>
51
52 /**
53 * Ensure that the library used for compiling this generated header is at
54 * least as new as the version current when the header template was released
55 * (not counting patch version increments). Also ensure that the oldest
56 * tolerable version is at least as old as what was current when the header
57 * template was released.
58 */
59 #define AO_TEMPLATE_VERSION 172034
60 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
61 || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
62 # error option template version mismatches autoopts/options.h header
63 Choke Me.
64 #endif
65
66 #if GCC_VERSION > 40400
67 #define NOT_REACHED __builtin_unreachable();
68 #else
69 #define NOT_REACHED
70 #endif
71
72 /**
73 * Enumeration of each option type for complexity
74 */
75 typedef enum {
76 INDEX_OPT_THRESHOLD = 0,
77 INDEX_OPT_HORRID_THRESHOLD = 1,
78 INDEX_OPT_NESTING_PENALTY = 2,
79 INDEX_OPT_DEMI_NESTING_PENALTY = 3,
80 INDEX_OPT_SCALE = 4,
81 INDEX_OPT_HISTOGRAM = 5,
82 INDEX_OPT_SCORES = 6,
83 INDEX_OPT_IGNORE = 7,
84 INDEX_OPT_NO_HEADER = 8,
85 INDEX_OPT_UNIFDEF = 9,
86 INDEX_OPT_UNIF_EXE = 10,
87 INDEX_OPT_INPUT = 11,
88 INDEX_OPT_TRACE = 12,
89 INDEX_OPT_VERSION = 13,
90 INDEX_OPT_HELP = 14,
91 INDEX_OPT_MORE_HELP = 15,
92 INDEX_OPT_SAVE_OPTS = 16,
93 INDEX_OPT_LOAD_OPTS = 17
94 } teOptIndex;
95 /** count of all options for complexity */
96 #define OPTION_CT 18
97 /** complexity version */
98 #define COMPLEXITY_VERSION "1.13"
99 /** Full complexity version text */
100 #define COMPLEXITY_FULL_VERSION "complexity (GNU Complexity) 1.13"
101
102 /**
103 * Interface defines for all options. Replace "n" with the UPPER_CASED
104 * option name (as in the teOptIndex enumeration above).
105 * e.g. HAVE_OPT(THRESHOLD)
106 */
107 #define DESC(n) (complexityOptions.pOptDesc[INDEX_OPT_## n])
108 /** 'true' if an option has been specified in any way */
109 #define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n)))
110 /** The string argument to an option. The argument type must be \"string\". */
111 #define OPT_ARG(n) (DESC(n).optArg.argString)
112 /** Mask the option state revealing how an option was specified.
113 * It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
114 * \a OPTST_DEFINED, \a OPTST_RESET or zero.
115 */
116 #define STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK)
117 /** Count of option's occurrances *on the command line*. */
118 #define COUNT_OPT(n) (DESC(n).optOccCt)
119 /** mask of \a OPTST_SET and \a OPTST_DEFINED. */
120 #define ISSEL_OPT(n) (SELECTED_OPT(&DESC(n)))
121 /** 'true' if \a HAVE_OPT would yield 'false'. */
122 #define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n)))
123 /** 'true' if OPTST_DISABLED bit not set. */
124 #define ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n)))
125 /** number of stacked option arguments.
126 * Valid only for stacked option arguments. */
127 #define STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt)
128 /** stacked argument vector.
129 * Valid only for stacked option arguments. */
130 #define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs)
131 /** Reset an option. */
132 #define CLEAR_OPT(n) STMTS( \
133 DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \
134 if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \
135 DESC(n).fOptState |= OPTST_DISABLED; \
136 DESC(n).optCookie = NULL )
137 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
138 /**
139 * Enumeration of complexity exit codes
140 */
141 typedef enum {
142 COMPLEXITY_EXIT_SUCCESS = 0,
143 COMPLEXITY_EXIT_FAILURE = 1,
144 COMPLEXITY_EXIT_NOMEM = 3,
145 COMPLEXITY_EXIT_HORRID_FUNCTION = 4,
146 COMPLEXITY_EXIT_NO_DATA = 5,
147 COMPLEXITY_EXIT_ASSERT = 6,
148 COMPLEXITY_EXIT_BAD_FILE = 32,
149 COMPLEXITY_EXIT_USAGE_ERROR = 64,
150 COMPLEXITY_EXIT_NO_CONFIG_INPUT = 66,
151 COMPLEXITY_EXIT_LIBOPTS_FAILURE = 70
152 } complexity_exit_code_t;
153 /**
154 * Interface defines for specific options.
155 * @{
156 */
157 #define VALUE_OPT_THRESHOLD 't'
158
159 #define OPT_VALUE_THRESHOLD (DESC(THRESHOLD).optArg.argInt)
160 #define SET_OPT_THRESHOLD(a) STMTS( \
161 DESC(THRESHOLD).optActualIndex = 0; \
162 DESC(THRESHOLD).optActualValue = VALUE_OPT_THRESHOLD; \
163 DESC(THRESHOLD).fOptState &= OPTST_PERSISTENT_MASK; \
164 DESC(THRESHOLD).fOptState |= OPTST_SET; \
165 DESC(THRESHOLD).optArg.argInt = (a); \
166 (*(DESC(THRESHOLD).pOptProc))(&complexityOptions, \
167 complexityOptions.pOptDesc + 0); )
168 #define VALUE_OPT_HORRID_THRESHOLD 0x1001
169
170 #define OPT_VALUE_HORRID_THRESHOLD (DESC(HORRID_THRESHOLD).optArg.argInt)
171 #define SET_OPT_HORRID_THRESHOLD(a) STMTS( \
172 DESC(HORRID_THRESHOLD).optActualIndex = 1; \
173 DESC(HORRID_THRESHOLD).optActualValue = VALUE_OPT_HORRID_THRESHOLD; \
174 DESC(HORRID_THRESHOLD).fOptState &= OPTST_PERSISTENT_MASK; \
175 DESC(HORRID_THRESHOLD).fOptState |= OPTST_SET; \
176 DESC(HORRID_THRESHOLD).optArg.argInt = (a); \
177 (*(DESC(HORRID_THRESHOLD).pOptProc))(&complexityOptions, \
178 complexityOptions.pOptDesc + 1); )
179 #define VALUE_OPT_NESTING_PENALTY 'n'
180 #define VALUE_OPT_DEMI_NESTING_PENALTY 0x1002
181 #define VALUE_OPT_SCALE 's'
182
183 #define OPT_VALUE_SCALE (DESC(SCALE).optArg.argInt)
184 #define VALUE_OPT_HISTOGRAM 'h'
185 #define VALUE_OPT_SCORES 'c'
186
187 #define SET_OPT_SCORES STMTS( \
188 DESC(SCORES).optActualIndex = 6; \
189 DESC(SCORES).optActualValue = VALUE_OPT_SCORES; \
190 DESC(SCORES).fOptState &= OPTST_PERSISTENT_MASK; \
191 DESC(SCORES).fOptState |= OPTST_SET )
192 #define DISABLE_OPT_SCORES STMTS( \
193 DESC(SCORES).fOptState &= OPTST_PERSISTENT_MASK; \
194 DESC(SCORES).fOptState |= OPTST_SET | OPTST_DISABLED; \
195 DESC(SCORES).optArg.argString = NULL )
196 #define VALUE_OPT_IGNORE 'I'
197 #define VALUE_OPT_NO_HEADER 'H'
198 #define VALUE_OPT_UNIFDEF 'u'
199 #define VALUE_OPT_UNIF_EXE 0x1003
200 #define VALUE_OPT_INPUT 'i'
201 #define VALUE_OPT_TRACE 0x1004
202 /** option flag (value) for help-value option */
203 #define VALUE_OPT_HELP '?'
204 /** option flag (value) for more-help-value option */
205 #define VALUE_OPT_MORE_HELP '!'
206 /** option flag (value) for version-value option */
207 #define VALUE_OPT_VERSION 'v'
208 /** option flag (value) for save-opts-value option */
209 #define VALUE_OPT_SAVE_OPTS '>'
210 /** option flag (value) for load-opts-value option */
211 #define VALUE_OPT_LOAD_OPTS '<'
212 #define SET_OPT_SAVE_OPTS(a) STMTS( \
213 DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \
214 DESC(SAVE_OPTS).fOptState |= OPTST_SET; \
215 DESC(SAVE_OPTS).optArg.argString = (char const*)(a))
216 /*
217 * Interface defines not associated with particular options
218 */
219 #define ERRSKIP_OPTERR STMTS(complexityOptions.fOptSet &= ~OPTPROC_ERRSTOP)
220 #define ERRSTOP_OPTERR STMTS(complexityOptions.fOptSet |= OPTPROC_ERRSTOP)
221 #define RESTART_OPT(n) STMTS( \
222 complexityOptions.curOptIdx = (n); \
223 complexityOptions.pzCurOpt = NULL )
224 #define START_OPT RESTART_OPT(1)
225 #define USAGE(c) (*complexityOptions.pUsageProc)(&complexityOptions, c)
226
227 #ifdef __cplusplus
228 extern "C" {
229 #endif
230 /*
231 * global exported definitions
232 */
233 #define DEFAULT_PENALTY 1.9
234 #define DEFAULT_SCALE 19
235
236 typedef double score_t;
237 extern score_t penalty;
238
239 #include "complexity.h"
240 extern FILE * trace_fp;
241 extern int score_ct;
242 extern char const assert_fail_fmt[];
243
244 #define CX_ASSERT(_e) \
245 if (!(_e)) \
246 die(COMPLEXITY_EXIT_ASSERT, assert_fail_fmt, \
247 __FILE__, __LINE__, #_e);
248
249
250 /* * * * * *
251 *
252 * Declare the complexity option descriptor.
253 */
254 extern tOptions complexityOptions;
255
256 #if defined(ENABLE_NLS)
257 # ifndef _
258 # include <stdio.h>
259 # ifndef HAVE_GETTEXT
260 extern char * gettext(char const *);
261 # else
262 # include <libintl.h>
263 # endif
264
265 # ifndef ATTRIBUTE_FORMAT_ARG
266 # define ATTRIBUTE_FORMAT_ARG(_a)
267 # endif
268
269 static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
270 static inline char* aoGetsText(char const* pz) {
271 if (pz == NULL) return NULL;
272 return (char*)gettext(pz);
273 }
274 # define _(s) aoGetsText(s)
275 # endif /* _() */
276
277 # define OPT_NO_XLAT_CFG_NAMES STMTS(complexityOptions.fOptSet |= \
278 OPTPROC_NXLAT_OPT_CFG;)
279 # define OPT_NO_XLAT_OPT_NAMES STMTS(complexityOptions.fOptSet |= \
280 OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
281
282 # define OPT_XLAT_CFG_NAMES STMTS(complexityOptions.fOptSet &= \
283 ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
284 # define OPT_XLAT_OPT_NAMES STMTS(complexityOptions.fOptSet &= \
285 ~OPTPROC_NXLAT_OPT;)
286
287 #else /* ENABLE_NLS */
288 # define OPT_NO_XLAT_CFG_NAMES
289 # define OPT_NO_XLAT_OPT_NAMES
290
291 # define OPT_XLAT_CFG_NAMES
292 # define OPT_XLAT_OPT_NAMES
293
294 # ifndef _
295 # define _(_s) _s
296 # endif
297 #endif /* ENABLE_NLS */
298
299
300 noreturn extern void
301 vdie( int exit_code, char const * fmt, va_list);
302 noreturn extern void
303 die( int exit_code, char const * fmt, ...);
304 noreturn extern void
305 fserr(int exit_code, char const * op, char const * fn);
306
307 /**
308 * Print a COMPLEXITY_EXIT_NOMEM fatal error message and die.
309 *
310 * @param[in] sz the object size that was not allocated
311 * @param[in] what what that object was going to be
312 * @noreturn
313 */
314 noreturn static inline void nomem_err(size_t sz, char const * what)
315 {
316 char const * fmt = _("could not allocate %zu bytes for %s\n");
317 die(COMPLEXITY_EXIT_NOMEM, fmt, sz, what);
318 }
319 #ifdef __cplusplus
320 }
321 #endif
322 #endif /* AUTOOPTS_OPTS_H_GUARD */
323
324 /* opts.h ends here */