TEMU  4.4
The Terma Emulator
CommandLine.h File Reference
#include "temu-c/Support/Attributes.h"
#include "temu-c/Support/Objsys.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for CommandLine.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  temu_CmdArg
 

Typedefs

typedef int(* temu_CommandFunc) (void *)
 
typedef enum temu_CmdOptionKind temu_CmdOptionKind
 
typedef int(* temu_ObjectCommandFunc) (temu_Object *Obj, void *I, int argc, const temu_CmdArg args[])
 

Enumerations

enum  temu_CmdOptionKind {
  teCOK_String = 0, teCOK_Path, teCOK_Object, teCOK_Int,
  teCOK_Double, teCOK_Prop, teCOK_Iface, teCOK_Reg,
  teCOK_Field, teCOK_Class
}
 

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_createClassCmd (temu_Class *Cls, const char *Name, const char *Doc, temu_ObjectCommandFunc F)
 
TEMU_API void * temu_classGetCmd (temu_Class *Cls, const char *Name)
 
TEMU_API int temu_classCmdAddParam (void *Cmd, const char *Name, temu_CmdOptionKind Type, int Required, const char *Doc)
 
const TEMU_API temu_CmdArgtemu_classCmdGetOption (int argc, const temu_CmdArg args[], const char *OptName)
 
TEMU_API int64_t temu_classCmdGetOptionAsInteger (int argc, const temu_CmdArg args[], const char *OptName)
 
TEMU_API uint64_t temu_classCmdGetOptionAsUnsigned (int argc, const temu_CmdArg args[], const char *OptName)
 
TEMU_API int temu_objectInvokeCmd (temu_Object *Obj, void *I, const char *Name, int Argc, temu_CmdArg Argv[])
 
TEMU_API int temu_raiseCmdError (void *I, const char *S,...)
 
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)
 
const TEMU_API 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)
 
const TEMU_API 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)
 
const TEMU_API char * temu_cmdGetVariable (const char *Key)
 

Typedef Documentation

◆ temu_CmdOptionKind

◆ temu_CommandFunc

typedef int(* temu_CommandFunc) (void *)

User command handlers implement this interface. The pointer argument is a pointer to an opaque context. Use the functions below to access properties from the context.

◆ temu_ObjectCommandFunc

typedef int(* temu_ObjectCommandFunc) (temu_Object *Obj, void *I, int argc, const temu_CmdArg args[])

Enumeration Type Documentation

◆ temu_CmdOptionKind

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 

Any floating point number.

teCOK_Prop 

Property reference.

teCOK_Iface 

Interface reference.

teCOK_Reg 

Register reference.

teCOK_Field 

Register field reference.

teCOK_Class 

Class option.

Function Documentation

◆ temu_classCmdAddParam()

TEMU_API int temu_classCmdAddParam ( void *  Cmd,
const char *  Name,
temu_CmdOptionKind  Type,
int  Required,
const char *  Doc 
)

Add parameter to command

Parameters
CmdCommand handle
NameName of parameter to add
TypeType of the parameter
RequiredSet to 1 if the parameter must be set for the command
DocDocumentation string for the parameter
Returns
0 on success, other values indicates errors

◆ temu_classCmdGetOption()

const TEMU_API temu_CmdArg* temu_classCmdGetOption ( int  argc,
const temu_CmdArg  args[],
const char *  OptName 
)

Get named command option

Parameters
argcNumber of arguments
argsArgument vector
OptNameName of parameter / option to get
Returns
Pointer to command argument or NULL in case it is not found.

◆ temu_classCmdGetOptionAsInteger()

TEMU_API int64_t temu_classCmdGetOptionAsInteger ( int  argc,
const temu_CmdArg  args[],
const char *  OptName 
)

Get named command option as signed integer

Can only get valid numeric parameters. The function will never fail if the type is numeric and the option is required. For optional arguments, use the generic access function temu_classCmdGetOption()

Parameters
argcNumber of arguments
argsArgument vector
OptNameName of parameter / option to get
Returns
The value of the parameter converted to an integer.

◆ temu_classCmdGetOptionAsUnsigned()

TEMU_API uint64_t temu_classCmdGetOptionAsUnsigned ( int  argc,
const temu_CmdArg  args[],
const char *  OptName 
)

Get named command option as unsigned integer

Can only get valid numeric parameters. The function will never fail if the type is numeric and the option is required. For optional arguments, use the generic access function temu_classCmdGetOption()

Parameters
argcNumber of arguments
argsArgument vector
OptNameName of parameter / option to get
Returns
The value of the parameter converted to an unsigned integer.

◆ temu_classGetCmd()

TEMU_API void* temu_classGetCmd ( temu_Class Cls,
const char *  Name 
)

Get an already registered command handle from class

This function can be used to for example get commands registered in the metaclass, such as the new command. The command can then have arguments added.

Parameters
ClsClass pointer
NameName of command to get
Returns
Opaque handle to command. NULL in case of failure.

◆ temu_cmdAddOption()

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_cmdGetData()

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_cmdGetInterpreter()

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_cmdGetOptionAsInteger()

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_cmdGetOptionAsObject()

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_cmdGetOptionAsReal()

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_cmdGetOptionAsString()

const TEMU_API 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_cmdGetPosOpt()

const TEMU_API 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_cmdGetPosOptSize()

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_cmdGetVariable()

const TEMU_API 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_cmdOptionIsValid()

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_cmdSetVariable()

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_createClassCmd()

TEMU_API void* temu_createClassCmd ( temu_Class Cls,
const char *  Name,
const char *  Doc,
temu_ObjectCommandFunc  F 
)

Register a class command

Parameters
ClsClass pointer
NameName of command
DocDocumentation string for command
FCommand handler function
Returns
Opaque handle to command. NULL in case of failure.

◆ temu_createCmd()

TEMU_API void* temu_createCmd ( const char *  Name,
temu_CommandFunc  F,
const char *  Doc,
void *  Data 
)

Create and register global 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_execCommand()

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_execCommandFile()

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_objectInvokeCmd()

TEMU_API int temu_objectInvokeCmd ( temu_Object Obj,
void *  I,
const char *  Name,
int  Argc,
temu_CmdArg  Argv[] 
)

Invoke command on object

Parameters
ObjObject
IInterpreter context
NameName of command
ArgcNumber of arguments
ArgvArgument vector
Returns
Command result. 0 means success.

◆ temu_parseCommandLineOptions()

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_printCommandLineHelp()

TEMU_API void temu_printCommandLineHelp ( void  )

Print command line help to temu stderr stream.

◆ temu_raiseCmdError()

TEMU_API int temu_raiseCmdError ( void *  I,
const char *  S,
  ... 
)