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 
56 // User command handlers implement this interface. The pointer
57 // argument is a pointer to an opaque context. Use the functions below
58 // to access properties from the context.
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 
94 TEMU_API void *temu_createClassCmd(temu_Class *Cls, const char *Name,
95  const char *Doc, temu_ObjectCommandFunc F);
96 
97 TEMU_API void *temu_classGetCmd(temu_Class *Cls, const char *Name);
98 
99 TEMU_API int temu_classCmdAddParam(void *Cmd, const char *Name,
100  temu_CmdOptionKind Type, int Required,
101  const char *Doc);
102 
103 TEMU_API int temu_objectInvokeCmd(temu_Object *Obj, void *I, const char *Name,
104  int Argc, temu_CmdArg Argv[]);
105 
106 /*
107  * Raise an error in the interpreter for the current command
108  *
109  * \param I Interpreter (I-argument to command func)
110  * \param S Error string
111  * \result Returns -1 so it can be used as "return temu_raiseCmdError(I, "foo")"
112  * in the command handler.
113  */
114 TEMU_API int temu_raiseCmdError(void *I, const char *S, ...);
115 
124 
125 TEMU_API void *temu_createCmd(const char *Name, temu_CommandFunc F,
126  const char *Doc, void *Data);
127 
135 TEMU_API void temu_cmdAddOption(void *Cmd, const char *OptName,
136  temu_CmdOptionKind Type, int Required,
137  const char *Doc, const char *Default);
138 
144 TEMU_API void *temu_cmdGetData(void *Ctxt);
145 
151 TEMU_API void *temu_cmdGetInterpreter(void *Ctxt);
152 
159 TEMU_API int64_t temu_cmdGetOptionAsInteger(void *Ctxt, const char *OptName);
160 
167 TEMU_API void *temu_cmdGetOptionAsObject(void *Ctxt, const char *OptName);
168 
175 TEMU_API const char *temu_cmdGetOptionAsString(void *Ctxt, const char *OptName);
176 
183 TEMU_API double temu_cmdGetOptionAsReal(void *Ctxt, const char *OptName);
184 
190 TEMU_API size_t temu_cmdGetPosOptSize(void *Ctxt);
191 
198 TEMU_API const char *temu_cmdGetPosOpt(void *Ctxt, size_t Idx);
199 
206 TEMU_API int temu_cmdOptionIsValid(void *Ctxt, const char *OptName);
207 
212 TEMU_API int temu_cmdSetVariable(const char *Key, const char *Value);
213 
218 TEMU_API const char *temu_cmdGetVariable(const char *Key);
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #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:332
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)
Definition: CommandLine.h:68
Definition: CommandLine.h:69
temu_CmdOptionKind
Definition: CommandLine.h:61
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_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
Definition: CommandLine.h:67
#define TEMU_API
Definition: Attributes.h:53
Definition: Objsys.h:426
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
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
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_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