libxcoder  3.5.1
ni_getopt_logan.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 with Windows API.
26 *
27 *******************************************************************************/
28 
29 #pragma once
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
36 #ifdef _WIN32
37 #ifdef XCODER_DLL
38 #ifdef LIB_EXPORTS
39 #define LIB_API_GETOPT __declspec(dllexport)
40 #else
41 #define LIB_API_GETOPT __declspec(dllimport)
42 #endif
43 #else
44 #define LIB_API_GETOPT
45 #endif
46 #elif defined(__linux__) || defined(__APPLE__)
47 #define LIB_API_GETOPT
48 #endif
49 
50 extern LIB_API_GETOPT int optind, opterr, optopt;
51 extern LIB_API_GETOPT char *optarg;
52 
53 /* Describe the long-named options requested by the application.
54  The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
55  of 'struct option' terminated by an element containing a name which is
56  zero.
57 
58  The field 'has_arg' is:
59  no_argument (or 0) if the option does not take an argument,
60  required_argument (or 1) if the option requires an argument,
61  optional_argument (or 2) if the option takes an optional argument.
62 
63  If the field 'flag' is not NULL, it points to a variable that is set
64  to the value given in the field 'val' when the option is found, but
65  left unchanged if the option is not found.
66 
67  To have a long-named option do something other than set an 'int' to
68  a compiled-in constant, such as set a value from 'optarg', set the
69  option's 'flag' field to zero and its 'val' field to a nonzero
70  value (the equivalent single-letter option character, if there is
71  one). For long options that have a zero 'flag' field, 'getopt'
72  returns the contents of the 'val' field. */
73 
74 struct option
75 {
76  const char *name;
77  /* has_arg can't be an enum because some compilers complain about
78  type mismatches in all the code that assumes it is an int. */
79  int has_arg;
80  int *flag;
81  int val;
82 };
83 
84 /* Names for the values of the 'has_arg' field of 'struct option'. */
85 
86 #define no_argument 0
87 #define required_argument 1
88 #define optional_argument 2
89 
90 extern LIB_API_GETOPT int getopt(int argc, char *argv[], const char *optstring);
91 extern LIB_API_GETOPT int getopt_long(int argc, char* argv[], const char* optstring, const struct option *longopts, int *longindex);
92 
93 #ifdef __cplusplus
94 }
95 #endif
LIB_API_GETOPT int opterr
LIB_API_GETOPT int getopt_long(int argc, char *argv[], const char *optstring, const struct option *longopts, int *longindex)
LIB_API_GETOPT int getopt(int argc, char *argv[], const char *optstring)
LIB_API_GETOPT int optopt
LIB_API_GETOPT int optind
LIB_API_GETOPT char * optarg
int * flag
const char * name