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