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