libxcoder 5.6.0
Loading...
Searching...
No Matches
ni_getopt.h
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (C) 2022 NETINT Technologies
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 *
20 ******************************************************************************/
21
22/*!*****************************************************************************
23 * \file ni_getopt.h
24 *
25 * \brief Implementation of getopt() and getopt_long() for Windows environment
26 ******************************************************************************/
27
28#pragma once
29
30#ifdef __cplusplus
31extern "C"
32{
33#endif
34
35#ifdef _WIN32
36#ifdef XCODER_DLL
37#ifdef LIB_EXPORTS
38#define LIB_API_GETOPT __declspec(dllexport)
39#else
40#define LIB_API_GETOPT __declspec(dllimport)
41#endif
42#else
43#define LIB_API_GETOPT
44#endif
45#elif __linux__ || __APPLE__
46#define LIB_API_GETOPT
47#endif
48
49extern LIB_API_GETOPT int optind, opterr, optopt;
50extern LIB_API_GETOPT char *optarg;
51
52/* Describe the long-named options requested by the application.
53 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
54 of 'struct option' terminated by an element containing a name which is
55 zero.
56
57 The field 'has_arg' is:
58 no_argument (or 0) if the option does not take an argument,
59 required_argument (or 1) if the option requires an argument,
60 optional_argument (or 2) if the option takes an optional argument.
61
62 If the field 'flag' is not NULL, it points to a variable that is set
63 to the value given in the field 'val' when the option is found, but
64 left unchanged if the option is not found.
65
66 To have a long-named option do something other than set an 'int' to
67 a compiled-in constant, such as set a value from 'optarg', set the
68 option's 'flag' field to zero and its 'val' field to a nonzero
69 value (the equivalent single-letter option character, if there is
70 one). For long options that have a zero 'flag' field, 'getopt'
71 returns the contents of the 'val' field. */
72
73struct option
74{
75 const char *name;
76 /* has_arg can't be an enum because some compilers complain about
77 type mismatches in all the code that assumes it is an int. */
79 int *flag;
80 int val;
81};
82
83/* Names for the values of the 'has_arg' field of 'struct option'. */
84
85#define no_argument 0
86#define required_argument 1
87#define optional_argument 2
88
89extern LIB_API_GETOPT int getopt(int argc, char *argv[], const char *optstring);
90extern LIB_API_GETOPT int getopt_long(int argc, char* argv[], const char* optstring, const struct option *longopts, int *longindex);
91
92#ifdef __cplusplus
93}
94#endif
LIB_API_GETOPT int opterr
Definition ni_getopt.h:49
LIB_API_GETOPT int getopt_long(int argc, char *argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition ni_getopt.c:99
LIB_API_GETOPT int getopt(int argc, char *argv[], const char *optstring)
Definition ni_getopt.c:38
LIB_API_GETOPT int optopt
Definition ni_getopt.h:49
LIB_API_GETOPT int optind
Definition ni_getopt.c:34
LIB_API_GETOPT char * optarg
Definition ni_getopt.c:33
int * flag
Definition ni_getopt.h:79
const char * name
Definition ni_getopt.h:75
int val
Definition ni_getopt.h:80
int has_arg
Definition ni_getopt.h:78