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