File:  [Coherent Logic Development] / freem / doc / freem.texi
Revision 1.51: download - view: text, annotated - select for diffs
Mon May 5 14:26:59 2025 UTC (4 months, 3 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Add documentation TODO file

    1: \input texinfo
    2: @paragraphindent 0
    3: @setfilename freem.info
    4: @settitle The FreeM Manual
    5: 
    6: @copying
    7: This manual is for FreeM, (version 0.64.0-rc1), which is a free software implementation of the M programming language.
    8: 
    9: Print-optimized versions of this book are typeset in @emph{Computer Modern} by the author using the @emph{GNU Texinfo} tools.
   10: 
   11: Copyright @copyright{} 2014-2025 Coherent Logic Development LLC
   12: 
   13: @quotation
   14: Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover texts, and with no Back-Cover Texts.
   15: @end quotation
   16: @end copying
   17: 
   18: @titlepage
   19: 
   20: @title The FreeM Manual
   21: @subtitle @sc{The Official Manual of FreeM}
   22: @subtitle Version 0.64.0-rc1
   23: @c@vskip 10pt
   24: @c@center @image{freem-logo-sm,,,,.png}
   25: @author Serena Willis
   26: @page
   27: @vskip 0pt plus 1filll
   28: @insertcopying
   29: @end titlepage
   30: @contents
   31: 
   32: @ifnottex
   33: @node Top
   34: @top The FreeM Manual
   35: 
   36: This is the official manual for the FreeM programming language.
   37: @end ifnottex
   38: 
   39: @dircategory The FreeM Manual
   40: @direntry
   41: * FreeM: (freem).                       The FreeM M programming language.
   42: @end direntry
   43: 
   44: @menu
   45: * Introduction::                        About the FreeM Project, its history, and its goals.
   46: * Document Conventions::                Conventions used in this manual.
   47: * A Note on Standards::                 FreeM positioning regarding the M Development Committee.
   48: * FreeM Invocation::                    How to invoke FreeM from the command line.
   49: * The FreeM Environment Daemon::        Managing shared resources in the FreeM environment.
   50: * The FreeM Direct-Mode Environment::   Executing M programs interactively.
   51: * Debugging::                           The program development cycle of FreeM.
   52: 
   53: * Directives::                          Per-Routine Language Directives.
   54: * Intrinsic Special Variables::         Intrinsic Special Variables.
   55: * Intrinsic Functions::                 Intrinsic Functions.
   56: * OBJECT Methods::                      Methods for OBJECT variables.
   57: * STRING Methods::                      Methods for STRING variables.
   58: * Commands::                            Commands.
   59: * Structured System Variables::         Structured System Variables.
   60: * Operators::                           FreeM Operators.
   61: 
   62: * Routines::                            The units of M code in FreeM.
   63: * Types::                               FreeM data types.
   64: * Globals::                             FreeM persistent sparse arrays.
   65: * Concurrency Control::                 @code{LOCK}ing and transaction processing.
   66: * Local Variables::                     In-memory variables.
   67: * Scoping::                             Scoping in FreeM.
   68: * Decision Constructs::                 @code{IF}, @code{THEN}, @code{ELSE}, @code{$SELECT}, and postconditionals.
   69: * Branch Constructs::                   Labels, @code{GOTO}, @code{DO}, and @code{JOB}.
   70: * Loop Constructs::                     The @code{FOR} loop.
   71: * Modular Programming::                 Extrinsic functions and subroutines.
   72: * Object-Oriented Programming::         Classes and objects in FreeM.
   73: * Libraries::                           System and user libraries.
   74: * Sequential I/O::                      Processing sequential files in FreeM.
   75: * Network I/O::                         Handling network sockets in FreeM.
   76: * Extended Global References::          Accessing globals in non-default namespaces.
   77: * Global Aliasing::                     Defining alternate names for globals.
   78: * Global Mappings::                     Mapping global names to non-default namespaces.
   79: 
   80: * Asynchronous Event Handling::         Handling asynchronous events in FreeM.
   81: * Global Triggers::                     Responding to global accesses in M code.
   82: * Synchronous Event Handling::          Synchronous events in FreeM.
   83: 
   84: 
   85: * GUI Programming with MWAPI::          Creating graphical interfaces in FreeM.
   86: 
   87: * User-Defined Z Commands::             Adding your own Z commands to FreeM.
   88: * User-Defined Z Functions::            Adding your own Z functions to FreeM.
   89: * User-Defined SSVNs::                  Adding your own SSVNs to FreeM.
   90: 
   91: * Language Dialects::                   Controlling FreeM standards compliance.
   92: 
   93: * System Library Routines::             FreeM built-in library of M routines.
   94: 
   95: * Interrupt Handling::                  How FreeM handles interrupts.
   96: * Error Processing::                    How to handle errors in M program code.
   97: * FreeM Error Codes::                   Explanations of each FreeM error code.
   98: 
   99: * System Configuration::                Configuring your FreeM installation.
  100: * Accessing FreeM from C Programs::     How to use the mlib interface.
  101: 
  102: * FreeM Administrator::                 The fmadm system manager tool.
  103: * FreeM Legacy Utilities::              FreeM legacy system manager utilities.
  104: * FreeM VIEW Commands and Functions::   Getting and setting info about FreeM internals.
  105: * Implementation Limits::               FreeM limitations.
  106: * US-ASCII Character Set::              The US-ASCII character set.
  107: * FreeM Project Coding Standards::      How to write code for submission to the FreeM project.
  108: 
  109: * Index::               Complete index.
  110: @end menu
  111: 
  112: @node Introduction
  113: @unnumbered Introduction
  114: 
  115: FreeM started its life as @emph{FreeMUMPS}, written for MS-DOS and ported to SCO UNIX by a mysterious individual going by the name of "Shalom ha-Ashkenaz". It was released to MUG Deutschland in 1998. In 1999, Ronald L. Fox ported FreeM to the Red Hat Linux 5 distribution of the GNU/Linux operating system. Thereafter, maintenance was taken over by the Generic Universal M Project, which changed its name first to Public Standard MUMPS and then by popular request to FreeM.
  116: 
  117: When GT.M was open-sourced in late 1999, FreeM and GUMP were essentially abandoned. L.D. Landis, the owner of the original GUMP SourceForge project, and one of FreeM's significant contributors, passed maintenance of FreeM and ownership of its SourceForge project to Serena Willis in 2014. At this point, FreeM would not compile or run on modern Linux systems, so steps were taken to remedy the most pressing issues in the codebase. Limitations on the terminal size (previously hard-coded to 80x25) were lifted, and new @code{$VIEW} functions were added to retrieve the terminal size information. @code{$X} and @code{$Y} intrinsic special variables were updated to support arbitrary terminal sizes, and FreeM was once again able to build and run.
  118: 
  119: In February of 2020, work began in earnest to build a development and support infrastructure for FreeM and begin the careful process of refining it into a more stable and robust application.
  120: 
  121: For more information on FreeM history, see @code{@emph{$PREFIX}/share/freem/doc/freem_history.*} (distributed in PostScript, PDF, and plain text formats).
  122: 
  123: @section Production Readiness
  124: 
  125: FreeM is not yet production-ready. There are several show-stopping bugs that preclude a general release for public use:
  126: 
  127: @itemize @bullet
  128: 
  129: @item
  130: @code{@ref{VIEW}} commands and @code{@ref{$VIEW()}} functions are used extensively to configure and inspect the run-time behavior of FreeM, rather than the "canonical" SSVN-based approach.
  131: 
  132: @item
  133: Server sockets are not yet implemented.
  134: 
  135: @item
  136: There are some situations that can result in segmentation faults and/or lock-ups.
  137: 
  138: @item
  139: In spite of our best efforts, this manual is not yet complete.
  140: 
  141: @end itemize
  142: 
  143: @section Contributors
  144: Current contributors denoted with a @emph{+} following their name and role.
  145: @cindex contributors, ha-Ashkenaz, Shalom
  146: @cindex contributors, Best, John
  147: @cindex contributors, Diamond, Jon
  148: @cindex contributors, Fox, Ronald L.
  149: @cindex contributors, Gerum, Winfried
  150: @cindex contributors, Kreis, Greg
  151: @cindex contributors, Landis, Larry
  152: @cindex contributors, Milligan, Lloyd
  153: @cindex contributors, Morris, Steve
  154: @cindex contributors, Murray, John
  155: @cindex contributors, Pastoors, Wilhelm
  156: @cindex contributors, Schell, Kate
  157: @cindex contributors, Schofield, Lyle
  158: @cindex contributors, Stefanik, Jim
  159: @cindex contributors, Trocha, Axel
  160: @cindex contributors, Walters, Dick
  161: @cindex contributors, Whitten, David
  162: @cindex contributors, Wicksell, David
  163: @cindex contributors, Willis, Serena
  164: @cindex contributors, Zeck, Steve
  165: 
  166: @itemize @bullet
  167: 
  168: @item
  169: Shalom ha-Ashkenaz (Original Implementer)
  170: 
  171: @item
  172: John Best (IBM i and OS/400)
  173: 
  174: @item
  175: Jon Diamond (Library, Utilities, Conformance)
  176: 
  177: @item
  178: Ronald L. Fox (Initial port to Red Hat 5/libc-6)
  179: 
  180: @item
  181: Winfried Gerum (Code, Advice, MTA coordination)
  182: 
  183: @item
  184: Greg Kreis (Hardhats coordination, Dependencies)
  185: 
  186: @item
  187: Larry Landis (Coordination, Code, Documentation)
  188: 
  189: @item
  190: Rick Marshall (Testing, MDC Conformance) @emph{+}
  191: 
  192: @item
  193: Lloyd Milligan (Code, Testing, Documentation)
  194: 
  195: @item
  196: Steve Morris (Code, Microsoft)
  197: 
  198: @item
  199: John Murray (Code, Conformance)
  200: 
  201: @item
  202: Wilhelm Pastoors (Testing, Documentation)
  203: 
  204: @item
  205: Kate Schell (Coordination, Conformance, MTA, MDC, Advice)
  206: 
  207: @item
  208: Lyle Schofield (Advice, Prioritization, Tracking, Project Management)
  209: 
  210: @item
  211: Jim Stefanik (GNU/Linux on s390x, IBM AIX, IBM z/OS)
  212: 
  213: @item
  214: Axel Trocha (Code, Utilities)
  215: 
  216: @item
  217: Dick Walters (Project Lead, Chief Coordinator, MTA)
  218: 
  219: @item
  220: David Whitten (QA Test Suite, MDC, Advice) @emph{+}
  221: 
  222: @item
  223: David Wicksell (Debugging, Code, Testing) @emph{+}
  224: 
  225: @item
  226: Serena Willis (Current Maintainer and Project Lead) @emph{+}
  227: 
  228: @item
  229: Steve Zeck (Code)
  230: 
  231: @end itemize
  232: 
  233: @node Document Conventions
  234: @chapter Document Conventions
  235: @cindex document conventions
  236: @cindex conventions
  237: 
  238: @section Formatting Conventions
  239: 
  240: This manual uses the following formatting conventions:
  241: @itemize
  242: @item Code examples, filesystem paths, and commands are presented in @code{monospace}
  243: @item Placeholders where the reader is expected to supply a replacement value are presented in @code{@emph{monospace italics}}, and depending on context, may be surrounded by angle brackets
  244: @item New terminology is introduced in @emph{proportional italics}
  245: @end itemize
  246: 
  247: @section Definitions
  248: 
  249: FreeM uses abbreviations for common language elements:
  250: 
  251: @table @asis
  252: @item @emph{$PREFIX}
  253: Refers to the base filesystem location within which FreeM is installed. For most distribution methods of FreeM, @emph{$PREFIX} represents either @code{/} or @code{/usr/local}.
  254: @item @emph{dlabel}
  255: Refers to a label in an M routine, beginning in the first column of the line. Can be a @emph{name} or an @emph{intlit}.
  256: @item @emph{entryref}
  257: Refers to an M routine entry point, denoted in the format @code{@emph{dlabel} [+@emph{intexpr}][^@emph{routine}]}.
  258: @item @emph{expr}
  259: Refers to any expression. Often presented in the format @emph{expr V <type>}, where @emph{V} means @emph{giving}; e.g., @emph{expr V lvn} means @emph{expression giving local variable name}.
  260: @item @emph{glvn}
  261: Refers to the name of an M global, local, or structured system variable.
  262: @item @emph{gvn}
  263: Refers to the name of an M global variable.
  264: @item @emph{intexpr}
  265: Refers to an integer expression.
  266: @item @emph{intlit}
  267: Refers to an integer literal.
  268: @item @emph{ISV}, @emph{isv}
  269: Refers to an M intrinsic special variable; @code{$JOB} and @code{$IO} are examples of ISVs.
  270: @item @emph{L}
  271: Indicates a @emph{list} of the following item, e.g., @emph{L gvn} means @emph{list of global variable names}.
  272: @item @emph{lvn}
  273: Refers to the name of an M local variable.
  274: @item @emph{postcondition}
  275: A @emph{tvexpr} immediately following a command verb affecting that command's execution.
  276: @item @emph{strlit}
  277: Refers to an M string literal.
  278: @item @emph{ssvn}
  279: Refers to the name of an M structured system variable.
  280: @item @emph{tvexpr}
  281: Refers to a truth-valued expression, i.e., an expression interpreted as a truth value.
  282: @end table
  283: 
  284: @node A Note on Standards
  285: @chapter A Note on Standards
  286: @cindex MDC
  287: @cindex M Development Committee
  288: @cindex ANSI X11.1
  289: @cindex standards, ANSI
  290: @cindex standards, MDC
  291: 
  292: FreeM attempts to implement as many features as possible from the M Development Committee's unpublished @emph{Millennium Draft Standard}, as well as its predecessors.
  293: 
  294: The maintainer of FreeM (who is also the author of this book) is largely in favor of standardization efforts, and hopes that the MDC will resume activities, and will happily participate if it does so in an open, public, transparent, and democratic manner. Until then, however, FreeM will attempt to improve the M language, in cooperation with other free software M implementers where possible. Any breaking changes introduced in future MDC releases of the @emph{Standard} (such as the rumored @emph{M5}) which prove incompatible with FreeM will be handled via the @code{$DIALECT} special variable (to be changed to @code{$ZDIALECT} in a coming release).
  295: 
  296: The conformance document required per the @emph{Standard} should be installed as a @code{man} page on any computer system where FreeM is made available. Simply type @code{man freem_conformance} to access.
  297: 
  298: @node FreeM Invocation
  299: @chapter FreeM Invocation
  300: @cindex invocation, command-line
  301: @cindex options, command-line
  302: 
  303: @section Synopsis
  304: @example
  305: $ @command{./freem} [@emph{OPTIONS}...] [[-r <entryref>] | [--routine=<entryref>]]
  306: @end example
  307: 
  308: When FreeM loads, it searches the @code{SYSTEM} namespace for the @code{%SYSINIT} routine, and begins executing it.
  309: 
  310: When @code{-r} or @code{--routine} are passed on the command line, FreeM will load and run the specified routine after running @code{%SYSINIT}. Beginning with FreeM 0.1.7, routines invoked in this manner are no longer required to perform their own namespace setup with @code{VIEW} commands.
  311: 
  312: @section %SYSINIT Routine
  313: 
  314: The @code{%SYSINIT} routine runs every time a FreeM interpreter process starts. This routine defines some useful constants, enables handling of @code{TRIGGER} events, and handles the execution of code passed via the @code{-x|--execute} or routines passed via @code{-r|--routine}.
  315: 
  316: Do not modify the supplied @code{%SYSINIT} routine to add site-specific startup items. Instead, create a @code{LCLINIT} routine in the @code{USER} namespace of one or more environments. @code{%SYSINIT} will automatically run @code{LCLINIT} each time it starts.
  317: 
  318: @section Command-Line Options
  319: @cindex options, command-line
  320: 
  321: @table @asis
  322: 
  323: @item @option{-d}, @option{--daemon}
  324: Starts the FreeM environment daemon, exactly one of which must be running at all times in order for FreeM interpreter and fmadm processes to function.
  325: 
  326: @item @option{-e}, @option{--environment}
  327: Selects the environment to be used. If no environment is specified, @code{DEFAULT} is used.
  328: 
  329: @item @option{-k}, @option{--nofork}
  330: When used with @option{-d} or @option{--daemon}, causes the FreeM environment daemon to run instead in the foreground. Useful for debugging.
  331: 
  332: @item @option{-S}, @option{--shmsize}
  333: When used with @option{-d} or @option{--daemon}, specifies the number of bytes of shared memory FreeM will allocate for the @code{LOCK} table, job table, and IPC table. This will determine the maximum number of concurrent FreeM processes and @code{LOCK}s available in this environment. 
  334: 
  335: @item @option{-c}, @option{--config}
  336: Specify a configuration file other than @code{$PREFIX/etc/freem.conf}.
  337: 
  338: @item @option{-h}, @option{--help}
  339: Display a help message showing valid FreeM options.
  340: 
  341: @item @option{-i}, @option{--import}
  342: Causes your UNIX environment variables to be imported into FreeM's local symbol table.
  343: 
  344: @item @option{-f}, @option{--filter}
  345: Allows your M routines to be used as UNIX filters.
  346: 
  347: @item @option{-n @emph{<namespace-name>}}, @option{--namespace=@emph{<namespace-name>}}
  348: Selects the FreeM namespace to be entered on startup. Must be defined in @file{/etc/<environment>/freem.conf}.
  349: 
  350: @item @option{-r @emph{<entryref>}}, @option{--routine=@emph{<entryref>}}
  351: Causes @code{<entryref>} to be executed at load, instead of @code{%SYSINIT}.
  352: 
  353: @item @option{--standard=@emph{<standard>}}
  354: Sets the default FreeM dialect to use for new routine buffers.
  355: 
  356: Valid values for @code{@emph{<standard>}} are as follows:
  357: 
  358: @table @code
  359: @item @code{M77}
  360: Restricts FreeM to use only features specified by the 1977 M standard.
  361: @item @code{M84}
  362: Restricts FreeM to use only features specified by the 1984 M standard.
  363: @item @code{M90}
  364: Restricts FreeM to use only features specified by the 1990 M standard.
  365: @item @code{M95}
  366: Restricts FreeM to use only features specified by the 1995 M standard.
  367: @item @code{MDS}
  368: Restricts FreeM to use only features proposed by the Millennium Draft Standard.
  369: @item @code{M5}
  370: Restricts FreeM to use only features proposed by the upcoming M5 standard.
  371: @item @code{FREEM}, @code{EXTENDED}
  372: Removes all standards-based restrictions and allows full access to all FreeM features. This is the default value of @code{$DIALECT}.
  373: @end table
  374: 
  375: Please note that FreeM is not entirely standards-compliant, regardless of the value of @code{@emph{<standard>}}.
  376: 
  377: @item @option{-v}, @option{--version}
  378: Displays FreeM version information.
  379: 
  380: @item @option{-x @emph{<mcode>}}, @option{--execute=@emph{<mcode>}}
  381: Executes M code @code{<mcode>} at startup.
  382: 
  383: @end table
  384: 
  385: @section Using FreeM for Shell Scripting
  386: @cindex routines, as shell scripts
  387: @cindex shebang line
  388: @cindex shell scripting
  389: 
  390: FreeM M routines can be used as shell scripts by providing a @emph{shebang} line beginning with @code{#!/path/to/freem} as the first line of the routine.
  391: The following example presumes that FreeM is installed at @file{/usr/local/bin/freem} and uses the @code{USER} namespace:
  392: 
  393: @example
  394: #!/usr/local/bin/freem
  395: MYSCRIPT ;
  396:  SET ^$JOB($JOB,"NAMESPACE")="USER"
  397:  WRITE "This is output from an M routine used as a shell script.",!
  398:  Q
  399: @end example
  400: 
  401: Currently, the script needs to have a @file{.m} file extension. You will also need to select an appropriate namespace in your script using the @code{SET ^$JOB($JOB,"NAMESPACE")="@emph{<namespace>}"} command before attempting to call other routines or access globals.
  402: 
  403: You will also need to set the script's permissions to @emph{executable} in order for this to work:
  404: 
  405: @example
  406: $ chmod +x @emph{myscript.m}
  407: @end example
  408: 
  409: @node The FreeM Environment Daemon
  410: @chapter The FreeM Environment Daemon
  411: @cindex daemon, freem
  412: 
  413: The FreeM environment daemon manages shared resources for a given FreeM environment. These include the lock table, job table, inter-process communication, and concurrency control for transaction processing. Unlike some M implementations, the FreeM environment daemon does @emph{not} function as a write daemon for global storage.
  414: 
  415: One daemon process is required per FreeM environment, and can be started in the following ways, in order of preference:
  416: 
  417: @example
  418: $ sudo fmadm start environment [-e=<environment-name>]
  419: @end example
  420: 
  421: @example
  422: $ freem --daemon [--nofork] [--environment=<environment-name>] [--shmsize=<bytes>]
  423: @end example
  424: 
  425: If the daemon is started with @option{--nofork}, it will run in the foreground and its output will be reflected on the terminal. Otherwise, the daemon will run as a child process in the background and immediately return terminal control to the shell. The latter option is recommended in most cases.
  426: 
  427: The @option{--environment} option will start the daemon for the specified @emph{environment-name}. The default environment, if unspecified, is called @code{DEFAULT}. If using an environment other than @code{DEFAULT}, interpreter processes that wish to also connect to the same environment must also use the @option{--environment} option when starting, and @code{libfreem} clients must also pass the environment name as the first argument to the @code{freem_init()} function. Environments allow you to run multiple, isolated instances of FreeM on the same machine, whose globals and routines are distinct and unique.
  428: 
  429: The @option{--shmsize} option specifies the size in bytes of the FreeM shared memory segment. The default is 4194304 bytes. Increasing the size of the FreeM shared memory segment will, at the cost of increased memory usage, increase the number of concurrent jobs and lock table entries available to the environment; decreasing the size of the segment will have the expected opposite effect. Note that you must also pass @option{--shmsize} with the same number of bytes to any interpreter process to be used with an environment whose daemon uses a non-default shared memory segment size.
  430: 
  431: Attempting to start a FreeM interpreter process without a daemon running with the same environment name will result in an error.
  432: 
  433: @node The FreeM Direct-Mode Environment
  434: @chapter The FreeM Direct-Mode Environment
  435: @cindex command line interface
  436: @cindex direct mode
  437: @cindex execution, interactive
  438: @cindex modes, programmer
  439: 
  440: 
  441: The FreeM direct-mode environment is the mode entered when FreeM is invoked without the use of @option{-r @emph{<entryref>}} or @option{--routine=@emph{<entryref>}}:
  442: 
  443: @example
  444: Coherent Logic Development FreeM version 0.64.0-rc1 (x86_64-pc-linux-gnu)
  445: Copyright (C) 2014, 2020, 2021 Coherent Logic Development LLC
  446: 
  447: 
  448: USER>
  449: @end example
  450: 
  451: The prompt (@code{DEFAULT.USER>}) displays the current environment and namespace, @code{DEFAULT} and @code{USER}, respsectively. If any uncommitted direct-mode transactions have been started, the prompt will change to reflect the current value of @code{@ref{$TLEVEL}}:
  452: 
  453: @example
  454: TL1:DEFAULT.USER>
  455: @end example
  456: 
  457: In the above example, @code{TL1} indicates that @code{@ref{$TLEVEL}} is currently @emph{1}.
  458: 
  459: @section Direct-Mode Commands
  460: 
  461: When you are in direct mode, in addition to M commands, a number of internal commands are available to help developers be more productive:
  462: 
  463: @table @asis
  464: 
  465: @item @command{?}
  466: Accesses FreeM online help. Requires GNU @command{info(1)} to be installed on your local system.
  467: 
  468: @item @command{events}
  469: Writes a list of @emph{event classes} and their @code{ABLOCK} counts:
  470: 
  471: @example
  472: DEFAULT.USER> events
  473:  
  474: Event Class          Processing Mode ABLOCK Count
  475: -----------          --------------- ------------
  476: COMM                 Disabled        0
  477: HALT                 Disabled        0
  478: IPC                  Disabled        0
  479: INTERRUPT            Disabled        0
  480: POWER                Disabled        0
  481: TIMER                Disabled        0
  482: USER                 Disabled        0
  483: WAPI                 Disabled        0
  484: TRIGGER              Disabled        0
  485: @end example
  486: 
  487: 
  488: @anchor{trantab}
  489: @item @command{trantab}
  490: Displays information about any uncommitted transactions currently in-flight for this process.
  491: 
  492: @anchor{glstat}
  493: @item @command{trantab}
  494: Displays statistics about globals that have been opened in the current FreeM process.
  495: 
  496: @anchor{jobtab}
  497: @item @command{jobtab}
  498: Displays a summary of the FreeM job table.
  499: 
  500: @anchor{locktab}
  501: @item @command{locktab}
  502: Displays a list of @code{LOCK}s held in the current environment.
  503: 
  504: @anchor{rbuf}
  505: @item @command{rbuf}
  506: Lists the status of all FreeM routine buffers.
  507: 
  508: @anchor{wh}
  509: @item @command{wh}
  510: Forces an immediate flush of this process's @code{readline} history buffer to disk.
  511: 
  512: @anchor{shmstat}
  513: @item @command{shmstat}
  514: Displays the configuration of FreeM shared memory. Intended only for advanced debugging of the FreeM environment.
  515: 
  516: @anchor{shmpages}
  517: @item @command{shmpages}
  518: Lists the status of each FreeM shared memory page. Intended only for advanced debugging of the FreeM environment.
  519: 
  520: @anchor{history}
  521: @item @command{history}
  522: Prints a list of all the direct-mode commands you have entered across all sessions.
  523: 
  524: @anchor{rcl}
  525: @item @command{rcl @emph{<history-index>}}
  526: Allows you to recall command number @emph{<history-index>} and run it again. Obtain the value for @emph{<history-index>} from the output of the @command{history} command.
  527: 
  528: @item @command{!!}
  529: Launches a subshell within the FreeM direct mode, allowing the user to run operating system commands.
  530: 
  531: @example
  532: DEFAULT.USER> !!
  533: 
  534: Type Ctrl-D to exit from the shell
  535: $ uname -a
  536: Linux hesperos 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
  537: $ exit
  538: 
  539: DEFAULT.USER> 
  540: @end example
  541: 
  542: @item @command{!@emph{<external-command>}}
  543: Invokes a shell to run @emph{<external-command>} from within FreeM. This temporarily disables @command{SIGALRM} handling in FreeM, which may interrupt the use of event-driven M programming commands including @command{ASTART} and @command{ASTOP}.
  544: 
  545: If the @command{>} character is supplied immediately preceding @emph{<external-command>}, FreeM will append the contents of an M local or global variable referenced in @code{^$JOB($JOB,"PIPE_GLVN")} to the standard input stream of @emph{<external-command>}.
  546: 
  547: If the @command{<} character is supplied immediately preceding @emph{<external-command>}, FreeM will take the standard output stream of @emph{<external-command>} and store it in M local or global variable referenced by @code{^$JOB($JOB,"PIPE_GLVN")}.
  548: 
  549: The data value in the unsubscripted M local or global contains the number of lines in the input or output. Subscripts @code{(1)..(@emph{n})} contain the data for lines 1-@emph{n}.
  550: 
  551: @end table
  552: 
  553: @cindex HALT, in direct-mode
  554: If you issue a @code{@ref{HALT}} command at the direct-mode prompt, you will exit out of FreeM. However, if you issue a @code{@ref{HALT}} command when @code{@ref{$TLEVEL}} is greater than zero, you will be given the opportunity to commit or rollback any pending transactions:
  555: 
  556: @example
  557: DEFAULT.USER> TSTART
  558:  
  559: 
  560: TL1:DEFAULT.USER> SET ^MYGLOBAL=1
  561:  
  562:  
  563: TL1:DEFAULT.USER> HALT
  564:  
  565: UNCOMMITTED TRANSACTIONS EXIST:
  566:  
  567:  $TLEVEL 1*
  568:   Operations for Transaction ID: k8xj1de
  569:   1:	action = 0  key = ^MYGLOBAL  data = 1
  570:  
  571: Would you like to c)ommit or r)ollback the above transactions and their operations? ($TLEVEL = 1) r
  572: 
  573: 
  574: Transactions have been rolled back.
  575: @end example
  576: 
  577: In the above example, the user selected @code{r} to rollback the single pending transaction.
  578: 
  579: @section REPL Functionality
  580: @cindex REPL, direct-mode
  581: 
  582: FreeM direct mode allows you to enter M expressions directly from the direct-mode prompt, as long as they begin with a number:
  583: 
  584: @example
  585: DEFAULT.USER> S DENOM=10
  586:  
  587:  
  588: DEFAULT.USER> 100/DENOM
  589:  
  590: 10
  591: DEFAULT.USER> 
  592: @end example
  593: 
  594: Such expressions will be immediately evaluated, and the result printed on @code{@ref{$IO}}.
  595: 
  596: @node Debugging
  597: @chapter Debugging
  598: @cindex debugging
  599: 
  600: @section Debugging Synopsis
  601: FreeM includes an interactive debugger, entered using the @code{BREAK "DEBUG"} command. The debugger is also entered if @code{Ctrl-C} is pressed, @code{Ctrl-C} handling is enabled, and you are in direct mode.
  602: 
  603: If you would like to enter the debugger automatically each time an error is encountered, add the following to your @code{LCLINIT} routine:
  604: 
  605: @example
  606: S $ETR="B ""DEBUG"""
  607: @end example
  608: 
  609: @section Debugging Commands
  610: The debugger uses its own unique command language, where M commands are unavailable. Commands are as follows:
  611: 
  612: @table @asis
  613: @item @code{exit}, @code{quit}
  614: Exits the debugger and returns to direct mode or normal program execution.
  615: @item @code{e} @emph{glvn}, @code{examine} @emph{glvn}
  616: Prints the value of @emph{glvn} to the terminal.
  617: @item @code{t}, @code{trace}
  618: Toggles @emph{trace mode} on and off. When trace mode is on, FreeM will display information about each @code{DO} or @code{GOTO} command encountered, including the routine which invoked the branch, which type of branch was invoked, and the target of the branch.
  619: @item @code{s}, @code{step}
  620: Single-steps through FreeM code command-by-command.
  621: @item @code{n}, @code{next}
  622: Single-steps through FreeM code line-by-line.
  623: @item @code{c}, @code{cont}, @code{continue}
  624: Resumes normal program execution, disabling single-step mode.
  625: @item @code{bt}, @code{backtrace}
  626: Produces a stack trace.
  627: @item @code{h}, @code{halt}
  628: Halts the process being debugged and returns control to the operating system.
  629: @item @code{w [[+|-|?]@emph{<glvn>}]}, @code{watch [[+|-|?]@emph{<glvn>}]}
  630: With no arguments, toggles watchpoints on and off. With @code{+}, adds @emph{<glvn>} to the watchlist. With @code{-}, removes @emph{<glvn>} from the watchlist. With @code{?}, queries the watch status of @emph{<glvn>}.
  631: @end table
  632: 
  633: @node Directives
  634: @chapter Directives
  635: @cindex directives
  636: 
  637: In FreeM, a directive is an instruction embedded in an M comment, and passed to the interpreter to affect a change that is specific to the current routine only.
  638: 
  639: The format of a directive is @code{;%@emph{<directive-name>}}, where @code{@emph{<directive-name>}} is one of the directives listed below.
  640: 
  641: @menu
  642: * %DIALECT::            Sets the M dialect in effect.
  643: @end menu
  644: 
  645: @anchor{%DIALECT}
  646: @section %DIALECT
  647: @cindex %DIALECT
  648: @cindex directives, %DIALECT
  649: 
  650: Sets the M dialect in effect for the current routine buffer; also sets the @code{$DIALECT} special variable to match. See also @ref{$DIALECT}.
  651: 
  652: @emph{Syntax}
  653: 
  654: @example
  655: ;%DIALECT @emph{<dialect>}
  656: @end example
  657: 
  658: Valid values for @code{@emph{<dialect>}} are as follows:
  659: 
  660: @table @code
  661: @item @code{M77}
  662: Restricts FreeM to use only features specified by the 1977 M standard.
  663: @item @code{M84}
  664: Restricts FreeM to use only features specified by the 1984 M standard.
  665: @item @code{M90}
  666: Restricts FreeM to use only features specified by the 1990 M standard.
  667: @item @code{M95}
  668: Restricts FreeM to use only features specified by the 1995 M standard.
  669: @item @code{MDS}
  670: Restricts FreeM to use only features proposed by the Millennium Draft Standard.
  671: @item @code{M5}
  672: Restricts FreeM to use only features proposed by the upcoming M5 standard.
  673: @item @code{FREEM}, @code{EXTENDED}
  674: Removes all standards-based restrictions and allows full access to all FreeM features. This is the default value of @code{%DIALECT}.
  675: @end table
  676: 
  677: Please note that FreeM is not entirely standards-compliant, regardless of the value of @code{%DIALECT}.
  678: 
  679: 
  680: @node Intrinsic Special Variables
  681: @chapter Intrinsic Special Variables
  682: @cindex variables, intrinsic special
  683: 
  684: @menu
  685: * $DEVICE::                  $IO device status.
  686: * $DIALECT::                 Current M dialect.
  687: * $ECODE::                   Latest M error code.
  688: * $ESTACK::                  Error stack info.
  689: * $ETRAP::                   Standard error handler code.
  690: * $HOROLOG::                 Current date and time.
  691: * $IO::                      Current I/O device.
  692: * $JOB::                     PID of current process.
  693: * $KEY::                     Characters terminating last @code{READ} command.
  694: * $PDISPLAY::                Current primary MWAPI display.
  695: * $PRINCIPAL::               I/O channel of terminal.
  696: * $REFERENCE::               Most recent global reference.
  697: * $QUIT::                    Whether a @code{QUIT} command requires an argument in the current execution context.
  698: * $STACK::                   Current program execution stack level.
  699: * $STORAGE::                 Number of bytes available in the heap.
  700: * $SYSTEM::                  MDC system ID of FreeM.
  701: * $TEST::                    Truth value of last conditional expression or result of certain @code{LOCK} operations.
  702: * $TLEVEL::                  Current level of transaction nesting.
  703: * $WITH::                    Current variable prefix set by @code{ZWITH} command.
  704: * $X::                       Current horizontal screen position.
  705: * $Y::                       Current vertical screen position.
  706: * $ZA::                      Current position of file on @code{$IO}.
  707: * $ZB::                      Most recent keystroke.
  708: * $ZCONTROLC::               Control-C handling flag.
  709: * $ZDATE::                   Current date in locale-specific representation.
  710: * $ZERROR::                  Last error message.
  711: * $ZHOROLOG::                Date and time, including milliseconds.
  712: * $ZINRPT::                  State of the interrupt enable/disable flag.
  713: * $ZJOB::                    PID of parent process, if applicable.
  714: * $ZLOCAL::                  Last local variable reference.
  715: * $ZNAME::                   Name of current M routine.
  716: * $ZPRECISION::              Digits of arithmetical precision.
  717: * $ZREFERENCE::              Last gvn referenced.
  718: * $ZSYSTEM::                 Return value of last external command.
  719: * $ZTIME::                   Current time in locale-specific representation.
  720: * $ZTRAP::                   Entryref to be executed on error condition.
  721: * $ZUT::                     Microseconds since the UNIX epoch.
  722: * $ZVERSION::                Version of FreeM and GNU host triplet.
  723: @end menu 
  724: 
  725: @node $DEVICE
  726: @section $DEVICE
  727: @cindex $DEVICE
  728: @cindex intrinsic special variables, $DEVICE
  729: 
  730: Returns the status of the device currently in use.
  731: 
  732: If @code{$DEVICE} returns @emph{1}, an error condition exists on the current device. In this case, there will be two additional fields separated by commas, indicating the internal FreeM error code representing the error present on the device and a text explanation of the error.
  733: 
  734: @node $DIALECT
  735: @section $DIALECT
  736: @cindex $DIALECT
  737: @cindex intrinsic special variables, $DIALECT
  738: 
  739: Returns or sets the language dialect of the current routine.
  740: 
  741: Valid values for @code{$DIALECT} are as follows:
  742: 
  743: @table @code
  744: @item @code{M77}
  745: Restricts FreeM to use only features specified by the 1977 M standard.
  746: @item @code{M84}
  747: Restricts FreeM to use only features specified by the 1984 M standard.
  748: @item @code{M90}
  749: Restricts FreeM to use only features specified by the 1990 M standard.
  750: @item @code{M95}
  751: Restricts FreeM to use only features specified by the 1995 M standard.
  752: @item @code{MDS}
  753: Restricts FreeM to use only features proposed by the Millennium Draft Standard.
  754: @item @code{M5}
  755: Restricts FreeM to use only features proposed by the upcoming M5 standard.
  756: @item @code{FREEM}, @code{EXTENDED}
  757: Removes all standards-based restrictions and allows full access to all FreeM features. This is the default value of @code{$DIALECT}.
  758: @end table
  759: 
  760: Please note that FreeM is not entirely standards-compliant, regardless of the value of @code{$DIALECT}.
  761: 
  762: @node $ECODE
  763: @section $ECODE
  764: @cindex $ECODE
  765: @cindex intrinsic special variables, $ECODE
  766: 
  767: Returns a comma-delimited list of error conditions currently present, and is writable. An empty @code{$ECODE} indicates no errors.
  768: 
  769: Writing a value in the format @code{,<error-code>,} into @code{$ECODE} will raise that error condition.
  770: 
  771: @node $ESTACK
  772: @section $ESTACK
  773: @cindex $ESTACK
  774: @cindex intrinsic special variables, $ESTACK
  775: 
  776: Returns the depth of the program execution stack since the last time @code{$ESTACK} was @code{NEW}ed. @code{NEW}-able, but not @code{SET}-able. Differs from the @code{@ref{$STACK}} ISV in that it is @code{@ref{NEW}}-able, and resets to a value of 0 when @code{@ref{NEW}}ed.
  777: 
  778: @node $ETRAP
  779: @section $ETRAP
  780: @cindex $ETRAP
  781: @cindex intrinsic special variables, $ETRAP
  782: 
  783: Sets or retrieves the M code that is run when an error is encountered or @code{@ref{$ECODE}} is set to a non-blank value. @code{$ETRAP} code executes when @code{$ECODE} becomes non-blank.
  784: 
  785: 
  786: @node $HOROLOG
  787: @section $HOROLOG
  788: @cindex $HOROLOG
  789: @cindex intrinsic special variables, $HOROLOG
  790: 
  791: Returns a string containing the current date and time as @code{<days>,<seconds>}, where @code{<days>} represents the number of days since the M epoch (midnight on 31 December 1840),
  792: and @code{<seconds>} represents the number of seconds since the most recent midnight.
  793: 
  794: @cartouche
  795: @quotation
  796: @emph{FreeM Extension}
  797: 
  798: In FreeM, @code{$HOROLOG} is @code{@ref{SET}}table. Setting @code{$HOROLOG} will set the system clock if your user account has the appropriate permissions. If your user account does not have permissions to modify the system clock, FreeM will raise a @code{ZPROTECT} error.
  799: @end quotation
  800: @end cartouche
  801: 
  802: @node $IO
  803: @section $IO
  804: @cindex $IO
  805: @cindex intrinsic special variables, $IO
  806: 
  807: Represents the current input/output device. Read-only.
  808: 
  809: @node $JOB
  810: @section $JOB
  811: @cindex $JOB
  812: @cindex intrinsic special variables, $JOB
  813: 
  814: Represents the process ID of the FreeM instance currently in use.
  815: 
  816: @node $KEY
  817: @section $KEY
  818: @cindex $KEY
  819: @cindex intrinsic special variables, $KEY
  820: 
  821: Represents the sequence of control characters that terminated the last @code{@ref{READ}} command on @code{@ref{$IO}}.
  822: 
  823: @node $PDISPLAY
  824: @section $PDISPLAY
  825: @cindex $PDISPLAY
  826: @cindex intrinsic special variables, $PDISPLAY
  827: 
  828: Represents the current principal display for M Windowing API operations. Commonly used as an index into the @code{@ref{^$DISPLAY}} structured system variable.
  829: 
  830: @node $PRINCIPAL
  831: @section $PRINCIPAL
  832: @cindex $PRINCIPAL
  833: @cindex intrinsic special variables, $PRINCIPAL
  834: 
  835: Represents the primary input/output device. Usually a terminal or virtual terminal.
  836: 
  837: @node $REFERENCE
  838: @section $REFERENCE
  839: @cindex $REFERENCE
  840: @cindex intrinsic special variables, $REFERENCE
  841: 
  842: Returns the last @emph{glvn} referenced. Can be @code{@ref{SET}}, and also stacked with @code{@ref{NEW}}.
  843: 
  844: @node $QUIT
  845: @section $QUIT
  846: @cindex $QUIT
  847: @cindex intrinsic special variables, $QUIT
  848: 
  849: If the current execution context was invoked as an extrinsic function, @code{$QUIT} returns @emph{1}. Otherwise, returns @emph{0}.
  850: 
  851: When @code{$QUIT} returns @emph{1}, a subsequent @code{@ref{QUIT}} command must have an argument.
  852: 
  853: @node $STACK
  854: @section $STACK
  855: @cindex $STACK
  856: @cindex intrinsic special variables, $STACK
  857: 
  858: Represents the current stack level.
  859: 
  860: @node $STORAGE
  861: @section $STORAGE
  862: @cindex $STORAGE
  863: @cindex intrinsic special variables, $STORAGE
  864: 
  865: Represents the number of bytes of free space available in FreeM's heap.
  866: 
  867: @node $SYSTEM
  868: @section $SYSTEM
  869: @cindex $SYSTEM
  870: @cindex intrinsic special variables, $SYSTEM
  871: 
  872: Returns the MDC system ID of FreeM, as well as the environment ID of the current environment.
  873: 
  874: @node $TEST
  875: @section $TEST
  876: @cindex $TEST
  877: @cindex intrinsic special variables, $TEST
  878: 
  879: @code{$TEST} is a writable, @code{@ref{NEW}}-able ISV that is @emph{1} if the most recently evaluated expression was @emph{true}. Otherwise, returns @emph{0}.
  880: 
  881: @code{$TEST} is implicitly @code{NEW}ed when entering a new stack frame for extrinsic functions and argumentless @code{@ref{DO}}. @code{$TEST}
  882: is @emph{not} implicitly @code{NEW}ed when a new stack frame is entered with an argumented @code{DO}.
  883: 
  884: For single-line @code{@ref{IF}} or @code{@ref{ELSE}} expressions, you may use @code{@ref{THEN}} to stack @code{$TEST} until the end of the line. All new code should employ @code{THEN} in this manner, as stacking @code{$TEST} prevents a wide range of coding errors that can be very challenging to detect and eliminate.
  885: 
  886: @node $TLEVEL
  887: @section $TLEVEL
  888: @cindex $TLEVEL
  889: @cindex intrinsic special variables, $TLEVEL
  890: 
  891: Returns a numeric value indicating the current level of transaction nesting in the process. When @code{$TLEVEL} is greater than @emph{0},
  892: uncommitted transactions exist.
  893: 
  894: @node $WITH
  895: @section $WITH
  896: @cindex $WITH
  897: @cindex intrinsic special variables, $WITH
  898: 
  899: Returns the variable prefix set by the @code{@ref{ZWITH}} command.
  900: 
  901: @node $X
  902: @section $X
  903: @cindex $X
  904: @cindex intrinsic special variables, $X
  905: 
  906: Represents the current column position of the FreeM cursor.
  907: 
  908: @cartouche
  909: @quotation
  910: In FreeM, setting @code{$X} will move the FreeM cursor.
  911: @end quotation
  912: @end cartouche
  913: 
  914: 
  915: @node $Y
  916: @section $Y
  917: @cindex $Y
  918: @cindex intrinsic special variables, $Y
  919: 
  920: Represents the current row position of the FreeM cursor.
  921: 
  922: @cartouche
  923: @quotation
  924: In FreeM, setting @code{$Y} will move the FreeM cursor.
  925: @end quotation
  926: @end cartouche
  927: 
  928: 
  929: @node $ZA
  930: @section $ZA
  931: @cindex $ZA
  932: @cindex intrinsic special variables, $ZA
  933: @cindex intrinsic special variables, implementation-specific
  934: 
  935: On the @code{HOME} device, always @code{0}. On other devices, returns the current position of the file opened on I/O channel @code{@ref{$IO}}.
  936: 
  937: @node $ZB
  938: @section $ZB
  939: @cindex $ZB
  940: @cindex intrinsic special variables, $ZB
  941: @cindex intrinsic special variables, implementation-specific
  942: 
  943: Represents the last keystroke.
  944: 
  945: @node $ZCONTROLC
  946: @section $ZCONTROLC
  947: @cindex $ZCONTROLC
  948: @cindex intrinsic special variables, $ZCONTROLC
  949: @cindex intrinsic special variables, implementation-specific
  950: 
  951: Returns the status of the Ctrl-C flag and resets it to @emph{false}.
  952: 
  953: @node $ZDATE
  954: @section $ZDATE
  955: @cindex $ZDATE
  956: @cindex intrinsic special variables, $ZDATE
  957: @cindex intrinsic special variables, implementation-specific
  958: 
  959: Returns the current date, in the preferred representation for the current system locale.
  960: 
  961: @node $ZERROR
  962: @section $ZERROR
  963: @cindex $ZERROR
  964: @cindex intrinsic special variables, $ZERROR
  965: @cindex intrinsic special variables, implementation-specific
  966: 
  967: Returns the last error message.
  968: 
  969: @node $ZHOROLOG
  970: @section $ZHOROLOG
  971: @cindex $ZHOROLOG
  972: @cindex intrinsic special variables, $ZHOROLOG
  973: @cindex intrinsic special variables, implementation-specific
  974: 
  975: Output @code{@ref{$HOROLOG}}-style time, with the addition of milliseconds.
  976: 
  977: @node $ZINRPT
  978: @section $ZINRPT
  979: @cindex $ZINRPT
  980: @cindex intrinsic special variables, $ZINRPT
  981: @cindex intrinsic special variables, implementation-specific
  982: 
  983: Gets or sets the interrupt enable/disable flag.
  984: 
  985: @node $ZJOB
  986: @section $ZJOB
  987: @cindex $ZJOB
  988: @cindex intrinsic special variables, $ZJOB
  989: @cindex intrinsic special variables, implementation-specific
  990: 
  991: Returns the @code{@ref{$JOB}} value of the parent process if the current process was started by a @code{@ref{JOB}} command. Otherwise, returns an empty string.
  992: 
  993: @node $ZLOCAL
  994: @section $ZLOCAL
  995: @cindex $ZLOCAL
  996: @cindex intrinsic special variables, $ZLOCAL
  997: @cindex intrinsic special variables, implementation-specific
  998: 
  999: Returns the last local variable referenced.
 1000: 
 1001: @node $ZNAME
 1002: @section $ZNAME
 1003: @cindex $ZNAME
 1004: @cindex intrinsic special variables, $ZNAME
 1005: @cindex intrinsic special variables, implementation-specific
 1006: 
 1007: Returns the name of the current routine.
 1008: 
 1009: @node $ZPRECISION
 1010: @section $ZPRECISION
 1011: @cindex $ZPRECISION
 1012: @cindex intrinsic special variables, $ZPRECISION
 1013: @cindex intrinsic special variables, implementation-specific
 1014: 
 1015: Gets or sets the number of digits of numeric precision used for fixed-point decimal arithmetic. If @code{^$JOB($JOB,"MATH")} is @code{IEEE754}, @code{$ZPRECISION} defaults to 16 digits, with a maximum of 16 digits. If @code{^$JOB($JOB,"MATH")} is @code{FIXED}, @code{$ZPRECISION} defaults to 100 digits, with a maximum of 20,000 digits.
 1016: 
 1017: @xref{^$JOB}.
 1018: 
 1019: @node $ZREFERENCE
 1020: @section $ZREFERENCE
 1021: @cindex $ZREFERENCE
 1022: @cindex intrinsic special variables, $ZREFERENCE
 1023: @cindex intrinsic special variables, implementation-specific
 1024: 
 1025: Returns the last @emph{gvn} referenced.
 1026: 
 1027: @node $ZSYSTEM
 1028: @section $ZSYSTEM
 1029: @cindex $ZSYSTEM
 1030: @cindex intrinsic special variables, $ZSYSTEM
 1031: @cindex intrinsic special variables, implementation-specific
 1032: 
 1033: Represents the return value of the last external command run with @code{!}.
 1034: 
 1035: @node $ZTIME
 1036: @section $ZTIME
 1037: @cindex $ZTIME
 1038: @cindex intrinsic special variables, $ZTIME
 1039: @cindex intrinsic special variables, implementation-specific
 1040: 
 1041: Returns the system time in the preferred representation for the current system locale.
 1042: 
 1043: @node $ZTRAP
 1044: @section $ZTRAP
 1045: @cindex $ZTRAP
 1046: @cindex intrinsic special variables, $ZTRAP
 1047: @cindex intrinsic special variables, implementation-specific
 1048: 
 1049: Sets or retrieves the entryref to be executed when an M program execution error occurs under FreeM-style or DSM 2.0-style error processing.
 1050: 
 1051: In FreeM-style error processing, @code{$ZTRAP} is specific to each program execution stack level.
 1052: 
 1053: In DSM 2.0-style error processing, @code{$ZTRAP} is the same for all program execution stack levels.
 1054: 
 1055: When FreeM encounters an error, if @code{$ZTRAP} is nonempty and @code{$ETRAP} is empty, FreeM will perform an implicit @code{@ref{GOTO}} to the entryref indicated in @code{$ZTRAP}.
 1056: 
 1057: If @code{$ETRAP} is nonempty when FreeM encounters an error, the value of @code{$ZTRAP} is ignored, whether FreeM-style or DSM 2.0-style error processing is enabled.
 1058: 
 1059: @node $ZUT
 1060: @section $ZUT
 1061: @cindex $ZUT
 1062: @cindex intrinsic special variables, $ZUT
 1063: @cindex intrinsic special variables, implementation-specific
 1064: 
 1065: Returns the number of microseconds elapsed since the UNIX epoch (Jan 1, 1970 0:00:00).
 1066: 
 1067: @node $ZVERSION
 1068: @section $ZVERSION
 1069: @cindex $ZVERSION
 1070: @cindex intrinsic special variables, $ZVERSION
 1071: @cindex intrinsic special variables, implementation-specific
 1072: 
 1073: Returns the version of FreeM in use, as well as the GNU host triplet for the current FreeM build.
 1074: 
 1075: See @emph{https://wiki.osdev.org/Target_Triplet}.
 1076: 
 1077: @node Intrinsic Functions
 1078: @chapter Intrinsic Functions
 1079: 
 1080: @menu
 1081: * $ASCII()::                            Return ASCII code for character in string.
 1082: * $CHAR()::                             Return character for one or more ASCII codes.
 1083: * $DATA()::                             Retrieve definition and characteristics of array node.
 1084: * $EXTRACT()::                          Return a substring of a string.
 1085: * $FIND()::                             Find position of substring within string.
 1086: * $FNUMBER()::                          Format a number according to formatting codes.
 1087: * $GET()::                              Return value of glvn or a default if undefined.
 1088: * $INSTANCEOF()::                       Determine if lvn is an instance of a class.
 1089: * $JUSTIFY()::                          Right-justify a string based on specified length.
 1090: * $LENGTH()::                           Return length or delimiter-based piece count of string.
 1091: * $NAME()::                             Return canonical name from string representation of glvn.
 1092: * $NEXT()::                             Return next numeric subscript following given glvn.
 1093: * $ORDER()::                            Return next subscript at same level of specified glvn.
 1094: * $PIECE()::                            Return one or more delimited pieces of a string.
 1095: * $QLENGTH()::                          Return subscript count of glvn.
 1096: * $QSUBSCRIPT()::                       Return a specified subscript from glvn.
 1097: * $QUERY()::                            Return next subscript of specified glvn.
 1098: * $RANDOM()::                           Return pseudorandom integer up to a maximum value.
 1099: * $REVERSE()::                          Reverse a string.
 1100: * $SELECT()::                           Return value from first true condition in list of expressions.
 1101: * $STACK()::                            Return information about the program stack.
 1102: * $TEXT()::                             Return line of code from a routine.
 1103: * $TRANSLATE()::                        Substitute specified characters in a string.
 1104: * $TYPE()::                             Return class of the specified lvn.
 1105: * $VIEW()::                             Retrieve implementation-specific information.
 1106: * $ZBOOLEAN()::                         Perform boolean operations on numeric arguments.
 1107: * $ZCALL()::                            Unknown.
 1108: * $ZCRC()::                             Generate checksum of a string argument.
 1109: * $ZDATA()::                            Unknown.
 1110: * $ZDATE()::                            Convert @code{@ref{$HOROLOG}} string into human-readable date.
 1111: * $ZEDIT()::                            Unknown.
 1112: * $ZHOROLOG()::                         Convert date/time values to @code{@ref{$HOROLOG}} format.
 1113: * $ZKEY()::                             Unknown.
 1114: * $ZLENGTH()::                          Unknown.
 1115: * $ZLSD()::                             Compute Levenshtein distance between two arguments.
 1116: * $ZM()::                               Unknown.
 1117: * $ZNAME()::                            Unknown.
 1118: * $ZNEXT()::                            Unknown.
 1119: * $ZORDER()::                           Unknown.
 1120: * $ZPIECE()::                           Unknown.
 1121: * $ZPREVIOUS()::                        Unknown.
 1122: * $ZREPLACE()::                         Replace all instances of a substring within a string.
 1123: * $ZSYNTAX()::                          Perform syntax check on string argument.
 1124: * $ZTIME()::                            Convert a @code{@ref{$HOROLOG}} string into human-readable time.
 1125: @end menu
 1126: 
 1127: @node $ASCII()
 1128: @section $ASCII
 1129: @cindex $ASCII
 1130: @cindex intrinsic functions, $ASCII
 1131: 
 1132: Returns the ASCII code (in decimal) for one character in a string.
 1133: 
 1134: @example
 1135: SET RESULT=$ASCII(@emph{<string>}[,@emph{<index>}])
 1136: @end example
 1137: 
 1138: 
 1139: If @emph{<index>} is not supplied, @code{$ASCII} will return the ASCII code of the first character. Otherwise, returns the ASCII code of the character at position @emph{<index>}.
 1140: 
 1141: @node $CHAR()
 1142: @section $CHAR
 1143: @cindex $CHAR
 1144: @cindex intrinsic functions, $CHAR
 1145: 
 1146: Returns a string of characters corresponding to a list of ASCII codes.
 1147: 
 1148: @example
 1149: SET RESULT=$CHAR(@emph{<ascii-code>}[,@emph{<ascii-code>},...])
 1150: @end example
 1151: 
 1152: @node $DATA()
 1153: @section $DATA
 1154: @cindex $DATA
 1155: @cindex intrinsic functions, $DATA
 1156: 
 1157: Returns a numeric value 0, 1, 10, or 11, depending on whether a referenced node is defined, has data, or has children:
 1158: 
 1159: @example
 1160: SET RESULT=$DATA(@emph{<node>})
 1161: @end example
 1162: 
 1163: The return values are as follows:
 1164: 
 1165: @example
 1166: 0: @emph{<node>} is undefined
 1167: 1: @emph{<node>} has data but no children
 1168: 10: @emph{<node>} has children but no data
 1169: 11: @emph{<node>} has children and data
 1170: @end example
 1171: 
 1172: @node $EXTRACT()
 1173: @section $EXTRACT
 1174: @cindex $EXTRACT
 1175: @cindex intrinsic functions, $EXTRACT
 1176: 
 1177: Extracts a substring of a string.
 1178: 
 1179: The first argument is the source string.
 1180: 
 1181: The optional second argument specifies the starting position of the substring to extract, and defaults to @code{1}.
 1182: 
 1183: The optional third argument specifies the ending position of the substring to extract, and defaults to the value of the second argument, or @code{1}.
 1184: 
 1185: This example will extract the string @emph{FreeM} into the local variable @code{M}.
 1186: 
 1187: @example
 1188: SET NAME="FreeM is the best!"
 1189: SET M=$EXTRACT(NAME,1,5)
 1190: @end example
 1191: 
 1192: It is also possible to use @code{$EXTRACT} on the left-hand side of a @code{SET} assignment in order to modify a substring:
 1193: 
 1194: @example
 1195: DEFAULT.USER> SET FOO="ABCDEFG"
 1196: 
 1197: 
 1198: DEFAULT.USER> SET $EXTRACT(FOO,1,3)="XYZ"
 1199: 
 1200: 
 1201: DEFAULT.USER> WRITE FOO
 1202: 
 1203: XYZDEFG
 1204: @end example
 1205: 
 1206: @node $FIND()
 1207: @section $FIND
 1208: @cindex $FIND
 1209: @cindex intrinsic functions, $FIND
 1210: 
 1211: Finds the character immediately following the first occurence of a substring within a string.
 1212: 
 1213: The first argument is the source string.
 1214: 
 1215: The second argument is the substring to be located.
 1216: 
 1217: The optional third argument indicates the position within the source string at which to begin searching.
 1218: 
 1219: @node $FNUMBER()
 1220: @section $FNUMBER
 1221: @cindex $FNUMBER
 1222: @cindex intrinsic functions, $FNUMBER
 1223: 
 1224: Formats a number according to a particular set of formatting codes.
 1225: 
 1226: The first argument is the number to format.
 1227: 
 1228: The second argument is the series of formatting codes:
 1229: 
 1230: @table @asis
 1231: @item 'P' or 'p'
 1232: Will display negative numbers within parentheses instead of showing a minus sign.
 1233: @item , (comma)
 1234: Will add commas as thousands separators.
 1235: @item +
 1236: Will include a plus sign for positive numbers. Not compatible with 'P' or 'p'.
 1237: @item -
 1238: Will remove the minus sign from negative numbers. Not compatible with 'p' or 'P'.
 1239: @item 't' or 'T'
 1240: Will place the sign after the number instead of before the number.
 1241: @end table
 1242: 
 1243: The optional third argument is a number indicating how many digits to which the fractional part of the number will be zero-padded.
 1244: 
 1245: @node $GET()
 1246: @section $GET
 1247: @cindex $GET
 1248: @cindex intrinsic functions, $GET
 1249: 
 1250: Returns the value of a local, global, or SSVN if the specified item is defined, or a default value otherwise.
 1251: 
 1252: The first argument is the local, global, or SSVN to be examined.
 1253: 
 1254: The optional second argument is the default value to be returned if the referenced item is undefined, and defaults to the empty string.
 1255: 
 1256: @node $INSTANCEOF()
 1257: @section $INSTANCEOF
 1258: @cindex $INSTANCEOF
 1259: @cindex intrinsic functions, $INSTANCEOF
 1260: @cindex object functions, $INSTANCEOF
 1261: 
 1262: Returns @code{1} if the specified @emph{lvn} is an instance of class @emph{class}, or @code{0} otherwise.
 1263: 
 1264: The first argument is a string representing a valid FreeM local variable.
 1265: 
 1266: The second argument is a string representing a valid FreeM class.
 1267: 
 1268: @example
 1269: DEFAULT.USER> N STR=$$^%STRING
 1270: 
 1271: DEFAULT.USER> W $INSTANCEOF("STR","^%STRING")
 1272: 1
 1273: @end example
 1274: 
 1275: @node $JUSTIFY()
 1276: @section $JUSTIFY
 1277: @cindex $JUSTIFY
 1278: @cindex intrinsic functions, $JUSTIFY
 1279: 
 1280: Right-justifies a string based on a specified fixed length.
 1281: 
 1282: The first argument is the source string.
 1283: 
 1284: The second argument is the character length of the output.
 1285: 
 1286: The optional third argument controls the number of fractional digits to be included in the output, and defaults to the number of digits specified in the first argument.
 1287: 
 1288: @node $LENGTH()
 1289: @section $LENGTH
 1290: @cindex $LENGTH
 1291: @cindex intrinsic functions, $LENGTH
 1292: 
 1293: Returns the length of a string, or the number of items in a list delimited by a specified character (as used by @code{@ref{$PIECE()}}).
 1294: 
 1295: The first argument is the source string.
 1296: 
 1297: The optional second argument is the list delimiter to be used. When this argument is omitted, the length of the string in characters is returned.
 1298: 
 1299: @node $NAME()
 1300: @section $NAME
 1301: @cindex $NAME
 1302: @cindex intrinsic functions, $NAME
 1303: 
 1304: Returns the canonical name reference along with some or all of its subscripts.
 1305: 
 1306: The first argument is the source name.
 1307: 
 1308: The optional second argument indicates the maximum subscript count to be returned, and defaults to the subscript count of the source name.
 1309: 
 1310: @node $NEXT()
 1311: @section $NEXT
 1312: @cindex $NEXT
 1313: @cindex intrinsic functions, $NEXT
 1314: 
 1315: Deprecated. Use @code{$ORDER} instead.
 1316: 
 1317: @node $ORDER()
 1318: @section $ORDER
 1319: @cindex $ORDER
 1320: @cindex intrinsic functions, $ORDER
 1321: 
 1322: Returns the previous subscript or next subscript in a local, global, or a subset of structured system variables.
 1323: 
 1324: The first argument is the subscripted local, global, or SSVN.
 1325: 
 1326: The optional second argument can be @code{1} to retrieve the next subscript, or @code{-1} to return the previous.
 1327: 
 1328: @node $PIECE()
 1329: @section $PIECE
 1330: @cindex $PIECE
 1331: @cindex intrinsic functions, $PIECE
 1332: 
 1333: @emph{Syntax}
 1334: 
 1335: @code{$PIECE(@emph{s},@emph{d}[,@emph{n}[,@emph{end}]])}
 1336: 
 1337: Accesses the @code{n}th through @code{end} @code{d}-delimited pieces of string @code{s}.
 1338: 
 1339: The first argument is the string to be evaluated.
 1340: 
 1341: The second argument is the delimiter to be used.
 1342: 
 1343: The optional third argument is the first @code{d}-delimited piece to access, and defaults to @code{1}.
 1344: 
 1345: The optional fourth argument is the final @code{d}-delimited piece to access, and defaults to the value of the third argument (@code{n}).
 1346: 
 1347: Can be used on the left-hand side of an expression in order to @code{@ref{SET}} a value into a @code{d}-delimited piece of @code{s}, as in:
 1348: 
 1349: @example
 1350: ; ^snw="this^is^a^piece"
 1351: SET $PIECE(^snw,"^",2)="isn't" ; => "this^isn't^a^piece"
 1352: @end example
 1353: 
 1354: @node $QLENGTH()
 1355: @section $QLENGTH
 1356: @cindex $QLENGTH
 1357: @cindex intrinsic functions, $QLENGTH
 1358: 
 1359: @emph{Syntax}
 1360: 
 1361: @example
 1362: @code{$QLENGTH(@emph{expr V glvn})}
 1363: @end example
 1364: 
 1365: Returns the number of subscripts in @emph{glvn}.
 1366: 
 1367: @emph{Example}
 1368: @example
 1369: @code{SET SUBCT=$QLENGTH("^GBL(1,2,3)") ; => 3}
 1370: @end example
 1371: 
 1372: @node $QSUBSCRIPT()
 1373: @section $QSUBSCRIPT
 1374: @cindex $QSUBSCRIPT
 1375: @cindex intrinsic functions, $QSUBSCRIPT
 1376: 
 1377: @emph{Syntax}
 1378: 
 1379: @example
 1380: @code{$QSUBSCRIPT(@emph{expr V glvn},@emph{expr V n})}
 1381: @end example
 1382: 
 1383: In the RHS form, returns the @emph{n}th subscript of @emph{glvn}.
 1384: 
 1385: @emph{Example}
 1386: 
 1387: @example
 1388: @code{SET SUB=$QSUBSCRIPT("^GBL(1,2,3)",2) ; => 2}
 1389: @end example
 1390: 
 1391: @emph{Syntax}
 1392: 
 1393: @example
 1394: @code{SET $QSUBSCRIPT(@emph{expr V glvn},@emph{expr V n})=@emph{expr} ; => ^GBL(1,4,3)}
 1395: @end example
 1396: 
 1397: In the LHS form, sets the @emph{n}th subscript of @emph{glvn} to @emph{expr}.
 1398: 
 1399: @node $QUERY()
 1400: @section $QUERY
 1401: @cindex $QUERY
 1402: @cindex intrinsic functions, $QUERY
 1403: 
 1404: Returns the next subscripted reference in a global.
 1405: 
 1406: @emph{Syntax}
 1407: 
 1408: @example
 1409: @code{$QUERY(@emph{glvn})}
 1410: @end example
 1411: 
 1412: @emph{Example}
 1413: 
 1414: We will assume the following data structure exists:
 1415: @example
 1416: ^snw(1)=1
 1417: ^snw(1,2)="foo"
 1418: ^snw(2)=3
 1419: ^snw(3)=""
 1420: @end example
 1421: 
 1422: The following code will retrieve the next subscripted name after @code{^snw(1)}:
 1423: 
 1424: @example
 1425: @code{SET NEXTNAM=$QUERY(^snw(1)) ; => ^snw(1,2)}
 1426: @end example
 1427: 
 1428: @node $RANDOM()
 1429: @section $RANDOM
 1430: @cindex $RANDOM
 1431: @cindex intrinsic functions, $RANDOM
 1432: 
 1433: @emph{Syntax}
 1434: 
 1435: @example
 1436: $RANDOM(@emph{max})
 1437: @end example
 1438: 
 1439: Returns a pseudo-random integer in the range of @code{0..@emph{max} - 1} 
 1440: 
 1441: @node $REVERSE()
 1442: @section $REVERSE
 1443: @cindex $REVERSE
 1444: @cindex intrinsic functions, $REVERSE
 1445: 
 1446: @emph{Syntax}
 1447: 
 1448: @example
 1449: $REVERSE(@emph{s})
 1450: @end example
 1451: 
 1452: Returns the reverse of string @emph{s}.
 1453: 
 1454: @emph{Example}
 1455: 
 1456: @example
 1457: SET FOO=$REVERSE("ABC") ; => CBA
 1458: @end example
 1459: 
 1460: @node $SELECT()
 1461: @section $SELECT
 1462: @cindex $SELECT
 1463: @cindex intrinsic functions, $SELECT
 1464: 
 1465: Returns a value corresponding to the first true condition in a list of conditional expressions. Each argument is an expression, followed by a colon, followed by an expression whose value will be returned if the first expression is true. If no expressions are true, error condition @code{M4} is raised.
 1466: 
 1467: @emph{Example}
 1468: 
 1469: @example
 1470: SET FOO=$SELECT(1=2:"math is broken",1=1:"the world makes sense") ; => "the world makes sense"
 1471: @end example
 1472: 
 1473: @node $STACK()
 1474: @section $STACK
 1475: @cindex $STACK
 1476: @cindex intrinsic functions, $STACK
 1477: 
 1478: Returns information about the program execution stack. The @code{$STACK} intrinsic function has both a one-argument form and a two-argument form.
 1479: 
 1480: @emph{Syntax (One-Argument)}
 1481: 
 1482: @example
 1483:  $STACK(@emph{<num>})
 1484: @end example
 1485: 
 1486: If @emph{num} is @code{0}, returns the command with which this FreeM instance was invoked.
 1487: 
 1488: If @emph{num} is @code{-1}, returns the current program execution stack level.
 1489: 
 1490: If @emph{num} represents a valid program execution stack depth above @code{0}, returns one of the following values indicating the reason for which the referenced program execution stack level was created:
 1491: 
 1492: @table @asis
 1493: 
 1494: @item @code{$$}
 1495: If @code{$STACK(@emph{<num>})="$$"}, program execution stack level @code{num} was created as the result of an extrinsic function call
 1496: 
 1497: @item @emph{<m-command>}
 1498: If @code{$STACK(@emph{<num>})} returns a valid M command, the referenced program execution stack level was created as a result of the @emph{m-command} command.
 1499: 
 1500: @end table
 1501: 
 1502: @emph{Syntax (Two-Argument})
 1503: 
 1504: @example
 1505:  $STACK(@emph{<num>},"[ECODE|MCODE|PLACE]")
 1506: @end example
 1507: 
 1508: Returns the error codes, M program code, or entryref applicable to the action that created program execution stack level @emph{num}.
 1509: 
 1510: @node $TEXT()
 1511: @section $TEXT
 1512: @cindex $TEXT
 1513: @cindex intrinsic functions, $TEXT
 1514: 
 1515: Returns a line of code from a routine.
 1516: 
 1517: @node $TRANSLATE()
 1518: @section $TRANSLATE
 1519: @cindex $TRANSLATE
 1520: @cindex intrinsic functions, $TRANSLATE
 1521: 
 1522: Replaces characters in a string.
 1523: 
 1524: The first argument is a string expression representing the text to be changed.
 1525: 
 1526: The second argument is a list of characters to replace.
 1527: 
 1528: The third argument is a list of characters to use as the replacements for the characters in the second argument.
 1529: 
 1530: @emph{Example}
 1531: 
 1532: @example
 1533:  DEFAULT.USER> W $TRANSLATE("twig","wt","rb")
 1534:  brig
 1535: @end example
 1536: 
 1537: @node $TYPE()
 1538: @section $TYPE
 1539: @cindex $TYPE
 1540: @cindex intrinsic functions, $TYPE
 1541: @cindex object functions, $TYPE
 1542: 
 1543: Returns a string giving the class of the object specified in the parameter.
 1544: 
 1545: @xref{Object-Oriented Programming}
 1546: 
 1547: @node $VIEW()
 1548: @section $VIEW
 1549: @cindex $VIEW
 1550: @cindex intrinsic functions, $VIEW
 1551: 
 1552: @node $ZBOOLEAN()
 1553: @section $ZBOOLEAN
 1554: @cindex $ZBOOLEAN
 1555: @cindex intrinsic functions, $ZBOOLEAN
 1556: @cindex intrinsic functions, implementation-specific
 1557: 
 1558: 
 1559: Performs @emph{boolean-operation} on numeric arguments @emph{A} and @emph{B}.
 1560: 
 1561: @emph{Syntax}
 1562: 
 1563: @example
 1564: SET RESULT=$ZBOOLEAN(@emph{A},@emph{B},@emph{boolean-operation})
 1565: @end example
 1566: 
 1567: @code{$ZBOOLEAN} Operations (@emph{boolean-operation} values)
 1568: 
 1569: @table @code
 1570: @item 0
 1571: Always @emph{false}
 1572: @item 1
 1573: @code{A AND B}
 1574: @item 2
 1575: @code{A AND NOT B}
 1576: @item 3
 1577: @code{A}
 1578: @item 4
 1579: @code{NOT A AND B}
 1580: @item 5
 1581: @code{B}
 1582: @item 6
 1583: @code{A XOR B}
 1584: @item 7
 1585: @code{A OR B}
 1586: @item 8
 1587: @code{A NOR B}
 1588: @item 9
 1589: @code{A EQUALS B}
 1590: @item 10
 1591: @code{NOT B}
 1592: @item 11
 1593: @code{A OR NOT B}
 1594: @item 12
 1595: @code{NOT A}
 1596: @item 13
 1597: @code{NOT A OR B}
 1598: @item 14
 1599: @code{A NAND B}
 1600: @item 15
 1601: Always @emph{true}
 1602: @end table
 1603: 
 1604: @node $ZCALL()
 1605: @section $ZCALL
 1606: @cindex $ZCALL
 1607: @cindex intrinsic functions, $ZCALL
 1608: @cindex intrinsic functions, implementation-specific
 1609: 
 1610: Purpose unknown.
 1611: 
 1612: @node $ZCRC()
 1613: @section $ZCRC
 1614: @cindex $ZCRC
 1615: @cindex intrinsic functions, $ZCRC
 1616: @cindex intrinsic functions, implementation-specific
 1617: 
 1618: Returns a checksum of @code{arg1}.
 1619: 
 1620: @emph{Syntax}
 1621: 
 1622: @code{$ZCRC(@emph{arg1})}
 1623: 
 1624: @code{SET VAR=$ZCRC("MUMPS") ; => 86}
 1625: 
 1626: @node $ZDATA()
 1627: @section $ZDATA
 1628: @cindex $ZDATA
 1629: @cindex intrinsic functions, $ZDATA
 1630: @cindex intrinsic functions, implementation-specific
 1631: 
 1632: Purpose unknown.
 1633: 
 1634: @node $ZDATE()
 1635: @section $ZDATE
 1636: @cindex $ZDATE
 1637: @cindex intrinsic functions, $ZDATE
 1638: @cindex intrinsic functions, implementation-specific
 1639: 
 1640: Converts a @code{@ref{$HOROLOG}} string into a human-readable date.
 1641: 
 1642: @emph{Syntax}
 1643: 
 1644: @example
 1645: SET VAR=$ZDATE($H[,@emph{<format-string>}])
 1646: @end example
 1647: 
 1648: The optional @emph{<format-string>} follows the same rules as the UNIX @code{strftime} function. If @emph{<format-string>} is omitted, the value of @code{^$SYSTEM("ZDATE_FORMAT")} is used (typically @code{%x}).
 1649: 
 1650: @xref{^$SYSTEM}
 1651: 
 1652: @node $ZEDIT()
 1653: @section $ZEDIT
 1654: @cindex $ZEDIT
 1655: @cindex intrinsic functions, $ZEDIT
 1656: @cindex intrinsic functions, implementation-specific
 1657: 
 1658: Purpose unknown.
 1659: 
 1660: @node $ZHOROLOG()
 1661: @section $ZHOROLOG
 1662: @cindex $ZHOROLOG
 1663: @cindex intrinsic functions, $ZHOROLOG
 1664: @cindex intrinsic functions, implementation-specific
 1665: 
 1666: Converts date and/or time values producible by @code{@ref{$ZDATE()}} or @code{@ref{$ZTIME()}} to @code{@ref{$HOROLOG}} format.
 1667: 
 1668: @emph{Syntax}
 1669: 
 1670: @example
 1671: $ZHOROLOG(@emph{<date-value>},@emph{<format-string>})
 1672: @end example
 1673: 
 1674: @emph{<date-value>} is a date or time string compatible with the formats from @code{@ref{$ZDATE()}} or @code{@ref{$ZTIME}}.
 1675: 
 1676: @emph{<format-string>} is a format string of the same format as used by the @code{strptime(3)} UNIX function.
 1677: 
 1678: @node $ZKEY()
 1679: @section $ZKEY
 1680: @cindex $ZKEY
 1681: @cindex intrinsic functions, $ZKEY
 1682: @cindex intrinsic functions, implementation-specific
 1683: 
 1684: Purpose unknown.
 1685: 
 1686: @node $ZLENGTH()
 1687: @section $ZLENGTH
 1688: @cindex $ZLENGTH
 1689: @cindex intrinsic functions, $ZLENGTH
 1690: @cindex intrinsic functions, implementation-specific
 1691: 
 1692: Purpose unknown.
 1693: 
 1694: @node $ZLSD()
 1695: @section $ZLSD
 1696: @cindex $ZLSD
 1697: @cindex intrinsic functions, $ZLSD
 1698: @cindex intrinsic functions, implementation-specific
 1699: 
 1700: Returns the Levenshtein distance between two arguments. The Levenshtein distance represents the minimum number of edits needed to change the first argument into the second argument.
 1701: 
 1702: @emph{Syntax}
 1703: 
 1704: @code{SET VAR=$ZLSD(@emph{arg1},@emph{arg2})}
 1705: 
 1706: @emph{Example}
 1707: 
 1708: @code{SET VAR=$ZLSD("KITTENS","MITTENS") ; => 1}
 1709: 
 1710: @node $ZM()
 1711: @section $ZM
 1712: @cindex $ZM
 1713: @cindex intrinsic functions, $ZM
 1714: @cindex intrinsic functions, implementation-specific
 1715: 
 1716: Purpose unknown.
 1717: 
 1718: @node $ZNAME()
 1719: @section $ZNAME
 1720: @cindex $ZNAME
 1721: @cindex intrinsic functions, $ZNAME
 1722: @cindex intrinsic functions, implementation-specific
 1723: 
 1724: Purpose unknown.
 1725: 
 1726: @node $ZNEXT()
 1727: @section $ZNEXT
 1728: @cindex $ZNEXT
 1729: @cindex intrinsic functions, $ZNEXT
 1730: @cindex intrinsic functions, implementation-specific
 1731: 
 1732: Purpose unknown.
 1733: 
 1734: @node $ZORDER()
 1735: @section $ZORDER
 1736: @cindex $ZORDER
 1737: @cindex intrinsic functions, $ZORDER
 1738: @cindex intrinsic functions, implementation-specific
 1739: 
 1740: Purpose unknown.
 1741: 
 1742: @node $ZPIECE()
 1743: @section $ZPIECE
 1744: @cindex $ZPIECE
 1745: @cindex intrinsic functions, $ZPIECE
 1746: @cindex intrinsic functions, implementation-specific
 1747: 
 1748: Purpose unknown.
 1749: 
 1750: @node $ZPREVIOUS()
 1751: @section $ZPREVIOUS
 1752: @cindex $ZPREVIOUS
 1753: @cindex intrinsic functions, $ZPREVIOUS
 1754: @cindex intrinsic functions, implementation-specific
 1755: 
 1756: Purpose unknown.
 1757: 
 1758: @node $ZREPLACE()
 1759: @section $ZREPLACE
 1760: @cindex $ZREPLACE
 1761: @cindex intrinsic functions, $ZREPLACE
 1762: @cindex intrinsic functions, implementation-specific
 1763: 
 1764: Replaces all instances of @code{arg2} with @code{arg3} in string @code{arg1}.
 1765: 
 1766: @emph{Syntax}
 1767: @code{$ZREPLACE(@emph{arg1},@emph{arg2},@emph{arg3})}
 1768: 
 1769: @emph{Example}
 1770: 
 1771: @code{SET VAR=$ZREPLACE("CAT","C","B") ; => BAT}
 1772: 
 1773: @node $ZSYNTAX()
 1774: @section $ZSYNTAX
 1775: @cindex $ZSYNTAX
 1776: @cindex intrinsic functions, $ZSYNTAX
 1777: @cindex intrinsic functions, implementation-specific
 1778: 
 1779: @code{$ZSYNTAX} performs a very basic syntax check on @emph{expr V mcode}. Checks only for illegal commands, mismatched brackets, mismatched quotes, missing or surplus arguments, or surplus commas.
 1780: 
 1781: @emph{Syntax}
 1782: @example
 1783: $ZSYNTAX(@emph{expr V mcode})
 1784: @end example
 1785: 
 1786: If no syntax error is found, returns the empty string.
 1787: 
 1788: If a syntax error is found, returns a number indicating the position in @emph{expr V mcode} at which the error was found, followed by a comma, and the FreeM error code that was found.
 1789: 
 1790: @node $ZTIME()
 1791: @section $ZTIME
 1792: @cindex $ZTIME
 1793: @cindex intrinsic functions, $ZTIME
 1794: @cindex intrinsic functions, implementation-specific
 1795: 
 1796: Converts a @code{@ref{$HOROLOG}} string into a human-readable time.
 1797: 
 1798: @emph{Syntax}
 1799: 
 1800: @example
 1801: SET VAR=$ZTIME($H[,@emph{<format-string>}])
 1802: @end example
 1803: 
 1804: The optional @emph{<format-string>} follows the same rules as the UNIX @code{strftime(3)} function. If @emph{<format-string>} is omitted, the value of @code{^$SYSTEM("ZTIME_FORMAT")} is used (typically @code{%X}).
 1805: 
 1806: @node OBJECT Methods
 1807: @chapter OBJECT Methods
 1808: 
 1809: These methods are part of the @code{^%OBJECT} class, from which all FreeM objects ultimately inherit.
 1810: 
 1811: Please note that classes may override @code{^%OBJECT} methods (or methods of any class) in order to provide results more fitting to the class's abstraction goals.
 1812: 
 1813: @menu
 1814: * $$TONUMBER::          Returns the canonical numeric representation of the object.
 1815: * $$TYPE::              Returns the fully-qualified class name of the object.
 1816: * $$VALUE::             Returns the value of the object.
 1817: @end menu
 1818: 
 1819: @node $$TONUMBER
 1820: @section $$TONUMBER
 1821: 
 1822: Returns (when applicable) a canonical numeric representation of the referenced object.
 1823: 
 1824: @emph{Syntax}
 1825: 
 1826: @example
 1827: W $$MYOBJECT.TONUMBER(),!
 1828: @end example
 1829: 
 1830: If no canonical numeric representation of the object is possible, will return the empty string.
 1831: 
 1832: @node $$TYPE
 1833: @section $$TYPE
 1834: 
 1835: Returns the fully-qualified class of the referenced object.
 1836: 
 1837: @emph{Syntax}
 1838: 
 1839: @example
 1840: W $$MYOBJECT.TYPE()
 1841: @end example
 1842: 
 1843: Note that M variables that are created by non-object-oriented means will be objects of the @code{^%STRING} class.
 1844: 
 1845: @node $$VALUE
 1846: @section $$VALUE
 1847: 
 1848: Returns the value of the referenced object.
 1849: 
 1850: @emph{Syntax}
 1851: 
 1852: @example
 1853: W $$MYOBJECT.VALUE()
 1854: @end example
 1855: 
 1856: @node STRING Methods
 1857: @chapter STRING Methods
 1858: 
 1859: These are methods inherent to the @code{^%STRING} class, which is the default class for M variables created without specifying a class.
 1860: 
 1861: @menu
 1862: * $$ASCII::             Return the ASCII code of a character within the string.
 1863: * $$DATA::              Return tree characteristics of the string.
 1864: * $$DISTANCE::          Determine Levenstein distance between this string and another.
 1865: * $$EXTRACT::           Return a substring of the string.
 1866: * $$FIND::              Find the position of a substring within the string.
 1867: * $$FNUMBER::           Format numbers.
 1868: * $$JUSTIFY::           Pad the string to specific positions.
 1869: * $$LENGTH::            Return the length of the string.
 1870: * $$PIECECOUNT::        Return the count of pieces existing between instances of a delimiter.
 1871: * $$PIECE::             Return a delimited subset of the string.
 1872: * $$REPLACE::           Replace instances of a substring within the string.
 1873: * $$REVERSE::           Reverse the order of characters in the string.
 1874: * $$TOLOWER::           Return a lowercase version of the string.
 1875: * $$TOUPPER::           Return an uppercase version of the string.
 1876: * $$TRANSLATE::         Replace individual characters within the string.
 1877: @end menu
 1878: 
 1879: @node $$ASCII
 1880: @section $$ASCII
 1881: 
 1882: Returns the ASCII code of a character within the string. See @ref{$ASCII()}.
 1883: 
 1884: @emph{Syntax}
 1885: 
 1886: @example
 1887: W $$MYOBJECT.ASCII(3)
 1888: @end example
 1889: 
 1890: The above example returns the ASCII code in position 3 of string object @code{MYOBJECT}.
 1891: 
 1892: @node $$DATA
 1893: @section $$DATA
 1894: 
 1895: Returns the value of the @code{$DATA} intrinsic function as performed on the value of the object. See @ref{$DATA()}.
 1896: 
 1897: @emph{Syntax}
 1898: 
 1899: @example
 1900: W $$MYOBJECT.DATA()
 1901: @end example
 1902: 
 1903: @node $$DISTANCE
 1904: @section $$DISTANCE
 1905: 
 1906: Returns the Levenstein distance between the string and another string. See @ref{$ZLSD()}.
 1907: 
 1908: @emph{Syntax}
 1909: 
 1910: @example
 1911: W $$MYOBJECT.DISTANCE("someString")
 1912: @end example
 1913: 
 1914: @node $$EXTRACT
 1915: @section $$EXTRACT
 1916: 
 1917: Returns a substring of the string. See @ref{$EXTRACT()}.
 1918: 
 1919: @emph{Syntax}
 1920: 
 1921: @example
 1922: $$<objectName>.EXTRACT(<start>,<end>)
 1923: @end example
 1924: 
 1925: 
 1926: @node $$FIND
 1927: @section $$FIND
 1928: 
 1929: Finds the character immediately following the first occurence of a substring within a string.
 1930: 
 1931: The first argument is the substring to be located.
 1932: 
 1933: The second argument is the position within the string at which to begin searching.
 1934: 
 1935: See @ref{$FIND()}.
 1936: 
 1937: @node $$FNUMBER
 1938: @section $$FNUMBER
 1939: 
 1940: Formats a number according to a set of formatting codes.
 1941: 
 1942: The argument is a series of formatting codes. See @ref{$FNUMBER()} for details.
 1943: 
 1944: @node $$JUSTIFY
 1945: @section $$JUSTIFY
 1946: 
 1947: Right-justifies a string based on a specified fixed length.
 1948: 
 1949: The first argument is the character length of the output.
 1950: 
 1951: The second argument controls the number of fractional digits to be included in the output, and defaults to the number of digits specified in the first argument.
 1952: 
 1953: See @ref{$JUSTIFY()} for details.
 1954: 
 1955: @node $$LENGTH
 1956: @section $$LENGTH
 1957: 
 1958: Returns the length of the string.
 1959: 
 1960: @node $$PIECECOUNT
 1961: @section $$PIECECOUNT
 1962: 
 1963: Returns the number of items in a list delimited by the character specified in the argument.
 1964: 
 1965: @node $$PIECE
 1966: @section $$PIECE
 1967: 
 1968: @emph{Syntax}
 1969: 
 1970: @code{$PIECE(@emph{d}[,@emph{n}[,@emph{end}]])}
 1971: 
 1972: Accesses the @code{n}th through @code{end} @code{d}-delimited pieces of the string.
 1973: 
 1974: The first argument is the delimiter to be used.
 1975: 
 1976: The optional second argument is the first @code{d}-delimited piece to access, and defaults to @code{1}.
 1977: 
 1978: The optional third argument is the final @code{d}-delimited piece to access, and defaults to the value of the third argument (@code{n}).
 1979: 
 1980: 
 1981: @node $$REPLACE
 1982: @section $$REPLACE
 1983: 
 1984: @emph{Syntax}
 1985: @code{myString.$$REPLACE(@emph{arg1},@emph{arg2})}
 1986: 
 1987: Replaces all instances of @code{arg2} with @code{arg3} in @code{myString}.
 1988: 
 1989: @node $$REVERSE
 1990: @section $$REVERSE
 1991: 
 1992: Returns the reverse of the string.
 1993: 
 1994: @node $$TOLOWER
 1995: @section $$TOLOWER
 1996: 
 1997: Returns an all-lowercase version of the string.
 1998: 
 1999: @node $$TOUPPER
 2000: @section $$TOUPPER
 2001: 
 2002: Returns an all-uppercase version of the string.
 2003: 
 2004: @node $$TRANSLATE
 2005: @section $$TRANSLATE
 2006: 
 2007: Identical to @ref{$TRANSLATE()}, except that the arguments are shifted left by one, and the input string is implicit (the object).
 2008: 
 2009: @node Commands
 2010: @chapter Commands
 2011: @cindex commands
 2012: 
 2013: @menu
 2014: * @@::                                  Execute the following expression as M code.
 2015: * !::                                   Run an external program or command.
 2016: * !!::                                  Launch a subshell from FreeM direct mode.
 2017: * ABLOCK::                              Increment the block counter for one or more event classes.
 2018: * ASTART::                              Enable asynchronous event handling for one or more event classes.
 2019: * ASTOP::                               Disable asynchronous event handling for one or more event classes.
 2020: * AUNBLOCK::                            Decrement the block counter for one or more event classes.
 2021: * BREAK::                               Interrupt a running routine to allow interactive debugging.
 2022: * CLOSE::                               Close an input/output device.
 2023: * DO::                                  Transfer program control to one or more subroutines or introduces a new execution level.
 2024: * ELSE::                                Execute the remainder of a line if @code{@ref{$TEST}} evaluates @emph{false}.
 2025: * FOR::                                 Repeat execution of a line or block of code.
 2026: * GOTO::                                Unconditionally transfer program execution to a supplied @emph{entryref}.
 2027: * HALT::                                Terminate the current FreeM interpreter instance.
 2028: * HANG::                                Temporarily suspend the running program.
 2029: * IF::                                  Execute the remainder of a line if a conditional expression evaluates @emph{true}.
 2030: * JOB::                                 Execute an @emph{entryref} in a child process.
 2031: * KILL::                                Remove data from a local, global, or structured system variable.
 2032: * KSUBSCRIPTS::                         Kill only the descendant subscripts of a local, global, global, or structured system variable.
 2033: * KVALUE::                              Kill only the value of a local, global, or structured system variable.
 2034: * LOCK::                                Control advisory locking for concurrency control.
 2035: * MERGE::                               Merge contents of one local, global, or structured system variable into another.
 2036: * NEW::                                 Introduce a new scope for a specified local variable or intrinsic special variable or instantiate an object.
 2037: * OPEN::                                Open a sequential or socket input/output device.
 2038: * QUIT::                                End execution of the current process level, optionally with return value.
 2039: * READ::                                Read input from an input/output device.
 2040: * SET::                                 Set the value of a local variable, global, intrinsic special variable, or structured system variable.
 2041: * TCOMMIT::                             Commit a transaction.
 2042: * THEN::                                Preserve @code{@ref{$TEST}} until the end of the current line.
 2043: * TROLLBACK::                           Roll back all pending transactions.
 2044: * TSTART::                              Introduce a new transaction processing level.
 2045: * USE::                                 Set the currently-active input/output device.
 2046: * VIEW::                                Modify FreeM internal parameters.
 2047: * WRITE::                               Write output to current input/output device.
 2048: * XECUTE::                              Interpret string as M code.
 2049: * ZASSERT::                             Raise error when a conditional expression evaluates @emph{false}.
 2050: * ZBREAK::                              Enable/disable ZBREAK mode.
 2051: * ZCONST::                              Define a constant that cannot be altered after initial definition.
 2052: * ZGOTO::                               @code{GOTO} with @code{BREAK} control.
 2053: * ZHALT::                               Exit FreeM job with return value.
 2054: * ZINSERT::                             Insert code into routine buffer.
 2055: * ZJOB::                                Invoke job, ignoring any timeouts.
 2056: * ZLOAD::                               Load routine into routine buffer.
 2057: * ZMAP::                                Map a global name to a non-default namespace.
 2058: * ZNEW::                                Unknown.
 2059: * ZPRINT::                              Print contents of routine buffer.
 2060: * ZQUIT::                               Quit multiple stack levels at once.
 2061: * ZREMOVE::                             Remove code from routine buffer.
 2062: * ZSAVE::                               Save routine buffer to disk.
 2063: * ZTHROW::                              Programmatically raise an error condition.
 2064: * ZTRAP::                               Raise a FreeM error.
 2065: * ZUNMAP::                              Remove a mapping of a global to a non-default namespace.
 2066: * ZWATCH::                              Enable or disable watchpoints, or set or clear watchpoints on specified globals, locals, or structured system variables.
 2067: * ZWITH::                               Set prefix for future variable references.
 2068: * ZWRITE::                              Write local variable, global, or structured system variable to @code{@ref{$IO}}.
 2069: @end menu
 2070: 
 2071: @node @@
 2072: @section @@
 2073: @cindex @@
 2074: @cindex commands, @@
 2075: @cindex commands, implementation-specific
 2076: @cindex commands, non-standard
 2077: 
 2078: Executes FreeM code @emph{expr V mcode}.
 2079: 
 2080: @emph{Syntax}
 2081: 
 2082: @example
 2083: @@@emph{expr V mcode}
 2084: @end example
 2085: 
 2086: @emph{Example (Using Variable)}
 2087: 
 2088: @example
 2089: DEFAULT.USER> SET FOO="WRITE ""HELLO WORLD"",!"
 2090: DEFAULT.USER> @@FOO
 2091: 
 2092: HELLO WORLD
 2093: 
 2094: DEFAULT.USER>
 2095: @end example
 2096: 
 2097: @emph{Example (Using String Literal)}
 2098: 
 2099: @example
 2100: DEFAULT.USER> @@"WRITE ""HELLO WORLD"",!"
 2101: 
 2102: HELLO WORLD
 2103: 
 2104: DEFAULT.USER>
 2105: @end example
 2106: 
 2107: @emph{Example (Using Indirection)}
 2108: 
 2109: @example
 2110: DEFAULT.USER> SET FOO="BAR"
 2111: 
 2112: DEFAULT.USER> SET BAR="WRITE ""HELLO WORLD"",!"
 2113: 
 2114: DEFAULT.USER> @@@@FOO
 2115: 
 2116: HELLO WORLD
 2117: 
 2118: DEFAULT.USER>
 2119: @end example
 2120: 
 2121: 
 2122: @node !
 2123: @section !
 2124: @cindex !
 2125: @cindex commands, !
 2126: @cindex commands, external
 2127: @cindex commands, non-standard
 2128: @emph{FreeM Extension}
 2129: 
 2130: Invokes a shell to run @emph{<external-command>} from within FreeM. This temporarily disables @command{SIGALRM} handling in FreeM, which may interrupt the use of event-driven M programming commands including @command{ESTART} and @command{ESTOP}.
 2131: 
 2132: If the @command{<} character is supplied immediately preceding @emph{<external-command>}, FreeM will append the contents of M local variable @code{%} to @emph{<external-command>} as standard input.
 2133: 
 2134: If the @command{>} character is supplied immediately preceding @emph{<external-command>}, FreeM will take the standard output stream of @emph{<external-command>} and store it in M local variable @code{%}.
 2135: 
 2136: @code{%} contains the number of lines in the input or output. @code{%(1)..%(@emph{n})} contains the data for lines 1-@emph{n}.
 2137: 
 2138: @node !!
 2139: @section !!
 2140: @cindex !!
 2141: @cindex commands, !!
 2142: @cindex commands, external
 2143: @cindex commands, non-standard
 2144: @emph{FreeM Extension}
 2145: 
 2146: Launches a subshell within the FreeM direct mode, allowing the user to run operating system commands.
 2147: 
 2148: @example
 2149: DEFAULT.USER> !!
 2150: 
 2151: Type Ctrl-D to exit from the shell
 2152: $ uname -a
 2153: Linux hesperos 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
 2154: $ exit
 2155: 
 2156: DEFAULT.USER> 
 2157: @end example
 2158: 
 2159: 
 2160: @node ABLOCK
 2161: @section ABLOCK
 2162: @cindex ABLOCK
 2163: @cindex commands, ABLOCK
 2164: 
 2165: Increments the event block counter for one or more event classes. While the block counter for an event class is greater than zero, registered event handlers for that event class will not execute, and will instead be queued for later execution once the block counter reaches zero (all blocks removed).
 2166: 
 2167: An implicit @code{ABLOCK} on all event classes occurs when an event handler subroutine is executing. As soon as a @code{QUIT} is reached within an event handler, an implicit @code{ABLOCK} will occur.
 2168: 
 2169: @emph{Syntax}
 2170: 
 2171: @example
 2172:   ABLOCK@emph{:postcondition}
 2173: @end example
 2174: 
 2175: In its argumentless form, @code{ABLOCK} increments the block counter for @emph{all} event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2176: 
 2177: @example
 2178:   ABLOCK@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2179: @end example
 2180: 
 2181: In its inclusive form, @code{ABLOCK} increments the block counters for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2182: 
 2183: @example
 2184:   ABLOCK@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN}
 2185: @end example
 2186: 
 2187: In its exclusive form, @code{ABLOCK} increments the block counters for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2188: 
 2189: 
 2190: @node ASTART
 2191: @section ASTART
 2192: @cindex ASTART
 2193: @cindex commands, ASTART
 2194: 
 2195: Enables asynchronous event handling for one or more event classes.
 2196: 
 2197: @emph{Syntax}
 2198: 
 2199: @example
 2200:   ASTART@emph{:postcondition}
 2201: @end example
 2202: 
 2203: In its argumentless form, @code{ASTART} enables asynchronous event handling for all event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2204: 
 2205: @example
 2206:   ASTART@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2207: @end example
 2208: 
 2209: In its inclusive form, @code{ASTART} enables asynchronous event handling for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2210: 
 2211: @example
 2212:   ASTART@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN})
 2213: @end example
 2214: 
 2215: In its exclusive form, @code{ASTART} enables asynchronous event handling for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2216: 
 2217: @node ASTOP
 2218: @section ASTOP
 2219: @cindex ASTOP
 2220: @cindex commands, ASTOP
 2221: 
 2222: Disables asynchronous event handling for one or more event classes.
 2223: 
 2224: @emph{Syntax}
 2225: 
 2226: @example
 2227:   ASTOP@emph{:postcondition}
 2228: @end example
 2229: 
 2230: In its argumentless form, @code{ASTOP} disables asynchronous event handling for all event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2231: 
 2232: @example
 2233:   ASTOP@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2234: @end example
 2235: 
 2236: In its inclusive form, @code{ASTOP} disables asynchronous event handling for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2237: 
 2238: @example
 2239:   ASTOP@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN})
 2240: @end example
 2241: 
 2242: In its exclusive form, @code{ASTOP} disables asynchronous event handling for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2243: 
 2244: @node AUNBLOCK
 2245: @section AUNBLOCK
 2246: @cindex AUNBLOCK
 2247: @cindex commands, AUNBLOCK
 2248: 
 2249: Decrements the event block counter for one or more event classes.
 2250: 
 2251: @emph{Syntax}
 2252: 
 2253: @example
 2254:   AUNBLOCK@emph{:postcondition}
 2255: @end example
 2256: 
 2257: In its argumentless form, @code{AUNBLOCK} decrements the block counter for @emph{all} event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2258: 
 2259: @example
 2260:   AUNBLOCK@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2261: @end example
 2262: 
 2263: In its inclusive form, @code{AUNBLOCK} decrements the block counters for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2264: 
 2265: @example
 2266:   AUNBLOCK@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN}
 2267: @end example
 2268: 
 2269: In its exclusive form, @code{AUNBLOCK} decrements the block counters for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2270: 
 2271: 
 2272: @node BREAK
 2273: @section BREAK
 2274: @cindex BREAK
 2275: @cindex commands, BREAK
 2276: 
 2277: Interrupts running routine to allow interactive debugging.
 2278: 
 2279: @emph{Syntax}
 2280: 
 2281: @example
 2282: @code{BREAK@emph{:postcondition}}
 2283: @end example
 2284: 
 2285: In its argumentless form, @code{BREAK} suspends execution of running code, provided the optional @emph{postcondition} is @emph{true} or omitted.
 2286: 
 2287: @example
 2288: @code{BREAK@emph{:postcondition} @emph{breakflag}}
 2289: @end example
 2290: 
 2291: @emph{FreeM Extension}
 2292: 
 2293: In its single-argument form, @code{BREAK} enters the interactive debugger or sets @emph{Ctrl-C} handling and error handling characteristics, provided the optional @emph{postcondition} is @emph{true} or omitted.
 2294: The following table enumerates the possible values of @emph{breakflag}
 2295: 
 2296: @table @code
 2297: @item "DEBUG"
 2298: Enters the interactive debugger
 2299: @item 0
 2300: Disables @emph{Ctrl-C} handling
 2301: @item -2
 2302: Enables normal FreeM error handling
 2303: @item 2
 2304: Enables @emph{Digital Standard MUMPS} v2 error handling
 2305: @item @emph{any integer value other than 0, 2, or -2}
 2306: Enables @emph{Ctrl-C} handling
 2307: @end table
 2308: 
 2309: @node CLOSE
 2310: @section CLOSE
 2311: @cindex CLOSE
 2312: @cindex commands, CLOSE
 2313: 
 2314: Closes an input/output device.
 2315: 
 2316: @emph{Syntax}
 2317: 
 2318: @example
 2319: @code{CLOSE@emph{:postcondition}}
 2320: @end example
 2321: 
 2322: In its argumentless form, @code{CLOSE} closes all I/O devices except for device 0 (the @code{HOME} device), provided the optional @emph{postcondition} is @emph{true} or omitted.
 2323: 
 2324: @example
 2325: @code{CLOSE@emph{:postcondition} @emph{channel}}
 2326: @end example
 2327: 
 2328: In its single-argument form, @code{CLOSE} closes the I/O device associated with channel @emph{channel}, provided that @emph{channel} represents a currently-open device, and the optional @emph{postcondition} is @emph{true} or omitted.
 2329: 
 2330: @node DO
 2331: @section DO
 2332: @cindex DO
 2333: @cindex commands, DO
 2334: 
 2335: In its inclusive form, transfers program control to one or more specified subroutines, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Line levels of entryrefs specified in the argument list must be one, or error @code{M14} is raised.
 2336: 
 2337: @emph{Syntax}
 2338: 
 2339: @example
 2340: DO[@emph{:postcondition}] @emph{entryref}[@emph{:postcondition}[,...]]
 2341: @end example
 2342: 
 2343: @cartouche
 2344: @quotation
 2345: @emph{Non-Standard Behavior}
 2346: 
 2347: FreeM allows @code{DO} @emph{entryref}s to follow the format of @code{+@emph{intexpr}}. In this case, the value of @emph{intexpr} will be interpreted as an offset from the first line of the current routine.
 2348: @end quotation
 2349: @end cartouche
 2350: 
 2351: In its argumentless form, transfers control to the following block of code where the line level is one greater than the level at which @code{DO} was encountered, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2352: 
 2353: @emph{Syntax}
 2354: 
 2355: @example
 2356: DO[@emph{:postcondition}]
 2357: @end example
 2358: 
 2359: @node ELSE
 2360: @section ELSE
 2361: @cindex ELSE
 2362: @cindex commands, ELSE
 2363: 
 2364: Executes the remainder of the line of code on which @code{ELSE} is encountered only if @code{$TEST} evaluates to @emph{false}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2365: 
 2366: @emph{Syntax}
 2367: 
 2368: @example
 2369: ELSE[@emph{:postcondition}]
 2370: @end example
 2371: 
 2372: @cartouche
 2373: @quotation
 2374: @emph{Non-Standard Behavior}
 2375: 
 2376: FreeM allows a @emph{postcondition} on @code{ELSE}. While explicitly forbidden in the @emph{Standard}, it was decided that FreeM should allow postconditions everywhere, both for the sake of foolish consistency (the likes of which Emerson warned against), and for the benefit of entrants to a hypothetical future obfuscated M contest, and those with a Machiavellian predisposition to wicked perversions and undue cleverness.
 2377: 
 2378: Using postconditions on @code{ELSE} should be strictly avoided in production code, as they have no practical use, and may contribute to technical debt, hardening of the arteries, hobgoblins, a small mind, a surfeit of logic, climate change, @emph{Daily WTF} rants, or the meltdown of global financial markets.
 2379: @end quotation
 2380: @end cartouche
 2381: 
 2382: @node FOR
 2383: @section FOR
 2384: @cindex FOR
 2385: @cindex commands, FOR
 2386: 
 2387: In its argumentless form, repeatedly executes the remainder of the line on which @code{FOR} was encountered until a @code{QUIT}, @code{GOTO}, or end-of-line is encountered, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2388: 
 2389: @emph{Syntax}
 2390: 
 2391: @example
 2392: FOR[@emph{:postcondition}]
 2393: @end example
 2394: 
 2395: @cartouche
 2396: @quotation
 2397: @emph{Non-Standard Behavior}
 2398: 
 2399: When @code{$DIALECT} is set to @code{FREEM}, FreeM allows a @emph{postcondition} on @code{FOR}. Much like postconditions on @code{ELSE} and @code{IF}, this is explicitly forbidden in the @emph{standard}. The expression contained in the @emph{postcondition} is evaluated on each iteration of the @code{FOR} loop, and if it does not evaluate @emph{true}, the loop will be immediately exited. The effect is roughly similar to @code{WHILE} constructs present in other languages, but absent from standard M.
 2400: 
 2401: As with all non-standard features of FreeM, please exercise caution when using this feature, especially in code that is expected to run in other, less preternaturally-inclined M implementations.
 2402: @end quotation
 2403: @end cartouche
 2404: 
 2405: In its sentinel form, repeatedly executes the remainder of the line and sets a sentinel variable on each iteration, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2406: 
 2407: On the first iteration of the loop, @emph{glvn} will be set to @emph{initalizer-expression}. On each subsequent iteration, @emph{glvn} will be incremented by @emph{increment-expression}, and the loop will terminate when @emph{glvn} meets or exceeds the value of @emph{max-expression}.
 2408: 
 2409: @emph{Syntax}
 2410: 
 2411: @example
 2412: FOR[@emph{:postcondition}] @emph{glvn}=@emph{initializer-expression}:@emph{increment-expression}:@emph{max-expression}
 2413: @end example
 2414: 
 2415: @emph{Example}
 2416: 
 2417: @example
 2418: DEFAULT.USER> FOR I=1:1:10 WRITE I,!
 2419: 
 2420: 1
 2421: 2
 2422: 3
 2423: 4
 2424: 5
 2425: 6
 2426: 7
 2427: 8
 2428: 9
 2429: 10
 2430: 
 2431: DEFAULT.USER> FOR I=2:2:10 WRITE I,!
 2432: 
 2433: 2
 2434: 4
 2435: 6
 2436: 8
 2437: 10
 2438: @end example
 2439: 
 2440: In its explicit parameter form, a variable is set to each of a series of explicit values, once per iteration, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. The loop terminates when no more values are available.
 2441: 
 2442: @emph{Syntax}
 2443: 
 2444: @example
 2445: FOR[@emph{:postcondition}] @emph{glvn}=@emph{expr1}[,..@emph{exprN}]
 2446: @end example
 2447: 
 2448: @emph{Example}
 2449: 
 2450: @example
 2451: DEFAULT.USER> FOR I=60,"FOO",-3,"George",1450,$HOROLOG WRITE I,!
 2452: 
 2453: 60
 2454: FOO
 2455: -3
 2456: George
 2457: 1450
 2458: 66106,52388
 2459: @end example
 2460: 
 2461: @node GOTO
 2462: @section GOTO
 2463: @cindex GOTO
 2464: @cindex commands, GOTO
 2465: 
 2466: Transfers program execution to another line of code, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Attempting to @code{GOTO} a different line level or a different block when the line level of @code{GOTO} is greater than one will raise error @code{M45}.
 2467: 
 2468: @emph{Syntax}
 2469: 
 2470: @example
 2471: GOTO[@emph{:postcondition}] @emph{entryref}
 2472: @end example
 2473: 
 2474: @cartouche
 2475: @quotation
 2476: @emph{Non-Standard Behavior}
 2477: 
 2478: FreeM allows @code{GOTO} @emph{entryref}s to follow the format of @code{+@emph{intexpr}}. In this case, the value of @emph{intexpr} will be interpreted as an offset from the first line of the current routine.
 2479: @end quotation
 2480: @end cartouche
 2481: 
 2482: 
 2483: @node HALT
 2484: @section HALT
 2485: @cindex HALT
 2486: @cindex commands, HALT
 2487: 
 2488: Halts program execution and frees resources allocated during execution, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2489: 
 2490: @emph{Syntax}
 2491: 
 2492: @example
 2493: HALT[@emph{:postcondition}]
 2494: @end example
 2495: 
 2496: @node HANG
 2497: @section HANG
 2498: @cindex HANG
 2499: @cindex commands, HANG
 2500: 
 2501: Temporarily suspends the program for @emph{expr} seconds, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Values of @emph{expr} that are zero or less than zero are ignored.
 2502: 
 2503: @emph{Syntax}
 2504: 
 2505: @example
 2506: HANG[@emph{:postcondition}] @emph{expr}
 2507: @end example
 2508: 
 2509: @cartouche
 2510: @quotation
 2511: @emph{Non-Standard Behavior}
 2512: 
 2513: FreeM supports sub-second values for @emph{expr}.
 2514: @end quotation
 2515: @end cartouche
 2516: 
 2517: @node IF
 2518: @section IF
 2519: @cindex IF
 2520: @cindex commands, IF
 2521: 
 2522: In its argumented form, allows the remainder of the line of code following @code{IF} to execute only if all @emph{tvexpr}s evaluate to @emph{true}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2523: 
 2524: @emph{Syntax}
 2525: @example
 2526: IF[@emph{:postcondition}] @emph{tvexpr}[,...@emph{tvexpr}]
 2527: @end example
 2528: 
 2529: In its argumentless form, allows the remainder of the line of code following @code{IF} to execute only if @code{$TEST} evaluates to @emph{1}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2530: 
 2531: 
 2532: @emph{Syntax}
 2533: @example
 2534: IF[@emph{:postcondition}]  @emph{command...}
 2535: @end example
 2536: 
 2537: @cartouche
 2538: @quotation
 2539: @emph{Style Recommendation}
 2540: 
 2541: In the interest of readability and maintainability, we recommend avoiding the argumentless form of @code{IF} in new code. It is an obsolete relic of an era when routine sizes were severely limited, and can be difficult to spot, as the use of whitespace (@code{IF  @emph{command}}) makes the intent of its use non-obvious at a glance. It is also far too easy to inadvertently delete the extra space, leading to program errors easily avoided otherwise.
 2542: 
 2543: We recommend explicitly checking the value of @code{$TEST} instead, as in @code{IF $TEST @emph{command}} or @code{@emph{command}:$TEST ...}, as this makes the intent immediately clear both to M newcomers and seasoned experts, and sacrifices nothing of value, even on the oldest computer systems where FreeM can be used today.
 2544: @end quotation
 2545: @end cartouche
 2546: 
 2547: @node JOB
 2548: @section JOB
 2549: @cindex JOB
 2550: @cindex commands, JOB
 2551: 
 2552: Executes @emph{entryref} in a separate process, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2553: 
 2554: @emph{Syntax}
 2555: @example
 2556: JOB[@emph{:postcondition}] @emph{entryref}[:@emph{job-parameters}[:@emph{timeout}]]
 2557: @end example
 2558: 
 2559: If @emph{timeout} is supplied, FreeM will set @code{$TEST} to @emph{1} if the child process completes within @emph{timeout} seconds.
 2560: 
 2561: @node KILL
 2562: @section KILL
 2563: @cindex KILL
 2564: @cindex commands, KILL
 2565: 
 2566: In its inclusive form, @code{KILL} deletes the specified @emph{glvn}s and their descendant subscripts, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2567: 
 2568: @emph{Syntax}
 2569: @example
 2570: KILL[@emph{:postcondition}] @emph{glvn}[,...@emph{glvn}]
 2571: @end example
 2572: 
 2573: In its exclusive form, @code{KILL} deletes all local variables @emph{except} for those specified by @emph{lvn}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2574: 
 2575: @emph{Syntax}
 2576: @example
 2577: KILL[@emph{:postcondition}] (@emph{lvn}[,...@emph{lvn}])
 2578: @end example
 2579: 
 2580: In its argumentless form, @code{KILL} deletes all local variables, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2581: 
 2582: @emph{Syntax}
 2583: @example
 2584: KILL[@emph{:postcondition}]
 2585: @end example
 2586: 
 2587: @node KSUBSCRIPTS
 2588: @section KSUBSCRIPTS
 2589: @cindex KSUBSCRIPTS
 2590: @cindex commands, KSUBSCRIPTS
 2591: 
 2592: Kills only the descendant subscripts (but not the data value) of a referenced global, local, or SSVN (where allowed).
 2593: 
 2594: @emph{Syntax}
 2595: 
 2596: @example
 2597: KSUBSCRIPTS@emph{:postcondition} @emph{var1},...
 2598: @end example
 2599: 
 2600: In the above @emph{inclusive} form, @code{KVALUE} will kill the descendant subscripts at each local, global, or SSVN node specified in the list (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave the data value intact.
 2601: 
 2602: @cartouche
 2603: @quotation
 2604: @emph{Note}
 2605: The below @emph{argumentless} and @emph{exclusive} forms of @code{KSUBSCRIPTS} are not implemented in FreeM, as of version 0.64.0-rc1, but are planned for a future release.
 2606: @end quotation
 2607: @end cartouche
 2608: 
 2609: @example
 2610: KSUBSCRIPTS@emph{:postcondition}
 2611: @end example
 2612: 
 2613: In the above @emph{argumentless} form, @code{KSUBSCRIPTS} will kill the descendant subscripts at the root of each local variable (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave data values intact.
 2614: 
 2615: @example
 2616: KSUBSCRIPTS@emph{:postcondition} (@emph{var1},...)
 2617: @end example
 2618: 
 2619: In the above @emph{exclusive} form, @code{KSUBSCRIPTS} will kill the descendant subscripts of all local variables, @emph{with the exception of} those named in the list, provided that the optional @emph{postcondition} is @emph{true} or omitted, while leaving their data values intact.
 2620: 
 2621: 
 2622: @node KVALUE
 2623: @section KVALUE
 2624: @cindex KVALUE
 2625: @cindex commands, KVALUE
 2626: 
 2627: Kills only the data value (but not descendant subscripts) of a referenced global, local, or SSVN (where allowed).
 2628: 
 2629: @emph{Syntax}
 2630: 
 2631: @example
 2632: KVALUE@emph{:postcondition} @emph{var1},...
 2633: @end example
 2634: 
 2635: In the above @emph{inclusive} form, @code{KVALUE} will kill the data values at each local, global, or SSVN node specified in the list (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave descendant subscripts intact.
 2636: 
 2637: @cartouche
 2638: @quotation
 2639: @emph{Note}
 2640: The below @emph{argumentless} and @emph{exclusive} forms of @code{KVALUE} are not implemented in FreeM, as of version 0.64.0-rc1, but are planned for a future release.
 2641: @end quotation
 2642: @end cartouche
 2643: 
 2644: @example
 2645: KVALUE@emph{:postcondition}
 2646: @end example
 2647: 
 2648: In the above @emph{argumentless} form, @code{KVALUE} will kill the data values at the root of each local variable (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave descendant subscripts intact.
 2649: 
 2650: @example
 2651: KVALUE@emph{:postcondition} (@emph{var1},...)
 2652: @end example
 2653: 
 2654: In the above @emph{exclusive} form, @code{KVALUE} will kill the data values of all local variables, @emph{with the exception of} those named in the list, provided that the optional @emph{postcondition} is @emph{true} or omitted, while leaving their descendant subscripts intact.
 2655: 
 2656: @node LOCK
 2657: @section LOCK
 2658: @cindex LOCK
 2659: @cindex commands, LOCK
 2660: 
 2661: Acquires or releases ownership of names.
 2662: 
 2663: In its argumentless form, @code{LOCK} releases ownership of all names previously locked by the current process, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2664: 
 2665: @emph{Syntax}
 2666: @example
 2667: LOCK[@emph{:postcondition}]
 2668: @end example
 2669: 
 2670: In its incremental form, increments or decrements the lock counter for each specified @emph{name}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Ownership of each @emph{name} is considered to be the current process as long as the lock counter for @emph{name} is greater than zero. If @emph{timeout} is specified, FreeM will wait no more than @emph{timeout} seconds in attempting to acquire ownership of @emph{name}.
 2671: 
 2672: If @code{LOCK} succeeds within @emph{timeout}, @code{$TEST} is set to @emph{1}. Otherwise, @code{$TEST} is set to @emph{0}.
 2673: 
 2674: @emph{Syntax}
 2675: @example
 2676: LOCK[@emph{:postcondition}] [+|-]@emph{name}[:@emph{timeout}][,...[+|-]@emph{name}[:@emph{timeout}]]
 2677: @end example
 2678: 
 2679: @emph{Example}
 2680: 
 2681: This example will increment the lock counter for @code{^SNW} and decrement the lock counter for @code{^MJR}.
 2682: 
 2683: @example
 2684: LOCK +^SNW,-^MJR
 2685: @end example
 2686: 
 2687: In its non-incremental form, @code{LOCK} releases all @code{LOCK}s held by the current process, and then attempts to acquire a lock on each @emph{name}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. If @emph{timeout} is supplied, FreeM will attempt to lock @emph{name} for no more than @emph{timeout} seconds.
 2688: 
 2689: If @code{LOCK} succeeds within @emph{timeout}, @code{$TEST} is set to @emph{1}. Otherwise, @code{$TEST} is set to @emph{0}.
 2690: 
 2691: @emph{Syntax}
 2692: @example
 2693: LOCK[@emph{:postcondition}] @emph{name}[:@emph{timeout}][,...@emph{name}[:@emph{timeout}]]
 2694: @end example
 2695: 
 2696: @node MERGE
 2697: @section MERGE
 2698: @cindex MERGE
 2699: @cindex commands, MERGE
 2700: 
 2701: Merges the contents of one global, local, or SSVN subtree to another global, local, or SSVN.
 2702: 
 2703: @emph{Syntax}
 2704: 
 2705: @example
 2706: @code{MERGE A=^$JOB}
 2707: @end example
 2708: 
 2709: The above example will merge the @code{^$JOB} SSVN into the @code{A} local. Note that the FreeM implementation of @code{MERGE} does not yet support multiple merge arguments. Returns error @code{M19} if either the source or the target variable are descendants of each other.
 2710: 
 2711: @node NEW
 2712: @section NEW
 2713: @cindex NEW
 2714: @cindex commands, NEW
 2715: 
 2716: In all forms of @code{NEW}, @emph{name} must be a local variable name or @code{NEW}-able structured or intrinsic system variable.
 2717: 
 2718: In its inclusive form, @code{NEW} saves each specified @emph{name} on the process stack and removes it, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.  When the current stack frame is exited, the previous values are restored.
 2719: 
 2720: @emph{Syntax}
 2721: 
 2722: @example
 2723: NEW[@emph{:postcondition}] @emph{name}[,...@emph{name}]
 2724: @end example
 2725: 
 2726: In its exclusive form, @code{NEW} saves all local variables @emph{except} those named (each @emph{name}) and removes them, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. When the current stack frame is exited, the previous values are restored.
 2727: 
 2728: @emph{Syntax}
 2729: @example
 2730: NEW[@emph{:postcondition}] (@emph{name}[,...@emph{name}])
 2731: @end example
 2732: 
 2733: In its argumentless form, @code{NEW} saves all local variables and removes them, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. When the current stack frame is exited, the previous values are restored.
 2734: 
 2735: @emph{Syntax}
 2736: @example
 2737: NEW@emph{:postcondition} @emph{name}=@emph{expr}
 2738: @end example
 2739: 
 2740: In its initializing form, @code{NEW} stacks variable @emph{name} and sets its value to @emph{expr}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. When the current stack frame is exited, the previous value is restored.
 2741: 
 2742: @emph{Syntax}
 2743: @example
 2744: NEW@emph{:postcondition} @emph{name}=$%@emph{^CLASS}(@emph{initializer-list})
 2745: @end example
 2746: 
 2747: In its object-oriented form, @code{NEW} creates an instance of class @emph{^CLASS} in local variable @emph{name} and calls the constructor of @emph{^CLASS}, passing @emph{initializer-list} as its argument(s).
 2748: 
 2749: @node OPEN
 2750: @section OPEN
 2751: @cindex OPEN
 2752: @cindex commands, OPEN
 2753: 
 2754: Opens sequential or socket I/O devices and files and associates them with a numeric FreeM input/output channel.
 2755: 
 2756: @emph{Syntax (Sequential Files)}
 2757: 
 2758: @example
 2759: @code{OPEN@emph{:postcondition} @emph{channel}:"@emph{filename}/@emph{access-mode}"}
 2760: @end example
 2761: 
 2762: Opens @emph{filename} for reading and/or writing, and associates the file with FreeM I/O channel @emph{channel}, provided that the optional @emph{postcondition} is @emph{true} or omitted.
 2763: The below table lists the valid options for @emph{access-mode}:
 2764: 
 2765: @table @code
 2766: @item r
 2767: Read-only access
 2768: @item w
 2769: Create a new file for write access
 2770: @item a
 2771: Write access; append to existing file
 2772: @item r+
 2773: Read/write access
 2774: @end table
 2775: 
 2776: @cartouche
 2777: @quotation
 2778: @emph{I/O Path}
 2779: 
 2780: You cannot specify a fully-qualified filesystem path in the FreeM @code{OPEN} command. By default, FreeM will assume that @emph{filename} exists in the directory indicated in @code{^$JOB($JOB,"CWD")}. If you wish to
 2781: access files in other directories, you must first set the @emph{I/O Path} in @code{^$JOB($JOB,"IOPATH")}.
 2782: 
 2783: The following example will set the I/O path to @code{/etc}:
 2784: 
 2785: @example
 2786: @code{SET ^$JOB($JOB,"IOPATH")="/etc"}
 2787: @end example
 2788: 
 2789: @end quotation
 2790: @end cartouche
 2791: 
 2792: If @emph{channel} was already @code{OPEN}ed in the current process, calling @code{OPEN} on the same channel again implicitly closes the file or device currently associated with @emph{channel}.
 2793: 
 2794: @emph{Syntax (Network Sockets)}
 2795: 
 2796: Network sockets use a dedicated range of FreeM I/O channels ranging from 100-255. @code{OPEN}ing a socket I/O channel does @emph{not} implicitly connect the socket. Connecting the socket to the specified remote host is accomplished by the @code{/CONNECT} control mnemonic supplied to the @code{USE} command.
 2797: 
 2798: @example
 2799:   OPEN@emph{:postcondition} @emph{socket-channel}:"@emph{hostname-or-address}:@emph{port}:@emph{address-family}:@emph{connection-type}"
 2800: @end example
 2801: 
 2802: @emph{Socket Parameters}
 2803: 
 2804: @table @emph
 2805: 
 2806: @item socket-channel
 2807: The socket I/O channel to use. This must be in the range of 100-255.
 2808: 
 2809: @item hostname-or-address
 2810: The hostname or IP address to connect to. If a hostname is supplied, @code{OPEN} will implictly do a name lookup, the mechanism of which is typically determined by the configuration of @code{/etc/nsswitch.conf} on most UNIX and UNIX-like platforms.
 2811: 
 2812: @item port
 2813: The TCP or UDP port to which the socket will connect on the remote host.
 2814: 
 2815: @item address-family
 2816: The address family to use. Either @emph{IPV4} or @emph{IPV6}.
 2817: 
 2818: @item connection-type
 2819: Which connection type to use. Either @emph{TCP} or @emph{UDP}.
 2820: 
 2821: @end table
 2822: 
 2823: If you do not specify the address family and connection type, they will default to @emph{IPV4} and @emph{TCP}, respectively.
 2824: 
 2825: @node QUIT
 2826: @section QUIT
 2827: @cindex QUIT
 2828: @cindex commands, QUIT
 2829: 
 2830: @code{QUIT} will end execution of the current process level, optionally returning @emph{expr}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2831: 
 2832: @code{QUIT} with @emph{expr} when an argument is not expected will raise error @code{M16}; @code{QUIT} without @emph{expr} when an argument is expected will raise error @code{M17}.
 2833: 
 2834: Argumentless @code{QUIT} may also be used to exit a @code{FOR} loop occurring on the same line.
 2835: 
 2836: @emph{Syntax}
 2837: @example
 2838: QUIT[@emph{:postcondition}] [@emph{expr}]
 2839: @end example
 2840: 
 2841: @node READ
 2842: @section READ
 2843: @cindex READ
 2844: @cindex commands, READ
 2845: 
 2846: The @code{READ} command takes input from I/O channel @code{$IO} and stores it into specified variables, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2847: 
 2848: @emph{Syntax}
 2849: @example
 2850: READ[@emph{:postcondition}] @emph{read-argument}[,...@emph{read-argument}]
 2851: @end example
 2852: 
 2853: Each @emph{read-argument} may be one of the following:
 2854: 
 2855: @table @asis
 2856: 
 2857: @item String Literal
 2858: String literal @emph{read-argument}s will be output to @code{$IO} unmodified.
 2859: 
 2860: @item Format Specifier
 2861: One or more of the following:
 2862: 
 2863: @table @asis
 2864: @item @code{!} (newline)
 2865: Advances the cursor down by one line and returns it to the first column.
 2866: 
 2867: @item @code{#} (form-feed)
 2868: Advances the screen down by @code{$ZROWS} and moves the cursor to the upper-left corner of the screen.
 2869: 
 2870: @item @code{?@emph{n}} (position)
 2871: Advances the cursor and @code{$X} forward to position @emph{n}.
 2872: 
 2873: @end table
 2874: 
 2875: @item Single-Character Read (@code{*@emph{variable-name}[@emph{:timeout}]})
 2876: Reads one character into variable @emph{variable-name}. If the optional @emph{timeout} is specified, will wait @emph{timeout} seconds to retrieve one character. If a character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{1}. If no character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{0}.
 2877: 
 2878: @item Variable-Length Character Read (@code{@emph{variable-name}[@emph{:timeout}]})
 2879: Reads characters into @emph{variable-name} until the character or character pair in @code{^$DEVICE(@emph{io-channel},"OPTIONS","TERMINATOR")} is encountered. If the optional @emph{timeout} is specified, will wait @emph{timeout} seconds to retrieve characters. If characters are read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{1}. If no character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{0}.
 2880: 
 2881: @item Fixed-Length Character Read (@code{@emph{variable-name}#@emph{count}[@emph{:timeout}]})
 2882: Reads @emph{count} characters into @emph{variable-name}. If the optional @emph{timeout} is specified, will wait @emph{timeout} seconds to retrieve characters. If characters are read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{1}. If no character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{0}.
 2883: 
 2884: @item Control Mnemonic (@code{/@emph{control-mnemonic}[@emph{(arg1[,...argN])}]})
 2885: Outputs X3.64 control mnemonic @emph{control-mnemonic} to @code{$IO}. Please see the appendix on X3.64 Control Mnemonics for more information.
 2886: 
 2887: @end table
 2888: 
 2889: @node SET
 2890: @section SET
 2891: @cindex SET
 2892: @cindex commands, SET
 2893: 
 2894: The @code{SET} command places values into one or more variables, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2895: 
 2896: @emph{Syntax}
 2897: @example
 2898: SET[@emph{:postcondition}] @emph{set-argument}[=@emph{expression} | @emph{postfix-operator}][@emph{,...set-argument}[=@emph{expression} | @emph{postfix-operator}]]
 2899: @end example
 2900: 
 2901: Each @emph{set-argument} can be:
 2902: 
 2903: @table @asis
 2904: @item @emph{variable-name}
 2905: A local variable, global variable, writable intrinsic special variable, or writable structured system variable.
 2906: 
 2907: @item @emph{lhs-function}
 2908: @code{$EXTRACT} or @code{$PIECE}.
 2909: @end table
 2910: 
 2911: If any grouping of @emph{set-argument}s is surrounded by parentheses, all @emph{set-argument}s in the parenthesized group will be set to the result of @emph{expression}.
 2912: 
 2913: If @emph{postfix-operator} is used instead of @code{=@emph{expression}}, the results of applying @emph{postfix-operator} to the @emph{set-argument} will be stored in @emph{set-argument}. @emph{postfix-operator} may not be used following a parenthesized group of @emph{set-argument}s.
 2914: 
 2915: @emph{Example (postfix-operator)}
 2916: 
 2917: @example
 2918: SET A++,B-- ; increments A, decrements B
 2919: @end example
 2920: 
 2921: @node TCOMMIT
 2922: @section TCOMMIT
 2923: @cindex TCOMMIT
 2924: @cindex commands, TCOMMIT
 2925: 
 2926: Commits all pending transactions to the data files, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2927: 
 2928: @emph{Syntax}
 2929: @example
 2930: TCOMMIT[@emph{:postcondition}]
 2931: @end example
 2932: 
 2933: @node THEN
 2934: @section THEN
 2935: @cindex THEN
 2936: @cindex commands, THEN
 2937: 
 2938: Saves the value of @code{$TEST} until the end of the current line, restoring it at the end of the current line or when a @code{QUIT} is encountered. @code{THEN} should be used in all new code in conjunction with @code{IF}.
 2939: 
 2940: @emph{Example}
 2941: @example
 2942: IF 1 THEN  WRITE "HELLO!",!
 2943: @end example
 2944: 
 2945: @node TROLLBACK
 2946: @section TROLLBACK
 2947: @cindex TROLLBACK
 2948: @cindex commands, TROLLBACK
 2949: 
 2950: Rolls back all pending transactions for the current process, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2951: 
 2952: @emph{Syntax}
 2953: 
 2954: @example
 2955: TROLLBACK[@emph{:postcondition}]
 2956: @end example
 2957: 
 2958: @node TSTART
 2959: @section TSTART
 2960: @cindex TSTART
 2961: @cindex commands, TSTART
 2962: 
 2963: Introduces a new transaction level, incrementing @code{$TLEVEL}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Any global data file operations encountered when @code{$TLEVEL} is greater than zero will not be committed to the global data files until @code{TCOMMIT} is encountered.
 2964: 
 2965: If a transaction is restartable, variables in the @emph{variables-list} will be restored to their original values on a restart of the transaction.
 2966: 
 2967: @emph{Syntax}
 2968: 
 2969: @example
 2970: TSTART[@emph{:postcondition}] @emph{<variables-list>}:@emph{<transaction-parameters>}
 2971: @end example
 2972: 
 2973: @emph{<variables-list>} can be:
 2974: 
 2975: @table @asis
 2976: 
 2977: @item @code{()}
 2978: Do not save off any local variables. Makes the transaction non-restartable.
 2979: 
 2980: @item @code{*}
 2981: Save off all local variables. Makes the transaction restartable.
 2982: 
 2983: @item @code{@emph{variableName}}
 2984: Saves off only one local variable, @emph{variableName}. Makes the transaction restartable.
 2985: 
 2986: @item @code{(@emph{variableName1},...,@emph{variableNameN})}
 2987: Saves off all local variables listed. Makes the transaction restartable.
 2988: 
 2989: @end table
 2990: 
 2991: @emph{<transaction-parameters>} can be:
 2992: 
 2993: @table @asis
 2994: 
 2995: @item @code{S[ERIAL]}
 2996: Forces ACID properties on the transaction. When @code{SERIAL} is not selected, transactions occur in batch mode, and no attempt is made to guarantee ACID properties.
 2997: 
 2998: @item @code{T[RANSACTIONID]=@emph{transaction-id}}
 2999: Sets the ID of the transaction to @emph{transaction-id}
 3000: 
 3001: @end table
 3002: 
 3003: If you are using more than one transaction parameter, surround all of them in parentheses and separate them with commas, e.g.:
 3004: 
 3005: @example
 3006: TSTART (FOO,BAR):(SERIAL,TRANSACTIONID="FOO")
 3007: @end example
 3008: 
 3009: 
 3010: @node USE
 3011: @section USE
 3012: @cindex USE
 3013: @cindex commands, USE
 3014: 
 3015: Sets @code{$IO} to a particular FreeM I/O channel, allowing @code{READ}s from and @code{WRITE}s to the associated terminal, sequential file, or network socket. Also sets various device parameters.
 3016: 
 3017: @emph{Syntax (Terminal)}
 3018: 
 3019: @example
 3020:   USE@emph{:postcondition} @emph{io-channel}[:(@emph{right-margin}:@emph{input-field-length}:@emph{device-status-word}:@emph{position}:@emph{line-terminator}:@emph{break-key})]
 3021: @end example
 3022: 
 3023: For terminals, @emph{io-channel} must be 0.
 3024: 
 3025: Semantic and functional description of each device parameter TBA.
 3026: 
 3027: @emph{Syntax (Sequential Files)}
 3028: 
 3029: @example
 3030:   USE@emph{:postcondition} @emph{io-channel}[:@emph{seek-position}:@emph{terminator}:@emph{nodelay})]
 3031: @end example
 3032: 
 3033: For sequential files, @emph{io-channel} must be in the range 1-99.
 3034: 
 3035: Semantic and functional description of each device parameter TBA.
 3036: 
 3037: @emph{Syntax (Network Sockets)}
 3038: 
 3039: @example
 3040:   USE@emph{:postcondition} @emph{io-channel}
 3041: @end example
 3042: 
 3043: The above syntax will set @code{$IO} to @emph{io-channel}, directing successive @code{READ}s and @code{WRITE}s to @emph{io-channel}, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3044: 
 3045: @example
 3046:   USE@emph{:postcondition} @emph{io-channel}:/CONNECT
 3047: @end example
 3048: 
 3049: The above syntax will set @code{$IO} to @emph{io-channel}, as in the prior example, but will also attempt to connect to the host and port specified for @emph{io-channel} when it was @code{OPEN}ed. The @code{/CONNECT} control mnemonic is only valid for socket channels whose connection type is @code{TCP}. Using @code{/CONNECT} on a @code{UDP} socket channel will throw @code{SCKAERR} (error code 55).
 3050: 
 3051: For network sockets, @emph{io-channel} must be in the range 100-255.
 3052: 
 3053: @node VIEW
 3054: @section VIEW
 3055: @cindex VIEW
 3056: @cindex commands, VIEW
 3057: 
 3058: Provides write access to various FreeM internal parameters, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3059: 
 3060: @emph{Syntax}
 3061: @example
 3062: VIEW[@emph{:postcondition}] @emph{view-number}[:@emph{view-argument}[:@emph{view-argument}...]]
 3063: @end example
 3064: 
 3065: The @emph{view-number} argument can be one of the following:
 3066: 
 3067: @table @asis
 3068: 
 3069: @item @code{21} - Close All Globals
 3070: Closes all global data files open in the current process. Takes no arguments.
 3071: 
 3072: @emph{Syntax}
 3073: @example
 3074: VIEW 21
 3075: @end example
 3076: 
 3077: @item @code{52} - Set G0 Input Translation Table for @code{$IO}
 3078: 
 3079: @emph{Syntax}
 3080: @example
 3081: VIEW 52:@emph{expr V trantab}
 3082: @end example
 3083: 
 3084: @item @code{53} - Set G0 Output Translation Table for @code{$IO}
 3085: 
 3086: @emph{Syntax}
 3087: @example
 3088: VIEW 53:@emph{expr V trantab}
 3089: @end example
 3090: 
 3091: @item @code{54} - Set G1 Input Translation Table for @code{$IO}
 3092: 
 3093: @emph{Syntax}
 3094: @example
 3095: VIEW 54:@emph{expr V trantab}
 3096: @end example
 3097: 
 3098: @item @code{55} - Set G1 Output Translation Table for @code{$IO}
 3099: 
 3100: @emph{Syntax}
 3101: @example
 3102: VIEW 55:@emph{expr V trantab}
 3103: @end example
 3104: 
 3105: @item @code{62} - Set @code{$RANDOM} Seed Number
 3106: Sets the seed number used by @code{$RANDOM} to @emph{numexpr}.
 3107: 
 3108: @emph{Syntax}
 3109: @example
 3110: VIEW 62:@emph{numexpr}
 3111: @end example
 3112: 
 3113: @item @code{63} - Set @code{$RANDOM} Parameter A
 3114: Sets the number used for @code{$RANDOM} Parameter A to @emph{numexpr}.
 3115: 
 3116: @emph{Syntax}
 3117: @example
 3118: VIEW 63:@emph{numexpr}
 3119: @end example
 3120: 
 3121: @item @code{64} - Set @code{$RANDOM} Parameter B
 3122: Sets the number used for @code{$RANDOM} Parameter B to @emph{numexpr}.
 3123: 
 3124: @emph{Syntax}
 3125: @example
 3126: VIEW 64:@emph{numexpr}
 3127: @end example
 3128: 
 3129: @item @code{65} - Set @code{$RANDOM} Parameter C
 3130: Sets the number used for @code{$RANDOM} Parameter C to @emph{numexpr}.
 3131: 
 3132: @emph{Syntax}
 3133: @example
 3134: VIEW 65:@emph{numexpr}
 3135: @end example
 3136: 
 3137: @item @code{66} - Set or Clear @code{SIGTERM} Handling Flag
 3138: Enables or disables handling of @code{SIGTERM} UNIX signals. If @emph{tvexpr} evaluates to 1 (@emph{true}), @code{SIGTERM} handling will be enabled. Otherwise, @code{SIGTERM} handling will be disabled.
 3139: 
 3140: @emph{Syntax}
 3141: @example
 3142: VIEW 66:@emph{tvexpr}
 3143: @end example
 3144: 
 3145: @item @code{67} - Set or Clear @code{SIGHUP} Handling Flag
 3146: Enables or disables handling of @code{SIGHUP} UNIX signals. If @emph{tvexpr} evaluates to 1 (@emph{true}), @code{SIGHUP} handling will be enabled. Otherwise, @code{SIGHUP} handling will be disabled.
 3147: 
 3148: @emph{Syntax}
 3149: @example
 3150: VIEW 67:@emph{tvexpr}
 3151: @end example
 3152: 
 3153: @item @code{70} - Set @code{$ZSORT}/@code{$ZSYNTAX} Flag
 3154: Selects whether @code{$ZS} resolves to @code{$ZSORT} or @code{$ZSYNTAX}.
 3155: 
 3156: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZSYNTAX}. Otherwise, selects @code{$ZSORT}.
 3157: 
 3158: @emph{Syntax}
 3159: @example
 3160: VIEW 70:@emph{tvexpr}
 3161: @end example
 3162: 
 3163: @item @code{71} - Set @code{$ZNEXT}/@code{$ZNAME} Flag
 3164: Selects whether @code{$ZN} resolves to @code{$ZNEXT} or @code{$ZNAME}.
 3165: 
 3166: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZNAME}. Otherwise, selects @code{$ZNEXT}.
 3167: 
 3168: @emph{Syntax}
 3169: @example
 3170: VIEW 71:@emph{tvexpr}
 3171: @end example
 3172: 
 3173: @item @code{72} - Set @code{$ZPREVIOUS}/@code{$ZPIECE} Flag
 3174: Selects whether @code{$ZP} resolves to @code{$ZPREVIOUS} or @code{$ZPIECE}.
 3175: 
 3176: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZPIECE}. Otherwise, selects @code{$ZPREVIOUS}.
 3177: 
 3178: @emph{Syntax}
 3179: @example
 3180: VIEW 72:@emph{tvexpr}
 3181: @end example
 3182: 
 3183: @item @code{73} - Set @code{$ZDATA}/@code{$ZDATE} Flag
 3184: Selects whether @code{$ZD} resolves to @code{$ZDATA} or @code{$ZDATE}.
 3185: 
 3186: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZDATE}. Otherwise, selects @code{$ZDATA}.
 3187: 
 3188: @emph{Syntax}
 3189: @example
 3190: VIEW 73:@emph{tvexpr}
 3191: @end example
 3192: 
 3193: @item @code{79} - Set Old @code{ZJOB} vs. New @code{ZJOB} Flag
 3194: If @emph{tvexpr} evaluates to @emph{true}, sets the @code{ZJOB} mode to new, otherwise, sets it to old.
 3195: 
 3196: @emph{Syntax}
 3197: @example
 3198: VIEW 79:@emph{tvexpr}
 3199: @end example
 3200: 
 3201: @item @code{80} - Set or Clear 8-Bit Flag
 3202: If @emph{tvexpr} evaluates to @emph{true}, sets FreeM to 8-bit mode. Otherwise, sets FreeM to 7-bit mode.
 3203: 
 3204: @emph{Syntax}
 3205: @example
 3206: VIEW 80:@emph{tvexpr}
 3207: @end example
 3208: 
 3209: @item @code{81} - Set or Clear PF1 Flag
 3210: If @emph{tvexpr} evaluates to @emph{true}, sets the @code{PF1} flag. We do not yet know what this does.
 3211: 
 3212: @emph{Syntax}
 3213: @example
 3214: VIEW 81:@emph{tvexpr}
 3215: @end example
 3216: 
 3217: @item @code{83} - Set or Clear Text in @code{$ZERROR} Flag
 3218: If @emph{tvexpr} evaluates to @emph{true}, descriptive error messages will be included in @code{$ZERROR}. Otherwise, only the short error code (i.e. @emph{ZILLFUN}) will be included in @code{$ZERROR}.
 3219: 
 3220: @emph{Syntax}
 3221: @example
 3222: VIEW 83:@emph{tvexpr}
 3223: @end example
 3224: 
 3225: @item @code{92} - Set Type Mismatch Error Flag on @code{EUR2DEM}
 3226: If @emph{tvexpr} evaluates to @emph{true}, a type mismatch error will be thrown in @code{EUR2DEM} currency conversions in certain situations that we do not yet understand.
 3227: 
 3228: @emph{Syntax}
 3229: @example
 3230: VIEW 92:@emph{tvexpr}
 3231: @end example
 3232: 
 3233: @item @code{93} - Define @code{ZKEY} Production Rule
 3234: We do not know what this does.
 3235: 
 3236: @item @code{96} - Set Global Prefix
 3237: Forces global data filenames to be prefixed with the result of @emph{expr}.
 3238: 
 3239: @emph{Syntax}
 3240: @example
 3241: VIEW 96:@emph{expr V string}
 3242: @end example
 3243: 
 3244: @item @code{97} - Set Global Postfix
 3245: Forces global data filenames to be postfixed with the result of @emph{expr}.
 3246: 
 3247: @emph{Syntax}
 3248: @example
 3249: VIEW 97:@emph{expr V string}
 3250: @end example
 3251: 
 3252: @item @code{98} - Set Routine Extension
 3253: Sets the default extension for M routine filenames to the result of @emph{expr}.
 3254: 
 3255: @emph{Syntax}
 3256: @example
 3257: VIEW 98:@emph{expr V string}
 3258: @end example
 3259: 
 3260: @item @code{101} - Set @code{ierr}
 3261: Sets the FreeM internal @code{ierr} value to @emph{intexpr}. Used by some FreeM polyfills (commands or functions implemented in M code).
 3262: 
 3263: @emph{Syntax}
 3264: @example
 3265: VIEW 101:@emph{intexpr}
 3266: @end example
 3267: 
 3268: @item @code{102} - Set @code{ierr} (Deferred)
 3269: Sets the FreeM internal @code{ierr} value to @emph{intexpr}, but only after the current process stack level is exited. Used by FreeM polyfills to throw an error that will appear to come from the user's own code rather than the polyfill implementation M code.
 3270: 
 3271: @emph{Syntax}
 3272: @example
 3273: VIEW 102:@emph{intexpr}
 3274: @end example
 3275: 
 3276: @item @code{103} - Signal @code{MERGE} to @code{^$WINDOW} Complete
 3277: Signals FreeM's MWAPI implementation that a @code{MERGE} to @code{^$WINDOW} or descendant subscripts thereof has completed.
 3278: 
 3279: @emph{Syntax}
 3280: @example
 3281: VIEW 103[@emph{:subscript}]
 3282: @end example
 3283: 
 3284: @item @code{110} - Set Local @code{$ORDER}/@code{$QUERY} Data Value
 3285: Sets the local variable @code{$ORDER}/@code{$QUERY} data value to the result of @emph{expr}. We're not entirely sure what this is.
 3286: 
 3287: @emph{Syntax}
 3288: @example
 3289: VIEW 110:@emph{expr}
 3290: @end example
 3291: 
 3292: @item @code{111} - Set Global @code{$ORDER}/@code{$QUERY} Data Value
 3293: Sets the global variable @code{$ORDER}/@code{$QUERY} data value to the result of @emph{expr}. We're not entirely sure what this is.
 3294: 
 3295: @emph{Syntax}
 3296: @example
 3297: VIEW 111:@emph{expr}
 3298: @end example
 3299: 
 3300: @item @code{113} - Set @code{termio} Information
 3301: We don't know what this does.
 3302: 
 3303: @item @code{133} - Remember @code{ZLOAD} Directory on @code{ZSAVE}
 3304: We don't know what this does, but it takes a @emph{tvexpr}.
 3305: 
 3306: @emph{Syntax}
 3307: @example
 3308: VIEW 133:@emph{tvexpr}
 3309: @end example
 3310: 
 3311: @end table
 3312: 
 3313: 
 3314: 
 3315: @node WRITE
 3316: @section WRITE
 3317: @cindex WRITE
 3318: @cindex commands, WRITE
 3319: 
 3320: @node XECUTE
 3321: @section XECUTE
 3322: @cindex XECUTE
 3323: @cindex commands, XECUTE
 3324: 
 3325: @node ZASSERT
 3326: @section ZASSERT
 3327: @cindex ZASSERT
 3328: @cindex commands, ZASSERT
 3329: @cindex commands, debugging
 3330: @cindex commands, implementation-specific
 3331: @cindex commands, non-standard
 3332: @emph{FreeM Extension}
 3333: 
 3334: Triggers error @code{ZASSERT} if the supplied truth-valued expression @emph{tvexpr} is @emph{false} (@emph{1} is @emph{true}, and @emph{0} is @emph{false}), and that the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3335: 
 3336: The @code{ZASSERT} error is catchable whether using standard-style, FreeM-style, or DSM 2.0-style error processing.
 3337: 
 3338: @emph{Syntax}
 3339: 
 3340: @example
 3341:  ZASSERT@emph{:postcondition} @emph{<tvexpr>}
 3342: @end example
 3343: 
 3344: @emph{Example}
 3345: 
 3346: @example
 3347: DEFAULT.USER> SET DEBUG=1
 3348: 
 3349: 
 3350: DEFAULT.USER> ZASSERT:DEBUG 1=1
 3351: 
 3352: 
 3353: DEFAULT.USER> ZASSERT:DEBUG 1=0
 3354:  
 3355:  
 3356: >> Error ZASSERT:  programmer assertion failed in SYSTEM::^%SYSINIT  [$STACK = 0]
 3357: >> ZASSERT:DEBUG 1=0
 3358:                    ^
 3359: @end example
 3360: 
 3361: @node ZBREAK
 3362: @section ZBREAK
 3363: @cindex ZBREAK
 3364: @cindex commands, ZBREAK
 3365: @cindex commands, debugging
 3366: @cindex commands, implementation-specific
 3367: @cindex commands, non-standard
 3368: @emph{FreeM Extension}
 3369: 
 3370: Sets or clears the @code{ZBREAK} flag@footnote{NOTE: FreeM team needs to investigate how @code{zbreakon} and @code{zbflag} affect program execution.}, based on the result of evaluating @emph{tvexpr}.
 3371: 
 3372: @emph{Syntax}
 3373: 
 3374: @example
 3375: ZBREAK @emph{tvexpr}
 3376: @end example
 3377: 
 3378: @node ZCONST
 3379: @section ZCONST
 3380: @cindex ZCONST
 3381: @cindex commands, ZCONST
 3382: @cindex commands, non-standard
 3383: @emph{FreeM Extension}
 3384: 
 3385: Defines a local @emph{constant}, or variable that cannot be altered after its initial definition, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3386: 
 3387: Constants must only be locals, and globals are not supported.
 3388: 
 3389: @emph{Syntax}
 3390: 
 3391: @example
 3392: @code{ZCONST@emph{:postcondition} @emph{mref1}=@emph{initial-value1},...,@emph{mrefN}=@emph{initial-valueN}}
 3393: @end example
 3394: 
 3395: @node ZGOTO
 3396: @section ZGOTO
 3397: @cindex ZGOTO
 3398: @cindex commands, ZGOTO
 3399: @cindex commands, implementation-specific
 3400: @cindex commands, non-standard
 3401: @emph{FreeM Extension}
 3402: 
 3403: In its argumented form, enables @code{BREAK} mode and branches unconditionally to @emph{entryref}.
 3404: 
 3405: @emph{Syntax}
 3406: 
 3407: @example
 3408: ZGOTO @emph{entryref}
 3409: @end example
 3410: 
 3411: In its argumented form, resumes execution after a @code{BREAK}.
 3412: 
 3413: @emph{Syntax}
 3414: 
 3415: @example
 3416: ZGOTO
 3417: @end example
 3418: 
 3419: @node ZHALT
 3420: @section ZHALT
 3421: @cindex ZHALT
 3422: @cindex commands, ZHALT
 3423: @cindex commands, implementation-specific
 3424: @cindex commands, non-standard
 3425: @emph{FreeM Extension}
 3426: 
 3427: In its single-argumented form, @code{ZHALT} command is used to exit the FreeM process with a specific return value @emph{intexpr}.
 3428: 
 3429: @emph{Syntax}
 3430: 
 3431: @example
 3432: ZHALT @emph{intexpr}
 3433: @end example
 3434: 
 3435: In its argumentless form, @code{ZHALT} is synonymous with @code{HALT}.
 3436: 
 3437: @emph{Syntax}
 3438: 
 3439: @example
 3440: ZHALT
 3441: @end example
 3442: 
 3443: @node ZINSERT
 3444: @section ZINSERT
 3445: @cindex ZINSERT
 3446: @cindex commands, ZINSERT
 3447: @cindex commands, implementation-specific
 3448: @cindex commands, non-standard
 3449: @emph{FreeM Extension}
 3450: 
 3451: @node ZJOB
 3452: @section ZJOB
 3453: @cindex ZJOB
 3454: @cindex commands, ZJOB
 3455: @cindex commands, implementation-specific
 3456: @cindex commands, non-standard
 3457: @emph{FreeM Extension}
 3458: 
 3459: When @code{ZJOB} is used, the semantics are identical to @code{JOB}, with the exception that the @emph{timeout} is forced to be @code{0}, regardless of what the user specifies.
 3460: 
 3461: For more information, see @code{JOB}.
 3462: 
 3463: @node ZLOAD
 3464: @section ZLOAD
 3465: @cindex ZLOAD
 3466: @cindex commands, ZLOAD
 3467: @cindex commands, implementation-specific
 3468: @cindex commands, non-standard
 3469: @emph{FreeM Extension}
 3470: 
 3471: Loads routine @emph{<routine-name>} into FreeM's routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3472: 
 3473: @emph{Syntax}
 3474: 
 3475: @example
 3476: ZLOAD@emph{:postcondition} @emph{<routine-name>}
 3477: @end example
 3478: 
 3479: 
 3480: @node ZMAP
 3481: @section ZMAP
 3482: @cindex ZMAP
 3483: @cindex commands, ZMAP
 3484: @cindex commands, implementation-specific
 3485: @cindex commands, non-standard
 3486: 
 3487: Maps global name @code{gvn} to be mapped to the non-default namespace @emph{expr V namespace}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3488: 
 3489: @emph{Syntax}
 3490: 
 3491: @example
 3492: ZMAP[@emph{:postcondition}] GLOBAL @emph{gvn}=@emph{expr V namespace}
 3493: @end example
 3494: 
 3495: @node ZNEW
 3496: @section ZNEW
 3497: @cindex ZNEW
 3498: @cindex commands, ZNEW
 3499: @cindex commands, implementation-specific
 3500: @cindex commands, non-standard
 3501: @emph{FreeM Extension}
 3502: 
 3503: @node ZPRINT
 3504: @section ZPRINT
 3505: @cindex ZPRINT
 3506: @cindex commands, ZPRINT
 3507: @cindex commands, implementation-specific
 3508: @cindex commands, non-standard
 3509: @emph{FreeM Extension}
 3510: 
 3511: Prints the contents of the current routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3512: 
 3513: @emph{Syntax}
 3514: 
 3515: @example
 3516: ZPRINT@emph{:postcondition}
 3517: @end example
 3518: 
 3519: @node ZQUIT
 3520: @section ZQUIT
 3521: @cindex ZQUIT
 3522: @cindex commands, ZQUIT
 3523: @cindex commands, implementation-specific
 3524: @cindex commands, non-standard
 3525: @emph{FreeM Extension}
 3526: 
 3527: In its single-argument form, quits from @emph{levels} levels of the stack, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3528: 
 3529: In its argumentless form, quits from @code{$STACK} levels of the stack, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3530: 
 3531: @emph{Syntax}
 3532: 
 3533: @example
 3534: @code{ZQUIT@emph{:postcondition} [@emph{levels}]}
 3535: @end example
 3536: 
 3537: @node ZREMOVE
 3538: @section ZREMOVE
 3539: @cindex ZREMOVE
 3540: @cindex commands, ZREMOVE
 3541: @cindex commands, implementation-specific
 3542: @cindex commands, non-standard
 3543: @emph{FreeM Extension}
 3544: 
 3545: @node ZSAVE
 3546: @section ZSAVE
 3547: @cindex ZSAVE
 3548: @cindex commands, ZSAVE
 3549: @cindex commands, implementation-specific
 3550: @cindex commands, non-standard
 3551: @emph{FreeM Extension}
 3552: 
 3553: 
 3554: @node ZTHROW
 3555: @section ZTHROW
 3556: @cindex ZTHROW
 3557: @cindex commands, ZTHROW
 3558: @cindex commands, non-standard
 3559: @emph{FreeM Extension}
 3560: 
 3561: Raises an error condition as long as the optional @emph{postcondition} is @emph{true} or omitted.
 3562: 
 3563: @emph{Syntax}
 3564: 
 3565: @example
 3566: @code{ZTHROW@emph{:postcondition} @emph{expr V error-code}}
 3567: @end example
 3568: 
 3569: @emph{Example}
 3570: 
 3571: @example
 3572: @code{ZTHROW "M102"}
 3573: @end example
 3574: 
 3575: @node ZTRAP
 3576: @section ZTRAP
 3577: @cindex ZTRAP
 3578: @cindex commands, ZTRAP
 3579: @cindex commands, debugging
 3580: @cindex commands, implementation-specific
 3581: @cindex commands, non-standard
 3582: @emph{FreeM Extension}
 3583: 
 3584: Synonymous with @ref{ZTHROW}.
 3585: 
 3586: @node ZUNMAP
 3587: @section ZUNMAP
 3588: @cindex ZUNMAP
 3589: @cindex commands, ZUNMAP
 3590: @cindex commands, implementation-specific
 3591: @cindex commands, non-standard
 3592: 
 3593: Removes any mapping connecting @emph{gvn} to a non-default namespace, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3594: 
 3595: @emph{Syntax}
 3596: 
 3597: @example
 3598: ZUNMAP GLOBAL @emph{gvn}
 3599: @end example
 3600: 
 3601: @node ZWATCH
 3602: @section ZWATCH
 3603: @cindex ZWATCH
 3604: @cindex commands, ZWATCH
 3605: @cindex commands, debugging
 3606: @cindex commands, implementation-specific
 3607: @cindex commands, non-standard
 3608: @emph{FreeM Extension}
 3609: 
 3610: Sets a watchpoint on a global, local, or SSVN node.
 3611: 
 3612: @emph{Syntax}
 3613: 
 3614: 
 3615: In its @emph{argumentless} form, @code{ZWATCH} toggles watchpoints on and off, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3616: 
 3617: @example
 3618: ZWATCH[@emph{:postcondition}]
 3619: @end example
 3620: 
 3621: In its @emph{inclusive} form, @code{ZWATCH} adds, removes, or examines watchpoints, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3622: 
 3623: A @code{+} adds a new watchpoint to the following variable.
 3624: 
 3625: A @code{-} removes an existing watchpoint for the following variable.
 3626: 
 3627: A @code{?} examines the status of a watchpoint for the following variable.
 3628: 
 3629: @example
 3630: ZWATCH[@emph{:postcondition}] [+|-|?]@emph{var1}...,[+|-|?]@emph{varN}
 3631: @end example
 3632: 
 3633: 
 3634: The following example demonstrates turning watchpoint processing on and adding a watchpoint for global variable @code{^snw(1)}. It then changes the value of @code{^snw(1)}.
 3635: 
 3636: @example
 3637: DEFAULT.USER> ZWATCH
 3638:  
 3639: Watchpoints enabled.
 3640:  
 3641: DEFAULT.USER> ZWATCH +^SNW(1)
 3642:  
 3643: Added '^SNW("1")' to the watchlist.
 3644:  
 3645: DEFAULT.USER> SET ^SNW(1)="new value"
 3646:  
 3647: >> WATCHPOINT:  ^SNW("1") => 'new value' (changed 1 times)
 3648: 
 3649: @end example
 3650: 
 3651: The following example will remove that watchpoint:
 3652: 
 3653: @example
 3654: DEFAULT.USER> ZWATCH -^SNW(1)
 3655:  
 3656: Removed '^SNW("1")' from the watchlist.
 3657:  
 3658: DEFAULT.USER> ZWATCH ?^SNW(1)
 3659:  
 3660: '^SNW("1")' is not being watched.
 3661: @end example
 3662: 
 3663: @node ZWITH
 3664: @section ZWITH
 3665: @cindex ZWITH
 3666: @cindex commands, ZWITH
 3667: @cindex commands, non-standard
 3668: @emph{FreeM Extension}
 3669: 
 3670: NOTE: This command may be deprecated and removed in future FreeM releases.
 3671: 
 3672: Sets a prefix to be applied to all subsequent local variable or constant references.
 3673: 
 3674: @emph{Syntax}
 3675: 
 3676: @example
 3677: @code{ZWITH@emph{:postcondition} @emph{var-prefix}}
 3678: @end example
 3679: 
 3680: In the above single-argument form, sets the @code{$WITH} prefix to @emph{var-prefix}, provided that the optional @emph{postcondition} is either @emph{true} or omitted.
 3681: 
 3682: The @emph{var-prefix} argument may be a string literal or any valid FreeM expression.
 3683: 
 3684: @example
 3685: @code{ZWITH@emph{:postcondition}}
 3686: @end example
 3687: 
 3688: In the above argumentless form, clears the @code{$WITH} prefix, provided the optional @emph{postcondition} is either @emph{true} or omitted. Equivalent to @code{ZWITH ""}.
 3689: 
 3690: 
 3691: 
 3692: 
 3693: 
 3694: 
 3695: 
 3696: 
 3697: @node ZWRITE
 3698: @section ZWRITE
 3699: @cindex ZWRITE
 3700: @cindex commands, ZWRITE
 3701: @cindex commands, implementation-specific
 3702: @cindex commands, non-standard
 3703: @emph{FreeM Extension}
 3704: 
 3705: Writes the names and values of M variables to @code{$IO}.
 3706: 
 3707: @emph{Syntax}
 3708: 
 3709: @example
 3710: ZWRITE@emph{:postcondition}
 3711: @end example
 3712: 
 3713: In the argumentless form, writes the names and values of all local variables to @code{$IO} if the optional @emph{postcondition} is @emph{true} or omitted.
 3714: 
 3715: @example
 3716: ZWRITE@emph{:postcondition} @emph{ArrayName},@dots{}
 3717: @end example
 3718: 
 3719: In the inclusive form, writes the names and values of all local, global, or structured system variables specified in the list of @emph{ArrayName}s to @code{$IO} if the optional @emph{postcondition} is @emph{true} or omitted.
 3720: 
 3721: @example
 3722: ZWRITE@emph{:postcondition} (@emph{ArrayName},@dots{})
 3723: @end example
 3724: 
 3725: In the exclusive form, writes all local variables @emph{except} those specified in the list of @emph{ArrayName}s to @code{$IO} if the optional @emph{postcondition} is @emph{true} or omitted.
 3726: 
 3727: 
 3728: @node Structured System Variables
 3729: @chapter Structured System Variables
 3730: @cindex variables, structured system
 3731: @cindex structured system variables
 3732: @cindex SSVNs
 3733: 
 3734: @menu
 3735: * ^$CHARACTER::                         Character set information.
 3736: * ^$DEVICE::                            Device information.
 3737: * ^$DISPLAY::                           Information about graphic display.
 3738: * ^$EVENT::                             Information supplied about a synchronous or asynchronous event.
 3739: * ^$GLOBAL::                            Information about M globals.
 3740: * ^$JOB::                               Information about and control of FreeM jobs.
 3741: * ^$LOCK::                              Information about the FreeM lock table.
 3742: * ^$OBJECT::                            Information about FreeM objects.
 3743: * ^$ROUTINE::                           Information about FreeM routines.
 3744: * ^$SYSTEM::                            Information about the running system.
 3745: * ^$WINDOW::                            Configuration of MWAPI windows.
 3746: * ^$ZPROCESS::                          Information about and control of system processes.
 3747: * ^$ZRPI::                              Information about and control of Raspberry Pi GPIO pins.
 3748: @end menu
 3749: 
 3750: SSVN subscripts are each described in the following format:
 3751: 
 3752: @table @asis
 3753: @item @code{@emph{<ssvn-subscript-name>}} +/-R +/-U +/-D
 3754: @end table
 3755: 
 3756: The R, U, and D flags represent Read, Update, and Delete. A minus sign indicates that the given operation is @emph{not} allowed, and a plus sign indicates that the given operation @emph{is} allowed.
 3757: 
 3758: @node ^$CHARACTER
 3759: @section ^$CHARACTER
 3760: @cindex ^$CHARACTER
 3761: @cindex structured system variables, ^$CHARACTER
 3762: 
 3763: Exposes character set information. As FreeM currently only supports the @code{M} character set, the first subscript of @code{^$CHARACTER} must always be @code{"M"}.
 3764: 
 3765: The following values for the second subscript are supported:
 3766: 
 3767: @table @asis
 3768: 
 3769: @item @code{IDENT} +R -U -D
 3770: Returns the empty string.
 3771: 
 3772: @item @code{COLLATE} +R -U -D
 3773: Returns the empty string.
 3774: 
 3775: @item @code{INPUT} +R -U -D
 3776: Returns the empty string if the third subscript is @code{M}, otherwise, raises error @code{M38}.
 3777: 
 3778: @item @code{OUTPUT} +R -U -D
 3779: Returns the empty string if the third subscript is @code{M}, otherwise, raises error @code{M38}.
 3780: 
 3781: @end table
 3782: 
 3783: @node ^$DEVICE
 3784: @section ^$DEVICE
 3785: @cindex ^$DEVICE
 3786: @cindex structured system variables, ^$DEVICE
 3787: 
 3788: FreeM implements several important pieces of functionality in the @code{^$DEVICE} SSVN.
 3789: 
 3790: The first subscript of @code{^$DEVICE} represents the I/O channel of an @code{OPEN}ed device.
 3791: 
 3792: The following values for the second subscript are supported:
 3793: 
 3794: @table @asis
 3795: 
 3796: @item @code{$DEVICE}
 3797: Returns the value of @code{$DEVICE} for the specified I/O channel.
 3798: 
 3799: @item @code{$X} +R -U -D
 3800: Returns the horizontal cursor position of a terminal device. Only valid if the I/O channel is @code{0}.
 3801: 
 3802: @item @code{$Y} +R -U -D
 3803: Returns the vertical cursor position of a terminal device. Only valid if the I/O channel is @code{0}.
 3804: 
 3805: @item @code{ROWS} +R -U -D
 3806: Returns the number of character rows on the terminal device. Only valid if the I/O channel is @code{0}.
 3807: 
 3808: @item @code{COLUMNS} +R -U -D
 3809: Returns the number of character columns on the terminal device. Only valid if the I/O channel is @code{0}.
 3810: 
 3811: @item @code{CHARACTER} +R -U -D
 3812: Returns the character set of the specified I/O channel; always @code{M} in the current implementation.
 3813: 
 3814: @item @code{INPUT_BUFFER} +R +U -D
 3815: Returns or sets the contents of the input buffer for the specified I/O channel. Data populated in this node will remain in the buffer until subsequent @code{READ} command(s) remove it. This can be used to perform input buffer stuffing, i.e., to fill out an interactive form programmatically.
 3816: 
 3817: @item @code{NAME} +R -U -D
 3818: Returns the operating system's name for the file, device, or socket attached to the specified I/O channel.
 3819: 
 3820: @item @code{FD} +R -U -D
 3821: Returns the UNIX file descriptor of the specified I/O channel.
 3822: 
 3823: @item @code{MODE} +R -U -D
 3824: Returns one of @code{READ}, @code{WRITE}, @code{READWRITE}, or @code{APPEND}, depending on the mode in which the specified I/O channel was opened.
 3825: 
 3826: @item @code{EOF} +R -U -D
 3827: Returns @code{1} if the I/O channel has encountered an end-of-file condition; @code{0} otherwise. Only valid if the I/O channel is connected to a sequential file.
 3828: 
 3829: @item @code{LENGTH} +R -U -D
 3830: Returns the length of the file connected to the I/O channel. Only valid if the I/O channel is connected to a sequential file.
 3831: 
 3832: @item @code{NAMESPACE} +R -U -D
 3833: Returns the current @emph{mnemonic-space} in use for the referenced I/O channel. Always @code{X364} for terminals and blank for sequential files.
 3834: 
 3835: @item @code{TYPE} +R -U -D
 3836: Returns either @code{1,FILE}, @code{2,SOCKET}, or @code{4,TERMINAL}, depending on the device type associated with the specified I/O channel.
 3837: 
 3838: @item @code{OPTIONS} -R -U -D
 3839: The following subscripts reside beneath @code{^$DEVICE(<io-channel>,"OPTIONS")}, and this subscript may not be accessed without one of the following third-level subscripts being specified:
 3840: 
 3841: @table @asis
 3842: 
 3843: @item @code{DSW} +R +U -D
 3844: Sets or returns the current @emph{Device Status Word} controlling terminal characteristics. Only valid for I/O channel 0.
 3845: 
 3846: @item @code{TERMINATOR} +R +U -D
 3847: Sets or returns the @code{READ} terminator for the specified I/O channel. Must be either @code{$C(13,10)} or @code{$C(10)}. Currently only supported for socket devices (those having an I/O channel of 100-255).
 3848: 
 3849: @item @code{TERMID} +R -U -D
 3850: Returns the type of terminal connected to channel 0. Only valid for I/O channel 0.
 3851: 
 3852: @item @code{ECHO} +R +U -D
 3853: Enables or disables local echo of characters typed in a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 0 of the Device Status Word.
 3854: 
 3855: @item @code{DELMODE} +R +U -D
 3856: Enables or disables visual backspace during a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 2 of the Device Status Word.
 3857: 
 3858: @item @code{ESCAPE} +R +U -D
 3859: Enables or disables escape sequence processing during a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 6 of the Device Status Word.
 3860: 
 3861: @item @code{CONVUPPER} +R +U -D
 3862: Enables or disables automatic conversion to uppercase of alphabetical characters during a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 14 of the Device Status Word.
 3863: 
 3864: @item @code{DELEMPTY} +R +U -D
 3865: Enables or disables the automatic deletion of empty strings supplied to a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 19 of the Device Status Word.
 3866: 
 3867: @item @code{NOCTRLS} +R +U -D
 3868: TBD. Only valid for I/O channel 0. Corresponds to bit 20 of the Device Status Word.
 3869: 
 3870: @item @code{CTRLOPROC} +R +U -D
 3871: Enables or disables @emph{Ctrl-O} processing during @code{READ} commands. Only valid for I/O channel 0. Corresponds to bit 21 of the Device Status Word.
 3872: 
 3873: @item @code{NOTYPEAHEAD} +R +U -D
 3874: Enables or disables typeahead buffering during @code{READ} commands. Only valid for I/O channel 0. Corresponds to bit 25 of the Device Status Word.
 3875: @end table
 3876: @end table
 3877: 
 3878: @emph{Example}
 3879: 
 3880: The following example M code opens @code{/etc/freem.conf} and reads its contents line-by-line until the end of the file is reached.
 3881: 
 3882: @example
 3883:  SET ^$JOB($JOB,"IOPATH")="/etc"   ; set I/O path to /etc
 3884:  OPEN 1:"freem.conf/r" ; open freem.conf for reading
 3885:  ;
 3886:  ; read until we run out of lines
 3887:  ;
 3888:  FOR  USE 1 READ LINE USE 0 QUIT:^$DEVICE(1,"EOF")  D
 3889:  . WRITE LINE,!
 3890:  ;
 3891:  CLOSE 1
 3892:  QUIT
 3893: @end example
 3894: 
 3895: @node ^$DISPLAY
 3896: @section ^$DISPLAY
 3897: @cindex ^$DISPLAY
 3898: @cindex structured system variables, ^$DISPLAY
 3899: 
 3900: Provides information about the specified graphical display. The first subscript corresponds to a display number, which is an integer value, often corresponding to the current value of the @code{$PDISPLAY} ISV.
 3901: 
 3902: The following second-level subscripts and specified descendant subscripts are supported:
 3903: 
 3904: @table @asis
 3905: 
 3906: @item @code{CLIPBOARD} +R +U +D
 3907: Retrieves, sets, or erases the contents of the system clipboard.
 3908: 
 3909: @item @code{PLATFORM} +R -U -D
 3910: Retrieves the name and version of the underlying window system platform.
 3911: 
 3912: @item @code{SIZE} +R -U -D
 3913: Retrieves the display resolution of the specified graphical display. For instance, a 1080p display would have a @code{SIZE} value of @code{1920,1080}.
 3914: 
 3915: @item @code{SPECTRUM} +R -U -D
 3916: Retrieves the color depth (number of colors supported) of the specified graphical display.
 3917: 
 3918: @item @code{COLORTYPE} +R -U -D
 3919: Always returns @code{COLOR}, as monochrome and grayscale displays are not yet supported in FreeM.
 3920: 
 3921: @item @code{UNITS} +R -U -D
 3922: Returns the measurement unit of the specified display, i.e., @code{PIXEL}.
 3923: 
 3924: @item @code{TYPEFACE} +R -U -D
 3925: The third-level subscripts beneath this subscript represent a list of font families available on this display. The fourth level subscript is a list of sizes supported for the specified typeface, or @code{0} for vector typefaces, such as TrueType, OpenType, and Adobe Type 1 fonts.
 3926: 
 3927: @end table
 3928: 
 3929: @node ^$EVENT
 3930: @section ^$EVENT
 3931: @cindex ^$EVENT
 3932: @cindex structured system variables, ^$EVENT
 3933: 
 3934: The @code{^$EVENT} SSVN is not yet implemented.
 3935: 
 3936: @node ^$GLOBAL
 3937: @section ^$GLOBAL
 3938: @cindex ^$GLOBAL
 3939: @cindex structured system variables, ^$GLOBAL
 3940: 
 3941: The @code{^$GLOBAL} structured system variable provides information about M globals. The first-level subscript is a global name, sans the leading caret symbol.
 3942: 
 3943: The following second-level subscripts are supported:
 3944: 
 3945: @table @asis
 3946: 
 3947: @item @code{BYTES} +R -U -D
 3948: Returns the number of bytes this global occupies in fixed storage.
 3949: 
 3950: @item @code{BLOCKS} +R -U -D
 3951: Returns the number of blocks contained in this global.
 3952: 
 3953: @item @code{BLOCKSIZE} +R -U -D
 3954: Returns the size of data blocks for this global. Currently, FreeM only supports 1024-byte blocks.
 3955: 
 3956: @item @code{FILE} +R -U -D
 3957: Returns the full filesystem path to the data file where this global resides in fixed storage.
 3958: 
 3959: @item @code{NAMESPACE} +R +U +D
 3960: Returns or sets the name of the FreeM namespace to which this global belongs. @code{SET}ting this node creates a mapping for the specified global name to a non-default namespace. @code{KILL}ing this node restores the mapping configuration for the specified global to the default.
 3961: 
 3962: @end table
 3963: 
 3964: @node ^$JOB
 3965: @section ^$JOB
 3966: @cindex ^$JOB
 3967: @cindex structured system variables, ^$JOB
 3968: 
 3969: FreeM fully implements @code{^$JOB} per ANSI X11.1-1995, as well as several extensions proposed in the M Millennium Draft Standard.
 3970: 
 3971: The first subscript of @code{^$JOB} represents the @code{$JOB} of the process.
 3972: 
 3973: If you @code{KILL} a first-level subscript of @code{^$JOB}, the @code{SIGTERM} signal will be sent to the corresponding UNIX process, causing pending transactions to be rolled back and the process to be terminated. If the targeted process is in direct mode, the user will be prompted with options of either rolling back or committing any pending transactions.
 3974: 
 3975: The following subscripts are supported:
 3976: 
 3977: @table @asis
 3978: 
 3979: @item @code{GVNDEFAULT} +R +U +D
 3980: Contains a default expression to be evaluated if a global variable access attempt results in an @code{M7} error.
 3981: 
 3982: Equivalent to wrapping all global accesses in @code{$GET(@emph{global-name},@emph{string-expr})}.
 3983: 
 3984: @item @code{LVNDEFAULT} +R +U +D
 3985: Contains a default expression to be evaluated if a local variable access attempt results in an @code{M6} error.
 3986: 
 3987: Equivalent to wrapping all local accesses in @code{$GET(@emph{global-name},@emph{string-expr})}.
 3988: 
 3989: @item @code{LVNQOVAL} +R +U +D
 3990: Contains the data value (if any) at the subscripted local variable reference from the most recent @code{$ORDER} or @code{$QUERY} operation.
 3991: 
 3992: This node is useful for code that uses @code{$ORDER} or @code{$QUERY} heavily in loops that retrieve successive data values, as it will prevent an additional symbol table scan that would result from retrieving the data value in the usual way, thus improving application performance. However, this optimization comes at the cost of compatibility with other M implementations.
 3993: 
 3994: @item @code{GVNQOVAL} +R +U +D
 3995: Contains the data value (if any) at the subscripted global variable reference from the most recent @code{$ORDER} or @code{$QUERY} operation.
 3996: 
 3997: This node is useful for code that uses @code{$ORDER} or @code{$QUERY} heavily in loops that retrieve successive data values, as it will prevent an additional data file scan that would result from retrieving the data value in the usual way, thus improving application performance. However, this optimization comes at the cost of compatibility with other M implementations.
 3998: 
 3999: @item @code{ZCOMMANDS} +R +U -D
 4000: Contains a space-delimited list of @code{Z}-commands to be treated as intrinsic. Any @code{Z}-command not appearing in this list will be treated as a user-defined command.
 4001: 
 4002: For instance, if command @code{ZFOO} does @emph{not} appear in this list, FreeM will attempt to run @code{^%ZFOO} as a subroutine when the @code{ZFOO} command is encountered in program code.
 4003: 
 4004: If you remove a command from this list, you may provide your own private M implementation of the command in the manner described above.
 4005: 
 4006: If an argument is passed to a @code{Z}-command you implement in M, it is made available to your M code in a variable whose name is specified in @code{^$JOB($JOB,"ZCOMMAND_ARGUMENT_NAME")}, which defaults to @code{%}.
 4007: 
 4008: @item @code{PIPE_GLVN} +R +U -D
 4009: Contains an M local or global variable to be used as standard input or standard output for the external shell commands run by @code{!<} and @code{!>}.
 4010: 
 4011: @item @code{ZCOMMAND_ARGUMENT_NAME} +R +U -D
 4012: Returns or sets the variable name in which arguments to user-defined @code{Z}-commands are passed. Defaults to @code{%}.
 4013: 
 4014: @item @code{ZFUNCTIONS} +R +U -D
 4015: Contains a space-delimited list of @code{Z} functions to be treated as intrinsic. Any @code{Z} function not appearing in this list will be treated as a user-defined extrinsic function.
 4016: 
 4017: For instance, if function @code{$ZFOO} does @emph{not} appear in this list, FreeM will attempt to return the value of @code{$$^%ZFOO} called as an extrinsic function.
 4018: 
 4019: If you remove a function from this list, you may provide your own private M implementation of the function in the manner described above.
 4020: 
 4021: @item @code{ZSVS} +R +U -D
 4022: Contains a space-delimited list of @code{Z} special variables to be treated as intrinsic. Any @code{Z} special variable  not appearing in this list will be treated as a user-defined extrinsic function taking no arguments.
 4023: 
 4024: For instance, if the special variable @code{$ZFOO} does @emph{not} appear in this list, FreeM will attempt to return the value of @code{$$^%ZFOO} called as an extrinsic function.
 4025: 
 4026: If you remove a built-in special variable from this list, you may provide your own private M implementation of the special variable in the manner described above.
 4027: 
 4028: @item @code{BREAK_HANDLER} +R +U -D
 4029: Contains M code to be executed when the @code{BREAK} command is run.
 4030: 
 4031: @item @code{ROUTINE_BUFFER_SIZE} +R +U -D
 4032: Returns or sets the number of bytes allocated to each routine buffer. If @code{ROUTINE_BUFFER_AUTO_ADJUST} is set to @code{0}, this determines the maximum size of routines that FreeM will execute.
 4033: 
 4034: @item @code{ROUTINE_BUFFER_COUNT} +R +U -D
 4035: Returns or sets the number of routine buffers that FreeM will store in memory concurrently. Raising this value will increase memory usage, but will also increase performance if your applications call many different routines repeatedly.
 4036: 
 4037: @item @code{ROUTINE_BUFFER_AUTO_ADJUST} +R +U -D
 4038: Determines whether or not the size of routine buffers will be automatically adjusted at runtime. If set to @code{0}, routine buffers will be fixed to the byte size specified in @code{ROUTINE_BUFFER_SIZE} and may be manually resized using @code{ROUTINE_BUFFER_SIZE}. If set to @code{1}, routine buffers will grow automatically as necessary.
 4039: 
 4040: @item @code{SYMBOL_TABLE_SIZE} +R +U -D
 4041: Returns or sets the number of bytes allocated to each of the two FreeM symbol tables. If @code{SYMBOL_TABLE_AUTO_ADJUST} is @code{1}, this value is treated as a default, initial size. If @code{SYMBOL_TABLE_AUTO_ADJUST} is @code{0}, this value controls the fixed size of the two symbol tables.
 4042: 
 4043: @item @code{SYMBOL_TABLE_AUTO_ADJUST} +R +U -D
 4044: Determines whether or not the size of the two FreeM symbol tables will be automatically adjusted at runtime. If set to @code{0}, the symbol table will be fixed to the byte size specified in @code{SYMBOL_TABLE_SIZE} and may be manually resized by modifying @code{SYMBOL_TABLE_SIZE}. If set to @code{1}, the two symbol tables will grow automatically as necessary.
 4045: 
 4046: 
 4047: @item @code{USER_DEFINED_ISV_TABLE_SIZE} +R +U -D
 4048: Returns or sets the number of bytes allocated to the FreeM user-defined intrinsic special variable table. If @code{USER_DEFINED_ISV_TABLE_AUTO_ADJUST} is @code{1}, this value is treated as a default, initial size. If @code{USER_DEFINED_ISV_TABLE_AUTO_ADJUST} is @code{0}, this value controls the fixed byte size of the user-defined intrinsic special variable table.
 4049: 
 4050: @item @code{USER_DEFINED_ISV_TABLE_AUTO_ADJUST} +R +U -D
 4051: Determines whether or not the size of the FreeM user-defined intrinsic special variable table will be automatically adjusted at runtime. If set to @code{0}, the user-defined ISV table will be fixed to the byte size specified in @code{USER_DEFINED_ISV_TABLE_SIZE} and may be manually resized by modifying @code{USER_DEFINED_ISV_TABLE_SIZE}. If set to @code{1}, the user-defined ISV table will grow automatically as necessary.
 4052: 
 4053: @item @code{GVN_UNIQUE_CHARS} +R +U -D
 4054: Returns or sets the number of characters of a global name that make it unique, from 1 to 255.
 4055: 
 4056: @item @code{GVN_CASE_SENSITIVE} +R +U -D
 4057: Returns or sets the case sensitivity of global names. If set to @code{0}, global names are case-insensitive. If set to @code{1}, global names are case-sensitive.
 4058: 
 4059: @item @code{GVN_NAME_SUB_LENGTH} +R +U -D
 4060: Returns or sets the maximum number of characters of a global name plus all of its subscripts, from 1-255.
 4061: 
 4062: @item @code{GVN_SUB_LENGTH} +R +U -D
 4063: Returns or sets the maximum number of characters of a single global subscript, from 1-255.
 4064: 
 4065: @item @code{SINGLE_USER} +R +U -D
 4066: If set to @code{1}, FreeM will skip all file locking operations on globals. If set to @code{0}, FreeM will enforce file locking on both.
 4067: 
 4068: Setting @code{SINGLE_USER} to @code{1} will improve FreeM performance, but you must @emph{ONLY} use this on systems where you are absolutely sure that only one FreeM process will run at any given time, as running multiple instances of FreeM concurrently when any of them are set to @code{SINGLE_USER} mode @emph{will} cause global data corruption.
 4069: 
 4070: @item @code{CHARACTER} +R -U -D
 4071: Returns the character set of the job.
 4072: 
 4073: @item @code{CWD} +R +U -D
 4074: Returns or sets the current working directory of the job.
 4075: 
 4076: @item @code{OPEN} +R -U -D
 4077: The @code{^$JOB($JOB,"OPEN",<channel>} subscripts list the open I/O channels in the specified job.
 4078: 
 4079: @item @code{BERKELEYDB,FLUSH_THRESHOLD} +R +U -D
 4080: Returns or sets the number of write operations that will be cached in the BerkeleyDB global handler prior to flushing BerkeleyDB's cache to disk.
 4081: 
 4082: @item @code{EVENT} +R +U +D
 4083: The subtree contained under @code{^$JOB($J,"EVENT")} defines asynchronous event handlers for the current job. Please see @emph{Asynchronous Event Handling} for more information.
 4084: 
 4085: @item @code{GLOBAL} +R -U -D
 4086: Returns the global environment of the job.
 4087: 
 4088: @item @code{IOPATH} +R +U -D
 4089: Returns or sets the @emph{I/O path} to be used by the @code{OPEN} command.
 4090: 
 4091: @item @code{PRIORITY} +R +U -D
 4092: Returns or sets the @emph{nice} value of the FreeM job.
 4093: 
 4094: @item @code{REVSTR} +R +U -D
 4095: When set to 1, allows @code{$EXTRACT} to accept negative values.
 4096: 
 4097: @item @code{ROUTINE} +R -U -D
 4098: Returns the name of the routine currently being executed by the job.
 4099: 
 4100: @item @code{SYMTAB} +R +U -D
 4101: Returns or sets the current local variable symbol table in use.
 4102: 
 4103: FreeM supports two unique and independent symbol tables, allowing FreeM programs to maintain two independent sets of identically- or differently-named local variables per process.
 4104: 
 4105: The default symbol table is @code{0}, and the alternate symbol table is @code{1}, corresponding to the valid values for @code{^$JOB($JOB,"SYMTAB")}.
 4106: 
 4107: Setting this subscript to values other than @code{0} or @code{1} will result in a @code{ZINVEXPR} error.
 4108: 
 4109: @item @code{$PDISPLAY} +R -U -D
 4110: Returns the value of @code{$PDISPLAY} for the job.
 4111: 
 4112: @item @code{$PRINCIPAL} +R -U -D
 4113: Returns the value of @code{$PRINCIPAL} for the job.
 4114: 
 4115: @item @code{$TLEVEL} +R -U -D
 4116: Returns the current transaction level (value of @code{$TLEVEL} for the job.
 4117: 
 4118: @item @code{$IO} +R -U -D
 4119: Returns the current value of @code{$IO} for the job.
 4120: 
 4121: @item @code{USER} +R -U -D
 4122: Returns the UID of the user owning the job.
 4123: 
 4124: @item @code{GROUP} +R -U -D
 4125: Returns the GID of the group owning the job.
 4126: 
 4127: @item @code{NAMESPACE} +R +U -D
 4128: Returns or sets the name of the job's currently-active namespace.
 4129: 
 4130: @item @code{MATH} +R +U -D
 4131: Returns or sets the mode in which decimal comparisons and arithmetic calculations are conducted. Valid values are @code{FIXED}, for fixed-point decimals having up to 20,000 digits of precision, as determined by the @code{$ZPRECISION} intrinsic special variable, and @code{IEEE754}, to use IEEE 754 floating-point decimals. When in @code{IEEE754} mode, floating-point numbers support up to 16 digits of numeric precision.
 4132: 
 4133: @code{IEEE754} mode will make mathematical calculations significantly faster, especially when accelerated by a floating-point processor, at the expense of precision and accuracy.
 4134: 
 4135: @code{FIXED} mode is recommended for financial calculations, or where precision and accuracy are valued over performance. @code{FIXED} is the default mode of FreeM operation.
 4136: 
 4137: Attempting to @code{SET} this node to values other than @code{FIXED} or @code{IEEE754} will set @code{$ECODE} to @code{M29}.
 4138: 
 4139: @end table
 4140: 
 4141: @node ^$LOCK
 4142: @section ^$LOCK
 4143: @cindex ^$LOCK
 4144: @cindex structured system variables, ^$LOCK
 4145: 
 4146: The first-level subscript of @code{^$LOCK} is a lock name. The value at each node is the PID which owns the lock, a comma, and the lock counter for the locked resource.
 4147: 
 4148: Attempting to @code{SET} or @code{KILL} any node in @code{^$LOCK} will raise error @code{M29}.
 4149: 
 4150: @node ^$OBJECT
 4151: @section ^$OBJECT
 4152: @cindex ^$OBJECT
 4153: @cindex structured system variables, ^$OBJECT
 4154: 
 4155: @node ^$ROUTINE
 4156: @section ^$ROUTINE
 4157: @cindex ^$ROUTINE
 4158: @cindex structured system variables, ^$ROUTINE
 4159: 
 4160: The @code{^$ROUTINE} SSVN exposes a list of routines available in the current FreeM namespace, as well as additional attributes further describing each routine.
 4161: 
 4162: The first-level subscript is the name of a FreeM routine minus the leading caret symbol.
 4163: 
 4164: The following second-level subscripts are supported:
 4165: 
 4166: @table @asis
 4167: 
 4168: @item @code{CHARACTER} +R -U -D
 4169: Returns the character set of the routine.
 4170: 
 4171: @item @code{NAMESPACE} +R -U -D
 4172: Returns the name of the FreeM namespace in which the routine resides.
 4173: 
 4174: @item @code{PATH} +R -U -D
 4175: Returns the full filesystem path to the routine in fixed storage.
 4176: 
 4177: @end table
 4178: 
 4179: @node ^$SYSTEM
 4180: @section ^$SYSTEM
 4181: @cindex ^$SYSTEM
 4182: @cindex structured system variables, ^$SYSTEM
 4183: 
 4184: The @code{^$SYSTEM} SSVN exposes system-level implementation details.
 4185: 
 4186: The following first-level subscripts are supported:
 4187: 
 4188: @table @asis
 4189: 
 4190: @item @code{DEFPSIZE} +R -U -D
 4191: Returns the default size in bytes of the symbol table and routine buffer memory partition.
 4192: 
 4193: @item @code{DEFUDFSVSIZ} +R -U -D
 4194: Returns the default size in bytes of the user-defined intrinsic special variable table.
 4195: 
 4196: @item @code{DEFNSIZE} +R -U -D
 4197: Returns the default size of the @code{NEW} stack, in number of entries.
 4198: 
 4199: @item @code{MAXNO_OF_RBUF} +R -U -D
 4200: Returns the maximum number of routine buffers.
 4201: 
 4202: @item @code{DEFNO_OF_RBUF} +R -U -D
 4203: Returns the default number of routine buffers.
 4204: 
 4205: @item @code{DEFPSIZE0} +R -U -D
 4206: Returns the default size in bytes of each routine buffer.
 4207: 
 4208: @item @code{NO_GLOBLS} +R -U -D
 4209: Returns the maximum number of globals that can be concurrently opened.
 4210: 
 4211: @item @code{NO_OF_GBUF} +R -U -D
 4212: Returns the number of global buffers.
 4213: 
 4214: @item @code{NESTLEVLS} +R -U -D
 4215: Returns the depth of the @code{DO}, @code{FOR}, @code{XECUTE} stack.
 4216: 
 4217: @item @code{PARDEPTH} +R -U -D
 4218: Returns the maximum depth of the parser's parameter stack.
 4219: 
 4220: @item @code{PATDEPTH} +R -U -D
 4221: Returns the maximum number of @emph{patatom}s in each pattern.
 4222: 
 4223: @item @code{TRLIM} +R -U -D
 4224: Returns the trace limit of the @code{BUILTIN} global handler.
 4225: 
 4226: @item @code{ARGS_IN_ESC} +R -U -D
 4227: Returns the maximum number of arguments in a terminal escape sequence.
 4228: 
 4229: @item @code{ZTLEN} +R -U -D
 4230: Returns the maximum length of @code{$ZTRAP}.
 4231: 
 4232: @item @code{FUNLEN} +R -U -D
 4233: Returns the maximum length of the @code{$ZF} (function key) variable.
 4234: 
 4235: @item @code{NAME_LENGTH} +R -U -D
 4236: Returns the maximum length of variable names in the current FreeM build. Compatible with the same SSVN node in @emph{Reference Standard M}
 4237: 
 4238: @item @code{STRING_MAX} +R -U -D
 4239: Returns the maximum length of character strings in the current FreeM build. Compatible with the same SSVN node in @emph{Reference Standard M}
 4240: 
 4241: @item @code{$NEXTOK} +R -U -D
 4242: Returns a value indicating whether or not the @code{$NEXT} intrinsic function is allowed. In FreeM, @code{$NEXT} is always enabled, and this SSVN is provided solely for compatibility with @emph{Reference Standard M}. Thus, this SSVN node always returns @code{1}.
 4243: 
 4244: @item @code{EOK} +R -U -D
 4245: Returns a value indicating whether or not @code{E} notation for exponents is allowed. In FreeM, this feature is always enabled, and this SSVN is provided solely for compatibility with @emph{Reference Standard M}. Thus, this SSVN node always returns @code{1}.
 4246: 
 4247: @item @code{OFFOK} +R -U -D
 4248: Returns a value indicating whether or not offsets are allowed in @code{DO} and @code{GOTO}. In FreeM, this feature is always enabled, and this SSVN is provided solely for compatibility with @emph{Reference Standard M}. Thus, this SSVN node always returns @code{1}.
 4249: 
 4250: @item @code{BIG_ENDIAN} +R -U -D
 4251: Returns a 1 if FreeM is running on a big-endian platform, or a 0 otherwise. Compatible with the same SSVN node in @emph{Reference Standard M}.
 4252: 
 4253: @item @code{NAMESPACE} +R -U -D
 4254: The descendant subscripts of this node list each namespace in the current FreeM environment.
 4255: 
 4256: @item @code{MAPPINGS,GLOBAL} +R -U -D
 4257: Descendant subscripts of this node represent global name mappings set in @code{^$GLOBAL(@emph{gvn},"NAMESPACE")}
 4258: 
 4259: @end table
 4260: 
 4261: @node ^$WINDOW
 4262: @section ^$WINDOW
 4263: @cindex ^$WINDOW
 4264: @cindex structured system variables, ^$WINDOW
 4265: 
 4266: The @code{^$WINDOW} SSVN has no nodes yet defined. However, completing a @code{MERGE} to this SSVN will cause MWAPI-ish things to happen, and further work is proceeding on MWAPI implementation.
 4267: 
 4268: @node ^$ZPROCESS
 4269: @section ^$ZPROCESS
 4270: @cindex ^$ZPROCESS
 4271: @cindex structured system variables, ^$ZPROCESS
 4272: 
 4273: Provides access to @code{procfs}, which is a filesystem-like abstraction for UNIX process metadata contained in @code{/proc}, as well as features for examining and controlling the state of processes external to the FreeM interpreter.
 4274: 
 4275: The first subscript always represents the @emph{process ID} of the external process being acted upon.
 4276: 
 4277: The following values for the second subscript are supported:
 4278: 
 4279: 
 4280: @table @asis
 4281: 
 4282: @item @code{EXISTS} +R -U -D
 4283: Returns 1 if the referenced process exists; 0 otherwise.
 4284: 
 4285: @item @code{ATTRIBUTE} +R -U -D
 4286: Exposes the @code{/proc} files as descendant subscripts, i.e., @code{WRITE ^$ZPROCESS(2900,"ATTRIBUTE","cmdline"),!} would print the initial command line used to invoke process ID 2900. Note that the third subscript (the immediate descendant of the @code{ATTRIBUTE} subscript) is case sensitive.
 4287: 
 4288: @item @code{SIGNAL} -R +U -D
 4289: Allows signals to be sent to the referenced process. The following subscript is an integer value corresponding to the desired signal number. You may obtain a list of signal numbers on most UNIX systems with the command @code{kill -l}.
 4290: 
 4291: The constants @code{%SYS.SIGNAL.HUP}, @code{%SYS.SIGNAL.INT}, @code{%SYS.SIGNAL.KILL}, and @code{%SYS.SIGNAL.TERM} are provided for convenient use of this SSVN subscript.
 4292: 
 4293: @end table
 4294: 
 4295: @node ^$ZRPI
 4296: @section ^$ZRPI
 4297: @cindex ^$ZRPI
 4298: @cindex structured system variables, ^$ZRPI
 4299: 
 4300: The @code{^$ZRPI} structured system variable provides easy access to general-purpose input/output (GPIO) pins on Raspberry Pi single-board computers.
 4301: 
 4302: To initialize the GPIO subsystem, @code{SET ^$ZRPI("INITIALIZE")=1}.
 4303: 
 4304: Individual pins are accessed through @code{^$ZRPI("GPIO",<pin>,...)}, where @code{<pin>} represents the desired pin number. Descendant subscripts of @code{^$ZRPI("GPIO",<pin>)} are as follows:
 4305: 
 4306: @table @asis
 4307: 
 4308: @item @code{MODE} +R +U -D
 4309: Represents the operating mode of the selected pin. One of @code{INPUT}, @code{OUTPUT}, @code{PWM_OUTPUT}, or @code{GPIO_CLOCK}.
 4310: 
 4311: @item @code{DIGITAL} +R +U -D
 4312: Reads or writes the selected pin digitally. The value is limited to @code{1} or @code{0}.
 4313: 
 4314: @item @code{ANALOG} +R +U -D
 4315: Reads or writes the selected pin in an analog fashion. The value represents analog voltage.
 4316: 
 4317: @end table
 4318: 
 4319: @node Operators
 4320: @chapter Operators
 4321: 
 4322: @menu
 4323: * Unary +::                     Force a value to positive.
 4324: * Unary -::                     Force a value to negative.
 4325: * +::                           Add.
 4326: * +=::                          Add and assign.
 4327: * ++::                          Postfix increment.
 4328: * -::                           Subtract.
 4329: * -=::                          Subtract and assign.
 4330: * --::                          Postfix decrement.
 4331: * *::                           Multiply.
 4332: * *=::                          Multiply and assign.
 4333: * /::                           Divide.
 4334: * /=::                          Divide and assign.
 4335: * \::                           Integer divide.
 4336: * \=::                          Integer divide and assign.
 4337: * #::                           Modulo.
 4338: * #=::                          Modulo and assign.
 4339: * **::                          Exponentiate.
 4340: * **=::                         Exponentiate and assign.
 4341: * <::                           Less than.
 4342: * <=::                          Less than or equal to.
 4343: * >::                           Greater than.
 4344: * >=::                          Greater than or equal to.
 4345: * _::                           Concatenate.
 4346: * _=::                          Concatenate and assign.
 4347: * =::                           Equals.
 4348: * [::                           Contains.
 4349: * ]::                           Follows.
 4350: * ]]::                          Sorts after.
 4351: * ?::                           Pattern match.
 4352: * &::                           Logical AND.
 4353: * ! (Operator)::                Logical OR.
 4354: * '::                           Logical NOT.
 4355: * @@ (Operator)::               Indirect
 4356: @end menu
 4357: 
 4358: @node Unary +
 4359: @section Unary +
 4360: @cindex operators, unary +
 4361: 
 4362: Forces a number to positive, whether positive or negative. Also forces numeric coercion of strings.
 4363: 
 4364: @node Unary -
 4365: @section Unary -
 4366: @cindex operators, unary -
 4367: 
 4368: Forces a number to negative, whether positive or negative. Also forces numeric coercion of strings.
 4369: 
 4370: @node +
 4371: @section + (Add)
 4372: @cindex operators, +
 4373: 
 4374: @emph{Syntax}
 4375: 
 4376: @example
 4377: S X=1+2 ; => 3
 4378: @end example
 4379: 
 4380: Adds numbers together.
 4381: 
 4382: @node +=
 4383: @section += (Add/Assign)
 4384: @cindex operators, +=
 4385: 
 4386: @emph{Syntax}
 4387: 
 4388: @example
 4389: S X=5
 4390: S X+=3 ; => 8
 4391: @end example
 4392: 
 4393: Increments the variable on the LHS by the value on the RHS.
 4394: 
 4395: @node ++
 4396: @section ++ (Postfix Increment)
 4397: @cindex operators, ++
 4398: 
 4399: Increments a variable by 1.
 4400: 
 4401: @node -
 4402: @section - (Subtract)
 4403: @cindex operators, -
 4404: 
 4405: Subtracts one number from another.
 4406: 
 4407: @node -=
 4408: @section -= (Subtract/Assign)
 4409: @cindex operators, -=
 4410: 
 4411: @emph{Syntax}
 4412: 
 4413: @example
 4414: S X=5
 4415: S X-=3 ; => 2
 4416: @end example
 4417: 
 4418: Decrements the variable on the LHS by the value on the RHS.
 4419: 
 4420: @node --
 4421: @section -- (Postfix Decrement)
 4422: @cindex operators, --
 4423: 
 4424: Decrements the variable by one.
 4425: 
 4426: @node *
 4427: @section * (Multiply)
 4428: @cindex operators, *
 4429: 
 4430: Multiplies one number by another.
 4431: 
 4432: @node *=
 4433: @section *= (Multiply/Assign)
 4434: @cindex operators, *=
 4435: 
 4436: 
 4437: 
 4438: @node /
 4439: @section / (Divide)
 4440: @cindex operators, /
 4441: 
 4442: @node /=
 4443: @section /= (Divide/Assign)
 4444: @cindex operators, /=
 4445: 
 4446: @node \
 4447: @section \ (Integer Divide)
 4448: @cindex operators, \
 4449: 
 4450: @node \=
 4451: @section \= (Integer Divide/Assign)
 4452: @cindex operators, \=
 4453: 
 4454: @node #
 4455: @section # (Modulo)
 4456: @cindex operators, #
 4457: 
 4458: @node #=
 4459: @section #= (Modulo/Assign)
 4460: @cindex operators, #=
 4461: 
 4462: @node **
 4463: @section ** (Exponentiate)
 4464: @cindex operators, **
 4465: 
 4466: @node **=
 4467: @section **= (Exponentiate/Assign)
 4468: @cindex operators, **=
 4469: 
 4470: @node <
 4471: @section < (Less Than)
 4472: @cindex operators, <
 4473: 
 4474: @node <=
 4475: @section <= (Less Than or Equal To)
 4476: @cindex operators, <=
 4477: 
 4478: @node >
 4479: @section > (Greater Than)
 4480: @cindex operators, >
 4481: 
 4482: @node >=
 4483: @section >= (Greater Than or Equal To)
 4484: @cindex operators, >=
 4485: 
 4486: @node _
 4487: @section _ (Concatenate)
 4488: @cindex operators, _
 4489: 
 4490: @node _=
 4491: @section _= (Concatenate/Assign)
 4492: @cindex operators, _=
 4493: 
 4494: @node =
 4495: @section = (Equals)
 4496: @cindex operators, =
 4497: 
 4498: @node [
 4499: @section [ (Contains)
 4500: @cindex operators, [
 4501: 
 4502: @node ]
 4503: @section ] (Follows)
 4504: @cindex operators, ]
 4505: 
 4506: @node ]]
 4507: @section ]] (Sorts After)
 4508: @cindex operators, ]]
 4509: 
 4510: @node ?
 4511: @section ? (Pattern Match)
 4512: @cindex operators, ?
 4513: 
 4514: @node &
 4515: @section & (Logical AND)
 4516: @cindex operators, &
 4517: 
 4518: @node ! (Operator)
 4519: @section ! (Logical OR)
 4520: @cindex operators, !
 4521: 
 4522: @node '
 4523: @section ' (Logical NOT)
 4524: @cindex operators, '
 4525: 
 4526: @node @@ (Operator)
 4527: @section @@ (Indirect)
 4528: @cindex operators, @@
 4529: 
 4530: @node Routines
 4531: @chapter Routines
 4532: @cindex routines
 4533: 
 4534: A @emph{routine} is a file containing M source code to be processed by FreeM.
 4535: 
 4536: Routines exist within a @emph{namespace} (such as @code{SYSTEM} or @code{USER}), which in turn exist within an @emph{environment} (such as @code{DEFAULT}).
 4537: 
 4538: @menu
 4539: * Routine Naming::              Requirements and conventions for routine names.
 4540: @end menu
 4541: 
 4542: 
 4543: @node Routine Naming
 4544: @section Routine Naming
 4545: The routine's filename follows the format @code{NAME.m}, where @code{NAME} is the name of the routine, and @code{.m} is the filename extension.
 4546: 
 4547: Routine naming rules are as follows:
 4548: 
 4549: @itemize @bullet
 4550: @item Routine names must begin with an upper- or lower-case letter, or a @code{%} sign
 4551: @item Within the routine name, you may have upper-case or lower-case letters or digits
 4552: @item The entire routine name must not be longer than 255 characters
 4553: @end itemize
 4554: 
 4555: Routines whose names begin with @code{%} must be located in the @code{SYSTEM} namespace. Other routines may be located in any namespace.
 4556: 
 4557: @node Types
 4558: @chapter Types
 4559: @cindex types
 4560: @cindex data types
 4561: 
 4562: FreeM supports all @emph{libdatatype} types defined in the former MDC's @emph{Millennium Draft Standard}, with the exception of @code{MATRIX}, and with extensions supporting object-oriented programming. A notable enhancement in FreeM is that the library data types can be used in the @emph{formallist} of any extrinsic function or subroutine; not only in @emph{libraryelement}s.
 4563: 
 4564: @menu
 4565: * BOOLEAN::                     Truth values.
 4566: * COMPLEX::                     Numbers with real and imaginary parts.
 4567: * INTEGER::                     Numbers with no decimal part.
 4568: * REAL::                        Numbers with a decimal part.
 4569: * STRING::                      Arbitrary strings of characters.
 4570: * Custom Types (Classes)::      User-defined, object-oriented types.
 4571: @end menu
 4572: 
 4573: @node BOOLEAN
 4574: @section BOOLEAN
 4575: @cindex data types, BOOLEAN
 4576: @cindex types, BOOLEAN
 4577: 
 4578: The @code{BOOLEAN} type represents any M value that can be interpreted as a truth-value.
 4579: 
 4580: @node COMPLEX
 4581: @section COMPLEX
 4582: @cindex data types, COMPLEX
 4583: @cindex types, COMPLEX
 4584: 
 4585: The @code{COMPLEX} type is a complex number represented as a string in the format @code{@emph{<real-part>}%@emph{<imaginary-part>}}, where @emph{real-part} and @emph{imaginary-part} are both @code{REAL} numbers. See @ref{REAL} for more information.
 4586: 
 4587: FreeM will attempt to interpret any @code{COMPLEX} value according to the usual rules for M canonical numbers, i.e., the string @code{sabc123.345%fbd3.1} would be interpreted as a complex number with the real part being @code{123.345} and the imaginary part being @code{3.1}.
 4588: 
 4589: @node INTEGER
 4590: @section INTEGER
 4591: @cindex data types, INTEGER
 4592: @cindex types, INTEGER
 4593: 
 4594: An @code{INTEGER} is an interpretation of numeric data with any fractional part removed.
 4595: 
 4596: @node REAL
 4597: @section REAL
 4598: @cindex data types, REAL
 4599: @cindex types, REAL
 4600: 
 4601: A @code{REAL} is a numeric interpretation of data including a fractional part.
 4602: 
 4603: @node STRING
 4604: @section STRING
 4605: @cindex data types, STRING
 4606: @cindex types, STRING
 4607: 
 4608: The @code{STRING} is the fundamental FreeM data type. Other types are inferred from the context of their usage.
 4609: 
 4610: @subsection String Rules
 4611: 
 4612: The following rules apply to all FreeM strings:
 4613: 
 4614: @itemize
 4615: @item Must not exceed 255 characters
 4616: @item Must not contain @code{$C(0)}, @code{$C(201)}, or @code{$C(202)}
 4617: @end itemize
 4618: 
 4619: @subsection String Quoting Rules
 4620: Strings in FreeM must be surrounded in double quotes:
 4621: 
 4622: @example
 4623: SET MYSTRING="This is a string literal"
 4624: @end example
 4625: 
 4626: If you want to include double quotes inside of a string, simply double them:
 4627: 
 4628: @example
 4629: SET MYSTRING="This is a ""string literal"" with embedded double quotes"
 4630: @end example
 4631: 
 4632: 
 4633: @node Custom Types (Classes)
 4634: @section Custom Types (Classes)
 4635: @cindex data types, custom
 4636: @cindex types, custom
 4637: @cindex classes
 4638: 
 4639: See @ref{Object-Oriented Programming}.
 4640: 
 4641: @node Globals
 4642: @chapter Globals
 4643: @cindex globals
 4644: @cindex variables, global
 4645: @cindex data
 4646: 
 4647: @menu
 4648: * Globals Overview::            Basics of FreeM persistent storage.
 4649: * Creating Globals::            How to create globals.
 4650: * Removing Globals::            How to remove globals.
 4651: * Global Storage::              How globals are stored.
 4652: @end menu
 4653: 
 4654: @node Globals Overview
 4655: @section Globals Overview
 4656: 
 4657: FreeM supports typical M globals, which are often described as persistent, hierachical sparse arrays. Globals make it relatively simple to include persistent data in an application without requiring the developer to use an external database management system, and offer syntax and semantics so similar to M local variables and structured system variables that moving from one to the other is seamless.
 4658: 
 4659: Each global comprises three elements:
 4660: 
 4661: @itemize @bullet
 4662: @item
 4663: An alphabetic name beginning with a caret (@code{^}) or a caret and a percent sign (@code{^%})
 4664: @item
 4665: Optionally, one or more comma-delimited subscripts, enclosed in parentheses
 4666: @item
 4667: A value of up to 255 characters in length
 4668: @end itemize
 4669: 
 4670: A leading percent sign in the global name will force the named global into the @code{SYSTEM} namespace of the current FreeM environment.
 4671: 
 4672: @node Creating Globals
 4673: @section Creating Globals
 4674: @cindex globals, creating
 4675: 
 4676: To create a global, you can use the @code{SET} command:
 4677: 
 4678: @example
 4679: SET ^MYGLOBAL("foo","bar")="this is the data value"
 4680: @end example
 4681: 
 4682: @node Removing Globals
 4683: @section Removing Globals
 4684: @cindex globals, removing
 4685: 
 4686: To remove an entire global, you can use the @code{KILL} command with the unsubscripted name of the global:
 4687: 
 4688: @example
 4689: KILL ^MYGLOBAL
 4690: @end example
 4691: 
 4692: If you only want to remove part of a global, i.e., beginning at a certain subscript level, use the @code{KILL} command with a subscripted name:
 4693: 
 4694: @example
 4695: KILL ^MYGLOBAL("foo")
 4696: @end example
 4697: 
 4698: This will remove only the @code{"foo"} subscript and all of its children.
 4699: 
 4700: If you only want to remove the data value at a specific subscript level, leaving the subscript itself intact, use @code{KVALUE}:
 4701: 
 4702: @example
 4703: KVALUE ^MYGLOBAL("foo")
 4704: @end example
 4705: 
 4706: @node Global Storage
 4707: @section Global Storage
 4708: @cindex globals, storage
 4709: 
 4710: FreeM globals are stored in @code{$PREFIX/var/freem/@emph{<environment-name>}/@emph{<namespace-name>}/globals} in a binary format.
 4711: 
 4712: Global files have a header of the following format:
 4713: 
 4714: @verbatim
 4715: typedef struct global_header {
 4716:     
 4717:     char magic[5]; /* FRMGL */
 4718:     int format_version;
 4719:     char host_triplet[40];
 4720:     char host_id[256];
 4721:     
 4722:     unsigned long block_size;
 4723:     unsigned long last_transaction_id;
 4724: 
 4725:     long created;
 4726:     long last_backup;
 4727:     
 4728: } global_header;
 4729: @end verbatim
 4730: 
 4731: @node Concurrency Control
 4732: @chapter Concurrency Control
 4733: @cindex concurrency control
 4734: @cindex locking
 4735: @cindex transaction processing
 4736: 
 4737: @menu
 4738: * Concurrency Control Overview::                Basics of concurrency control.
 4739: * Advisory Locks::                              Coordinating access voluntarily.
 4740: * Transaction Processing::                      Ensuring logical consistency.
 4741: @end menu
 4742: 
 4743: @node Concurrency Control Overview
 4744: @section Concurrency Control Overview
 4745: 
 4746: Multitasking, multi-user FreeM applications must concern themselves with conscientious management of concurrent access to globals in order to maintain logical consistency and prevent concurrent reads and writes from conflicting with each other.
 4747: 
 4748: In FreeM, there are two mechanisms provided for managing concurrent global access: @emph{advisory locks}, and @emph{transaction processing}.
 4749: 
 4750: Advisory locks allow applications to voluntarily coordinate concurrent access to globals with the @code{LOCK} command, and require each application to check the @code{LOCK} status prior to accessing a global.
 4751: 
 4752: Transaction processing allows applications to delineate sets of global operations (sets, kills, etc.) as being part of a transaction, in which no operations are performed against the globals contained within the transaction until the transaction is committed. In addition, processes other than the one running the transaction will be forced to wait to access globals for either the duration of the commit phase (@emph{batch mode}), or for the entire duration of the transaction (@emph{serial mode}).
 4753: 
 4754: @node Advisory Locks
 4755: @section Advisory Locks
 4756: 
 4757: @node Transaction Processing
 4758: @section Transaction Processing
 4759: @cindex transaction processing
 4760: 
 4761: FreeM implements a significant subset of the transaction processing features from @emph{ANSI X11.1-1995}. This allows a series of global operations to be conducted all at once, either in batch mode (where concurrent operation is not interrupted until the last possible moment), or in serial mode (where writes are guaranteed to be atomic, consistent, isolated, and durable).
 4762: 
 4763: @subsection Theory of Operation
 4764: 
 4765: FreeM uses a pessimistic concurrency control mechanism for @code{SERIAL} transactions, meaning that any @code{TSTART} command that includes the @code{SERIAL} transaction parameter will cause the process to acquire the transaction processing mutex, which prevents any process but the one holding the mutex from performing any data access (read or write) until either @code{TCOMMIT} or @code{TROLLBACK} is called, either committing or rolling back the transaction, respectively.
 4766: 
 4767: Any transaction in between its @code{TSTART} and @code{TCOMMIT}/@code{TROLLBACK} is said to be @emph{in-flight}. During the in-flight stage, pending global operations are held only in memory and after-image journals.
 4768: 
 4769: FreeM maintains a list of all globals affected during a transaction in-flight. When a @code{TCOMMIT} is reached, FreeM will generate a @emph{checkpoint} of each global data file to be changed by the transaction. These checkpoints allow all FreeM globals to be restored to their pre-transaction state if a @code{TCOMMIT} should fail part of the way through its operation. 
 4770: 
 4771: Checkpoints can have one of two modes:
 4772: 
 4773: @table @asis
 4774: 
 4775: @item @code{CP_REMOVE}
 4776: Used for globals that did not exist prior to the beginning of this transaction. Simply marks the entire global data file for deletion in case of @code{TCOMMIT} failure.
 4777: 
 4778: @item @code{CP_RESTORE}
 4779: Used for globals that @emph{did} exist prior to the beginning of this transaction. In this case, the entire global data file is copied to a new file with a @code{.chk} extension. In cases of @code{TCOMMIT} failure, @code{CP_RESTORE} checkpoint files will be restored over the partially-modified live data file.
 4780: 
 4781: @end table
 4782: 
 4783: The below example shows a few global operations and checkpoints for a transaction in-flight using the @code{trantab} direct-mode command:
 4784: 
 4785: @verbatim
 4786: TL1:DEFAULT.USER> trantab
 4787:  $TLEVEL 1*
 4788:   Operations for Transaction ID: 6ea14aad-b8f1-47f9-9f52-4f513f892bc0 [RESTARTABLE SERIAL]
 4789: 
 4790:    OP. NO.   ACTION         KEY/DATA
 4791:    -------   ------         --------
 4792:    1         SET            ^FOO=3
 4793:    2         KILL           ^FOO
 4794:    3         SET            ^snw=10
 4795:    4         SET            ^BRANDNEW=6
 4796: 
 4797:   Global checkpoints:
 4798: 
 4799:    GLOBAL                        MODE                FILES
 4800:    ------                        ----                -----
 4801:    ^BRANDNEW                     CP_REMOVE           IN:   /usr/local/var/freem/USER/globals/^BRANDNEW
 4802:    ^snw                          CP_RESTORE          IN:   /usr/local/var/freem/USER/globals/^snw
 4803:                                                      OUT:  /usr/local/var/freem/USER/globals/^snw.23390.1.chk
 4804:    ^FOO                          CP_RESTORE          IN:   /usr/local/var/freem/USER/globals/^FOO
 4805:                                                      OUT:  /usr/local/var/freem/USER/globals/^FOO.23390.1.chk
 4806: @end verbatim
 4807: 
 4808: In the above example, @code{IN} files are the live data file that will be overwritten or removed, and @code{OUT} files are the checkpoints themselves. Note that @code{OUT} files are only used for @code{CP_RESTORE} checkpoints.
 4809: 
 4810: @subsection Using Transaction Processing
 4811: 
 4812: To use transactions in FreeM, you need to be familiar with three commands:
 4813: 
 4814: @itemize @bullet
 4815: @item
 4816: @code{TSTART}
 4817: @item
 4818: @code{TCOMMIT}
 4819: @item
 4820: @code{TROLLBACK}
 4821: @end itemize
 4822: 
 4823: With transaction processing, global variable operations occurring between @code{TSTART} and @code{TCOMMIT} commands will be contained within the transaction.
 4824: 
 4825: The atomicity, consistency, isolation, and durability facets of FreeM transaction hinge on the transaction mode.
 4826: 
 4827: @subsubsection BATCH Transactions
 4828: @code{BATCH} transactions offer higher performance, and allow other applications aside from the one doing the transaction to continue normal operations until the transaction is committed with @code{TCOMMIT}. In batch mode, other processes are only locked out of normal operation during the commit phase of the transaction.
 4829: 
 4830: The effect of this is that the operations within the batch transaction will not be interleaved with global writes from other applications, but the entire lifetime of the transaction is not guaranteed to be serialized with respect to the transaction processing activities of other running applications in the environment.
 4831: 
 4832: @subsubsection SERIAL Transactions
 4833: @code{SERIAL} transactions offer full ACID compliance at the expense of multiprocessing performance. In serial mode, a @code{TSTART} blocks all activity from all other FreeM processes in the environment, and this blocking effect is not released until the transaction is committed with @code{TCOMMIT} or rolled back with @code{TROLLBACK} (or due to abnormal conditions in the environment that preclude the successful completion of the transaction).
 4834: 
 4835: @node Local Variables
 4836: @chapter Local Variables
 4837: @cindex variables, local
 4838: @cindex local variables
 4839: 
 4840: @menu
 4841: * Local Variables Overview::            The basics of locals.
 4842: * Creating Local Variables::            Creating locals with SET.
 4843: * Removing Local Variables::            Removing locals with KILL.
 4844: @end menu
 4845: 
 4846: @node Local Variables Overview
 4847: @section Local Variables Overview
 4848: 
 4849: FreeM @emph{local variables} have the same data structure as global variables, but are scoped to a single FreeM process, and stored in memory.
 4850: 
 4851: Each local comprises three elements:
 4852: 
 4853: @itemize @bullet
 4854: @item
 4855: An alphabetic name beginning with a letter or a percent sign (@code{%})
 4856: @item
 4857: Optionally, one or more comma-delimited subscripts, enclosed in parentheses
 4858: @item
 4859: A value of up to 255 characters in length
 4860: @end itemize
 4861: 
 4862: @node Creating Local Variables
 4863: @section Creating Local Variables
 4864: @cindex local variables, creating
 4865: 
 4866: To create a local variable, use the @code{SET} command:
 4867: 
 4868: @example
 4869: SET MYLOCAL("foo","bar")="this is the data value"
 4870: @end example
 4871: 
 4872: @node Removing Local Variables
 4873: @section Removing Local Variables
 4874: @cindex local variables, removing
 4875: 
 4876: To remove an entire local variable, you can use the @code{KILL} command with the unsubscripted name of the variable:
 4877: 
 4878: @example
 4879: KILL MYLOCAL
 4880: @end example
 4881: 
 4882: If you only want to remove part of a local variable, i.e., beginning at a certain subscript level, use the @code{KILL} command with a subscripted name:
 4883: 
 4884: @example
 4885: KILL MYLOCAL("foo")
 4886: @end example
 4887: 
 4888: This will remove only the @code{"foo"} subscript and all of its children.
 4889: 
 4890: If you only want to remove the data value at a specific subscript level, leaving the subscript itself intact, use @code{KVALUE}:
 4891: 
 4892: @example
 4893: KVALUE MYLOCAL("foo")
 4894: @end example
 4895: 
 4896: @node Scoping
 4897: @chapter Scoping
 4898: @cindex scoping
 4899: 
 4900: By default, FreeM local variables and their values are scoped to the entire process, meaning that any function or subroutine can access and modify their values. This can lead to pernicious bugs.
 4901: 
 4902: M provides the @code{NEW} command to work around these issues. When @code{NEW} is called with a local variable as its argument, FreeM will scope the variable to the process stack frame in which the @code{NEW} command occured. When exiting the stack frame (i.e. with the @code{QUIT} command), FreeM will restore the variable to its value prior to being @code{NEW}ed.
 4903: 
 4904: @emph{Example}
 4905: 
 4906: @example
 4907: MYRTN ;
 4908:   S J=1 ; set local variable J to 1
 4909:   W J,! ; this will output "1"
 4910:   D X   ; execute subroutine X
 4911:   W J,! ; this will output "1", as the value of J was restored
 4912:   Q
 4913:   ;;
 4914: X ;
 4915:   N J   ; stack J
 4916:   S J=6 ; set its value to 6
 4917:   W J,! ; this will output "6"
 4918:   Q     ; quit from the subroutine, destroying its stack frame
 4919:   ;;
 4920: @end example
 4921: 
 4922: @section Scoping Considerations for $TEST
 4923: 
 4924: In M, the truth value of comparisons, logic operations, and certain forms of @code{LOCK} is stored in the @code{$TEST} intrinsic special variable, which follows the same rules as any M local variable.
 4925: 
 4926: This is probably the most significant design flaw of the language, as the side effects of logic on @code{$TEST} lead to incredibly difficult bugs. However, M allows @code{$TEST} to be @code{NEW}ed, and FreeM provides the @code{THEN} command@footnote{From MDC Type A extension X11/1998-31} to help in the case of conditionals. @code{THEN} stacks @code{$TEST} to the end of the line.
 4927: 
 4928: When writing new M code in FreeM, we strongly suggest using @code{THEN} as follows:
 4929: 
 4930: @example
 4931: MYRTN ;
 4932:   IF MYVAR=1 THEN DO SUBRT
 4933: @end example
 4934: 
 4935: This is instead of the traditional form:
 4936: 
 4937: @example
 4938: MYRTN ;
 4939:   IF MYVAR=1 DO SUBR
 4940: @end example
 4941: 
 4942: @cartouche
 4943: @quotation
 4944: @emph{Style Recommendation}
 4945: 
 4946: Note that @code{THEN} is not in any currently published version of the @emph{Standard}, but is part of MDC Type A extension X11/1998-31. However, we recommend using @code{THEN} instead of favoring portability, as there is no defensible reason for this incredibly simple feature @emph{not} to be ubiquitous.
 4947: 
 4948: If you use other M implementations, you should bug the implementers to implement @code{THEN}, as it at least partially mitigates an inexcusable flaw in the design of M.
 4949: @end quotation
 4950: @end cartouche
 4951: 
 4952: @node Decision Constructs
 4953: @chapter Decision Constructs
 4954: @cindex decision constructs
 4955: @cindex IF
 4956: @cindex ELSE
 4957: @cindex THEN
 4958: @cindex postconditionals
 4959: 
 4960: @node Branch Constructs
 4961: @chapter Branch Constructs
 4962: @cindex branch constructs
 4963: @cindex DO
 4964: @cindex GOTO
 4965: @cindex JOB
 4966: 
 4967: @node Loop Constructs
 4968: @chapter Loop Constructs
 4969: @cindex loop constructs
 4970: @cindex FOR
 4971: 
 4972: @node Modular Programming
 4973: @chapter Modular Programming
 4974: @cindex modular programming
 4975: @cindex functions, extrinsic
 4976: @cindex subroutines
 4977: 
 4978: @menu
 4979: * Subroutines::         Making sections of code reusable.
 4980: * Extrinsic Functions:: Reusable code that returns a value.
 4981: @end menu
 4982: 
 4983: @node Subroutines
 4984: @section Subroutines
 4985: 
 4986: @node Extrinsic Functions
 4987: @section Extrinsic Functions
 4988: 
 4989: @node Object-Oriented Programming
 4990: @chapter Object-Oriented Programming
 4991: @cindex object-oriented programming
 4992: @cindex programming, object-oriented
 4993: 
 4994: @menu
 4995: * Classes::                             The organizing concept of object-oriented programming.
 4996: * Inheritance::                         Making one class derive from another.
 4997: * Methods::                             Attach code to classes.
 4998: * Public and Private Variables::        Determining accessibility.
 4999: * Instantiating Objects::               Creating instances of classes.
 5000: @end menu
 5001: 
 5002: @node Classes
 5003: @section Classes
 5004: @subsection Class Overview
 5005: 
 5006: A @emph{class} is the primary organizing concept of FreeM support for object-oriented programming, and in FreeM, is simply an M routine with a few special properties:
 5007: 
 5008: @example
 5009: MYCLASS(THIS,INIT):OBJECT ; Constructor for MYCLASS, inherits OBJECT
 5010:   ; two private variables
 5011:   S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1)
 5012:   S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2)
 5013:   Q
 5014:   ;
 5015: DESTROY(THIS) ; This is the destructor
 5016:   Q
 5017: @end example
 5018: 
 5019: The above example demonstrates general class syntax.
 5020: 
 5021: @subsection Constructors
 5022: 
 5023: A @emph{constructor} is an M entry point that is called when a new instance of a class is created.
 5024: 
 5025: A constructor must be the first entry point in a class routine, its tag must match the class/routine name, and it must take two arguments, @code{THIS} and @code{INIT}.
 5026: 
 5027: @code{THIS} represents the instance of the object being accessed, and @code{INIT} represents an initializer that can be used to assign an initial value to the object when instantiating the class.
 5028: 
 5029: A constructor looks like this:
 5030: 
 5031: @example
 5032: %FRACTION(THIS,INIT):OBJECT ;
 5033:    S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1)
 5034:    S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2)
 5035:    Q
 5036: @end example
 5037: 
 5038: @emph{Syntax}
 5039: @example
 5040: @emph{<class-name>}(THIS,INIT)[:@emph{<superclass>}]
 5041: @end example
 5042: 
 5043: In the above example, @emph{<superclass>} represents the name of a class from which this class should inherit. In this case, the @code{FRACTION} class inherits from the @code{OBJECT} class. Note that this is not strictly necessary in this case, as all classes in FreeM automatically inherit from @code{OBJECT}.
 5044: 
 5045: @subsection Destructors
 5046: A @code{destructor} is called when you @code{KILL} an instance variable. Its tag must be @code{DESTROY}, and it must take one argument (@code{THIS}).
 5047: 
 5048: The destructor should be used to clean up any resources used by class methods.
 5049: 
 5050: A destructor looks like this:
 5051: 
 5052: @example
 5053: DESTROY(THIS) ;
 5054:   ; free any resources that should be freed at the end of the object's lifetime
 5055:   Q
 5056: @end example
 5057: 
 5058: @node Inheritance
 5059: @section Inheritance
 5060: 
 5061: Every class you create will automatically inherit the methods and functionality of the @code{OBJECT} class, supplied with FreeM.
 5062: 
 5063: When attempting to call a method, FreeM will first search the class routine for a matching entry point, and then follow the inheritance chain upwards until a matching entry point is found. If the final class in the chain does not have a matching entry point, FreeM will try to find a matching entry point in the @code{OBJECT} class.
 5064: 
 5065: Inheritance is achieved by specifying the name of the superclass in the constructor:
 5066: 
 5067: @example
 5068: CLASS(THIS,INIT):SUPERCLASS
 5069: @end example
 5070: 
 5071: @subsection Runtime Polymorphism
 5072: 
 5073: You can achieve runtime polymorphism by subclassing, and defining methods in the subclass that match the names of existing methods in the superclass. Following FreeM inheritance rules, the overridden method in the subclass will be called, and the method in the superclass will not.
 5074: 
 5075: Note that the overridden method in the subclass can take a different set or number of arguments than the @emph{formallist} of the superclass method would specify.
 5076: 
 5077: @node Methods
 5078: @section Methods
 5079: Class methods are defined as tags with @emph{formallist}s in a class routine, and per the typical FreeM object pattern, must take at least one argument, being @code{THIS} (representing a reference to the object instance being accessed).
 5080: 
 5081: The following class (@code{MYCLASS}) has a constructor, a destructor, and a method called @code{MYMETHOD}:
 5082: 
 5083: @example
 5084: %MYCLASS(THIS,INIT) ;
 5085:   Q THIS
 5086: DESTROY(THIS) ;
 5087:   Q
 5088: MYMETHOD(THIS) ;
 5089:   Q "VALUE"
 5090: @end example
 5091: 
 5092: The dot operator is used to invoke class methods:
 5093: 
 5094: @example
 5095: DEFAULT.USER> N MYOBJ=$#^%MYCLASS("")
 5096: DEFAULT.USER> W MYOBJ.MYMETHOD()
 5097: VALUE
 5098: @end example
 5099: 
 5100: @node Public and Private Variables
 5101: @section Public and Private Variables
 5102: 
 5103: FreeM supports private fields with the @code{:PRIVATE} specifier in the @code{SET} command, enforcing classical object-oriented data encapsulation. The @code{:PUBLIC} specifier is provided for completeness, and is the default.
 5104: 
 5105: The below constructor for a @code{FRACTION} class defines two private fields:
 5106: 
 5107: @example
 5108: %FRACTION(THIS,INIT):OBJECT ;
 5109:    S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1)
 5110:    S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2)
 5111:    Q
 5112: @end example   
 5113: 
 5114: Either of the following commands will create a public field:
 5115: 
 5116: @example
 5117:   S THIS("VARNAM")="Initial Value"
 5118:   S THIS("VARNAM"):PUBLIC="Initial Value"
 5119: @end example
 5120: 
 5121: Attempting to access private fields from outside of the class will raise error condition @code{ZOBJFLDACCV}. 
 5122: 
 5123: @node Instantiating Objects
 5124: @section Instantiating Objects
 5125: 
 5126: To instantiate an object (i.e., create an object from a certain class), you will use the @code{NEW} command as follows:
 5127: 
 5128: @example
 5129: NEW MYSTR=$#^%STRING("myString")
 5130: @end example
 5131: 
 5132: This will create a local variable called MYSTR of type STRING, and initialize it with the value myString. 
 5133: 
 5134: @subsection Determining Object Class
 5135: 
 5136: To determine the class of any FreeM local variable, you will use the @code{$$TYPE()} method:
 5137: 
 5138: @example
 5139: USER> W MYSTR.$$TYPE()
 5140: ^%STRING
 5141: @end example
 5142: 
 5143: The @code{$$TYPE()} method is a member of the @code{OBJECT} class. 
 5144: 
 5145: @node Libraries
 5146: @chapter Libraries
 5147: @cindex libraries
 5148: 
 5149: @node Sequential I/O
 5150: @chapter Sequential I/O
 5151: 
 5152: @node Network I/O
 5153: @chapter Network I/O
 5154: @cindex networks, input and output
 5155: 
 5156: Network I/O in FreeM is supplied through I/O channels 100-255. The normal @code{READ} and @code{WRITE} syntax will work with network sockets, with a few exceptions.
 5157: 
 5158: @section Opening and Connecting a Client Socket
 5159: @cindex networks, opening and connecting client sockets
 5160: 
 5161: To open a client socket and connect to it, you will need to call the @code{OPEN} command and the @code{USE} command:
 5162: 
 5163: @example
 5164:   ;
 5165:   ; Set socket read terminator to LF
 5166:   ;
 5167:   SET ^$DEVICE(100,"OPTIONS","TERMINATOR")=$C(10)
 5168:   ;
 5169:   ; Open an IPv4 TCP socket to mail.mydomain.com on port 25 (SMTP)
 5170:   ; and connect to it
 5171:   ;
 5172:   OPEN 100:"mail.mydomain.com:25:IPV4:TCP"
 5173:   USE 100:/CONNECT
 5174:   ;
 5175:   ; Read a line of input from the remote host and write it to the terminal
 5176:   ;
 5177:   NEW LINE
 5178:   READ LINE
 5179:   USE 0
 5180:   WRITE LINE,!
 5181:   ;
 5182:   ; CLOSE the socket and disconnect
 5183:   ;
 5184:   CLOSE 100
 5185:   QUIT
 5186: @end example
 5187: 
 5188: @node Extended Global References
 5189: @chapter Extended Global References
 5190: @cindex global references, extended
 5191: @cindex extended global references
 5192: 
 5193: @section Standard Extended Global References
 5194: @cindex extended global references, standard
 5195: 
 5196: FreeM supports extended global references, allowing the user to access globals in namespaces other than the current default namespace and the @code{SYSTEM} namespace, without switching to the other namespace.
 5197: 
 5198: For example, if you are in the @code{USER} namespace, the following code will print the value of @code{^VA(200,0)} in the @code{VISTA} namespace:
 5199: 
 5200: @example
 5201:   WRITE ^|"VISTA"|VA(200,0),!
 5202: @end example
 5203: 
 5204: You may also use an expression that resolves to a string containing a valid namespace name:
 5205: 
 5206: @example
 5207:   SET NS="VISTA"
 5208:   WRITE ^|NS|VA(200,0),!
 5209: @end example  
 5210: 
 5211: @node Global Aliasing
 5212: @chapter Global Aliasing
 5213: @cindex aliasing, global
 5214: @cindex globals, aliasing
 5215: 
 5216: FreeM provides the ability to set alternative names for M global variables.
 5217: 
 5218: To create an alias of @code{^FOO} named @code{^BAR}, use the following command:
 5219: 
 5220: @example
 5221:   SET ^$JOB($JOB,"ALIASES","^BAR")="^FOO"
 5222: @end example
 5223: 
 5224: If such an alias is set, any reference to global variable @code{^BAR} will affect @code{^FOO} instead of @code{^BAR} until @code{^$JOB($JOB,"ALIASES","^BAR")} is @code{KILL}ed. If @code{^BAR} existed prior to the definition of this alias, its data will be unavailable to and unaffected by application code.  
 5225: 
 5226: @node Global Mappings
 5227: @chapter Global Mappings
 5228: @cindex mappings, global
 5229: @cindex globals, mapping
 5230: 
 5231: FreeM supports creating persistent mappings through which arbitrary global names may be mapped to specific namespaces. This allows non-@code{%} globals to be stored in the @code{SYSTEM} namespace, or @code{%} globals to be stored in non-@code{SYSTEM} namespaces.
 5232: 
 5233: To map the @code{^FOO} global to the @code{SYSTEM} namespace, any of the following will work:
 5234: 
 5235: @example
 5236:   MAP GLOBAL ^FOO="SYSTEM"
 5237:   SET ^$GLOBAL("FOO","NAMESPACE")="SYSTEM"
 5238:   SET ^$SYSTEM("MAPPINGS","GLOBAL","^FOO")="SYSTEM"
 5239: @end example
 5240: 
 5241: There is no functional difference in any of the three approaches; the method you choose is a matter of personal preference.
 5242: 
 5243: To remove the above mapping, any of the following examples will also work:
 5244: 
 5245: @example
 5246:   UNMAP GLOBAL ^FOO
 5247:   KILL ^$GLOBAL("FOO","NAMESPACE")
 5248:   KILL ^$SYSTEM("MAPPINGS","GLOBAL","^FOO")
 5249: @end example
 5250: 
 5251: 
 5252: 
 5253: @node Asynchronous Event Handling
 5254: @chapter Asynchronous Event Handling
 5255: @cindex event handling, asynchronous
 5256: 
 5257: Asynchronous event handling in FreeM follows the specifications of the unpublished MDC @emph{Millennium Draft Standard}.
 5258: 
 5259: @section Setting Up Async Event Handlers
 5260: 
 5261: Asynchronous event handlers are configured through the @code{^$JOB} structured system variable for job-specific events, and the @code{^$SYSTEM} structured system variable for system-wide events. In order to become proficient in writing asynchronous event handling code, you need to be aware of several important concepts:
 5262: 
 5263: @table @emph
 5264: 
 5265: @item Event Classes
 5266: @emph{Event classes} denote particular categories of events. These include @code{COMM}, @code{HALT}, @code{IPC}, @code{INTERRUPT}, @code{POWER}, @code{TIMER}, @code{TRIGGER}, and @code{USER} event classes. At present, only @code{INTERRUPT} and @code{TRIGGER} event classes are supported.
 5267: 
 5268: @item Event Identifiers
 5269: @emph{Event identifiers} denote the precise nature of the event that has occurred. For instance, resizing the terminal window in which a FreeM job is running will send an event of class @code{INTERRUPT} with an event identifier of @code{SIGWINCH} (short for @emph{SIGnal WINdow CHange}).
 5270: 
 5271: @item Event Handlers
 5272: @emph{Event handlers} are M routines or subroutines that can be registered to run when an event of a certain event class occurs.
 5273: 
 5274: @item Event Registration
 5275: @emph{Event registration} is the process of modifying the @code{^$JOB} or @code{^$SYSTEM} SSVN to associate a particular event class and event identifier with an event handler routine or subroutine.
 5276: 
 5277: @item Event Blocking and Unblocking
 5278: @emph{Event blocking} is the means by which asynchronous event handling can be temporarily suspended. For example, asynchronous events are temporarily and implicitly blocked for the duration of event handler execution, unless explicitly un-blocked within the event handler. Event handling can also be blocked and unblocked programatically from M code using the @code{ABLOCK} and @code{AUNBLOCK} commands.
 5279: 
 5280: @end table
 5281: 
 5282: The following sections of this chapter will take you step-by-step through setting up an event handler for @code{SIGWINCH} signal handling.
 5283: 
 5284: @section Registering an Asynchronous Event Handler
 5285: @cindex event handlers, registration
 5286: 
 5287: To register a job-specific event handler that will only execute in the current FreeM process, use the following syntax:
 5288: 
 5289: @example
 5290:   SET ^$JOB($JOB,"EVENT",@emph{event-class},@emph{event-identifier})=@emph{entryref}
 5291: @end example
 5292: 
 5293: To register a system-wide event handler that will execute in every FreeM process, use the following syntax:
 5294: 
 5295: @example
 5296:   SET ^$SYSTEM("EVENT",@emph{event-class},@emph{event-identifier})=@emph{entryref}
 5297: @end example
 5298: 
 5299: For example, use the following to register @code{^RESIZE} as an asynchronous event handler for @code{SIGWINCH} events:
 5300: 
 5301: @example
 5302:   SET ^$JOB($JOB,"EVENT","INTERRUPT","SIGWINCH")="^RESIZE"
 5303: @end example
 5304: 
 5305: This by itself will not enable asynchronous event handling, as it merely @emph{registers} an event handler, associating it with event class @code{INTERRUPT} and event identifier @code{SIGWINCH}.
 5306: 
 5307: @section Enabling Asynchronous Event Handling
 5308: @cindex event handlers, enabling
 5309: 
 5310: In order to enable asyncronous event handling, the @code{ASTART} command is used. In the following example, we will enable asynchronous event handling for the @code{INTERRUPT} event class:
 5311: 
 5312: @example
 5313:   ASTART "INTERRUPT"
 5314: @end example
 5315: 
 5316: Omitting the @code{"INTERRUPT"} argument will enable asynchronous event handling for @emph{all} event classes. See @code{ASTART} in the commands section for more details.
 5317: 
 5318: Once this is done, any event handlers registered for the @code{INTERRUPT} event class in @code{^$JOB} will be executed asynchronously as appropriate.
 5319: 
 5320: Please note that @code{ASTART "TRIGGER"} is run implicitly at FreeM startup, to ensure consistency in applications depending on business logic contained in system-wide global triggers. To disable this behavior, add @code{ASTOP "TRIGGER"} to the @code{LOCAL.STARTUP} routine in the @code{USER} namespace. If @code{LOCAL.STARTUP} does not yet exist in your environment, you may create it by typing @code{fmadm edit routine USER LOCAL.STARTUP} from your UNIX command-line shell.
 5321: 
 5322: @section Disabling Asynchronous Event Handling
 5323: @cindex event handlers, disabling
 5324: 
 5325: To disable asynchronous event handling, the @code{ASTOP} command is used. In the following example, we will disable asynchronous event handling for the @code{INTERRUPT} event class:
 5326: 
 5327: @example
 5328:   ASTOP "INTERRUPT"
 5329: @end example
 5330: 
 5331: Omitting the @code{"INTERRUPT"} argument will disable asynchronous event handling for @emph{all} event classes. See @code{ASTOP} in the commands section for more details.
 5332: 
 5333: You may also disable asynchronous event handling for a specific event identifier by @code{KILL}ing the appropriate node in the @code{^$JOB} SSVN, which unregisters the event handler altogether. The following example will unregister the event handler for the @code{SIGWINCH} event identifier:
 5334: 
 5335: @example
 5336:   KILL ^$JOB($JOB,"EVENT","INTERRUPT","SIGWINCH")
 5337: @end example  
 5338: 
 5339: @section Temporarily Blocking Asynchronous Event Handling
 5340: @cindex event handlers, blocking
 5341: 
 5342: To temporarily block processing of specific event classes, you will use the @code{ABLOCK} command. @code{ABLOCK} functions incrementally, that is, each successive call to @code{ABLOCK} will increment a counter of blocks held for the specified event class or classes, and each successive call to @code{AUNBLOCK} will decrement that counter. Event handling for the specified event classes will be blocked as long as the @code{ABLOCK} counter for those classes is greater than zero. Thus, event blocking is cumulative, in a manner similar to M incremental locks.
 5343: 
 5344: The following example blocks asynchronous event handling for the @code{INTERRUPT} event class:
 5345: 
 5346: @example
 5347:   ABLOCK "INTERRUPT"
 5348: @end example
 5349: 
 5350: Note that entering an event handler causes an implicit @code{ABLOCK} of @emph{all} event classes, to prevent event handlers from interrupting other event handlers during their execution. This may be overridden by calling @code{AUNBLOCK} for one or more event classes within an event handler. However, unblocking event handling during an event handler should be done with great caution, as this can make the flow of code execution somewhat unpredictable, especially if M globals are modified inside of an event handler routine or subroutine.
 5351: 
 5352: Modifying M globals within event handlers is allowed but strongly discouraged, as doing so can lead to logical corruption of the data. If you must modify an M global within an event handler, guard all such operations with prodigious and careful use of @code{LOCK}s, ensuring that such modifications occur in the desired logical order.
 5353: 
 5354: @node Global Triggers
 5355: @chapter Global Triggers
 5356: @cindex global triggers
 5357: @cindex triggers
 5358: 
 5359: Global triggers use the FreeM asynchronous event handling subsystem to allow a FreeM process to execute arbitrary M code when a particular action occurs on a particular global.
 5360: 
 5361: To set up a global trigger, you must set up an event handler for event class @code{TRIGGER}. The event identifier must be in the format of @code{"<action>:<gvn>"}, where @emph{<gvn>} is a global variable name, and @emph{<action>} is one of the following:
 5362: 
 5363: @table @asis
 5364: 
 5365: @item @code{DATA}
 5366: Trigger will fire when the @code{$DATA} intrinsic function is called on @emph{<gvn>}.
 5367: 
 5368: @item @code{GET}
 5369: Trigger will fire when @emph{<gvn>} is read from.
 5370: 
 5371: @item @code{INCREMENT}
 5372: Trigger will fire when intrinsic function @code{$INCREMENT} is called on @emph{<gvn>}.
 5373: 
 5374: @item @code{KILL}
 5375: Trigger will fire when @emph{<gvn>} is @code{KILL}ed.
 5376: 
 5377: @item @code{NEXT}
 5378: Trigger will fire when intrinsic function @code{$NEXT} is called on @emph{<gvn>}.
 5379: 
 5380: @item @code{ORDER}
 5381: Trigger will fire when intrinsic function @code{$ORDER} is called on @emph{<gvn>}.
 5382: 
 5383: @item @code{QUERY}
 5384: Trigger will fire when intrinsic function @code{$QUERY} is called on @emph{<gvn>}.
 5385: 
 5386: @item @code{SET}
 5387: Trigger will fire when @code{SET @emph{<gvn>}=@emph{value}} occurs.
 5388: 
 5389: @item @code{ZDATA}
 5390: Trigger will fire when intrinsic function @code{ZDATA} is called on @emph{<gvn>}.
 5391: 
 5392: @end table
 5393: 
 5394: When a @code{TRIGGER} event occurs, the @code{"GLOBAL"} node of the @code{^$EVENT} structured system variable will be populated with the global reference that invoked the trigger event.
 5395: 
 5396: If a @code{SET} or @code{KILL} trigger was the source of the @code{TRIGGER} event, the @code{OLD_VALUE} node of @code{^$EVENT} will be populated with original value of @code{^$EVENT("GLOBAL")} prior to the change, and @code{NEW_VALUE} will be populated with the new value. This allows triggers to contain logic to undo global changes. This functionality can also be used to provide auditing of specific global changes.
 5397: 
 5398: The following example shows a trigger implemented for @code{SET} operations on the @code{^DD} global.
 5399: 
 5400: @example
 5401: TRIGGER ;
 5402:     ;
 5403:     ; Set up a SET trigger on ^DD
 5404:     ;
 5405:     SET ^$JOB($JOB,"EVENT","TRIGGER","SET:^DD")="ONSET^TRIGGER"
 5406:     ;
 5407:     ; Enable the TRIGGER event class
 5408:     ;
 5409:     ASTART "TRIGGER"
 5410:     ;
 5411:     ; Try setting a node in ^DD
 5412:     ;
 5413:     SET ^DD(1)="Test"
 5414:     ;
 5415:     ; Quit
 5416:     ;
 5417:     QUIT
 5418:     ;
 5419:     ;
 5420: ONSET ;
 5421:     WRITE "The "_^$EVENT("GLOBAL")_" global node was SET.",!
 5422:     QUIT
 5423: @end example
 5424: 
 5425: You can also set up a trigger that applies to all FreeM processes by setting descendant subscripts of @code{^$SYSTEM("EVENT","TRIGGER",...)} instead of using @code{^$JOB($JOB,"EVENT","TRIGGER",...)}.
 5426: 
 5427: @node Synchronous Event Handling
 5428: @chapter Synchronous Event Handling
 5429: 
 5430: @node GUI Programming with MWAPI
 5431: @chapter GUI Programming with MWAPI
 5432: 
 5433: @node User-Defined Z Commands
 5434: @chapter User-Defined Z Commands
 5435: 
 5436: @node User-Defined Z Functions
 5437: @chapter User-Defined Z Functions
 5438: 
 5439: @cindex z functions, user-defined
 5440: 
 5441: @node User-Defined SSVNs
 5442: @chapter User-Defined SSVNs 
 5443: 
 5444: @cindex structured system variables, user-defined
 5445: @cindex structured system variables
 5446: 
 5447: @node Language Dialects
 5448: @chapter Language Dialects
 5449: 
 5450: @cindex language dialects
 5451: @cindex dialects, language
 5452: 
 5453: 
 5454: @node System Library Routines
 5455: @chapter System Library Routines
 5456: @cindex system library routines
 5457: 
 5458: @section ^%ZCOLUMNS
 5459: @cindex ^%ZCOLUMNS
 5460: @cindex system library routines, ^%ZCOLUMNS
 5461: 
 5462: This routine is the implementation of the @code{$ZCOLUMNS} intrinsic special variable.
 5463: 
 5464: @section %SYSINIT
 5465: @cindex %SYSINIT
 5466: @cindex system library routines, %SYSINIT
 5467: 
 5468: This routine is the default startup routine for FreeM running in direct mode.
 5469: 
 5470: Running @code{DO INFO} from direct mode will use this routine to display information about the current FreeM status and namespace configuration.
 5471: 
 5472: @section ^%ZHELP
 5473: @cindex ^%ZHELP
 5474: @cindex system library routines, ^%ZHELP
 5475: 
 5476: This routine implements the online help feature of FreeM, invoked by typing @code{?} in direct mode. It simply asks the underlying system to execute the command @command{info freem}.
 5477: 
 5478: @section ^%ZROWS
 5479: @cindex ^%ZROWS
 5480: @cindex system library routines, ^%ZROWS
 5481: 
 5482: This routine is the implementation of the @code{$ZROWS} intrinsic special variable.
 5483: 
 5484: @node Interrupt Handling
 5485: @chapter Interrupt Handling
 5486: @cindex interrupt handling
 5487: 
 5488: When FreeM receives the @code{SIGINT} signal, either by pressing @code{Ctrl-C} during program execution, or by external signal from the operating system, the FreeM environment daemon, or another external process, one of two things can happen, depending on the state of the @code{$ZI} special variable:
 5489: 
 5490: @table @asis
 5491: @item @code{$ZI} evaluates @emph{true}
 5492: In this case, the @code{ZINRPT} error is raised, and normal error handling procedures apply. If neither @code{$ZTRAP} nor @code{$ETRAP} are set, FreeM prints an error diagnostic on the home device and will exit the FreeM process in application mode (i.e., the @code{freem} executable was started with the @code{--routine} or @code{-r} flag), or return to the direct mode prompt otherwise.
 5493: 
 5494: This is the default behavior of FreeM.
 5495: @item @code{$ZI} evaluates @emph{false}
 5496: In this case, no error is raised, but the @code{$ZCONTROLC} flag is set. In this mode of operation, it is up to program code to check for @code{$ZCONTROLC} and take appropriate action.
 5497: 
 5498: Checking the value of @code{$ZCONTROLC} will reset it to @emph{false}.
 5499: @end table
 5500: 
 5501: In either case, if asynchronous event handling is enabled for the @code{INTERRUPT} event class (i.e., @code{ASTART "INTERRUPT"} or @code{ASTART} have been invoked by the current process), an asynchronous event of event class @code{INTERRUPT} and event identifier @code{SIGINT} will be enqueued. 
 5502: 
 5503: @node Error Processing
 5504: @chapter Error Processing
 5505: @cindex error processing
 5506: 
 5507: FreeM exposes three means of processing M program execution errors:
 5508: 
 5509: @table @emph
 5510: 
 5511: @item FreeM-style error processing
 5512: FreeM-style error processing exposes a read/write error trap in @code{$ZTRAP}. The contents of @code{$ZTRAP} must be either empty or a valid M entryref, to which FreeM will @code{GOTO} if an error occurs. Each program stack execution level can have its own @code{$ZTRAP} error handler enabled.
 5513: 
 5514: @item DSM 2.0-style error processing
 5515: DSM 2.0-style error processing emulates the @code{$ZTRAP} behavior of Digital Standard MUMPS v2. It has the same behavior as FreeM-style error handling, with the exception that in DSM 2.0-style error processing, only one @code{$ZTRAP} error handler is set across all program stack execution levels.
 5516: 
 5517: @item Standard error processing
 5518: Standard error processing uses the @code{NEW}-able @code{$ETRAP} variable to store error handler code, which may be any valid M code. The code in @code{$ETRAP} will run when an error occurs or the @code{$ECODE} ISV becomes non-empty. Stack information for standard error handling is provided by the @code{$STACK} ISV, the @code{$STACK()} intrinsic pseudo-function, and the @code{NEW}-able @code{$ESTACK} ISV.
 5519: 
 5520: If @code{$ETRAP} is non-empty when an error condition occurs, @code{$ZTRAP} is ignored, regardless of whether FreeM-style or DSM 2.0-style error processing is enabled at the time of the error.
 5521: 
 5522: @end table
 5523: 
 5524: For further information on switching between FreeM-style and DSM 2.0-style @code{$ZTRAP} error handling, see the documentation for the @code{BREAK} command.
 5525: 
 5526: @node FreeM Error Codes
 5527: @chapter FreeM Error Codes
 5528: @cindex Error Codes
 5529: 
 5530: @table @asis
 5531: 
 5532: @item @code{ZINRPT} - @emph{interrupt}
 5533: Raised when an interrupt signal is received.
 5534: 
 5535: @item @code{ZBKERR} - @emph{BREAK point}
 5536: Raised when a @code{BREAK} point is reached.
 5537: 
 5538: @item @code{ZNOSTAND} - @emph{non standard syntax}
 5539: Raised when features incompatible with the current value of @code{$DIALECT} are used.
 5540: 
 5541: @item @code{ZUNDEF} - @emph{variable not found}
 5542: Raised when an undefined local or global variable is accessed. This error code has been deprecated in favor of standard error codes @code{M6} and @code{M7}.
 5543: 
 5544: @item @code{ZLBLUNDEF} - @emph{label not found}
 5545: Raised when a referenced label is not found.
 5546: 
 5547: @item @code{ZMISSOPD} - @emph{missing operand}
 5548: Raised when an operand is missing from an expression.
 5549: 
 5550: @item @code{ZMISSOP} - @emph{missing operator}
 5551: Raised when an operator is missing from an expression.
 5552: 
 5553: @item @code{ZILLOP} - @emph{unrecognized operator}
 5554: Raised when an unrecognized operator is encountered in an expression.
 5555: 
 5556: @item @code{ZQUOTER} - @emph{unmatched quotes}
 5557: Raised when unbalanced quotes are encountered.
 5558: 
 5559: @item @code{ZCOMMAER} - @emph{comma expected}
 5560: Raised when a comma is expected in program syntax but is not found.
 5561: 
 5562: @item @code{ZASSIGNER} - @emph{equals '=' expected}
 5563: Raised when an equals sign is expected in program syntax but is not found.
 5564: 
 5565: @item @code{ZARGER} - @emph{argument not permitted}
 5566: Raised when an argument is encountered in a syntactic position where arguments are not permitted.
 5567: 
 5568: @item @code{ZSPACER} - @emph{blank ' ' expected}
 5569: Raised when a space character is expected in program syntax but is not found.
 5570: 
 5571: @item @code{ZBRAER} - @emph{unmatched parentheses}
 5572: Raised when unbalanced parentheses are detected in program syntax.
 5573: 
 5574: @item @code{ZLVLERR} - @emph{level error}
 5575: Raised when a level error occurs.
 5576: 
 5577: @item @code{ZDIVER} - @emph{divide by zero}
 5578: Raised when program code attempts to divide by zero. Deprecated in favor of standard error code @code{M9}.
 5579: 
 5580: @item @code{ZILLFUN} - @emph{function not found}
 5581: Raised when program code attempts to call intrinsic or extrinsic functions that are not defined.
 5582: 
 5583: @item @code{ZFUNARG} - @emph{wrong number of function arguments}
 5584: Raised when an intrinsic or extrinsic function is called with the wrong number of arguments.
 5585: 
 5586: @item @code{ZZTERR} - @emph{ZTRAP error}
 5587: Raised when a @code{$ZTRAP} error occurs.
 5588: 
 5589: @item @code{ZNEXTERR} - @emph{$NEXT/$ORDER error}
 5590: Raised when an error occurs in @code{$NEXT} or @code{$ORDER}.
 5591: 
 5592: @item @code{ZSELER} - @emph{$SELECT error}
 5593: Raised when an error occurs in @code{$SELECT}
 5594: 
 5595: @item @code{ZCMMND} - @emph{illegal command}
 5596: Raised when program code attempts to execute an illegal command.
 5597: 
 5598: @item @code{ZARGLIST} - @emph{argument list incorrect}
 5599: Raised when the argument list supplied to an M language element does not match that language element's syntactic requirements.
 5600: 
 5601: @item @code{ZINVEXPR} - @emph{invalid expression}
 5602: Raised when an invalid expression is encountered.
 5603: 
 5604: @item @code{ZINVREF} - @emph{invalid reference}
 5605: Raised when an invalid variable reference is encountered.
 5606: 
 5607: @item @code{ZMXSTR} - @emph{string too long}
 5608: Raised when a string is encountered that exceeds @code{^$SYSTEM("STRING_MAX")}.
 5609: 
 5610: @item @code{ZTOOPARA} - @emph{too many parameters}
 5611: Raised when too many parameters are passed to a function or subroutine.
 5612: 
 5613: @item @code{ZNOPEN} - @emph{unit not open}
 5614: Raised when attempting to access an I/O channel that has not been opened.
 5615: 
 5616: @item @code{ZNODEVICE} - @emph{unit does not exist}
 5617: Raised when attempting to access a device that does not exist.
 5618: 
 5619: @item @code{ZPROTECT} - @emph{file protection violation}
 5620: Raised when attempting to access a file or device to which you do not have permission.
 5621: 
 5622: @item @code{ZGLOBER} - @emph{global not permitted}
 5623: Raised when attempting to use a global in a syntactic element where global variables are not permitted.
 5624: 
 5625: @item @code{ZFILERR} - @emph{file not found}
 5626: Raised when attempting to access a file that does not exist.
 5627: 
 5628: @item @code{ZPGMOV} - @emph{program overflow}
 5629: Raised when a program overflows the limits of a routine buffer.
 5630: 
 5631: @item @code{ZSTKOV} - @emph{stack overflow}
 5632: Raised when @code{DO}, @code{FOR}, or @code{XECUTE} nesting levels exceed the value in @code{^$SYSTEM("NESTLEVLS")}.
 5633: 
 5634: @item @code{ZSTORE} - @emph{symbol table overflow}
 5635: Raised when program code attempts to store too much data in the local symbol table. Should not occur unless symbol table auto-adjust is disabled.
 5636: 
 5637: @item @code{ZNOREAD} - @emph{file won't read}
 5638: Raised when program code attempts to read from an unreadable file.
 5639: 
 5640: @item @code{ZNOWRITE} - @emph{file won't write}
 5641: Raised when program code attempts to write to an unwritable file.
 5642: 
 5643: @item @code{ZNOPGM} - @emph{routine not found}
 5644: Raised when an attempt is made to load or execute a routine that does not exist in the current namespace.
 5645: 
 5646: @item @code{ZNAKED} - @emph{illegal naked reference}
 5647: Raised when an attempt is made to use an illegal naked reference.
 5648: 
 5649: @item @code{ZSBSCR} - @emph{illegal subscript}
 5650: Raised when an illegal subscript access is attempted.
 5651: 
 5652: @item @code{ZISYNTX} - @emph{insert syntax}
 5653: Raised when illegal insert syntax is used.
 5654: 
 5655: @item @code{ZDBDGD} - @emph{global data degradation}
 5656: Raised when corruption is detected in global data files.
 5657: 
 5658: @item @code{ZKILLER} - @emph{job kill signal}
 5659: Raised on a job kill signal.
 5660: 
 5661: @item @code{ZHUPER} - @emph{hangup signal}
 5662: Raised on a job hangup signal.
 5663: 
 5664: @item @code{ZMXNUM} - @emph{numeric overflow}
 5665: Raised when an assignment or expression result exceeds @code{$ZPRECISION}.
 5666: 
 5667: @item @code{ZNOVAL} - @emph{function returns no value}
 5668: Raised when a function does not return a value. Extrinsic functions must @code{QUIT} with a value.
 5669: 
 5670: @item @code{ZTYPEMISMATCH} - @emph{type mismatch}
 5671: Raised when a type mismatch occurs.
 5672: 
 5673: @item @code{ZMEMOV} - @emph{out of memory}
 5674: Raised when FreeM runs out of heap memory.
 5675: 
 5676: @item @code{ZNAMERES} - @emph{error in name resolution}
 5677: Raised when an attempted name resolution fails.
 5678: 
 5679: @item @code{ZSCKCREAT} - @emph{error creating socket}
 5680: Raised when an error occurs creating a socket for network I/O.
 5681: 
 5682: @item @code{ZSCKIFAM} - @emph{invalid address family (must be IPV4 or IPV6)}
 5683: Raised when the address family specified in an @code{OPEN} command for a socket I/O channel is not IPV4 or IPV6.
 5684: 
 5685: @item @code{ZSCKITYP} - @emph{invalid connection type (must be TCP or UDP)}
 5686: Raised when the connection type specified in an @code{OPEN} command for a socket I/O channel is not @code{TCP} or @code{UDP}.
 5687: 
 5688: @item @code{ZSCKIPRT} - @emph{invalid port number}
 5689: Raised when the port number specified in an @code{OPEN} command for a socket I/O channel is invalid. Valid TCP and UDP ports are in the range of 1-65535.
 5690: 
 5691: @item @code{ZSCKCERR} - @emph{connection error}
 5692: Raised when an error occurs on a @code{USE <channel>:/CONNECT} command.
 5693: 
 5694: @item @code{ZSCKAERR} - @emph{USE action invalid for connection type (possibly CONNECT on UDP socket?)}
 5695: Raised when an attempt is made to @code{USE <channel>:/CONNECT} on a UDP socket I/O channel. The UDP protocol is connectionless.
 5696: 
 5697: @item @code{ZSCKACON} - @emph{attempted to CONNECT an already-connected socket}
 5698: Raised when an attempt is made to @code{USE <channel>:/CONNECT} on a TCP socket I/O channel that is already connected.
 5699: 
 5700: @item @code{ZSCKNCON} - @emph{attempted to READ from a disconnected TCP socket}
 5701: Raised when an attempt is made to @code{READ} a TCP socket that has not yet been connected.
 5702: 
 5703: @item @code{ZSCKEOPT} - @emph{error setting socket options}
 5704: Raised when an error is encountered while setting socket options.
 5705: 
 5706: @item @code{ZSCKERCV} - @emph{error in READ from socket}
 5707: Raised when an error occurs in a socket I/O channel @code{READ}.
 5708: 
 5709: @item @code{ZSCKESND} - @emph{error in WRITE to socket}
 5710: Raised when an error occurs while attempting to @code{WRITE} to a socket I/O channel.
 5711: 
 5712: @item @code{ZNORPI} - @emph{^$ZRPI only supported on Raspberry Pi hardware}
 5713: Raised when an attempt is made to use the @code{^$ZRPI} structured system variable on a platform other than the Raspberry Pi single-board computer.
 5714: 
 5715: @item @code{ZCREDEF} - @emph{cannot redefine CONST}
 5716: Raised when attempts are made to redefine a @code{CONST} after its initial definition.
 5717: 
 5718: @item @code{ZCMODIFY} - @emph{cannot modify CONST}
 5719: Raised when attempts are made to change the value of a @code{CONST}.
 5720: 
 5721: @item @code{ZFILEXWR} - @emph{cannot open existing file for WRITE}
 5722: Raised when an attempt is made to open an existing file in write (but not append) mode.
 5723: 
 5724: @item @code{INEWMULT} - @emph{initializing NEW with multiple setarguments not supported}
 5725: Raised when you attempt to use multiple setarguments with initializing @code{NEW}, e.g. @code{NEW X=2,Y=3}.
 5726: 
 5727: @item @code{ZECODEINV} - @emph{invalid value for $ECODE}
 5728: Raised when attempts are made to set @code{$ECODE} to an invalid error code value. Obsolete and replaced by standard error code @code{M101}.
 5729: 
 5730: @item @code{ZASSERT} - @emph{programmer assertion failed}
 5731: Raised when an @code{ZASSERT} expression's result is not true.
 5732: 
 5733: @item @code{ZUSERERR} - @emph{user-defined error}
 5734: Raised when program code calls @code{THROW} with an error code argument for which the first character is @code{U}, or when @code{$ECODE} is set to an error code for which the first character is @code{U}.
 5735: 
 5736: Custom error messages for @code{ZUSERERR} may be set in @code{^$JOB($JOB,"USER_ERRORS",<user_error_code>)}, where @code{<user_error_code>} represents the custom error code.
 5737: 
 5738: For example:
 5739: 
 5740: @example
 5741: DEFAULT.USER> S ^$JOB($JOB,"USER_ERRORS","UBLACKHOLE")="black hole encountered"
 5742: 
 5743: 
 5744: DEFAULT.USER> THROW UBLACKHOLE
 5745: 
 5746: 
 5747: >> Error UBLACKHOLE:  black hole encountered in SYSTEM::^%SYSINIT  [$STACK = 0]
 5748: >> THROW UBLACKHOLE
 5749:                   ^
 5750: @end example
 5751: 
 5752: @item @code{ZSYNTERR} - @emph{syntax error}
 5753: Raised when a syntax error without a more specific error code is encountered.
 5754: 
 5755: @item @code{ZCTRLB} - @emph{break}
 5756: Pseudo-error used by the FreeM debugger. Not visibly raised in normal program operation.
 5757: 
 5758: @item @code{ZASYNC} - @emph{asynchronous interruption}
 5759: Pseudo-error used by the FreeM asynchronous events subsystem. Not visibly raised in normal program operation.
 5760: 
 5761: @item @code{M1} - @emph{naked indicator undefined}
 5762: Raised when an attempt is made to use a naked reference before the naked indicator is set.
 5763: 
 5764: @item @code{M2} - @emph{invalid combination with $FNUMBER code atom}
 5765: 
 5766: 
 5767: @item @code{M3} - @emph{$RANDOM seed less than 1}
 5768: 
 5769: 
 5770: @item @code{M4} - @emph{no true condition in $SELECT}
 5771: 
 5772: 
 5773: @item @code{M5} - @emph{line reference less than zero}
 5774: 
 5775: 
 5776: @item @code{M6} - @emph{undefined local variable}
 5777: 
 5778: 
 5779: @item @code{M7} - @emph{undefined global variable}
 5780: 
 5781: 
 5782: @item @code{M8} - @emph{undefined intrinsic special variable}
 5783: 
 5784: 
 5785: @item @code{M9} - @emph{divide by zero}
 5786: 
 5787: 
 5788: @item @code{M10} - @emph{invalid pattern match range}
 5789: 
 5790: 
 5791: @item @code{M11} - @emph{no parameters passed}
 5792: 
 5793: 
 5794: @item @code{M12} - @emph{invalid line reference (negative offset)}
 5795: 
 5796: 
 5797: @item @code{M13} - @emph{invalid line reference (line not found)}
 5798: 
 5799: 
 5800: @item @code{M14} - @emph{line level not 1}
 5801: 
 5802: 
 5803: @item @code{M15} - @emph{undefined index variable}
 5804: 
 5805: 
 5806: @item @code{M16} - @emph{argumented QUIT not allowed}
 5807: 
 5808: 
 5809: @item @code{M17} - @emph{argumented QUIT required}
 5810: 
 5811: 
 5812: @item @code{M18} - @emph{fixed length READ not greater than zero}
 5813: 
 5814: 
 5815: @item @code{M19} - @emph{cannot copy a tree or subtree onto itself}
 5816: 
 5817: 
 5818: @item @code{M20} - @emph{line must have a formal parameter list}
 5819: 
 5820: 
 5821: @item @code{M21} - @emph{algorithm specification invalid}
 5822: 
 5823: 
 5824: @item @code{M22} - @emph{SET or KILL to ^$GLOBAL when data in global}
 5825: 
 5826: 
 5827: @item @code{M23} - @emph{SET or KILL to ^$JOB for non-existent job number}
 5828: 
 5829: 
 5830: @item @code{M24} - @emph{change to collation algorithm while subscripted local variables defined}
 5831: 
 5832: 
 5833: @item @code{M26} - @emph{non-existent environment}
 5834: 
 5835: 
 5836: @item @code{M27} - @emph{attempt to rollback a transaction that is not restartable}
 5837: 
 5838: 
 5839: @item @code{M28} - @emph{mathematical function, parameter out of range}
 5840: 
 5841: 
 5842: @item @code{M29} - @emph{SET or KILL on structured system variable not allowed by implementation}
 5843: 
 5844: 
 5845: @item @code{M30} - @emph{reference to global variable with different collating sequence within a collating algorithm}
 5846: 
 5847: 
 5848: @item @code{M31} - @emph{control mnemonic used for device without a mnemonic space selected}
 5849: 
 5850: 
 5851: @item @code{M32} - @emph{control mnemonic used in user-defined mnemonic space which has no associated line}
 5852: 
 5853: 
 5854: @item @code{M33} - @emph{SET or KILL to ^$ROUTINE when routine exists}
 5855: 
 5856: 
 5857: @item @code{M35} - @emph{device does not support mnemonic space}
 5858: 
 5859: 
 5860: @item @code{M36} - @emph{incompatible mnemonic spaces}
 5861: 
 5862: 
 5863: @item @code{M37} - @emph{READ from device identified by empty string}
 5864: 
 5865: 
 5866: @item @code{M38} - @emph{invalid structured system variable subscript}
 5867: 
 5868: 
 5869: @item @code{M39} - @emph{invalid $NAME argument}
 5870: 
 5871: 
 5872: @item @code{M40} - @emph{call-by-reference in JOB actual parameter}
 5873: 
 5874: 
 5875: @item @code{M41} - @emph{invalid LOCK argument within a transaction}
 5876: 
 5877: 
 5878: @item @code{M42} - @emph{invalid QUIT within a transaction}
 5879: 
 5880: 
 5881: @item @code{M43} - @emph{invalid range value ($X, $Y}
 5882: 
 5883: 
 5884: @item @code{M44} - @emph{invalid command outside of a transaction}
 5885: 
 5886: 
 5887: @item @code{M45} - @emph{invalid GOTO reference}
 5888: 
 5889: 
 5890: @item @code{M56} - @emph{identifier exceeds maximum length}
 5891: 
 5892: 
 5893: @item @code{M57} - @emph{more than one defining occurrence of label in routine}
 5894: 
 5895: 
 5896: @item @code{M58} - @emph{too few formal parameters}
 5897: 
 5898: 
 5899: @item @code{M60} - @emph{illegal attempt to use an undefined SSVN}
 5900: 
 5901: 
 5902: @item @code{M101} - @emph{invalid value for $ECODE}
 5903: 
 5904: 
 5905: @item @code{M102} - @emph{synchronous and asynchronous event processing cannot be simultaneously enabled for the same event class}
 5906: 
 5907: 
 5908: @item @code{M103} - @emph{invalid event identifier}
 5909: 
 5910: 
 5911: @item @code{M104} - @emph{ETRIGGER event identifier for IPC event class does not match job process identifier}
 5912: 
 5913: 
 5914: @end table
 5915: 
 5916: 
 5917: @node System Configuration
 5918: @chapter System Configuration
 5919: @cindex configuration, system
 5920: 
 5921: @section Installing FreeM
 5922: @cindex installation
 5923: 
 5924: @subsection Installation Methods
 5925: 
 5926: FreeM allows the following installation methods:
 5927: @table @asis
 5928: @item Binary Repository
 5929: On recent versions the Ubuntu and Debian distributions of GNU/Linux, we provide package repositories from which FreeM may easily be installed. See the @emph{FreeM Wiki} for more information, and @emph{https://packages.coherent-logic.com} for instructions.
 5930: 
 5931: If available, this is the simplest method of installing FreeM.
 5932: @item Binary Packages
 5933: We provide binary packages of FreeM for @emph{dpkg} and @emph{rpm}-based distributions of GNU/Linux, and @emph{pkgadd} packages for Solaris 8-10. If you cannot use repositories, this is the easiest option.
 5934: 
 5935: See @emph{https://freem.coherent-logic.com/binaries.cfm} for downloads and instructions.
 5936: @item Source Archive
 5937: If you prefer installing from source, we recommend that you download the latest @emph{.tar.gz} file from @emph{https://freem.coherent-logic.com/downloads.cfm}, and follow these steps:
 5938: 
 5939: @example
 5940: $ gunzip freem-@emph{<version>}.tar.gz
 5941: $ tar xf freem-@emph{<version>}.tar
 5942: $ cd freem
 5943: $ ./configure # see the Build Configuration section for optional flags
 5944: $ make
 5945: $ sudo make install
 5946: @end example
 5947: 
 5948: Once this process has been completed, you may proceed to @emph{Initial Configuration}.
 5949: 
 5950: Installation from source archive is the most challenging but flexible supported option for advanced users.
 5951: @item CVS Repository
 5952: If you wish to try the bleeding-edge development version of FreeM, you may do so by following these steps:
 5953: 
 5954: @verbatim
 5955: $ cvs -d :pserver:anonymous@cvs.coherent-logic.com:/home/cvsroot co freem
 5956: $ cd freem
 5957: $ ./autogen.sh
 5958: $ ./configure # see the Build Configuration section for optional flags
 5959: $ make
 5960: $ sudo make install
 5961: @end verbatim
 5962: 
 5963: Once this process has been completed, you may proceed to @emph{Initial Configuration}.
 5964: 
 5965: This installation method is by far the most complicated, and is intended only for those who wish to contribute to FreeM development. It is not intended for end users, and no technical support will be provided.
 5966: 
 5967: See the @emph{Contributor Guide} on the @emph{FreeM Wiki} for more information.
 5968: @end table
 5969: @subsection Build Configuration
 5970: @cindex build configuration
 5971: 
 5972: When configuring FreeM with the supplied @code{configure} script, there are some FreeM-specific options that may be used to compile in optional features, or exclude default ones:
 5973: 
 5974: @table @asis
 5975: 
 5976: @item @code{--enable-mwapi} (EXPERIMENTAL)
 5977: Enables experimental support for the M Windowing API (ANSI @emph{X11.6-1995}) using the OSF/Motif widget toolkit. Requires that you have the @code{X11}, @code{Xt}, @code{ICE}, and @code{Xm} libraries, as well as all of their C header files.
 5978: 
 5979: Please consult your operating system's documentation for the correct commands to install the required libraries.
 5980: 
 5981: @emph{Example}
 5982: 
 5983: @example
 5984: $ ./configure --enable-mwapi
 5985: $ make
 5986: $ sudo make install
 5987: @end example
 5988: 
 5989: @end table
 5990: 
 5991: @subsection Initial Configuration
 5992: Once FreeM is installed, you will need to configure it:
 5993: 
 5994: @enumerate
 5995: @item Create a user and group, each named @emph{freem}, under which FreeM will run
 5996: @item Add any user accounts that will need to run FreeM to the @emph{freem} group
 5997: @item Have all users added in step 2 sign out and sign in for the new group membership to take effect 
 5998: @item Run @code{fmadm configure} with superuser privileges to create the @code{DEFAULT} environment with @code{SYSTEM} and @code{USER} namespaces and default after-image journal settings, and populate the bundled vendor routines
 5999: @item Run @code{fmadm start environment} with superuser privileges to start the @code{DEFAULT} environment
 6000: @item Make sure the environment is ready by running @code{fmadm status environment} with superuser privileges
 6001: @end enumerate
 6002: 
 6003: @subsubsection Creating Additional Environments
 6004: To create additional environments, do the following steps:
 6005: 
 6006: @enumerate
 6007: @item Create a new user and group for the environment @emph{(optional)}
 6008: @item Run @code{fmadm configure -e=@emph{<environment>} -u=@emph{<username>} -g=@emph{<groupname>} [-E=@emph{true|false}]} @emph{(the @code{-E} flag enables or disables the environment)}
 6009: @item Run @code{fmadm start environment -e=@emph{<environment>}} to start the environment
 6010: @item Run @code{fmadm status environment} to make sure the environment is healthy
 6011: @end enumerate
 6012: 
 6013: @subsubsection Additional Customization
 6014: 
 6015: See the FreeM @emph{environment catalog} at @code{@emph{$PREFIX}/etc/freem/env.conf}, and the @emph{fmadm}(1) @code{man} page for more information.
 6016: 
 6017: @emph{$PREFIX} represents the root location of your FreeM installation. This can be @code{/usr/local}, @code{/}, or others, depending on how FreeM was built and installed.
 6018: 
 6019: @node Accessing FreeM from C Programs
 6020: @chapter Accessing FreeM from C Programs
 6021: 
 6022: FreeM provides a library, @file{libfreem.so}, as well as corresponding header file @file{freem.h}, allowing C programmers to write programs that access FreeM globals, locals, structured system variables, subroutines, and extrinsic functions. This functionality can be used to implement language bindings and data access drivers for external systems.
 6023: 
 6024: In order to be used in your C programs, your C programs must link with @file{libfreem.so} and include @file{freem.h}. This will allow your C code access to the function prototypes, data structures, and constants required for calling the @file{libfreem.so} APIs.
 6025: 
 6026: You must exercise caution in developing programs that interface with FreeM through @file{libfreem.so} to ensure that all @file{libfreem.so} API calls are serialized, as FreeM and the @file{libfreem.so} library are neither thread-safe nor reentrant.
 6027: 
 6028: You must also avoid setting signal handlers for @code{SIGALRM}, as FreeM uses @code{SIGALRM} to manage timeouts for @command{LOCK}, @command{READ}, and @command{WRITE}.
 6029: 
 6030: @section freem_ref_t Data Structure
 6031: @cindex libfreem, data structures: freem_ref_t
 6032: 
 6033: The @code{libfreem} API uses a @code{struct} of type @code{freem_ref_t} in order to communicate state, pass in values, and return results.
 6034: 
 6035: The data structure, defined in @file{freem.h}, looks like this:
 6036: 
 6037: @verbatim
 6038: typedef struct freem_ref_t {
 6039: 
 6040:     /*
 6041:      * The 'reftype' field can be one of:
 6042:      * 
 6043:      *  MREF_RT_LOCAL
 6044:      *  MREF_RT_GLOBAL
 6045:      *  MREF_RT_SSV
 6046:      */
 6047:     short reftype;
 6048: 
 6049:     /*
 6050:      * The 'name' field is the name of the local variable,
 6051:      * global variable, or SSVN (without ^ or ^$).
 6052:      */
 6053:     char name[256];    
 6054: 
 6055:     /*
 6056:      * Returned data goes in a string, so you've got to figure out the
 6057:      * whole M canonical number thing yourself. Good luck. :-)
 6058:      */
 6059:     char value[STRLEN];   
 6060: 
 6061:     short status;
 6062: 
 6063:     unsigned int subscript_count;
 6064:     char subscripts[255][256];
 6065: 
 6066: } freem_ref_t;
 6067: @end verbatim
 6068: 
 6069: @emph{freem_ref_t Members}
 6070: 
 6071: @table @asis
 6072: @cindex libfreem, freem_ref_t.reftype
 6073: @item @option{reftype}
 6074: The @option{reftype} member determines whether we are operating on a local variable, a global variable, or a structured system variable. It may be set to any of following constants: @code{MREF_RT_LOCAL}, @code{MREF_RT_GLOBAL}, or @code{MREF_RT_SSV}.
 6075: 
 6076: @cindex libfreem, freem_ref_t.name
 6077: @item @option{name}
 6078: The @option{name} member contains the name of the global, local, or SSVN to be accessed. You @emph{must not} include leading characters, such as @code{^} or @code{^$}.
 6079: 
 6080: @cindex libfreem, freem_ref_t.value
 6081: @item @option{value}
 6082: This member contains the value read from or the value to be written to the global, local, or SSVN.
 6083: 
 6084: @cindex libfreem, freem_ref_t.status
 6085: @item @option{status}
 6086: This member gives us various API status values after the API call returns. In general, this value is also returned by each API function.
 6087: 
 6088: @cindex libfreem, freem_ref_t.subscript_count
 6089: @item @option{subscript_count}
 6090: The number of subscripts to be passed into the API function being called. This value represents the maximum index into the first dimension of the @code{subscripts} array.
 6091: 
 6092: @cindex libfreem, freem_ref_t.subscripts
 6093: @item @option{subscripts}
 6094: A two-dimensional array containing the subscripts to which we are referring in this API call. 
 6095: 
 6096: @end table
 6097: 
 6098: @section freem_ent_t Data Structure
 6099: @cindex libfreem, data structures: freem_ent_t
 6100: 
 6101: The @code{freem_function()} and @code{freem_procedure()} APIs in @code{libfreem} use the @code{freem_ent_t} struct in order to indicate the name of the entry point being called, any arguments being passed to it, and the return value of the called function (not used for @code{freem_procedure()}).
 6102: 
 6103: The data structure, defined in @file{freem.h}, looks like this:
 6104: 
 6105: @verbatim
 6106: typedef struct freem_ent_t {
 6107: 
 6108:     /* name of function or procedure entry point */
 6109:     char name[256];
 6110: 
 6111:     /* return value */
 6112:     char value[STRLEN];
 6113: 
 6114:     /* value of ierr on return */
 6115:     short status;
 6116: 
 6117:     /* argument count and array */
 6118:     unsigned int argument_count;
 6119:     char arguments[255][256];
 6120: 
 6121: } freem_ent_t;
 6122: @end verbatim
 6123: 
 6124: @emph{freem_ent_t Members}
 6125: 
 6126: @table @asis
 6127: 
 6128: @item @option{name}
 6129: @cindex libfreem, freem_ent_t.name
 6130: The @option{name} member contains the name of the extrinsic function or procedure to be called.
 6131: 
 6132: @cindex libfreem, freem_ent_t.value
 6133: @item @option{value}
 6134: This member contains the value returned by the function called. Not used by @code{freem_procedure()}. 
 6135: 
 6136: @cindex libfreem, freem_ent_t.status
 6137: @item @option{status}
 6138: This member gives us the value of @code{ierr} after the function or procedure call returns. The possible values of @code{ierr} are listed in @code{merr.h}.
 6139: 
 6140: @cindex libfreem, freem_ent_t.argument_count
 6141: @item @option{argument_count}
 6142: The number of arguments to be passed into the extrinsic function or procedure being called. This value represents the maximum index into the first dimension of the @code{arguments} array.
 6143: 
 6144: @cindex libfreem, freem_ent_t.arguments
 6145: @item @option{arguments}
 6146: A two-dimensional array containing the arguments to be passed into the extrinsic function or procedure being called.
 6147: 
 6148: @end table
 6149: 
 6150: @section freem_init()
 6151: @cindex libfreem, freem_init()
 6152: 
 6153: Initializes @code{libfreem} in preparation for calling other APIs.
 6154: 
 6155: @emph{Synopsis}
 6156: 
 6157: @code{pid_t freem_init(char *environment_name, char *namespace_name);}
 6158: 
 6159: @emph{Parameters}
 6160: 
 6161: @table @asis
 6162: @item @code{environment_name}
 6163: Specifies the environment to use.
 6164: @item @code{namespace_name}
 6165: Specifies the namespace to use.
 6166: @end table
 6167: 
 6168: @emph{Return Values}
 6169: 
 6170: Returns the process ID of the @code{libfreem} process on success, or @code{-1} on failure.
 6171: 
 6172: @emph{Example}
 6173: 
 6174: This example prompts the user to enter a FreeM namespace and then attempts to initialize @code{libfreem} to use the selected namespace.
 6175: 
 6176: @verbatim
 6177: #include <stdio.h>
 6178: #include <string.h>
 6179: #include <freem.h>
 6180: 
 6181: int main(int argc, char **argv, char **envp)
 6182: {
 6183:     char namespace[256];
 6184: 
 6185:     /* get the namespace name to use */
 6186:     printf("Enter FreeM namespace to use: ");
 6187:     fgets(namespace, 255, stdin);
 6188: 
 6189:     /* remove the trailing newline */
 6190:     namespace[strcspn(buffer, "\n")] = '\0';
 6191: 
 6192:     /* initialize libfreem using the provided namespace */
 6193:     if(freem_init("DEFAULT", namespace) == TRUE) {
 6194:         printf("\nSuccess\n");
 6195:     }
 6196:     else {
 6197:         printf("\nFailure\n");
 6198:     }
 6199:      
 6200:     return 0;
 6201: }
 6202: @end verbatim
 6203: 
 6204: @section freem_version()
 6205: @cindex libfreem, freem_version()
 6206: 
 6207: Returns the version of FreeM in use.
 6208: 
 6209: @emph{Synopsis}
 6210: 
 6211: @code{short freem_version(char *result);}
 6212: 
 6213: @emph{Parameters}
 6214: 
 6215: @table @asis
 6216: @item @code{result}
 6217: The @code{result} parameter is a pointer to a buffer in which the FreeM version information will be returned. The caller must allocate memory for this buffer prior to calling this API. It should be at least 20 bytes in length.
 6218: @end table
 6219: 
 6220: @emph{Return Value}
 6221: 
 6222: Returns @code{0}.
 6223: 
 6224: @emph{Example}
 6225: 
 6226: This example will display the FreeM version on standard output.
 6227: 
 6228: @verbatim
 6229: #include <stdio.h>
 6230: #include <string.h>
 6231: #include <freem.h>
 6232: 
 6233: int main(int argc, char **argv, char **envp)
 6234: {
 6235:     char version[20] = {0};
 6236: 
 6237:     freem_init(``USER'');
 6238:     freem_version(version);
 6239: 
 6240:     printf(``FreeM version:  %s\n'', version);
 6241: 
 6242: }
 6243: @end verbatim
 6244: 
 6245: @section freem_set()
 6246: @cindex libfreem, freem_set()
 6247: 
 6248: Sets a FreeM local node, global node, or writable SSVN node. 
 6249: 
 6250: @emph{Synopsis}
 6251: 
 6252: @code{short freem_set(freem_ref_t *ref);}
 6253: 
 6254: @emph{Parameters}
 6255: 
 6256: @table @asis
 6257: @item @code{freem_ref_t}
 6258: This parameter is a pointer to a @code{freem_ref_t} struct. The caller must allocate the memory for this struct.
 6259: @end table
 6260: 
 6261: @emph{Return Value}
 6262: 
 6263: Returns @code{OK} on success, or one of the other error values defined in @code{merr.h}.
 6264: 
 6265: @emph{Example}
 6266: 
 6267: This example sets the value @code{blue} into global node @code{^car("color")}.
 6268: 
 6269: @verbatim
 6270: #include <stdio.h>
 6271: #include <string.h>
 6272: #include <freem.h>
 6273: 
 6274: int main(int argc, char **argv, char **envp)
 6275: {
 6276:     freem_ref_t ref;
 6277: 
 6278:     /* we're setting a global */
 6279:     ref.reftype = MREF_RT_GLOBAL;
 6280: 
 6281:     /* access global "car" */
 6282:     strcpy(ref.name, "car");
 6283: 
 6284:     /* set up the subscripts */
 6285:     ref.subscript_count = 1;
 6286:     strcpy(ref.subscripts[0], "color");
 6287:  
 6288: 
 6289:     /* use the USER namespace */
 6290:     freem_init("USER");
 6291: 
 6292:     /* write the data out */
 6293:     freem_set(&ref);
 6294:     
 6295: }
 6296: @end verbatim
 6297: 
 6298: @section freem_get()
 6299: @cindex libfreem, freem_get()
 6300: 
 6301: Retrieves a FreeM local node, global node, or writable SSVN node.
 6302: 
 6303: @emph{Synopsis}
 6304: 
 6305: @code{short freem_get(freem_ref_t *ref);}
 6306: 
 6307: @emph{Parameters}
 6308: 
 6309: @table @asis
 6310: @item @code{freem_ref_t}
 6311: This parameter is a pointer to a @code{freem_ref_t} struct. The caller must allocate the memory for this struct.
 6312: @end table
 6313: 
 6314: @emph{Return Value}
 6315: 
 6316: Returns @code{OK} on success, or one of the other error values defined in @code{merr.h}.
 6317: 
 6318: @emph{Example}
 6319: 
 6320: This example retrieves the character set of the current process.
 6321: 
 6322: @verbatim
 6323: #include <stdio.h>
 6324: #include <sys/types.h>
 6325: #include <unistd.h>
 6326: #include <string.h>
 6327: #include <freem.h>
 6328: 
 6329: int main(int argc, char **argv, char)
 6330: {
 6331:     pid_t pid;
 6332:     freem_ref_t ref;
 6333: 
 6334:     /* get the PID of this process */
 6335:     pid = getpid();
 6336: 
 6337:     /* we want to access an SSVN */
 6338:     ref.reftype = MREF_RT_SSV;
 6339:     
 6340:     /* set up the name and subscripts */
 6341:     strcpy(ref.name, "JOB");
 6342: 
 6343:     ref.subscript_count = 2;
 6344:     sprintf(ref.subscripts[0], "%d", pid);
 6345:     strcpy(ref.subscripts[1], "CHARACTER");
 6346: 
 6347:     /* initialize libfreem, using the USER namespace */
 6348:     freem_init("USER");
 6349: 
 6350:     /* call libfreem API */
 6351:     freem_get(&ref);
 6352: 
 6353:     /* output the character set info */
 6354:     printf("PID %d character set is '%s'\n", pid, ref.value);
 6355: }
 6356: @end verbatim
 6357: 
 6358: @section freem_kill()
 6359: @cindex libfreem, freem_kill()
 6360: 
 6361: Deletes a FreeM local node, global node, or killable SSVN node, as well as all of its children.
 6362: 
 6363: @emph{short freem_kill(freem_ref_t *ref);}
 6364: 
 6365: @emph{Parameters}
 6366: 
 6367: @table @asis
 6368: @item @code{freem_ref_t}
 6369: This parameter is a pointer to a @code{freem_ref_t} struct. The caller must allocate the memory for this struct.
 6370: @end table
 6371: 
 6372: @emph{Return Value}
 6373: 
 6374: Returns @code{OK} on success, or one of the other error values defined in @code{merr.h}.
 6375: 
 6376: @emph{Example}
 6377: 
 6378: @verbatim
 6379: #include <stdio.h>
 6380: #include <string.h>
 6381: #include <freem.h>
 6382: 
 6383: int main(int argc, char **argv, char **envp)
 6384: {
 6385:     freem_ref_t ref;
 6386: 
 6387:     /* we're killing a global node */
 6388:     ref.reftype = MREF_RT_GLOBAL;
 6389: 
 6390:     /* access global "car" */
 6391:     strcpy(ref.name, "car");
 6392: 
 6393:     /* set up the subscripts */
 6394:     ref.subscript_count = 0;
 6395: 
 6396:     /* use the USER namespace */
 6397:     freem_init("USER");
 6398: 
 6399:     /* kill the global and all its descendant subscripts */
 6400:     freem_kill(&ref);    
 6401: }
 6402: @end verbatim
 6403: 
 6404: @section freem_data()
 6405: @cindex libfreem, freem_data()
 6406: 
 6407: @section freem_order()
 6408: @cindex libfreem, freem_order()
 6409: 
 6410: @section freem_query()
 6411: @cindex libfreem, freem_query()
 6412: 
 6413: @section freem_lock()
 6414: @cindex libfreem, freem_lock()
 6415: 
 6416: @section freem_unlock()
 6417: @cindex libfreem, freem_unlock()
 6418: 
 6419: @section freem_tstart()
 6420: @cindex libfreem, freem_tstart()
 6421: 
 6422: @section freem_trestart()
 6423: @cindex libfreem, freem_trestart()
 6424: 
 6425: @section freem_trollback()
 6426: @cindex libfreem, freem_trollback()
 6427: 
 6428: @section freem_tlevel()
 6429: @cindex libfreem, freem_tlevel()
 6430: 
 6431: @section freem_tcommit()
 6432: @cindex libfreem, freem_tcommit()
 6433: 
 6434: @section freem_function()
 6435: @cindex libfreem, freem_function()
 6436: 
 6437: @section freem_procedure()
 6438: @cindex libfreem, freem_procedure()
 6439: 
 6440: @node FreeM Administrator
 6441: @appendix FreeM Administrator
 6442: @cindex utilities, system management
 6443: @cindex utilities, fmadm
 6444: @cindex fmadm
 6445: 
 6446: The @code{fmadm} utility is the preferred method of managing a FreeM installation, and will eventually replace all of the existing utilities.
 6447: Unlike the existing, legacy utilities, @code{fmadm} presents a consistent, simple interface for all FreeM management tasks, and is namespace-aware.
 6448: This appendix will document each @code{fmadm} facility as it is implemented, until all of the legacy utilities have been replaced.
 6449: 
 6450: The @code{fmadm} utility's functions all follow the below, consistent syntax:
 6451: 
 6452: @example
 6453: usage:  fmadm <action> <object> <namespace> [OPTIONS]
 6454: @end example
 6455: 
 6456: The @emph{action} keyword can be one of the following:
 6457: 
 6458: @table @emph
 6459: 
 6460: @item list
 6461: Lists instances of @emph{object}
 6462: 
 6463: @item examine
 6464: Examines a single instance of @emph{object}
 6465: 
 6466: @item verify
 6467: Verifies the integrity of @emph{object}
 6468: 
 6469: @item compact
 6470: Compacts @emph{object}
 6471: 
 6472: @item repair
 6473: Repairs integrity problems in @emph{object}
 6474: 
 6475: @item create
 6476: Creates an instance of @emph{object}
 6477: 
 6478: @item remove
 6479: Removes an instance of @emph{object}
 6480: 
 6481: @item import
 6482: Imports an @emph{object}
 6483: 
 6484: @item export
 6485: Exports an @emph{object}
 6486: 
 6487: @item backup
 6488: Creates a backup of @emph{object}
 6489: 
 6490: @item restore
 6491: Restores a backup of @emph{object}
 6492: 
 6493: @item migrate
 6494: Migrates an instance of @emph{object} from an older FreeM version to the current version
 6495: 
 6496: @item edit
 6497: Edits an instance of @emph{object}
 6498: 
 6499: @end table
 6500: 
 6501: The @emph{object} keyword can be one of the following:
 6502: 
 6503: @table @emph
 6504: 
 6505: @item lock
 6506: The FreeM @code{LOCK} table.
 6507: 
 6508: Supported actions are @code{list} and @code{remove}.
 6509: 
 6510: @item journal
 6511: FreeM after-image journaling.
 6512: 
 6513: Supported actions are @code{examine} and @code{restore}.
 6514: 
 6515: The @code{examine} action will dump the after-image journal entries for the selected namespace in human-readable format.
 6516: 
 6517: The @code{restore} action will play after-image journals forward for the selected namespace.
 6518: 
 6519: @item namespace
 6520: FreeM namespaces (collections of M routines and globals).
 6521: 
 6522: No actions yet implemented.
 6523: 
 6524: @item global
 6525: The data files representing each FreeM @emph{global}.
 6526: 
 6527: Supported actions are @code{list}, @code{examine}, @code{remove}, and @code{verify}.
 6528: 
 6529: @item routine
 6530: An M routine, stored as a @code{.m} file.
 6531: 
 6532: Supported actions are @code{list}, @code{examine}, @code{remove}, @code{import}, @code{export}, @code{backup}, and @code{edit}.
 6533: 
 6534: @item job
 6535: A UNIX process representing an instance of the FreeM runtime.
 6536: 
 6537: Supported actions are @code{list} and @code{examine}.
 6538: 
 6539: @end table
 6540: 
 6541: 
 6542: @node FreeM Legacy Utilities
 6543: @appendix FreeM Legacy Utilities
 6544: @cindex utilities, legacy
 6545: 
 6546: @section Global Compactor (gcompact)
 6547: @cindex utilities, legacy, gcompact
 6548: 
 6549: Compacts the specified global in place.
 6550: 
 6551: @emph{Syntax}
 6552: 
 6553: @example
 6554: gcompact @emph{/path/to/global/file}
 6555: @end example
 6556: 
 6557: @section Block Examiner (gfix)
 6558: @cindex utilities, gfix
 6559: 
 6560: The @emph{gfix} interactive utility program permits navigation of the B-tree structure of the specified global a block at a time.
 6561: 
 6562: @emph{Syntax}
 6563: 
 6564: @example
 6565: gfix @emph{</path/to/global/file>}
 6566: @end example
 6567: 
 6568: @section Global Repair Tool (grestore)
 6569: @cindex utilities, legacy, grestore
 6570: 
 6571: This utility will fix problems with the specified global.
 6572: 
 6573: @emph{Syntax}
 6574: 
 6575: @example
 6576: grestore @emph{</path/to/global/file>}
 6577: @end example
 6578: 
 6579: @node FreeM VIEW Commands and Functions
 6580: @appendix FreeM VIEW Commands and Functions
 6581: 
 6582: @section VIEW 16: Total Count of Error Messages/View Single Error Message
 6583: @cindex VIEW commands/functions, 16, total count of error messages/view single error message
 6584: 
 6585: Unknown semantics
 6586: 
 6587: @section VIEW 17: Intrinsic Z-Commands
 6588: @cindex VIEW commands/functions, 17, intrinsic Z-commands
 6589: 
 6590: Allows the user to retrieve or specify the list of intrinsic Z-commands that FreeM will attempt to run internally, allowing intrinsic Z-commands implemented internally to be replaced with M equivalents implemented as %-routines in the @code{SYSTEM} namespace.
 6591: 
 6592: @section VIEW 18: Intrinsic Z-Functions
 6593: @cindex VIEW commands/functions, 18, intrinsic Z-functions
 6594: 
 6595: Allows the user to retrieve or specify the list of intrinsic Z-functions that FreeM will attempt to run internally, allowing intrinsic Z-functions implemented internally to be replaced with M equivalents implemented as %-routines in the @code{SYSTEM} namespace.
 6596: 
 6597: @section VIEW 19: Intrinsic Special Variables
 6598: @cindex VIEW commands/functions, 19, intrinsic special variables
 6599: 
 6600: Allows the user to retrieve or specify which special variables are implemented internally.
 6601: 
 6602: @section VIEW 20: Break Service Code
 6603: @cindex VIEW commands/functions, 20, break service code
 6604: 
 6605: Allows the user to view or specify the code that will be run when a @code{BREAK} is encountered.
 6606: 
 6607: @section VIEW 21: View Size of Last Global
 6608: @cindex VIEW commands/functions, 21, view size of last global
 6609: 
 6610: Allows the user to view the size of the last referenced global.
 6611: 
 6612: @section VIEW 22: Count VIEW 22 Aliases
 6613: @cindex VIEW commands/functions, 22, count VIEW 22 aliases
 6614: 
 6615: Retrieves the number of VIEW 22 aliases in effect.
 6616: 
 6617: @section VIEW 23: View Contents of Input Buffer
 6618: @cindex VIEW commands/functions, 23, input buffer contents
 6619: 
 6620: Retrieves the contents of the I/O input buffer.
 6621: 
 6622: @section VIEW 24: Maximum Number of Screen Rows
 6623: @cindex VIEW commands/functions, 24, maximum number of screen rows
 6624: 
 6625: Retrieves the maximum number of screen rows supported in the current FreeM build.
 6626: 
 6627: @section VIEW 25: Maximum Number of Screen Columns
 6628: @cindex VIEW commands/functions, 25, maximum number of screen columns
 6629: 
 6630: Retrieves the maximum number of screen columns supported in the current FreeM build.
 6631: 
 6632: @section VIEW 26: DO/FOR/XECUTE Stack Pointer
 6633: @cindex VIEW commands/functions, 26, DO/FOR/XECUTE stack pointer
 6634: 
 6635: Retrieves the @code{DO}, @code{FOR}, and @code{XECUTE} stack pointer.
 6636: 
 6637: @section VIEW 27: DO/FOR/XECUTE Stack Pointer (On Error)
 6638: @cindex VIEW commands/functions, 27, DO/FOR/XECUTE stack pointer, on error
 6639: 
 6640: Retrieves the @code{DO}, @code{FOR}, and @code{XECUTE} stack pointer (on error).
 6641: 
 6642: @section VIEW 29: Copy Symbol Table
 6643: @cindex VIEW commands/functions, 29, copy symbol table
 6644: 
 6645: Copies the symbol table? We aren't currently aware of what this means.
 6646: 
 6647: @section VIEW 30: Inspect Arguments
 6648: @cindex VIEW commands/functions, 30, inspect arguments
 6649: 
 6650: Retrieves the arguments passed to the @code{freem} executable.
 6651: 
 6652: @section VIEW 31: Count Environment Variables
 6653: @cindex VIEW commands/functions, 31, count environment variables
 6654: 
 6655: Allows the user to inspect the number of variables in the process environment table.
 6656: 
 6657: @emph{Syntax}
 6658: 
 6659: @example
 6660: WRITE $VIEW(31),!
 6661: @end example
 6662: 
 6663: @node Implementation Limits
 6664: @appendix Implementation Limits
 6665: 
 6666: @cindex limitations, memory
 6667: @cindex maximum size, routine
 6668: @cindex maximum size, global
 6669: @cindex maximum size, string
 6670: 
 6671: @node US-ASCII Character Set
 6672: @appendix US-ASCII Character Set
 6673: 
 6674: @multitable {Code} {Character} 
 6675: @item Code @tab Character
 6676: @item 000 @tab @code{<NUL>}
 6677: @item 001 @tab @code{<SOH>}
 6678: @item 002 @tab @code{<STX>}
 6679: @item 003 @tab @code{<ETX>}
 6680: @item 004 @tab @code{<EOT>}
 6681: @item 005 @tab @code{<ENQ>}
 6682: @item 006 @tab @code{<ACK>}
 6683: @item 007 @tab @code{<BEL>}
 6684: @item 008 @tab @code{<BS>}
 6685: @item 009 @tab @code{<HT>}
 6686: @item 010 @tab @code{<LF>}
 6687: @item 011 @tab @code{<VT>}
 6688: @item 012 @tab @code{<FF>}
 6689: @item 013 @tab @code{<CR>}
 6690: @item 014 @tab @code{<SO>}
 6691: @item 015 @tab @code{<SI>}
 6692: @item 016 @tab @code{<DLE>}
 6693: @item 017 @tab @code{<DC1>}
 6694: @item 018 @tab @code{<DC2>}
 6695: @item 019 @tab @code{<DC3>}
 6696: @item 020 @tab @code{<DC4>}
 6697: @item 021 @tab @code{<NAK>}
 6698: @item 022 @tab @code{<SYN>}
 6699: @item 023 @tab @code{<ETB>}
 6700: @item 024 @tab @code{<CAN>}
 6701: @item 025 @tab @code{<EM>}
 6702: @item 026 @tab @code{<SUB>}
 6703: @item 027 @tab @code{<ESC>}
 6704: @item 028 @tab @code{<FS>}
 6705: @item 029 @tab @code{<GS>}
 6706: @item 030 @tab @code{<RS>}
 6707: @item 031 @tab @code{<US>}
 6708: @item 032 @tab @code{<space>}
 6709: @item 033 @tab !
 6710: @item 034 @tab ``
 6711: @item 035 @tab #
 6712: 
 6713: 
 6714: @end multitable
 6715: 
 6716: @node FreeM Project Coding Standards
 6717: @appendix FreeM Project Coding Standards
 6718: 
 6719: @section Module Headers
 6720: @cindex coding standards, module headers
 6721: 
 6722: Module headers should adhere to the following format (where @code{Dollar} should be replaced with a dollar sign):
 6723: 
 6724: @verbatim
 6725: /*
 6726:  *   DollarIdDollar
 6727:  *    Function prototypes, structs, and macros for FreeM
 6728:  *    binding library
 6729:  *
 6730:  *  
 6731:  *   Author: Serena Willis <snw@coherent-logic.com>
 6732:  *    Copyright (C) 1998 MUG Deutschland
 6733:  *    Copyright (C) <Year> Coherent Logic Development LLC
 6734:  *
 6735:  *   This file is part of FreeM.
 6736:  *
 6737:  *   FreeM is free software: you can redistribute it and/or modify
 6738:  *   it under the terms of the GNU Affero Public License as published by
 6739:  *   the Free Software Foundation, either version 3 of the License, or
 6740:  *   (at your option) any later version.
 6741:  *
 6742:  *   FreeM is distributed in the hope that it will be useful,
 6743:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 6744:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 6745:  *   GNU Affero Public License for more details.
 6746:  *
 6747:  *   You should have received a copy of the GNU Affero Public License
 6748:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
 6749:  *
 6750:  *   DollarLogDollar
 6751:  *
 6752:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
 6753:  * SPDX-License-Identifier: AGPL-3.0-or-later
 6754:  **/
 6755: @end verbatim
 6756: 
 6757: @section Variable Naming
 6758: @cindex coding standards, variable naming
 6759: 
 6760: Variables should be named in all lowercase letters, and words within them delimited by underscores, such as @code{my_useful_variable}. @code{PascalCase} and @code{camelCase} are not to be used in this codebase under any circumstances.
 6761: 
 6762: Constants defined via the C preprocessor should be in all uppercase letters, with words within them likewise delimited by underscores, such as:
 6763: 
 6764: @verbatim
 6765: #define MY_USEFUL_CONSTANT 1
 6766: @end verbatim
 6767: 
 6768: @section Indentation and General Layout
 6769: @cindex coding standards, indentation
 6770: @cindex coding standards, layout
 6771: 
 6772: This project uses four spaces for indentation. Tabs are not to be used under any circumstances, and all source files must use a linefeed character to delineate lines. If you are working on a Windows machine, you must take care to follow this, as Windows will use a carriage return followed by a linefeed by default.
 6773: 
 6774: This project follows a modified version of what is known as the Stroustrup indentation style.
 6775: 
 6776: @section Brace Placement (Functions)
 6777: @cindex coding standards, brace placement, functions
 6778: 
 6779: We use modern, ANSI-style function prototypes, with the type specifier on the same line as the function name. You may encounter other styles in the code, but we are transitioning to the new style as time permits.
 6780: 
 6781: Below is a correct example:
 6782: 
 6783: @verbatim
 6784: int main(int argc, char **argv, char **envp)
 6785: {
 6786: 
 6787: }
 6788: @end verbatim
 6789: 
 6790: @section Brace Placement (if-for-while-do)
 6791: @cindex coding standards, brace placement, if-for-while-do
 6792: 
 6793: The @code{if} keyword should be followed by one space, then the opening paren and conditional expression. We also use Stroustrup-style @code{else} blocks, rather than the K&R 'cuddled' @code{else}:
 6794: 
 6795: @verbatim
 6796: if (x) {
 6797: ...
 6798: }
 6799: else {
 6800: ...
 6801: }
 6802: 
 6803: while (1) {
 6804: ...
 6805: }
 6806: 
 6807: for (i = 1; i < 10; i++) {
 6808: ...
 6809: }
 6810: 
 6811: do {
 6812: ...
 6813: } while (x);
 6814: @end verbatim
 6815: 
 6816: Single-statement if blocks should be isolated to a single line:
 6817: 
 6818: @verbatim
 6819: if (x) stmt();
 6820: @end verbatim
 6821: 
 6822: not:
 6823: 
 6824: @verbatim
 6825: if (x)
 6826:     stmt ();
 6827: @end verbatim
 6828: 
 6829: Notice that there is a space between @code{if} and @code{(x)}, and also between @code{stmt} and @code{()}. This should be followed throughout the code.
 6830: 
 6831: If an @code{if} block has an @code{else if} or @code{else}, all parts of the construct must be bracketed, even if one or more of them contain only one statement:
 6832: 
 6833: @verbatim
 6834: if (x) {
 6835:     foo();
 6836: }
 6837: else if (y) {
 6838:     bar();
 6839: }
 6840: else {
 6841:     bas();
 6842: }
 6843: @end verbatim
 6844: 
 6845: @section Labels and goto
 6846: @cindex coding standards, labels
 6847: @cindex coding standards, goto
 6848: 
 6849: Labels must begin in column 1, and have two lines of vertical space above and one beneath.
 6850: 
 6851: @section Preprocessor Conditionals
 6852: @section coding standards, preprocessor conditionals
 6853: 
 6854: I have struggled with this, but have settled upon the standard practice of keeping them in column 1.
 6855: 
 6856: @section Overall Program Spacing
 6857: @cindex coding standards, spacing of programs
 6858: 
 6859: @itemize @bullet
 6860: @item
 6861: Variable declarations fall immediately beneath the opening curly brace, and should initialize the variable right there whenever initialization is used.
 6862: 
 6863: @item
 6864: One line between the last variable declaration and the first line of real code.
 6865: 
 6866: @item
 6867: The @code{return} statement of a function (when used as the last line of a function) should have one blank line above it and none below it.
 6868: 
 6869: @item
 6870: Really long functions (those whose entire body is longer than 24 lines) should have a comment immediately following the closing curly brace of the function, telling you what function the closing brace terminates.
 6871: @end itemize
 6872: 
 6873: @section The switch() Statement
 6874: @cindex coding standards, switch()
 6875: 
 6876: We indent @code{case} one level beneath @code{switch()}, and the code within each @code{case} beneath the @code{case}. Each @code{case} should have one line of vertical whitespace above it:
 6877: 
 6878: @verbatim
 6879: switch(foo) {
 6880: 
 6881:     case some_const:
 6882:         foo();
 6883: 
 6884:         break;
 6885: 
 6886:     case some_other_const:
 6887:         bar();
 6888: 
 6889:         break;	    
 6890: 
 6891:     default:
 6892:         exit(1);
 6893: 
 6894:         break;
 6895: }
 6896: @end verbatim
 6897: 
 6898: @section Comments
 6899: @cindex coding standards, comments
 6900: 
 6901: We use C-style comments (@code{/* comment */}) exclusively, even on single-line comments. C++ comments (@code{// comment}) are not permitted.
 6902: 
 6903: @node Index
 6904: @unnumbered Index
 6905: 
 6906: @printindex cp
 6907: 
 6908: @bye

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>