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