TEMU  3.0
The Terma Emulator
CommandLine.h
Go to the documentation of this file.
1 //===-- temu-c/CommandLine.h - TEMU Command Line ---------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2015, 2019
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_COMMAND_LINE
10 #define TEMU_COMMAND_LINE
11 
13 #include "temu-c/Support/Objsys.h"
14 #include <stddef.h>
15 #include <stdint.h>
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
35 TEMU_API int temu_parseCommandLineOptions(int argc, const char *argv[]);
36 
41 
47 TEMU_API int temu_execCommandFile(const char *File);
48 
54 TEMU_API int temu_execCommand(const char *Cmd);
55 
59 typedef int (*temu_CommandFunc)(void *);
60 
61 typedef enum temu_CmdOptionKind {
73 
74 typedef struct {
75  const char *Name;
77  union {
78  const char *String;
79  const char *Path;
81  int64_t Integer;
82  double Real;
88  };
89 } temu_CmdArg;
90 
91 typedef int (*temu_ObjectCommandFunc)(temu_Object *Obj, void *I, int argc,
92  const temu_CmdArg args[]);
93 
103 TEMU_API void *temu_createClassCmd(temu_Class *Cls, const char *Name,
104  const char *Doc, temu_ObjectCommandFunc F);
116 TEMU_API void *temu_classGetCmd(temu_Class *Cls, const char *Name);
117 
128 TEMU_API int temu_classCmdAddParam(void *Cmd, const char *Name,
129  temu_CmdOptionKind Type, int Required,
130  const char *Doc);
131 
140 TEMU_API const temu_CmdArg* temu_classCmdGetOption(int argc, const temu_CmdArg args[], const char *OptName);
153 TEMU_API int64_t temu_classCmdGetOptionAsInteger(int argc, const temu_CmdArg args[], const char *OptName);
154 
167 TEMU_API uint64_t temu_classCmdGetOptionAsUnsigned(int argc, const temu_CmdArg args[], const char *OptName);
168 
179 TEMU_API int temu_objectInvokeCmd(temu_Object *Obj, void *I, const char *Name,
180  int Argc, temu_CmdArg Argv[]);
181 
182 /*
183  * Raise an error in the interpreter for the current command
184  *
185  * \param I Interpreter (I-argument to command func)
186  * \param S Error string
187  * \result Returns -1 so it can be used as "return temu_raiseCmdError(I, "foo")"
188  * in the command handler.
189  */
190 TEMU_API int temu_raiseCmdError(void *I, const char *S, ...);
191 
200 
201 TEMU_API void *temu_createCmd(const char *Name, temu_CommandFunc F,
202  const char *Doc, void *Data);
203 
211 TEMU_API void temu_cmdAddOption(void *Cmd, const char *OptName,
212  temu_CmdOptionKind Type, int Required,
213  const char *Doc, const char *Default);
214 
220 TEMU_API void *temu_cmdGetData(void *Ctxt);
221 
227 TEMU_API void *temu_cmdGetInterpreter(void *Ctxt);
228 
235 TEMU_API int64_t temu_cmdGetOptionAsInteger(void *Ctxt, const char *OptName);
236 
243 TEMU_API void *temu_cmdGetOptionAsObject(void *Ctxt, const char *OptName);
244 
251 TEMU_API const char *temu_cmdGetOptionAsString(void *Ctxt, const char *OptName);
252 
259 TEMU_API double temu_cmdGetOptionAsReal(void *Ctxt, const char *OptName);
260 
266 TEMU_API size_t temu_cmdGetPosOptSize(void *Ctxt);
267 
274 TEMU_API const char *temu_cmdGetPosOpt(void *Ctxt, size_t Idx);
275 
282 TEMU_API int temu_cmdOptionIsValid(void *Ctxt, const char *OptName);
283 
288 TEMU_API int temu_cmdSetVariable(const char *Key, const char *Value);
289 
294 TEMU_API const char *temu_cmdGetVariable(const char *Key);
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif /* !TEMU_COMMAND_LINE */
int(* temu_CommandFunc)(void *)
Definition: CommandLine.h:59
TEMU_API int temu_cmdOptionIsValid(void *Ctxt, const char *OptName)
TEMU_API int temu_parseCommandLineOptions(int argc, const char *argv[])
Definition: Objsys.h:335
Path is a string, but with auto completion of file names.
Definition: CommandLine.h:63
const char * String
Definition: CommandLine.h:78
TEMU_API void * temu_cmdGetData(void *Ctxt)
TEMU_API void * temu_createClassCmd(temu_Class *Cls, const char *Name, const char *Doc, temu_ObjectCommandFunc F)
TEMU_API const char * temu_cmdGetVariable(const char *Key)
Interface reference.
Definition: CommandLine.h:68
Register reference.
Definition: CommandLine.h:69
temu_CmdOptionKind
Definition: CommandLine.h:61
TEMU_API uint64_t temu_classCmdGetOptionAsUnsigned(int argc, const temu_CmdArg args[], const char *OptName)
TEMU_API int temu_classCmdAddParam(void *Cmd, const char *Name, temu_CmdOptionKind Type, int Required, const char *Doc)
TEMU_API void * temu_cmdGetInterpreter(void *Ctxt)
TEMU_API int64_t temu_classCmdGetOptionAsInteger(int argc, const temu_CmdArg args[], const char *OptName)
TEMU_API int64_t temu_cmdGetOptionAsInteger(void *Ctxt, const char *OptName)
temu_PropName PRef
Definition: CommandLine.h:83
Any integer number.
Definition: CommandLine.h:65
TEMU_API int temu_execCommand(const char *Cmd)
temu_CmdOptionKind Type
Definition: CommandLine.h:76
Property reference.
Definition: CommandLine.h:67
#define TEMU_API
Definition: Attributes.h:53
Definition: Objsys.h:435
Class option.
Definition: CommandLine.h:71
double Real
Definition: CommandLine.h:82
const char * Name
Definition: CommandLine.h:75
TEMU_API int temu_cmdSetVariable(const char *Key, const char *Value)
Definition: Objsys.h:82
Register field reference.
Definition: CommandLine.h:70
TEMU_API void * temu_cmdGetOptionAsObject(void *Ctxt, const char *OptName)
temu_IfaceRef IRef
Definition: CommandLine.h:84
TEMU_API double temu_cmdGetOptionAsReal(void *Ctxt, const char *OptName)
temu_Object * Obj
Definition: CommandLine.h:80
const char * Path
Definition: CommandLine.h:79
Any floating point number.
Definition: CommandLine.h:66
TEMU_API void temu_printCommandLineHelp(void)
TEMU_API const char * temu_cmdGetOptionAsString(void *Ctxt, const char *OptName)
TEMU_API int temu_objectInvokeCmd(temu_Object *Obj, void *I, const char *Name, int Argc, temu_CmdArg Argv[])
TEMU_API void * temu_classGetCmd(temu_Class *Cls, const char *Name)
TEMU_API const temu_CmdArg * temu_classCmdGetOption(int argc, const temu_CmdArg args[], const char *OptName)
temu_PropName RegRef
Definition: CommandLine.h:85
int64_t Integer
Definition: CommandLine.h:81
TEMU_API int temu_execCommandFile(const char *File)
TEMU_API const char * temu_cmdGetPosOpt(void *Ctxt, size_t Idx)
Object is a named object.
Definition: CommandLine.h:64
temu_Class * Class
Definition: CommandLine.h:87
int(* temu_ObjectCommandFunc)(temu_Object *Obj, void *I, int argc, const temu_CmdArg args[])
Definition: CommandLine.h:91
TEMU_API void * temu_createCmd(const char *Name, temu_CommandFunc F, const char *Doc, void *Data)
TEMU_API int temu_raiseCmdError(void *I, const char *S,...)
Definition: CommandLine.h:62
TEMU_API size_t temu_cmdGetPosOptSize(void *Ctxt)
temu_PropName FieldRef
Definition: CommandLine.h:86
TEMU_API void temu_cmdAddOption(void *Cmd, const char *OptName, temu_CmdOptionKind Type, int Required, const char *Doc, const char *Default)
Definition: CommandLine.h:74
Definition: Objsys.h:111