TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
CommandLine.h File Reference
#include "temu-c/Support/Attributes.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for CommandLine.h:

Go to the source code of this file.

Typedefs

typedef int(* temu_CommandFunc )(void *)
 
typedef enum temu_CmdOptionKind temu_CmdOptionKind
 Option types. More...
 

Enumerations

enum  temu_CmdOptionKind {
  teCOK_String = 0, teCOK_Path, teCOK_Object, teCOK_Int,
  teCOK_Double, teCOK_Prop, teCOK_Iface
}
 Option types. More...
 

Functions

TEMU_API int temu_parseCommandLineOptions (int argc, const char *argv[])
 
TEMU_API void temu_printCommandLineHelp (void)
 
TEMU_API int temu_execCommandFile (const char *File)
 
TEMU_API int temu_execCommand (const char *Cmd)
 
TEMU_API void * temu_createCmd (const char *Name, temu_CommandFunc F, const char *Doc, void *Data)
 
TEMU_API void temu_cmdAddOption (void *Cmd, const char *OptName, temu_CmdOptionKind Type, int Required, const char *Doc, const char *Default)
 
TEMU_API void * temu_cmdGetData (void *Ctxt)
 
TEMU_API void * temu_cmdGetInterpreter (void *Ctxt)
 
TEMU_API int64_t temu_cmdGetOptionAsInteger (void *Ctxt, const char *OptName)
 
TEMU_API void * temu_cmdGetOptionAsObject (void *Ctxt, const char *OptName)
 
TEMU_API const char * temu_cmdGetOptionAsString (void *Ctxt, const char *OptName)
 
TEMU_API double temu_cmdGetOptionAsReal (void *Ctxt, const char *OptName)
 
TEMU_API size_t temu_cmdGetPosOptSize (void *Ctxt)
 
TEMU_API const char * temu_cmdGetPosOpt (void *Ctxt, size_t Idx)
 
TEMU_API int temu_cmdOptionIsValid (void *Ctxt, const char *OptName)
 
TEMU_API int temu_cmdSetVariable (const char *Key, const char *Value)
 
TEMU_API const char * temu_cmdGetVariable (const char *Key)
 

Typedef Documentation

Option types.

typedef int(* temu_CommandFunc)(void *)

Definition at line 58 of file CommandLine.h.

Enumeration Type Documentation

Option types.

Enumerator
teCOK_String 
teCOK_Path 

Path is a string, but with auto completion of file names.

teCOK_Object 

Object is a named object.

teCOK_Int 

Any integer number.

teCOK_Double 
teCOK_Prop 
teCOK_Iface 

Definition at line 61 of file CommandLine.h.

Function Documentation

TEMU_API void temu_cmdAddOption ( void *  Cmd,
const char *  OptName,
temu_CmdOptionKind  Type,
int  Required,
const char *  Doc,
const char *  Default 
)

Add named argument to command

Parameters
CmdPointer to the command object
OptNameOption name
TypeOption type
RequiredPass 0 if the option is not required, otherwise required
DocOption documentation
DefaultDefault value of the option
TEMU_API void* temu_cmdGetData ( void *  Ctxt)

Get data pointer from command context This function shall be called in a command handler on the passed context.

Parameters
CtxtPointer to the context of the command
Returns
data pointer
TEMU_API void* temu_cmdGetInterpreter ( void *  Ctxt)

Get pointer to the command interpreter This function shall be called in a command handler on the passed context.

Parameters
CtxtPointer to the context of the command
Returns
Pointer to interpreter
TEMU_API int64_t temu_cmdGetOptionAsInteger ( void *  Ctxt,
const char *  OptName 
)

Get named option as integer from command context This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
OptNameOption name
Returns
The integer bound to the named argument
TEMU_API void* temu_cmdGetOptionAsObject ( void *  Ctxt,
const char *  OptName 
)

Get named option as object pointer from command context This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
OptNameOption name
Returns
Pointer to the option object
TEMU_API double temu_cmdGetOptionAsReal ( void *  Ctxt,
const char *  OptName 
)

Get named option as double from command context This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
OptNameOption name
Returns
The real value of the option as double
TEMU_API const char* temu_cmdGetOptionAsString ( void *  Ctxt,
const char *  OptName 
)

Get named option as string from command context This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
OptNameOption name
Returns
C-string of the name of the option
TEMU_API const char* temu_cmdGetPosOpt ( void *  Ctxt,
size_t  Idx 
)

Get positional option at index This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
IdxIndex of the option
Returns
The option at position Idx as a C-string
TEMU_API size_t temu_cmdGetPosOptSize ( void *  Ctxt)

Get number of positional options given This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
Returns
The number of position optionals in Ctxt
TEMU_API const char* temu_cmdGetVariable ( const char *  Key)

Get a variable in the command line

Parameters
KeyVariable name
Returns
In case the variable is not found NULL, otherwise a borrowed string.
TEMU_API int temu_cmdOptionIsValid ( void *  Ctxt,
const char *  OptName 
)

Return 1 if the option is valid, 0 if invalid / not set This function shall be called in a command handler on the passed context.

Parameters
CtxtCommand context
OptNameOption name
Returns
1 if the option is valid, 0 if invalid / not set
TEMU_API int temu_cmdSetVariable ( const char *  Key,
const char *  Value 
)

Set a variable in the command line

Parameters
KeyVariable name (must match [A-Za-z_][A-Za-z0-9_]*)
ValueValue to assign to variable
Returns
Non-zero on errors
TEMU_API void* temu_createCmd ( const char *  Name,
temu_CommandFunc  F,
const char *  Doc,
void *  Data 
)

Create and register command

Parameters
NameName of command
FCommand function to invoke
DocDocumentation string
DataData pointer. Some commands e.g. disassemble will increase the address between invocations. This must be saved in some data object which can be provided when the command is created.
TEMU_API int temu_execCommand ( const char *  Cmd)

Executes a single command

Parameters
CmdThe command to be executed
Returns
0 on success, otherwise a non-zero value
TEMU_API int temu_execCommandFile ( const char *  File)

Executes the commands in the file "File"

Parameters
FilePath to the file with the commands to be executed
Returns
0 on success, otherwise a non-zero value
TEMU_API int temu_parseCommandLineOptions ( int  argc,
const char *  argv[] 
)

Parses command line options The TEMU command supports a number of built in command line options. A simulator embedding TEMU may want initialise these options in the same way that the TEMU CLI does. Note that not all options are supported this way as some options will only be registered by the temu CLI application itself.

In general interactive options will not work (options that can be interpreted as a command). It is possible to use temu_printCommandLineHelp() to list currently registered options from an application that embedds temu.

Parameters
argcNumber of arguments
argvCommand line arguments
Returns
0 on success, otherwise non-zero value.
TEMU_API void temu_printCommandLineHelp ( void  )

Print command line help to stdout