127 lines
3.5 KiB
C
127 lines
3.5 KiB
C
|
//----------------------------------------------------------------------------//
|
||
|
// GNU GPL OS/K //
|
||
|
// //
|
||
|
// Authors: spectral` //
|
||
|
// NeoX //
|
||
|
// //
|
||
|
// Desc: Command line parsing utilities //
|
||
|
//----------------------------------------------------------------------------//
|
||
|
|
||
|
#ifndef _KALBASE_H
|
||
|
#include <kalbase.h>
|
||
|
#endif
|
||
|
|
||
|
//------------------------------------------//
|
||
|
// Start of header //
|
||
|
//------------------------------------------//
|
||
|
|
||
|
#ifndef _KALEXTRAS_ARGV_H
|
||
|
#define _KALEXTRAS_ARGV_H
|
||
|
|
||
|
//------------------------------------------//
|
||
|
// Types //
|
||
|
//------------------------------------------//
|
||
|
|
||
|
//
|
||
|
// Option types
|
||
|
//
|
||
|
typedef enum {
|
||
|
//
|
||
|
// A flag option, without any more parameters
|
||
|
//
|
||
|
CMDOPT_FLAG,
|
||
|
|
||
|
//
|
||
|
// An option that expects a parameter
|
||
|
//
|
||
|
CMDOPT_PARAM,
|
||
|
|
||
|
} CmdOptType_t;
|
||
|
|
||
|
//
|
||
|
// An option for a command, e.g. "-o file" in "cc -o file"
|
||
|
//
|
||
|
typedef struct {
|
||
|
//
|
||
|
// The option's name, e.g. "help" for "--help"
|
||
|
// May be 0, but only if letter is not zero
|
||
|
//
|
||
|
const char *longName;
|
||
|
|
||
|
//
|
||
|
// The option's letter, e.g. 'h' for '-h'
|
||
|
//
|
||
|
int letter;
|
||
|
|
||
|
//
|
||
|
// The option's group, for sorting during --help
|
||
|
// Must be positive and < 256, or option won't shop up
|
||
|
// during help texts
|
||
|
//
|
||
|
int group;
|
||
|
|
||
|
//
|
||
|
// The option's type, see above
|
||
|
//
|
||
|
CmdOptType_t type;
|
||
|
|
||
|
//
|
||
|
// Address of the variable to put the parameter into
|
||
|
// Should be an int point for flag arguments, string
|
||
|
// pointer for parameter arguments
|
||
|
//
|
||
|
void *param;
|
||
|
|
||
|
//
|
||
|
// The option's help text
|
||
|
// If this is 0, this option is hidden
|
||
|
//
|
||
|
const char *helpText;
|
||
|
|
||
|
} CmdOption_t;
|
||
|
|
||
|
//------------------------------------------//
|
||
|
// Functions //
|
||
|
//------------------------------------------//
|
||
|
|
||
|
int KalComputeArgC(const char *argv[]);
|
||
|
|
||
|
size_t KalComputeArgVSize(const char *argv[]);
|
||
|
|
||
|
error_t KalCmdLineToArgV(const char *cmdLine,
|
||
|
int *argcPtr,
|
||
|
const char *argv[]);
|
||
|
|
||
|
error_t KalArgVToCmdLine(const char *cmdLine,
|
||
|
size_t lengthMax,
|
||
|
int argc,
|
||
|
const char *argv[]);
|
||
|
|
||
|
error_t KalParseCmdLine(const char *cmdLine,
|
||
|
CmdOption_t *options);
|
||
|
|
||
|
error_t KalParseArgV(int argc,
|
||
|
const char *argv[],
|
||
|
CmdOption_t *options);
|
||
|
|
||
|
//
|
||
|
// The "Ex" variants reacts to "--help" and "--version" by themselves
|
||
|
//
|
||
|
|
||
|
error_t KalParseCmdLineEx(const char *cmdLine,
|
||
|
CmdOption_t *options,
|
||
|
const char *progDesc,
|
||
|
const char *groupDescs[]);
|
||
|
|
||
|
error_t KalParseArgVEx(int argc,
|
||
|
const char *argv[],
|
||
|
CmdOption_t *options,
|
||
|
const char *progDesc,
|
||
|
const char *groupDescs[]);
|
||
|
|
||
|
//------------------------------------------//
|
||
|
// End of header //
|
||
|
//------------------------------------------//
|
||
|
|
||
|
#endif
|