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