spBase
Loading...
Searching...
No Matches
spOption.h
Go to the documentation of this file.
1
4#ifndef __SPOPTION_H
5#define __SPOPTION_H
6
7#include <stdarg.h>
8
9#include <sp/spDefs.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
20#define SP_USAGE_LABEL_STRING "???"
21
22#define SP_MAX_SETUP_LINE 512
23#define SP_MAX_SETUP_NAME 128
24/*#define SP_MAX_SETUP_VALUE 256*/
25#define SP_MAX_SETUP_VALUE 8192
26
27#define SP_UNKNOWN (-1)
28
29#define SP_MAX_EXIT_CALLBACK 16
30typedef void (*spExitFunc)(int status);
31
32typedef void (*spExitCallbackFunc)(void *);
34typedef unsigned short spOptionType;
36#define SP_TYPE_NONE 0
37#define SP_TYPE_BOOL 1
38#define SP_TYPE_STRING 2
39#define SP_TYPE_INT 3
40#define SP_TYPE_SHORT 4
41#define SP_TYPE_LONG 5
42#define SP_TYPE_FLOAT 6
43#define SP_TYPE_DOUBLE 7
44#define SP_TYPE_CHAR 8
45#define SP_TYPE_STRING_A 9 /* string array */
46#define SP_TYPE_ENUM 10
47#define SP_TYPE_USER 16
48#define SP_TYPE_BOOLEAN SP_TYPE_BOOL
49#define SP_TYPE_STRING_S SP_TYPE_STRING_A
50
51#define SP_TYPE_EDITABLE (1<<8)
52#define SP_TYPE_LIST (1<<9)
53#define SP_TYPE_COMBO (1<<10)
54#define SP_TYPE_TOGGLE (1<<11)
55#define SP_TYPE_SHOW_TIP (1<<12)
56#define SP_TYPE_NO_GUI (1<<13)
57#define SP_TYPE_INPUT_ONLY (1<<14) /* 0.8.19+ */
58#define SP_TYPE_OUTPUT_ONLY (1<<15) /* 0.8.19+ */
59
60#define SpNullOption(flag, subflag, type) {flag, subflag, NULL, NULL, type, NULL, NULL}
61
62typedef struct _spOptions *spOptions;
67typedef struct _spOption {
68 const char *flag;
69 const char *subflag;
70 const char *desc;
71 const char *label;
73 void *value;
74 const char *def_value;
75} spOption;
76
77#if defined(MACOS)
78#pragma import on
79#endif
80
84extern void spIgnoreUnknownOption(spOptions options, spBool flag);
85extern int spGetNumOption(spOptions options);
86extern spOption *spGetOptionList(spOptions options);
87extern char *xspCutOptionValue(const char *value, int index);
88extern int spConvertOptionValue(spOption *option, const char *value);
89extern spOptions spAllocOptions(int num_option, spOption *option_list);
90extern spOptions spCopyOptions(int num_option, spOption *option_list);
91extern spOptions spInitOptions(int num_option, spOption *option_list);
92extern void _spFreeOptionsAndValues(spOptions options, spBool free_values);
93extern void _spFreeOptions(spOptions options);
94extern spOptions _spGetOptions(int argc, char **argv, int num_option, spOption *option_list,
95 int num_file, const char **labels);
97extern void spSetSection(spOptions options, int section);
99extern void spSetSetup(const char *filename);
103extern spBool spAddExitCallback(spExitCallbackFunc callback, void *data);
105extern spBool spRemoveExitCallback(spExitCallbackFunc callback, void *data);
107extern void spExit(int status);
109extern char *spGetOptionValue(int argc, char **argv, spOptions options);
111extern void spGetOptionsValue(int argc, char **argv, spOptions options);
112extern void spUpdateOptionsValue(int argc, char **argv, spOptions options);
114extern void spCheckNumFile(spOptions options);
116extern const char *spGetFile(spOptions options);
117extern char *xspGetOptionLabel(spOption *option, int index);
118extern void spSetOptionDescOffset(int offset);
120extern void spSetHelpMessage(spBool *flag, const char *format, ...);
121extern void spPrintHelpHeader(const char *format, ...);
123extern void spPrintHelp(const char *format, ...);
125extern void spPrintError(const char *format, ...);
127extern void spPrintMan(spOptions options, const char *description, const char *author);
129extern spBool spReadSetup(const char *filename, spOptions options);
131extern spBool spWriteSetup(const char *filename, spOptions options);
132extern spBool spGetOptionValueString(spOption *option, char *buf, int buf_size); /* 0.8.18+ */
133extern spBool spPrintOption(spOption *option);
134extern spBool spPrintOptions(spOptions options);
135extern void spPrintUsageHeader(void);
136extern void spPrintUsage(void);
138extern void spUsage(void);
139
140 /*----@addtogroup spOptionGroup----*/
141
142#if defined(_WIN32)
143extern void spSetHInstanceWin(void *hinstance, unsigned long reason);
144extern void *spGetHInstanceWin(void);
145#endif
146
147/* Do not use the following function. This is for internal use. */
148extern spBool spSetExitFunc(spExitFunc func);
149extern spBool spEmitExitCallback(void);
150
151#if defined(MACOS)
152#pragma import off
153#endif
154
156 /*----@addtogroup spOptionGroup----*/
157
158#define spFreeOptions(options) {_spFreeOptions(options); (options) = NULL;}
159#define spFreeOptionsAndValues(options, free_values) {_spFreeOptionsAndValues(options, free_values); (options) = NULL;}
161#define spGetOptions(argc, argv, option, file_label) \
162_spGetOptions(argc, argv, spArraySize(option), option, spArraySize(file_label), file_label)
163
164/*#define spEqType(type1, type2) (((0xff & type1) == (0xff & type2)) ? 1 : 0)*/
166#define spStrToBool(value) (((*(value) == 'T') || spStrEq(value, "1") || spStrEq(value, "ON") || spStrEq(value, "On")) ? SP_TRUE : SP_FALSE)
168#define spBoolToStr(value) (((value) == SP_TRUE) ? "True" : "False")
169
170 /*----@addtogroup spOptionGroup----*/
171
172#ifdef __cplusplus
173} /* Close scope of 'extern "C"' declaration */
174#endif
175
176#endif /* __SPOPTION_H */
int spBool
Definition spDefs.h:248
void spSetSection(spOptions options, int section)
char * spGetOptionValue(int argc, char **argv, spOptions options)
spBool spWriteSetup(const char *filename, spOptions options)
void spSetSetup(const char *filename)
unsigned short spOptionType
Definition spOption.h:34
void spUsage(void)
spBool spWriteGlobalSetup(void)
void spCheckNumFile(spOptions options)
spBool spAddExitCallback(spExitCallbackFunc callback, void *data)
void(* spExitCallbackFunc)(void *)
Definition spOption.h:32
struct _spOptions * spOptions
Definition spOption.h:62
void spGetOptionsValue(int argc, char **argv, spOptions options)
const char * spGetFile(spOptions options)
void spSetHelpMessage(spBool *flag, const char *format,...)
spBool spRemoveExitCallback(spExitCallbackFunc callback, void *data)
void spPrintError(const char *format,...)
spBool spReadSetup(const char *filename, spOptions options)
void spExit(int status)
void spPrintMan(spOptions options, const char *description, const char *author)
spBool spEqType(spOptionType type1, spOptionType type2)
void spPrintHelp(const char *format,...)
void spIgnoreUnknownOption(spOptions options, spBool flag)
Definition spOption.h:67
void * value
Definition spOption.h:73
const char * desc
Definition spOption.h:70
const char * label
Definition spOption.h:71
const char * subflag
Definition spOption.h:69
const char * def_value
Definition spOption.h:74
const char * flag
Definition spOption.h:68
spOptionType type
Definition spOption.h:72