Macro Language Primitives

Summary
Macro Language Primitives
Constants
BPACKAGESBRIEF packages default.
CRISP_OPSYSOperating system identifier.
GRBACKUPBackup path.
GRDICTIONARIESDictionary locales.
GRDICTIONARYDictionary search path.
GRFILEDefault empty file name.
GRFLAGSDefault command line arguments.
GRHELPHelp search path.
GRINIT_FILEGRIEF initialisation name.
GRKBDPATHKeyboard library search path.
GRLEVELGRIEF Nesting level.
GRLOG_FILEGRIEF diagnostics log file name.
GRPATHMacro object search path.
GRPROFILEProfile directory override.
GRPROGNAMEGRIEF application path.
GRRCGRIEF resource file path.
GRRC_FILEGRIEF initialisation name.
GRRESTORE_FILEGRIEF restore file name.
GRSTATE_DBGRIEF state database name.
GRSTATE_FILEGRIEF state file name.
GRTEMPLATESource template search path.
GRTERMTerminal override.
GRTERMCAPTerminal capability database.
GRTMPTemporary dictionary.
GRVERSIONMAJORGRIEF major version.
GRVERSIONMINORGRIEF minor version.
GRVERSIONSBackup versions.
errnoLast system errno number.
Macros
__breakswSwitch break statement.
autoloadRegister location of one or more macros.
blessAssociate an object with a class/module.
breakbreak statement.
call_registered_macroInvoke registered macro callbacks.
caseSwitch case statement.
catchCatch statement.
continueLoop continuation.
create_dictionaryCreate a dictionary.
delete_dictionaryDestroy a dictionary.
delete_macroDelete a macro from memory.
dict_clearClear a dictionary.
dict_deleteRemove a dictionary item.
dict_eachIterator a dictionary.
dict_existsDictionary item existence check.
dict_keysIterator dictionary keys.
dict_listRetrieve dictionary items.
dict_nameRetrieve a dictionary name.
dict_valuesIterator dictionary values.
dodo statement.
elseelse statement.
execute_macroInvokes a command by name.
exitExit current process level.
finallyFinally statement.
first_timeDetermine a macros initialisation status.
forfor statement.
foreachContainer iterator.
fstypeFile system type.
get_propertyRetrieve a dictionary item.
ifif statement.
inq_btn2_actionRetrieve the second button action.
inq_calledGet the name of the calling macro.
inq_macroDetermine whether a macro or primitive exists.
inq_macro_historyRetrieve macro execution history.
inq_moduleRetrieve the current module.
inq_msg_levelGet the message level.
list_of_dictionariesList of created dictionaries.
load_macroLoad a macro object.
macroDefine a macro body.
moduleAssign a module identifier.
nothingNoop.
register_macroRegister a callback procedure.
reload_bufferReload the buffer content.
replacementOverload an existing macro definition.
requireEnforce the use of an external module.
reregister_macroRegister a unique callback procedure.
restore_positionRestore a previously saved position.
returnReturn from a macro.
returnsReturn an expression from a macro.
save_positionSaves current cursor/buffer state.
set_btn2_actionSet the second button action.
set_calling_nameSet the name of the calling macro.
set_macro_historySet the macro execution history.
set_propertySet a dictionary item.
switchSwitch statement.
throwThrow an exception.
tryTry statement.
unregister_macroRemove a registered macro.
whilewhile statement.

Constants

BPACKAGES

extern const string BPACKAGES;

BRIEF packages default.

Description

The BPACKAGES global string is used to specify the BRIEF language sensitive editing modes.  This is a hangover from the PC version of BRIEF, it is used to configure old-style package support; see the macro source language.cr.

BPACKAGES shall be referenced on the first running of GRIEF and then exported into the GRIEF runtime configuration file.  The initial value of BPACKAGES is either imported from the environment or if not available then the following default is used.

.c.cc.CC.cpp.h.H.hpp-c:hilite,t;.default:hilite,template,regular;

Package Specification

You can attach these packages so that they are automatically used with program source files that have special file extensions.  The packages configuration is used by all file extension dependent packages.

The format of the package specification is,

package: extension[,extension]...[-equivalent]:\
package [args],package...;extension...
extension

The extension element is the file extension that will invoke a specific style.  One or more comma separated extension can be specified for each style.

Note: the special extension “default” is used to specify all extensions not specifically included in the packages string.

equivalent

The equivalent element is an optional value which specifies that the preceding extensions should be treated the same as the “equivalent extension” by the language sensitive features, an extension override.

All extensions preceding the equivalent extension back to preceding semicolon, another equivalent extension, or the beginning of the packages definition are affected by the command.  Hence given:

package: .asm:.r;.cpp.hpp.h-c:smart

GRIEF shall consider extensions .cpp, .hpp and .h equivalent to the extension .c, and would use .c the smart editing package for all three.  Note also that since .c has not been explicitly specified as an extension, no packages are assigned to it.  The following is required to complete the recipe:

package: .asm:r;.cpp.hpp.h.c-c:smart

GRIEF shall first check for the package using the actual extension before for one with the equivalent extension.  If in the previous example, smart indentation was available for .cpp files, GRIEF would use the .cpp support over the .c support.

This feature is useful when the extension is not automatically recognised and is unable to provide smart indenting.  Using extension equivalence, informs GRIEF that an unsupported extension should be treated like an equivalent supported one.

package: .default:hilite;.c:hilite,t 1 1 0 1

The extension .default is used as a wild card (or default), to any match an extension not explicitly listed.  The above example enables the hilite package on implicitly supported file types, plus an explicit configuration for the .c extension.

package

Is the macro package attached to the extension.  Each extension can have multiple packages associated with it, as long as the package don’t conflict.

See Also

GRTEMPLATE

CRISP_OPSYS

extern const string CRISP_OPSYS;

Operating system identifier.

Description

The CRISP_OPSYS global constant is assigned the name associated with the current running operating system.

See Also

GRPROGNAME

GRBACKUP

extern const string GRBACKUP;

Backup path.

Description

The GRBACKUP global string is used to specify the default backup directory, when buffer backups are enabled.  In the absence of any buffer or global set_backup_option BK_DIR configuration nor the GRBACKUP environment variable, GRIEF renames the original file with a .bak extension.

Compatible

GRBACKUP is equivalent to the BRIEF BBACKUP environment variable.

See Also

GRVERSIONS

GRDICTIONARIES

extern const string GRDICTIONARIES;

Dictionary locales.

Description

The GRDICTIONARIES global string is used to specify the dictionary locales to be applied during spell check operations, stated as a list of comma separated dictionary names.

Example
GRDICTIONARIES=en_GB,en_US

The default value assigned when no value is available.

GRDICTIONARIES=en_US,en_GB,default

The value of GRDICTIONARIES can be dumped by running GRIEF with the --config command line option.

gr --config

See Also

GRPATH, GRDICTIONARY

GRDICTIONARY

extern const string GRDICTIONARY;

Dictionary search path.

Description

The GRDICTIONARY global specifies the directory from which dictionaries are to be sourced during spell check operations.

See Also

GRPATH, GRDICTIONARIES, <vars>

GRFILE

extern const string GRFILE;

Default empty file name.

Description

The GRFILE global string is used to specify the file name used on start up as the default buffer name to be created, when no explicit files are stated on the command line.

The initial value of GRFILE is either imported from the environment or if not available then a value of newfile is used.

GRFILE=newfile

See Also

GRFLAGS

GRFLAGS

extern const string GRFLAGS;

Default command line arguments.

Description

The GRFLAGS global string is used to specify the default implied command line arguments.  GRIEF processes the switches stated in GRFLAGS before processing the explicit flags on the command line.

The GRFLAGS variable provides a means to set up private user options to be automatically applied on each execution.  For example, your GRIEF profile macro can be automatic loaded on start using:

GRFLAGS="-mmyprofile"

The initial value of GRFLAGS is either imported from the environment or if not available then a system dependent default is used.

Compatible

GRFLAGS is equivalent to the BRIEF BFLAGS environment variable.

See Also

GRFILE

GRHELP

extern const string GRHELP;

Help search path.

Description

The GRHELP global string is used to specify the directory name stating the search path which GRIEF shall utilise to locate the help database.  The initial value of GRHELP is either imported from the environment or if not available is derived from the location of the running application.

Directly setting this value within the session environment permits an alternative GRIEF installation.

Example

Default Unix definition.

/usr/local/grief/help

The value of GRHELP can be dumped by running GRIEF with the --config command line option.

gr --config

Compatible

GRHELP is equivalent to the BRIEF BHELP environment variable.

See Also

GRPATH, GRBACKUP, GRDICTIONARIES, <vars>

GRINIT_FILE

extern const string GRINIT_FILE;

GRIEF initialisation name.

Description

The GRINIT_FILE global constant is assigned to the system dependent initialisation file name.

The GRINIT_FILE file contains optional runtime configuration settings to initialise GRIEF when it starts.

  • On Unix systems, “.grinit”.
  • On Windows systems, “_grinit”.
Location

The standard location of the configuration is either within profile directory or the home directory.

  • On Unix style systems, the home directory of the current user is specified by the $HOME environment variable; this is also represented by the ~ directory.
~/.grinit
  • On Windows systems, the home directory is normally a derived from the $HOMEDRIVE and $HOMEPATH environment variables or system calls.
$HOMEDRIVE\$HOMEPATH\_grinit

Within all environments the GRPROFILE override can be used to state an alternative location.

The sysinfo macro can be used to see the current home and/or profile specifications.

See Also

GRRESTORE_FILE, GRSTATE_FILE, GRSTATE_DB

GRKBDPATH

extern const string GRKBDPATH;

Keyboard library search path.

Description

The GRKBDPATH global string is used to specify the directory name stating the location shall utilise to keyboard library definitions.  The initial value of GRKBDPATH is either imported from the environment or if not available is derived from GRTEMPLATE.

These macros build the global list variable, kbd_labels, that is then is used by the int_to_key to derive the displayable label.

The keyboard library macro is only relevant within several help functions, so that meaningful keyboard labels can be given.  For example, you might have a META key rather than an ALT key.

list
kbd_labels = {
AF(1), "<Meta-F1>",
AF(2), "<Meta-F2>",
AF(3), "<Meta-F3>",
AF(4), "<Meta-F4>",
AF(5), "<Meta-F5>",
AF(6), "<Meta-F6>",
AF(7), "<Meta-F7>",
AF(8), "<Meta-F8>",
AF(9), "<Meta-F9>",
AF(10), "<Meta-F10>",
AF(11), "<Meta-F11>",
AF(12), "<Meta-F12>"
};

See Also

GRTEMPLATE

GRLEVEL

extern const int GRLEVEL;

GRIEF Nesting level.

Description

The GRLEVEL global constant is set by GRIEF to the current nesting level, stating the number of current invocations of GRIEF within the same session.  This value allows the user to determine that there are nested invocations of GRIEF running; see inq_brief_level.

Compatible

GRLEVEL is equivalent to the BRIEF BLEVEL environment variable.

It is a hangover from BRIEF which displays the level number in the bottom right corner.  Unlike BRIEF the value only represents the number of instances running within the current terminal session; with each terminal maintaining an independent nesting level.

See Also

GRPATH, GRHELP

GRLOG_FILE

extern const string GRLOG_FILE;

GRIEF diagnostics log file name.

Description

The GRLOG_FILE global constant is assigned to the system dependent default file name:

  • On Unix systems, “.grief.log”.
  • On Windows systems, “grief.log”.

GRPATH

extern const string GRPATH;

Macro object search path.

Description

The GRPATH global string is used to specify one or more directory names stating the search path which GRIEF shall utilise to locate macro objects during autoload and require operations.  The initial value of GRPATH is either imported from the environment or if not available is derived from the location of the running application.

Same as the system PATH environment variable, the directories contained within GRPATH should use the operating system dependent delimiter generally either a semi-colon (;) for DOS/Windows or a colon (:) for Unix style systems.

Directly setting this value within the session environment permits an alternative GRIEF installation.

Example

Possible Unix definition, allowing access to both user localised and global macros.

$HOME/grief:/usr/local/grief/macro

The value of GRPATH can be dumped by running GRIEF with the --config command line option.

gr --config

Compatible

GRPATH is equivalent to the BRIEF BPATH environment variable.

See Also

GRHELP, GRBACKUP, GRDICTIONARIES

GRPROFILE

extern const string GRPROFILE;

Profile directory override.

Description

The GRPROFILE global string is used to specify an override to the standard users home directory; it is utilised by several macros to source runtime configuration details.  GRPROFILE provides the user a means of stating an alternative location.

See Also

GRPATH

GRPROGNAME

extern const string GRPROGNAME;

GRIEF application path.

Description

The GRPROGNAME global constant is assigned the full-path of the current running application;

See Also

GRINIT_FILE

GRRC

extern const string GRRC;

GRIEF resource file path.

Description

The GRRC global constant is assigned the full-path of the active resource file, if any.

See Also

GRRC_FILE

GRRC_FILE

extern const string GRRC_FILE;

GRIEF initialisation name.

Description

The GRRC_FILE global constant is assigned to the system dependent resource file name.  The resource file is an alternative source of application arguments, equivalent to the GRFLAGS environment variable.

The resource file provides a means to set up private user options to be automatically applied on each execution.

  • Unix style systems, “.grrc”.
  • Windows systems, either “.grrc” or “_grrc”

The resource file is used to specify implied command line arguments.  GRIEF either processes the switches stated within GRFLAGS or the resource file before processing the explicit flags on the command line.  As such, if both are present GRFLAGS has priority.

For example, your GRIEF profile macro can be automatic loaded on start using:

# .grrc example
-mmyprofile

The character `#’ introduces a comment if used at the beginning of a line.  Lines starting with `#’ are ignored as are blank lines.  One or more white-space separated options can be stated per-line but it is advised to use one for readability.

Processing may be inhibited by using the --norc option on the command line, disabling both GRFLAGS and resource file processing.

Location

The standard location of the configuration is within the home directory.

  • Unix style systems, the home directory of the current user is specified by the $HOME environment variable; this is also represented by the ~ directory.
~/.grrc
  • Windows systems, the home directory is normally a derived from the $HOMEDRIVE and $HOMEPATH environment variables or system calls.
$HOMEDRIVE\$HOMEPATH\_grrc

The GRRC global string shall represent the path of the resolved resource file.

The sysinfo macro can be used to see the path of the active resource name.

See Also

GRRC, GRINIT_FILE, <vars>

GRRESTORE_FILE

extern const string GRRESTORE_FILE;

GRIEF restore file name.

Description

The GRRESTORE_FILE global constant is assigned to the system dependent default file name, for example .grief.

See Also

GRSTATE_FILE, GRSTATE_DB, GRINIT_FILE

GRSTATE_DB

extern const string GRSTATE_DB;

GRIEF state database name.

Description

The GRSTATE_DB global constant is assigned to the system dependent default file name, for example grstatedb.

See Also

GRRESTORE_FILE, GRSTATE_FILE, GRINIT_FILE

GRSTATE_FILE

extern const string GRSTATE_FILE;

GRIEF state file name.

Description

The GRSTATE_FILE global constant is assigned to the system dependent default file name, for example .grstate.

See Also

GRRESTORE_FILE, GRSTATE_DB, GRINIT_FILE

GRTEMPLATE

extern const string GRTEMPLATE;

Source template search path.

Description

The GRTEMPLATE global string is used to specify the language sensitive file and function header generator.  The initial value of GRTEMPLATE is either imported from the environment or if not available is derived from the location of the running application.

Template syntax examples; see the macro source macro funchead.cr for details.

Synopsis:
%[1%FTYPE% %FNAME%%FOPEN% %FARGS% %FCLOSE% // single arg]%

%[2%FTYPE% %FNAME%%FOPEN% %FARGS(13)% %FCLOSE% // multi arg]%

%FTYPE% %FNAME%
%FOPEN%
%FARGS(,72)%
%FCLOSE%

Purpose:
%FDESC%

Parameters:
FINPUTS(9)
%FINPUTS(9)%

FINPUTS(0,+10)
%FINPUTS(0,+10)%

FINPUTS(0,+10,-2)
%FINPUTS(0,+10,-2)%

FINPUTS(0,32,,80,1,,1)
%FINPUTS(0,32,,80,1,,1)%

FINPUTS(0,32,-4,60,1,1)
%FINPUTS(0,32,-4,60,1,1)%

FINPUTS(0,-1)
%FINPUTS(0,-1)%

FINPUTS(0,20,,70,1,1,1)
%FINPUTS(0,20,,70,1,1,1)%

Returns:
%FTYPE% -

See Also

BPACKAGES

GRTERM

extern const string GRTERM;

Terminal override.

Description

The GRTERM global string is used to specify the identifier for the current terminal type as defined by the UNIX terminfo database, similar to the system TERM environment variable.  GRTERM should be considered as an override to the standard system TERM specification; it may be used in preference to TERM allowing a GRIEF specialisation without affecting other console applications.

The leading component of the GRTERM specification consists of the terminal base-name.  Following the base-name, you may add any reasonable number of hyphen-separated feature suffixes, for example:

xterm-256color

Some of the standard features include,

Feature
Description
m, mono
Mono terminal.
256, 256color
Terminal supports 256 colours.
16, 16color
Terminal supports 16 colours.
88
Terminal support 88 colours.

During initialisation GRIEF firstly references GRTERM and then secondary the system TERM environment variable values.  The derived terminal base-name causes the associated tty macro is be loaded; this macro has the responsible for configuring GRIEF’s keyboard and screen layout using set_term_feature and set_term_keyboard plus related primitives.

See Also

GRTERMCAP

GRTERMCAP

extern const string GRTERMCAP;

Terminal capability database.

Description

The GRTERMCAP global string is used to specify the path to the terminal capability database, similar to the system TERMCAP environment variable.  GRTERMCAP should be considered as an override to the standard system TERM specification; it may be used in preference to TERMCAP allowing a GRIEF specialisation without affecting other console applications.

See Also

GRTERM, <vars>

GRTMP

extern const string GRTMP;

Temporary dictionary.

Description

The GRTMP global string is used to specify the directory within which temporary files are to be created.  GRTMP should be considered as an override to the standard system temporary directory specification.

GRIEF firstly references GRTMP; if this is not defined it tries BTMP secondary and then system dependent alternatives, for example TEMP and TEMPDIR.

If no temporary is not defined, or if it is set to the name of a directory that does not exist, temporary files shall be created within a system dependent default.

Compatible

GRTMP is equivalent to the BRIEF BTMP environment variable.

See Also

GRPATH, <vars>

GRVERSIONMAJOR

extern const int GRVERSIONMAJOR;

GRIEF major version.

Description

The GRVERSIONMAJOR global constant is set to the minor number of the running GRIEF implementation version.

See Also

GRVERSIONMINOR

GRVERSIONMINOR

extern const int GRVERSIONMINOR;

GRIEF minor version.

Description

The GRVERSIONMINOR global constant is set to the minor number of the running GRIEF implementation version.

See Also

GRVERSIONMAJOR, <vars>

GRVERSIONS

extern const int GRVERSIONS;

Backup versions.

Description

The GRVERSIONS global string is used to specify the number of backup versions to be maintained for each modified file, when buffer backups are enabled.  When stated GRIEF shall keep multiple backup copies of each edited file.  In the absence of any buffer or global set_backup_option BK_VERSIONS configuration nor the GRVERSIONS environment variable, GRIEF simple keeps the previous image.

When enabled, GRIEF creates a set of n directories given by GRVERSION named 1 through to n; the directory name being number of previous edit sessions the files contained within represent.

For example, given GRBACKUP=~/.backups and GRVERSIONS=3 the following directory structure shall be maintained.

~/.backups
~/.backups/1
~/.backups/2
~/.backups/3

During backup operations, starting from n-1 in reverse order the previous images are rolled into the higher sequenced directory; with any images within the last directory being removed.  Finally the most recent is saved into the root of the tree.  On completion the oldest version of a file can be found in the nth directory; the next oldest is in n - 1.  The most recent backup is the file in the backup directory.

Given the edited file myfile.txt against the above configuration the following backup images may exist:

~/.backups/myfile.txt       [latest]
~/.backups/1/myfile.txt
~/.backups/2/myfile.txt
~/.backups/3/myfile.txt [oldest]

See Also

GRBACKUP

errno

extern int errno;

Last system errno number.

Description

When a system call detects an error, it returns an integer value indicating failure (usually -1) and sets the variable errno accordingly.  This allows interpretation of the failure on receiving a -1 and to take action accordingly.

Successful calls never set errno; once set, it remains until another error occurs.  It should only be examined after an error.  Note that a number of system calls overload the meanings of these error numbers, and that the meanings must be interpreted according to the type and circumstances of the call.

See Error Codes for the list of manifest constants exported.

Portability

The values reported by errno are system and function dependent.

See Also

perror, strerror

Macros

__breaksw

__breaksw;

Switch break statement.

Description

The __breaksw statement is used to implement the break statement within switch statements.

Note:

The __breaksw() primitive is internal to the macro language.  It is generated by the GRIEF macro compiler when a break statement is encountered within a switch statement; it is not intended for direct use.

Returns

nothing

See Also

Jump Statements, switch, while, do, for

autoload

void autoload(string filename,
string function,
 ...)

Register location of one or more macros.

Description

The autoload() primitive informs the macro loader about the existence of global macros.  The primitive registers the specified macro function against the macro object image filename, permitting an arbitrary number of macro names after the initial function; as such one or more function references may be associated.

Whenever the macro engine encounters an undefined macro reference, it searches the internal autoload list for a definition.  If available, the associated macro object shall be loaded as normal, with the loader searching the GRPATH definition for the underlying object image.

If during an autoload driven load the referenced function was not resolved the following diagnostic shall be generated.

load_macro: macro 'xxx' not resolved during autoload.

A function reference may only be associated with one macro object, with any secondary references ignored generating the following diagnostic message.

autoload: 'xxx' already defined.

Example

The macros modeline and mode are registers against the macro object modeline.

autoload("modeline", "modeline", "mode");

Parameters

filenameString that contains the name of the compiled macro file.
functionString containing the name of the macro function.
...Additional macro function names.

Returns

nothing

Portability

n/a

See Also

require

bless

int bless([int ref],
[string classname])

Associate an object with a class/module.

Description

The bless primitive is reserved for future use.

This primitive informs the dictionary referenced by ref that it is now an object in the classname package.  If classname is omitted, the current module is used.  Because a bless is often the last thing in a constructor, it returns the reference for convenience.

The bless primitive enables Perl style objects.

Note:

Consider always blessing objects in classname’s that are mixed case, using a leading upper-case; Namespaces with all lowercase names are considered reserved for GRIEF pragmata.

Parameters

n/a

Returns

The bless statement returns the dictionary identifier.

Portability

A GriefEdit extension.

See Also

module

break

break;

break statement.

Description

The break statement is used to terminate switch, while, do and for loops.

Returns

nothing

See Also

Jump Statements, switch, while, do, for

call_registered_macro

int call_registered_macro(int type)

Invoke registered macro callbacks.

Description

The call_registered_macro() primitive invokes all of functions which have register against the particular event type type.

See register_macro for the particulars on the different registered event types.

Parameters

typeEvent type to be invoked.

Returns

The call_registered_macro returns nothing.

Portability

The set of available events differ between systems.

See Also

register_macro

case

'case' expr:

Switch case statement.

Description

The switch and case statements help control complex conditional and branching operations.

The body of a switch statement may have an arbitrary number of unique case labels.

If condition evaluates to the value that is equal to the value of one of case expressions, then control is transferred to the statement that is labelled with that expression.

If condition evaluates to the value that does not match any of the case labels, and the default label is present, control is transferred to the statement labelled as the default label.

Parameters

exprCase value, which can be an integer, float or string expression.

Returns

nothing

See Also

Selection Statements, switch

catch

catch statement;

Catch statement.

Description

The catch statement is reserved for future use, shall implement try, catch and finally constructs.

Parameters

none

Returns

nothing

Portability

A GriefEdit extension.

See Also

try, finally, throw

continue

continue;

Loop continuation.

Description

The continue statement forces transfer of control to the controlling expression of the smallest enclosing do, for, or <while >loop.

A continue statement may only appear within a loop body, and causes a jump to the inner-most loop-continuation statement (the end of the loop body).

In a while loop, the jump is effectively back to the while.

In a do loop, the jump is effectively down to the while

In a for statement, the jump is effectively to the closing brace of the compound-statement that is the subject of the for loop.  The third expression in the for statement, which is often an increment or decrement operation, is then executed before control is returned to the loop’s conditional expression.

Parameters

none

Returns

nothing.

Portability

n/a

See Also

Jump Statements, while, for, foreach

create_dictionary

int create_dictionary(string ~name,
 int ~tablesize,
int ~tablefactor)

Create a dictionary.

Description

The create_dictionary() primitive creates a new dictionary resource.

A dictionary is a collections of associations.  Dictionaries consist of pairs of keys and their corresponding values, both arbitrary data values.  Dictionaries are also known as associative arrays or hash tables.

Parameters

nameOptional string containing the unique dictionary name, if omitted the dictionary shall be unnamed.
sizeOptional position integer specifying the size of the underlying table.
factorOptional position integer specifying the table fill factor.

Returns

The create_dictionary() primitive returns the identifier associated with the new dictionary.

Portability

A GriefEdit extension.

See Also

delete_dictionary, set_property, get_property

delete_dictionary

int delete_dictionary(int obj_id)

Destroy a dictionary.

Description

The delete_dictionary() primitive destroys the specified dictionary obj_id.

Parameters

obj_idDictionary identifier.

Returns

The delete_dictionary() primitive returns 0 on success, otherwise -1 on error.

Portability

A GriefEdit extension.

See Also

create_dictionary

delete_macro

void delete_macro(string macro)

Delete a macro from memory.

Description

The delete_macro macro deletes a macro file, which contains one or more macros, from memory; the underlying macro object retains unchanged.

Any keyboard references and variables, both global and buffer will be retained.  If any of the macros within the deleted macro object are referenced at a later time, the normal macro load logical is applied which may in turn reload the object.

Note:

This primitive is provided for BRIEF compatibility and is currently a no-op as macros are not directly deletable.  The storage allocated to a macro shall be lost when a macro by the same name is loaded from another file.

Parameters

macroString containing the name of a macro file to be deleted.  If no extension is supplied, then .cm shall be appended.  If omitted the user is prompted.

Returns

nothing

Portability

Not implemented.

See Also

load_macro

dict_clear

int dict_clear(int obj_id)

Clear a dictionary.

Description

The dict_clear() primitive removes all items of the specified dictionary obj_id.

Parameters

obj_idDictionary identifier.

Returns

The dict_clear() primitive returns 0 on success, otherwise -1 on error.

Portability

A GriefEdit extension.

See Also

delete_dictionary, dict_delete, dict_each, dict_keys, dict_values

dict_delete

int dict_delete(int obj_id,
string key)

Remove a dictionary item.

Description

The dict_delete() primitive removes the item associated with the item key from the specified dictionary obj_id.

Parameters

obj_idDictionary identifier.
keyItem key.

Returns

The dict_delete() primitive returns 0 on success, otherwise -1 on error.

Portability

A GriefEdit extension.

See Also

delete_dictionary, dict_clear, dict_each, dict_keys, dict_values

dict_each

int dict_each(int obj_id,
  [string key],
 [declare value])

Iterator a dictionary.

Description

The dict_each() primitive iterates thru a dictionary.

Returns the element index started at one and populates key and value with the entry details, so one may iterate over all elements within the dictionary.

There is no guarantee of order, entries are returned in an apparently random order; driven by the underlying hashing value.

When the dictionary is entirely read, a zero or FALSE value is returned.

You must not modify the dictionary whilst iterating over it.  There is a single iterator for each dictionary, shared by dict_each, dict_keys and dict_values primitives, as such care should be taken not to intermix their usage.

The following prints out your environment like the printenv program, only in a different order:

int index;
while ((index = dict_each(dict, key, value)) >= 0) {
insertf("%d:%s=%s\n", index, key, value);
}

Parameters

obj_idDictionary identifier.
keyRetrieval key.
valueValue.

Returns

The primitive returns the positive element index on success, otherwise zero at the end of the dictionary.

Portability

A GriefEdit extension.

See Also

create_dictionary, dict_keys, dict_values

dict_exists

int dict_exists(  int obj_id,
string key)

Dictionary item existence check.

Description

The dict_exists() primitive determines the existence of an item within the specified dictionary obj_id.

Parameters

obj_idDictionary identifier.
keyItem key.

Returns

The dict_exists() primitive returns TRUE on success otherwise FALSE.

Portability

A GriefEdit extension.

See Also

create_dictionary, dict_each, dict_keys, dict_values

dict_keys

int dict_keys(int obj_id,
  [string key])

Iterator dictionary keys.

Description

The dict_keys() primitive iterates thru a dictionary.

Returns the element index started at one and populates key with the entry details, so one may iterate over all elements within the dictionary.

There is no guarantee of order, entries are returned in an apparently random order; driven by the underlying hashing value.

When the dictionary is entirely read, a zero or FALSE value is returned.

You must not modify the dictionary whilst iterating over it.  There is a single iterator for each dictionary, shared by dict_each, dict_keys and dict_values primitives, as such care should be taken not to intermix their usage.

The following prints out your environment like the printenv program, only in a different order:

int index;
while ((index = dict_keys(dict, key)) >= 0) {
insertf("%d:%s\n", index, key);
}

Parameters

obj_idDictionary identifier.
keyRetrieval key.

Returns

The primitive returns the positive element index on success, otherwise zero at the end of the dictionary.

Portability

A GriefEdit extension.

See Also

create_dictionary, dict_each, dict_values

dict_list

list dict_list(int obj_id,
 [int keys = TRUE])

Retrieve dictionary items.

Description

The dict_list() primitive retrieves the keys or values contained within the specified dictionary obj_id.

Parameters

obj_idDictionary identifier.
keysOptional boolean value unless FALSE key values are retrieved otherwise values are retrieved.

Returns

The dict_list() primitive returns a list of values containing all the keys or values within the specified dictionary, otherwise a null list.

Portability

A GriefEdit extension.

See Also

create_dictionary

dict_name

string dict_name(int obj_id)

Retrieve a dictionary name.

Description

The dict_name() primitive retrieves the name associated with the specified dictionary obj_id.

Parameters

obj_idDictionary identifier.

Returns

The dict_name() primitive returns the name of the dictionary otherwise an empty string.

Portability

A GriefEdit extension.

See Also

create_dictionary

dict_values

int dict_values(int obj_id,
  [declare value])

Iterator dictionary values.

Description

The dict_values() primitive iterates thru a dictionary.

Returns the element index started at one and populates value with the entry details, so one may iterate over all elements within the dictionary.

There is no guarantee of order, entries are returned in an apparently random order; driven by the underlying hashing value.

When the dictionary is entirely read, a zero or FALSE value is returned.

You must not modify the dictionary whilst iterating over it.  There is a single iterator for each dictionary, shared by dict_each, dict_keys and dict_values primitives, as such care should be taken not to intermix their usage.

The following prints out your environment like the printenv program, only in a different order:

int index;
while ((index = dict_each(dict, value)) >= 0) {
insertf("%d=%s\n", index, value);
}

Parameters

obj_idDictionary identifier.
valueValue.

Returns

The primitive returns the positive element index on success, otherwise zero at the end of the dictionary.

Portability

A GriefEdit extension.

See Also

create_dictionary, dict_each, dict_keys

do

do statement; while (condition);

do statement.

Description

The do statement implements the do-while loop construct.

do {
statements;
} while (condition);

Executes statements one or more times until condition is non-zero.  The condition is tested after each iteration of the loop.

Portability

n/a

See Also

Iteration Statements, while, break, continue, for, if

else

if (expr) true-body else false-body

else statement.

Description

The else statement implements the secondary condition in the if-then-else construct.

See Also

Selection Statements

execute_macro

declare execute_macro([string cmd],
...)

Invokes a command by name.

Description

The execute_macro() primitive invokes the specified command cmd, which if omitted the user shall be prompted as follows:

Command:

When an invoked command is undefined, GRIEF shall attempt to load the associated macro file sourced from the directories listed in the GRPATH.  If the macro file is successfully loaded and the command is found, the macro is then executed.

Note:

The execute_macro primitive cannot be overloaded with a replacement macro.

Parameters

cmdOptional string buffer containing the command to be executed.  Otherwise if omitted the user shall be prompted for the command.
...Depending on the macro, the executed command may expect a sequence of additional arguments.

Returns

The execute_macro() primitive returns the result of the executed command, otherwise upon an error -2 shall be returned..

Portability

n/a

See Also

load_macro

exit

void exit([string y_or_w])

Exit current process level.

Description

The exit() primitive signals to leave the current process loop, which if the top level loop causes GriefEdit to terminate to the operating system.

Upon leaving the top level prior to exiting when modified buffers are present the user shall be prompted as to whether or not the buffers should be saved, as follows;

1 buffer has not been saved. Exit [ynw]?

The user may have all modified buffers saved prior to terminating by replying with either “W” or “w”, otherwise terminate without saving any buffers using “Y” or “y”.  Alternatively the user may reject the exit signal altogether with a reply of “N” or “n”.

Parameters

y_or_wOptional string that is applied to the answer regarding the action to occur when modified buffers are detected; Y or y GriefEdit shall exit without saving any modifiers buffers, whereas W or w all modified buffers are written.
Any other values other than “YyWW” shall cause the user to be prompted.  In addition, the parameter is ignored if exit is being applied to a secondary process loop, which would not cause GriefEdit to terminate.

Returns

nothing

Portability

n/a

See Also

abort, process

finally

finally statement;

Finally statement.

Description

The finally statement is reserved for future use, shall implement try, catch and finally constructs.

Parameters

none

Returns

nothing

Portability

A GriefEdit extension.

See Also

try, catch, throw

first_time

int first_time()

Determine a macros initialisation status.

Description

The first_time() primitive returns true if this is the first invocation of the calling macro since loading.

Each macro maintains a first_time status, which during the first execution of the macro is true and all subsequent calls shall be *false.  This primitive is generally used to perform run-time subsystem initialisation, for example.

if (first_time()) {
initialise();
}

The loading of macro resets the first_time flag, is effect deleting the macro and reloading will look like it was never loaded.

Note:

A GRIEF macro compiler utilises this primitive to perform run-time initialisation of function static variables.

Parameters

none

Returns

The first_time() primitive returns true (non-zero) if the first invocation of the associated macro, zero otherwise.

Portability

n/a

See Also

static

for

for ([initialise];
[condition];
[increment]) statements;

for statement.

Description

The for statement implements the for loop construct.

for (initialise; condition; increment)
{
statements;
}

Repeatedly performing statements while the condition is true (non-zero).

When the for function starts, initialise is evaluated once.  It evaluates condition and if the result is non-zero, it evaluates the statements.  Finally, increment is evaluated, and control returns to the condition evaluation.  The process is repeated from here until the condition is evaluated zero.

Portability

n/a

See Also

Iteration Statements, break, continue, while, do

foreach

void foreach(<body>,
<expr>,
<key>,
<value>,
<index>,
<increment>)

Container iterator.

Description

The foreach statement is reserved for future use.

Parameters

n/a

Returns

The foreach statement returns the element index retrieved, otherwise -1 upon an end-of-source condition or error.

Portability

n/a

See Also

list_each, dict_each

fstype

int fstype([string path])

File system type.

Description

The fstype() primitive retrieves the underlying file-system type.

Parameters

pathOptional string containing path on the file-system to be tested, if omitted the current working directory is referenced.

Returns

The fstype() primitive returns a system dependent file-system identifier, otherwise -1 on error or not supported.

Portability

A GriefEdit extension.

See Also

stat

get_property

declare get_property(int obj_id,
string key)

Retrieve a dictionary item.

Description

The get_property() primitive retrieves the value of an item from the specified dictionary obj_id.

This primitive is generally not required within the GRIEF Macro Language.  When the user accesses an object member, the compiler converts the construct into calls to this macro.

The following are equivalent;

        get_property(object, "member");
and:
object.member;

Parameters

obj_idDictionary identifier.
keyItem key.

Returns

The get_property() primitive returns the item value otherwise NULL.

Portability

A GriefEdit extension.

See Also

create_dictionary, set_property, dict_exists, dict_each

if

if (expr) true-body

if statement.

Description

The if statement implements the if-then-else construct.  The else is optional.  Evaluates the condition expr; if the condition is non-zero, executes the if_statements; otherwise, it executes the else_statements.

if (condition)
{ if_statements }
[else]
{ else_statements }

See Also

Selection Statements, else, while

inq_btn2_action

int inq_btn2_action()

Retrieve the second button action.

Description

The inq_btn2_action() primitive is reserved for future BRIEF compatibility.

The inq_btn2_action() primitive retrieves the current action status of the second mouse button.  The function can be used to assign a mouse action handler into a newly pushed keyboard, which shall be automatically removed upon the keyboard destruction.

Parameters

none

Returns

Returns the current action button status.

Portability

n/a

inq_called

string inq_called()

Get the name of the calling macro.

Description

The inq_called() primitive returns the callers name, allowing macros to differentiate between being called directly from the command prompt, or from another macro.

This primitive is provided to support replacement macros and to allow macros to determine whether user prompts get_parm are suitable and message output may be required.

Returns

The inq_calling() primitive returns a string containing the name of the macro which called the current macro, otherwise an empty string where invoked from the keyboard.

The set_calling_name can be used to modify the value returned in-turn controlling the behaviour of the macros which are then invoked.

See Also

set_calling_name, replacement

inq_macro

int inq_macro(string name,
 [int mode = 0])

Determine whether a macro or primitive exists.

Description

The inq_macro() primitive tests whether the specified macro name exists within a stated namespace(s) defined by mode.

Parameters

nameString containing the macro name to be tested.
modeOptional integer test type, if omitted defaults to 0, see table for mode behaviours.

Tests

The following test behaviours are available given by mode;

Value
Description
0x00
Default behaviour if mode is omitted.
inq_macro tests specified macro name against both runtime loaded macros and built-in primitive.
It returns 1 if the macro exists (loaded, autoload or a primitive replacement), 0 if it is a built-in primitive, otherwise -1 if neither a built-in primitive nor macro.
Note: The returns are incompatible with the original BRIEF implementation.
0x01
inq_macro only tests whether the specified macro name is runtime loaded macro, ignoring built-in primitives.
It returns 1 if the macro is loaded, 2 if it exists as an autoload but has yet to be loaded otherwise 0 if the macro does not exist.
0x02
inq_macro returns the assigned positive module number (See: inq_module) if the macro has been loaded, 0 i it is an autoload, otherwise -1 if the macro does not exist.
0x03
inq_macro only tests whether the specified macro name is a primitive, ignoring runtime loaded macros
It returns 1 if the primitive exists, 2 if it has been replaced (See: replacement) otherwise 0 if the primitive does not exist.

Returns

The inq_macro() primitive returns a mode specified value, otherwise -1 if the stated mode was invalid.

Portability

The autoload visibility under mode 0x01 and mode 0x03 are GriefEdit extensions.

See Also

load_macro

inq_macro_history

string inq_macro_history([int index = 0])

Retrieve macro execution history.

Description

The inq_macro_history() primitive retrieves the name of the previously executed macro as a result of a keyboard binding.

If index is specified, it specifies the history index starting at an offset of zero, otherwise the most recent (i.e. index 0) is returns.

The home and end macros are good examples of its usage, which modify their behaviour based upon previous operations.

Parameters

indexOptional int index.

Returns

The inq_macro_history() primitive returns the name of the macro invoked, otherwise an empty string if the item does not exist.

Portability

A GriefEdit extension, matching similar CRiSPEdit functionality of the same name.

See Also

set_macro_history, inq_command

inq_module

string inq_module([int test = 1])

Retrieve the current module.

Description

The inq_module() primitive retrieves the module name assigned with the calling macro.  When loaded macros are automaticly assigned with a unique module name or can be specificly assigned using the module primitive.

Module names are used to implement name spaces for static macro functions or to provide a way of creating a macro package split amongst source files.

Example

The following example setups a static scoped callback function

void
main(void)
{
register_callback( inq_module() + "::callback" );
}

static void
callback(void)
{
}

Returns

The inq_module() primitive returns the name of the current module.

Portability

A GriefEdit extension.

See Also

module, static, <scope>

inq_msg_level

int inq_msg_level()

Get the message level.

Description

The inq_msg_level() primitive retrieves the current message level.

0All messages are enabled; the default value.
1Normal messages are not displayed, error messages still display.
2Error messages are suppressed.
3Suppress all messages, both message and error.

Parameters

none

Returns

The inq_msg_level() primitive returns the message level.

Portability

n/a

See Also

set_msg_level

list_of_dictionaries

list list_of_dictionaries(  [bool nonempty = false],
[bool named = false])

List of created dictionaries.

Description

The list_of_dictionaries() primitive retrieves a list of dictionary identifiers created by the create_dictionary primitive.

Parameters

nonemptyEmpty diction filter.  Optional integer boolean flag.  If specified and is not-zero, then empty directionaries shall be filtered.
namedNamed dictionary filter.  Optional integer boolean flag.  If specified and is not-zero, then unnamed directionaries shall be filtered.

Returns

The list_of_dictionaries() primitive retrieves a list of dictionaries.

Portability

A GriefEdit extension.

See Also

create_dictionary

load_macro

int load_macro(string filename,
 [int reload = 1])

Load a macro object.

Description

The load_macro() primitive loads the specified macro object filename, resolving all external references in the file.

If filename does not contain a path specification, then all directories contained within the GRPATH environment variable are searched.

If reload is either omitted or non-zero, the macro shall be reloaded regardless of whether the object image has already been loaded using load_macro or a autoload reference.  Otherwise if zero the image shall not be reloaded if a image with the same name was loaded previously.

Once a successful load the macro objects main entry point is executed.

Note:

Upon loading pre-compiled macro objects (.cm), several interface checks occur confirming whether the object is compatible with the current GRIEF version, for example engine version number and primitive count.  Check failure results in a load error and suitable diagnostics being echoed on the command prompt.

Parameters

filenameString containing the macro object to be loaded.  If the specified file has an extension, then an exact match is located.  Otherwise files matching one of the following extensions are .cm, .cr, and .m are located.
reloadOptional boolean flag, if given as false and the same macro object was previously loaded, nothing shall be loaded.

Returns

The load_macro() primitive returns 1 if macro file was successfully loaded; return 2 if reload is non-zero an a loaded image already exists; otherwise 0 on failure.

Portability

Unlike BRIEF, macros in source form (.m files) can be loaded with this macro.

The reload option is an GriefEdit extension.

See Also

autoload, inq_macro, main

macro

declare macro(list declaration)

Define a macro body.

Description

The macro internal primitive is the mechanism by which macros are imported during the loading of a macro object.

Parameters

declList containing the macro declaration, including scoping flags, macro name and the function body.

Note:

This interface should be considered as a internal primitive, reserved for exclusive use by the GRIEF Macro Compiler and may change without notice.  Management of macro definitions plus any associated argument binding shall be handled automatically by the compiler.

Registering an ill-formed macro declaration shall have undefined effects, most likely resulting in GRIEF crashes.

Returns

Result of any main and/or associated internal _init execution.

Portability

n/a

See Also

replacement

module

int module(string modulename)

Assign a module identifier.

Description

GRIEF provides a mechanism for alternative namespaces, being an abstract container providing context for the items, to protect modules from accessing on each other’s variables.

The purpose of this functionality is to provide data hiding within a set of common macro files (objects), by allowing separate function and variables namespaces.  Each namespace creates a container for a set of symbols, providing a level of indirection to specific identifiers, thus making it possible to distinguish between identifiers with the same exact name, in effect reducing naming conflicts in unrelated objects (See: Scope).

The module statement declares the object as being in the given namespace.  The scope of the module declaration is from the declaration itself and effects all current and future declarations within the associated object.

The intended usage of the module() primitive is the within the main function in all of the related objects.

The namespace specification should be a string containing a valid sequence of identifier symbols of the form

[A-Za-z_][A-Za-z_0-9]*

Namespaces are in conjunction with static scoping of members ((see static )).  If you are writing a set of macros some of which are internal and some for external use, then you can use the static declaration specifier to restrict the visibility of a member variable or function.

However as static functions are hidden from usage outside their own macro file (or module), this can present a problem with functionality which involves the usage of callbacks (e.g. assign_to_key).  In this case, the :: (scope resolution) operator is used to qualify hidden names so that they can still be used.

Multiple objects can contained within the same namespace.  The module primitive allows you to refer to static functions defined in another macro file explicitly, using the “::” naming modifier, and also allows static macro functions to be accessed in callbacks.  Upon a module being associated, it is possible to refer use the syntax “<module-name>::<function>” to refer to a function in callbacks.

Example

void
main()
{
module("my_module");
assign_to_key("<Alt-D>", "my_module::doit");

// which to has the identical behaviour as
assign_to_key("<Alt-D>", "::doit");

// and
assign_to_key("<Alt-D>", inq_module() + "::doit");
}

static void
doit()
{
:
:
}

Returns

The module primitive returns 0 on success, otherwise 1 if module already existed or -1 if called outside the context of any macro file.

Portability

A GriefEdit extension.

See Also

inq_module, <scope>, static, assign_to_key

nothing

void nothing()

Noop.

Description

The nothing() primitive is a no operation, noop for short, This primitive it acts as a place holder when a dummy function is required, effectively does nothing at all.

Parameters

none

Returns

nothing

Portability

n/a

See Also

error

register_macro

int register_macro(int type,
 string macro,
 [int local = FALSE])

Register a callback procedure.

Description

The registered_macro() primitive registers a function to be invoked upon the trigger of the event type type.  Multiple macros may be associated against any particular event type, in which case upon execution they are called in FIFO order.

The argument macro is the name of a macro to be invoked upon the event being triggered.  If local is specified and is non-zero, then the macro is only registered against the current buffer, otherwise the event may be triggered even when the current buffer is not selected.

Registered macros may be invoked using call_registered_macro and removed by using the unregister_macro primitive.

Constant
Description
REG_TYPED
Character typed.
REG_EDIT
Different file edited.
REG_ALT_H
ALT-H pressed in response to a prompt.
REG_UNASSIGNED
Unassigned key pressed.
REG_IDLE
Idle time expired.
REG_EXIT
About to exit.
REG_NEW
New file edited and readin.
REG_CTRLC
CTRL-C (SIGINT) pressed during macro.
REG_INVALID
Invalid key pressed during response input.
REG_INTERNAL
Internal error.
REG_MOUSE
Mouse callback.
REG_PROC_INPUT
Process input available.
REG_KEYBOARD
Keyboard buffer empty.
REG_STARTUP
Startup complete.
REG_BOOKMARK
Bookmark dropped/deleted.
REG_INSERT_MODE
Insert mode has changed.
REG_BUFFER_MOD
Buffer has been modified.
REG_BUFFER_WRITE
Buffer write operation.
REG_BUFFER_RENAME
Buffer rename operation.
REG_BUFFER_DELETE
buffer delete operation.
REG_FILE_SAVE
File write request.
REG_FILE_WRITTEN
File write completion.
REG_FILE_CHANGE
File external change.
REG_SIGUSR1
SIGUSR1 signal trap.
REG_SIGUSR2
SIGUSR2 signal trap.

Parameters

typeEvent type against which to register.
nameName of the macro to be registered.
localOptional int, Whether the trigger is of local or global scope.  Note currently local is only effective on REG_TYPED.

Returns

The registered_macro() primitive returns 1 if the macro was successfully registered, 0 if already registered, otherwise -1 on error.

Portability

The set of available events differ between systems.

See Also

reload_buffer

int reload_buffer([int bufnum],
[string encoding])

Reload the buffer content.

Description

The reload_buffer() primitive is reserved for future use.

Parameters

bufnumOptional buffer number, if omitted the current buffer shall be referenced.
encodingOptional string containing the character encoding to be applied to the source file.

Returns

n/a

Portability

n/a

See Also

edit_file

replacement

replacement <macro-definition>

Overload an existing macro definition.

Description

The replacement macro modifier is used to explicity declare overloaded interfaces, which is a macro that supersedes (or complements) either another macro or directly executable function of the same name.

Replacement macros are used to intercept calls to other macros or functions and are usually to enhance existing the functionality of thoses commands without rewriting them completely.

For example the following macro replaces edit_file;

edit_file()
{
edit_file();
beep();
}

Any reference to edit_file() in the replacement macro refers to the function which is replaces; hence in this example edit_file(), then calls the orginal edit_file() and then beeps() on its return.

During a compile when a macro which overloads an built-in macro is encountered, the compiler shall generate a warning message.  To suppress the warning the keyword replacement should be stated prior to the function name, as follows:

replacement
edit_file()
{
edit_file();
beep();
}

Note that the only behaviour effected by the replacement keyword is the warning suppression and defining a function the same as built-in shall always result in an implicit function overloading.  As such the two examples are functionality equivalent.

Returns

n/a

Portability

n/a

See Also

macro, static, extern, global

require

int require(string filename)

Enforce the use of an external module.

Description

The require() primitive enforces that the specified macro object filename be loaded if it has not already been loaded.

This primitive is similar to using load_macro with a reload option of zero, but is provided as a more convenient and explicit form.

The best practice of this primitive, use require within the main function of any given macro object.

void main(void)
{
require("utils"); // our external dependency
}

Note:

autoload and require usage should generally be exclusive for any given macro object.

Within CRiSPEdit™ documentation it is stated that the results are undefined due to the tables maintained for each are separate which can result in the macro being mistakenly loaded more then once.  As such the side-effect of the reload shall be any global state the macro was maintained shall be lost.

Under GRIEF their usage may be mixed yet for compatibility this style of usage should be avoided.

Returns

Returns 0 if already loaded; 1 if the macro as loaded.  Otherwise -1 if the macro file could not be loaded.

Portability

n/a

See Also

load_macro, autoload

reregister_macro

int reregister_macro(int type,
 string macro,
 [int local = FALSE])

Register a unique callback procedure.

Description

The reregistered_macro() primitive registers a unique function to be invoked upon the trigger of the event type type.  Similar to register_macro yet only permits a single instance of the given function tp be registered.

This primitive allows macros to unconditionally register handlers without need to know whether a previous instance has been installed, unlike register_macro which shall permit multiple instances to exist.

See register_macro for the particulars on the different registered event types.

Parameters

typeEvent type against which to register.
nameName of the macro to be registered.
localOptional int, Whether the trigger is of local or global scope.  Note currently local is only effective on REG_TYPED.

Returns

The reregistered_macro() primitive returns 1 if the macro was uniquely registered, 0 if already registered, otherwise -1 on error.

Portability

The set of available events differ between systems.

See Also

register_macro

restore_position

int restore_position([int what = 1])

Restore a previously saved position.

Description

The restore_position() primitive restores a previously saved position from the position stack.  The argument what is an optional integer expression which controls the state that is restored.

When states what, specifies the information which is restored.  If omitted what is equivalent to one;

0Nothing, with the save information being discarded.
1The cursor position is restored.
2The buffer is restored, with the cursor located in the current window at its previous position.
3Reserved.
4The previous buffer and window are restored, with the cursor located at its previous position.

Parameters

whatOptional integer states the what elements of the position state to be restored.

Returns

The restore_position() primitive returns 1 on success, otherwise zero or less on error.

Portability

n/a

See Also

save_position

return

return [<expression>];

Return from a macro.

Description

The return() primitive terminate the current macro and returns the given value expression.  If specified expression may be an integer, string or list expression which matches the return type of the associated macro.

If return or returns is not called, the return value for a macro is indeterminate.

Parameters

expressionOptional value to be returned, which should match the return type of the associated macro.

Returns

nothing

See Also

returns, exit, *

returns

returns (expression);

Return an expression from a macro.

Description

The returns() primitive sets the return value of the current macro to expression, which may be an integer, string or list expression which matches the return type of the associated macro.

This primitive is similar to the return statement, except it does not cause the current macro to terminate.  It simply sets GRIEF’s internal accumulator with the value of the expression; as such any following may overwrite the value.

Note:

If return or returns is not called, the return value for a macro is indeterminate.

Note:

This primitive is not strictly compatible with the returns macro of BRIEF and is not generally recommended as statements following may have side effects.

Parameters

expressionValue to be returned, which should match the return type of the associated macro.

Returns

nothing

See Also

Jump Statements, return, exit

save_position

void save_position()

Saves current cursor/buffer state.

Description

The save_position() primitive pushes the current buffer, window and cursor position into the position stack, allowing them to be restored later using restore_position.

As these states are maintained by a stack in LIFO (Last In First Out) order each invocation of save_position should have a corresponding invocation of restore_position, otherwise saved positions shall accumulate consuming system resources.

Note:

That the position stack is an independent of any buffer permitting restore_position to be called to pop off the top entry of the stack even when the current buffer is not the same as buffer referenced by the top of the saved position stack.

Parameters

none

Returns

nothing

Portability

n/a

See Also

restore_position

set_btn2_action

int set_btn2_action([int action])

Set the second button action.

Description

The set_btn2_action() primitive is reserved for future BRIEF compatibility.

The set_btn2_action() primitive sets or toggles the default action for the second mouse button.  If action is zero, the Quick-Edit action will be the default.  If action is non-zero, the Quick-Menu action will be the default.  If action is omitted, the current setting shall be toggled.

Parameters

actionOptional integer, the new Quick-Menu button action.

Returns

Returns the previous action button status.

Portability

n/a

set_calling_name

void set_calling_name(string name =  NULL)

Set the name of the calling macro.

Description

The set_calling_name() primitive sets the calling name of the current macro, which is the name that would be returned by inq_name() within any macros called.  If omitted then the name is cleared and returned to the original name.

set_calling_name is used to modify the value returned in-turn controlling the behaviour of the macros which are then invoked.

Another common use is within replacement macros, to forward the original callers name onto the next macro.

set_calling_name(inq_called());

Returns

Nothing

See Also

inq_called, replacement

set_macro_history

string set_macro_history(  [int index = 0],
[string value])

Set the macro execution history.

Description

The set_macro_history() primitive replaces an entry within the macro execution history.

index specifies the history index starting at an offset of zero.  value is new replace name.

Note:

GRIEF maintains the history to the depth of 16.

Parameters

indexOptional int index.

Returns

The set_macro_history() primitive returns the previous value name of entry replaced, otherwise an empty string if the item does not exist.

Portability

A GriefEdit extension, matching similar CRiSPEdit functionality of the same name.

See Also

inq_macro_history

set_property

int set_property(  int obj_id,
string key,
 [declare value])

Set a dictionary item.

Description

The set_property() primitive sets the value of an item within the specified dictionary obj_id.

This primitive is generally not required within the GRIEF Macro Language.  When the user accesses an object member, the compiler converts the construct into calls to this macro.

The following are equivalent;

        set_property(object, "member", value);
and:
object.member = value;

Parameters

obj_idDictionary identifier.
keyItem key.
valueItem value.

Returns

The set_property() primitive returns TRUE on success otherwise FALSE.

Portability

A GriefEdit extension.

See Also

create_dictionary, get_property, dict_exists, dict_each

switch

switch(expr) statement

Switch statement.

Description

The switch and case statements help control complex conditional and branching operations.  The switch statement transfers control to a statement within its body.  The body of a switch statement may have an arbitrary number of unique case labels, for example.

switch (value) {
case 1:
w = "one";
break;
case 2:
w = "two";
break;
default:
w = "others";
break;
}

If condition evaluates to the value that is equal to the value of one of case expressions, then control is transferred to the statement that is labelled with that expression.

If condition evaluates to the value that does not match any of the case labels, and the default label is present, control is transferred to the statement labelled as the default label.

The break statement, when encountered in statement exits the switch statement.

Parameters

exprSwitch value, which can be an integer, float or string expression.

Returns

nothing

Portability

n/a

See Also

Selection Statements, case, break

throw

throw expr;

Throw an exception.

Description

The throw statement is reserved for future use.

Exceptions are used to indicate that an error has occurred while running the program.  Exception objects that describe an error are created and then thrown with the throw primitive.  The runtime then searches for the most compatible exception handler.

Parameters

exprException value.

Returns

nothing

Portability

A GriefEdit extension.

See Also

try, catch, finally

try

try statement; catch statement; finally statement;

Try statement.

Description

The try statement is reserved for future use, which shall implement try, catch and finally exception constructs.

Exceptions are used to indicate that an error has occurred while running the program.  Exception objects that describe an error are created and then thrown with the throw primitive.  The runtime then searches for the most compatible exception handler.

try {
statement;

} catch type {
statement;

} finally {
statement;

}

Parameters

none

Returns

nothing

Portability

A GriefEdit extension.

See Also

catch, finally, throw

unregister_macro

int unregister_macro(int type,
 string macro,
 [int local = FALSE])

Remove a registered macro.

Description

The unregistered_macro() primitive removes a previously registered macro.

If a particular macro has been registered multiple times than for each successful registration a corresponding unregister must occur to remove all instances; unregister_macro may be called in a loop until all instances are removed.

Parameters

typeEvent type against which to unregister.
nameName of the macro to be unregistered.
localOptional int, Whether the trigger is of local or global scope.  Note currently local is only effective on REG_TYPED.

Returns

The unregistered_macro() primitive returns 1 if macro was registered and has now been unregistered, otherwise 0.

Portability

The set of available events differ between systems.

See Also

register_macro

while

while ([condition]) statements;

while statement.

Description

The while statement implements the while loop construct.

while (condition)
{
statements;
}

Repeatedly performs statements while the condition is true (non-zero).  In each iteration of the loop, it first tests the condition, and if it is true it executes statement.  This cycle is continued until condition is false (zero).

Portability

n/a

See Also

Iteration Statements, break, continue, for, do

$Id: $

To send feedback on this topic email: grie.nosp@m.fedit@gmai.nosp@m.l.com

Copyright © Adam Young All Rights Reserved.

extern const string BPACKAGES;
BRIEF packages default.
extern const string CRISP_OPSYS;
Operating system identifier.
extern const string GRBACKUP;
Backup path.
extern const string GRDICTIONARIES;
Dictionary locales.
extern const string GRDICTIONARY;
Dictionary search path.
extern const string GRFILE;
Default empty file name.
extern const string GRFLAGS;
Default command line arguments.
extern const string GRHELP;
Help search path.
extern const string GRINIT_FILE;
GRIEF initialisation name.
extern const string GRKBDPATH;
Keyboard library search path.
extern const int GRLEVEL;
GRIEF Nesting level.
extern const string GRLOG_FILE;
GRIEF diagnostics log file name.
extern const string GRPATH;
Macro object search path.
extern const string GRPROFILE;
Profile directory override.
extern const string GRPROGNAME;
GRIEF application path.
extern const string GRRC;
GRIEF resource file path.
extern const string GRRC_FILE;
GRIEF initialisation name.
extern const string GRRESTORE_FILE;
GRIEF restore file name.
extern const string GRSTATE_DB;
GRIEF state database name.
extern const string GRSTATE_FILE;
GRIEF state file name.
extern const string GRTEMPLATE;
Source template search path.
extern const string GRTERM;
Terminal override.
extern const string GRTERMCAP;
Terminal capability database.
extern const string GRTMP;
Temporary dictionary.
extern const int GRVERSIONMAJOR;
GRIEF major version.
extern const int GRVERSIONMINOR;
GRIEF minor version.
extern const int GRVERSIONS;
Backup versions.
extern int errno;
Last system errno number.
__breaksw;
Switch break statement.
void autoload(string filename,
string function,
 ...)
Register location of one or more macros.
int bless([int ref],
[string classname])
Associate an object with a class/module.
break;
break statement.
int call_registered_macro(int type)
Invoke registered macro callbacks.
'case' expr:
Switch case statement.
catch statement;
Catch statement.
continue;
Loop continuation.
int create_dictionary(string ~name,
 int ~tablesize,
int ~tablefactor)
Create a dictionary.
int delete_dictionary(int obj_id)
Destroy a dictionary.
void delete_macro(string macro)
Delete a macro from memory.
int dict_clear(int obj_id)
Clear a dictionary.
int dict_delete(int obj_id,
string key)
Remove a dictionary item.
int dict_each(int obj_id,
  [string key],
 [declare value])
Iterator a dictionary.
int dict_exists(  int obj_id,
string key)
Dictionary item existence check.
int dict_keys(int obj_id,
  [string key])
Iterator dictionary keys.
list dict_list(int obj_id,
 [int keys = TRUE])
Retrieve dictionary items.
string dict_name(int obj_id)
Retrieve a dictionary name.
int dict_values(int obj_id,
  [declare value])
Iterator dictionary values.
do statement; while (condition);
do statement.
if (expr) true-body else false-body
else statement.
declare execute_macro([string cmd],
...)
Invokes a command by name.
void exit([string y_or_w])
Exit current process level.
finally statement;
Finally statement.
int first_time()
Determine a macros initialisation status.
for ([initialise];
[condition];
[increment]) statements;
for statement.
void foreach(<body>,
<expr>,
<key>,
<value>,
<index>,
<increment>)
Container iterator.
int fstype([string path])
File system type.
declare get_property(int obj_id,
string key)
Retrieve a dictionary item.
if (expr) true-body
if statement.
int inq_btn2_action()
Retrieve the second button action.
string inq_called()
Get the name of the calling macro.
int inq_macro(string name,
 [int mode = 0])
Determine whether a macro or primitive exists.
string inq_macro_history([int index = 0])
Retrieve macro execution history.
string inq_module([int test = 1])
Retrieve the current module.
int inq_msg_level()
Get the message level.
list list_of_dictionaries(  [bool nonempty = false],
[bool named = false])
List of created dictionaries.
int load_macro(string filename,
 [int reload = 1])
Load a macro object.
declare macro(list declaration)
Define a macro body.
int module(string modulename)
Assign a module identifier.
void nothing()
Noop.
int register_macro(int type,
 string macro,
 [int local = FALSE])
Register a callback procedure.
int reload_buffer([int bufnum],
[string encoding])
Reload the buffer content.
replacement <macro-definition>
Overload an existing macro definition.
int require(string filename)
Enforce the use of an external module.
int reregister_macro(int type,
 string macro,
 [int local = FALSE])
Register a unique callback procedure.
int restore_position([int what = 1])
Restore a previously saved position.
return [<expression>];
Return from a macro.
returns (expression);
Return an expression from a macro.
void save_position()
Saves current cursor/buffer state.
int set_btn2_action([int action])
Set the second button action.
void set_calling_name(string name =  NULL)
Set the name of the calling macro.
string set_macro_history(  [int index = 0],
[string value])
Set the macro execution history.
int set_property(  int obj_id,
string key,
 [declare value])
Set a dictionary item.
switch(expr) statement
Switch statement.
throw expr;
Throw an exception.
try statement; catch statement; finally statement;
Try statement.
int unregister_macro(int type,
 string macro,
 [int local = FALSE])
Remove a registered macro.
while ([condition]) statements;
while statement.
int set_backup_option(int what,
 [int bufnum],
 parameter)
Set backup options.
string int_to_key(int key)
Convert an keycode to mnemonic key string.
int inq_brief_level()
Retrieve the editor nesting level.
int set_term_feature(  int|string ident,
 [string|int value])
Set a terminal attribute.
int set_term_keyboard(list kbd)
Define terminal keyboard definitions.
string perror( [int errnum = errno],
string format,
 ...)
Print error.
string strerror([int errnum = errno],
 [string &manifest],
[int multi = FALSE])
String error.
A jump statement causes execution to continue at a specific place in a program, without executing any other intervening statements.
A selection statement evaluates an expression, called the controlling expression, then based on the result selects from a set of statements are then executed.
Iteration statements control looping.
void abort()
Abnormal process.
void process()
Invoke a Grief engine.
static var1, var2, ..;
Define a function or module scope.
int list_each(list lst,
 declare &value,
 [int increment = 1])
Iterator though the list elements.
int stat([string path],
[int size],
 [int mtime],
[int ctime],
 [int atime],
[int mode],
[int uid],
[string uid2name],
 [int gid],
[string gid2name],
 [int nlink],
[int inode])
Obtain file information.
int get_parm( [int argument],
declare &symbol,
  [string prompt],
 [int length = MAXPROMPT],
  [declare default],
 [int one = FALSE])
Retrieve the value of a macro parameter.
int message(string format,
 ...)
Display a message on the command line.
string inq_command()
Retrieve name of last keyboard command.
int set_msg_level(int level)
Set level of informational messages.
void main()
Macro entry point.
void _init()
Internal macro initialisation.
Variables and functions can be used only in certain regions of a program.
int assign_to_key([string key],
[string macro])
Assign command to key or key sequence.
int error(string format,
 ...)
Issue an error message on the command line.
int edit_file(...)
Edit a file.
extern <type> sym1, sym2, ..;
Declare an external variable.
global sym1, sym2, ..;
Declare a global variable.