comparison src/dmargs.h @ 1742:ddec147d1f90

Bring in changes from the th-libs version of commandline argument handling.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 09 Jun 2018 17:56:07 +0300
parents 7ed25973dbcb
children c801995cbb13
comparison
equal deleted inserted replaced
1741:6f1313c761aa 1742:ddec147d1f90
1 /* 1 /*
2 * Simple commandline argument processing functions 2 * Simple commandline argument processing functions
3 * Programmed and designed by Matti 'ccr' Hamalainen 3 * Programmed and designed by Matti 'ccr' Hamalainen
4 * (C) Copyright 2002-2015 Tecnic Software productions (TNSP) 4 * (C) Copyright 2002-2018 Tecnic Software productions (TNSP)
5 * 5 *
6 * Please read file 'COPYING' for information on license and distribution. 6 * Please read file 'COPYING' for information on license and distribution.
7 */ 7 */
8 /// @file
9 /// @brief Simple commandline argument processing functions
8 #ifndef DMARGS_H 10 #ifndef DMARGS_H
9 #define DMARGS_H 11 #define DMARGS_H
10 12
11 #include "dmlib.h" 13 #include "dmlib.h"
12 14
13 #ifdef __cplusplus 15 #ifdef __cplusplus
14 extern "C" { 16 extern "C" {
15 #endif 17 #endif
16 18
17 /* Option flags 19 /** @def Option argument flags
18 */ 20 */
19 #define OPT_NONE (0) // Simple option with no arguments 21 #define OPT_NONE (0) ///< Simple option with no arguments
20 #define OPT_ARGREQ (1) // Option requires an argument 22 #define OPT_ARGREQ (1) ///< Option requires an argument
21 #define OPT_ARGMASK (1) // Mask for option argument flags 23 #define OPT_ARGMASK (1) ///< Mask for option argument flags
22 24
23 #define OPTH_BAILOUT 0x0001 // Bail out on errors 25 /** @def Option processing flags
24 #define OPTH_ONLY_OPTS 0x0010 // Handle only options 26 */
25 #define OPTH_ONLY_OTHER 0x0020 // Handle only "non-options" 27 #define OPTH_BAILOUT 0x0001 ///< Bail out on errors
26 #define OPTH_ONLY_MASK 0x00f0 // Mask 28 #define OPTH_ONLY_OPTS 0x0010 ///< Handle only options
29 #define OPTH_ONLY_OTHER 0x0020 ///< Handle only "non-options"
30 #define OPTH_ONLY_MASK 0x00f0 ///< Mask
27 31
28 32
29 /* Option argument structure 33 /** Option argument structure
30 */ 34 */
31 typedef struct 35 typedef struct
32 { 36 {
33 int id; 37 int id; ///< Option ID (should be unique for each option)
34 char optShort; 38 char o_short; ///< Short option name (one character)
35 char *optLong; 39 char *o_long; ///< Long option name
36 char *desc; 40 char *desc; ///< Option description
37 int flags; 41 int flags; ///< Flags (see OPT_*)
38 } DMOptArg; 42 } DMOptArg;
39 43
40 44
41 BOOL dmArgsProcess(int argc, char *argv[], 45 BOOL dmArgsProcess(int argc, char *argv[],
42 const DMOptArg optList[], int noptList, 46 const DMOptArg *opts, const int nopts,
43 BOOL (*handleOptionCB)(int, char *, char *), 47 BOOL (*handle_option)(int id, char *, char *),
44 BOOL (*handleFileCB)(char *), BOOL); 48 BOOL (*handle_other)(char *), const int flags);
45 49
46 void dmArgsPrintHelp(FILE *, 50 void dmArgsPrintHelp(FILE *, const DMOptArg *opts,
47 const DMOptArg optList[], 51 const int nopts, const int flags);
48 const int noptList,
49 const int flags);
50
51 52
52 #ifdef __cplusplus 53 #ifdef __cplusplus
53 } 54 }
54 #endif 55 #endif
55 #endif // DMARGS_H 56 #endif // DMARGS_H