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