MeteoIODoc 20241222.207bde49
getopt.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2//this comes from https://github.com/skandhurkat/Getopt-for-Visual-Studio/blob/master/getopt.h
3#ifndef __GETOPT_H__
15#define __GETOPT_H__
16
17 /* All the headers include this file. */
18#include <crtdefs.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24 extern int optind; /* index of first non-option in argv */
25 extern int optopt; /* single option character, as parsed */
26 extern int opterr; /* flag to enable built-in diagnostics... */
27 /* (user may set to zero, to suppress) */
28
29 extern char* optarg; /* pointer to argument of current option */
30
31 extern int getopt(int nargc, char* const* nargv, const char* options);
32
33#ifdef _BSD_SOURCE
34 /*
35 * BSD adds the non-standard `optreset' feature, for reinitialisation
36 * of `getopt' parsing. We support this feature, for applications which
37 * proclaim their BSD heritage, before including this header; however,
38 * to maintain portability, developers are advised to avoid it.
39 */
40# define optreset __mingw_optreset
41 extern int optreset;
42#endif
43#ifdef __cplusplus
44}
45#endif
46/*
47 * POSIX requires the `getopt' API to be specified in `unistd.h';
48 * thus, `unistd.h' includes this header. However, we do not want
49 * to expose the `getopt_long' or `getopt_long_only' APIs, when
50 * included in this manner. Thus, close the standard __GETOPT_H__
51 * declarations block, and open an additional __GETOPT_LONG_H__
52 * specific block, only when *not* __UNISTD_H_SOURCED__, in which
53 * to declare the extended API.
54 */
55#endif /* !defined(__GETOPT_H__) */
56
57#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
58#define __GETOPT_LONG_H__
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64 struct option /* specification for a long form option... */
65 {
66 const char* name; /* option name, without leading hyphens */
67 int has_arg; /* does it take an argument? */
68 int* flag; /* where to save its status, or NULL */
69 int val; /* its associated status value */
70 };
71
72 enum /* permitted values for its `has_arg' field... */
73 {
74 no_argument = 0, /* option never takes an argument */
75 required_argument, /* option always requires an argument */
76 optional_argument /* option may take an argument */
77 };
78
79 extern int getopt_long(int nargc, char* const* nargv, const char* options,
80 const struct option* long_options, int* idx);
81 extern int getopt_long_only(int nargc, char* const* nargv, const char* options,
82 const struct option* long_options, int* idx);
83 /*
84 * Previous MinGW implementation had...
85 */
86#ifndef HAVE_DECL_GETOPT
87 /*
88 * ...for the long form API only; keep this for compatibility.
89 */
90# define HAVE_DECL_GETOPT 1
91#endif
92
93#ifdef __cplusplus
94}
95#endif
96
97#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */
int optreset
Definition: getopt.c:62
int getopt_long_only(int nargc, char *const *nargv, const char *options, const struct option *long_options, int *idx)
Definition: getopt.c:508
@ required_argument
Definition: getopt.h:75
@ optional_argument
Definition: getopt.h:76
@ no_argument
Definition: getopt.h:74
int val
Definition: getopt.h:69
int optopt
Definition: getopt.c:61
int getopt(int nargc, char *const *nargv, const char *options)
Definition: getopt.c:476
int getopt_long(int nargc, char *const *nargv, const char *options, const struct option *long_options, int *idx)
Definition: getopt.c:495
int has_arg
Definition: getopt.h:67
int * flag
Definition: getopt.h:68
int optind
Definition: getopt.c:60
char * optarg
Definition: getopt.c:63
const char * name
Definition: getopt.h:66
int opterr
Definition: getopt.c:59
Definition: getopt.h:65