Initializing help system before first use

mmsystem

Topics covered in this chapter:

The mmsystem module provides a set of procedures and functions related to the operating system. Note that the behavior of these operators may vary between systems. To use this module, the following line must be included in the header of the Mosel model file:

 uses 'mmsystem'

New functionality for the Mosel language

The type text

This module provides the type text for text manipulation. Like the Mosel basic type string, this new type may be generated from all objects that can be converted to a text representation and supports the usual string operations (like concatenation or formatting). In addition, text objects can be generated from structured entities (like arrays or lists); altered (one can get and change a single as well as a sequence of characters in a text); offer a wider set of operations (like insertion/deletion/search of substrings) and, as all module types, are passed by reference to subroutines. Note that this type supports creation of constants (i.e. it can be used in sets of constants) and implicit conversion from string: a routine expecting a text as parameter may be used with a string instead (in this case the compiler creates a temporary text from the provided string). When creating a text object from a structured type it is possible to specify a limit on the size of the generated string. For instance if S is a set, text(S,128) will produce a textual representation of S of at most 128 characters.

The type date

As the name suggests, the type date is used to represent a calendar date. Internally, a date is stored as three independent integers for representing the year (-32768 to 32767), the month (-128 to 127) and the day in the month (-128 to 127). The validity of a date can be checked using the function isvalid. A date object can be initialized by a text string, a single or three numerical values. In the first case, the conversion is processed using a predefined date format (see datefmt); in the second case, the integer is interpreted as the number of days elapsed since 1/1/1970 (this value can be negative); finally, if three integers are used, they are respectively interpreted as the year, month and day for the date. The constant SYS_NOW may also be used to initialize a date: date(SYS_NOW) is the current date (local time). This type also supports creation of constants (i.e. it can be used in sets of constants), assignment, comparison as well as difference (returned in number of days) and addition/subtraction of an integer (number of days).

The type time

The type time is used to represent a time during the day. Internally, a time object is stored as an integer representing a number of milliseconds. A time object can be initialized by a text string or one to four numerical values. In the first case, the conversion is processed using a predefined time format (see timefmt); in the second case, the integer is interpreted as a number of milliseconds. When two to four integers are used, they are understood as the hours, minutes, seconds and milliseconds. The constant SYS_NOW may also be used to initialize a time: time(SYS_NOW) is the current time (local time). This type also supports creation of constants (i.e. it can be used in sets of constants), assignment, comparison as well as difference (returned in number of milliseconds) and addition/subtraction of an integer (number of milliseconds).

The type datetime

The type datetime is used to represent a timestamp by combining a date and a time. A datetime object can be initialized by a text string, a pair date and time or a numerical value. In the first case, the conversion is processed using a predefined time format (see datetimefmt); in the third case, the number is interpreted as the number of seconds elapsed since 1/1/1970 at midnight (this value can be negative). If the provided number is a real value, the fractional part is stored as a number of milliseconds. The constant SYS_NOW may also be used to initialize a datetime: datetime(SYS_NOW) is the current date and time (local time). This type also supports creation of constants (i.e. it cand be used in sets of constants), assignment, comparison as well as difference (returned in number of seconds) and addition/subtraction of a numerical value (number of seconds).

The type parsectx

This module publishes a set of routines for parsing input text strings (for instance parseint or nextfield). These routines use several module parameters for both their configuration and as a way to record their internal state: a variable of type parsectx may be used as a replacement for these module parameters in order to implement parsing procedures independent of the rest of the program. A single parsectx object integrates endparse (see sys_endparse), sepchar (see sys_sepchar), trim (see sys_trim) and qtype (see sys_qtype). The current value of each of these components can be accessed using the corresponding set and get routine (for instance getendparse).

The type textarea

The textarea type is used by the regular expression matching function regmatch to return locations in the input string. Each text area is defined by a starting position (that is an offset in the original string) and an ending position characterised by the offset of the character following the region to be considered. Functions getstart and getsucc can be used to retrieve these properties.

For instance, the following statement displays the region ta of the text txt:

writeln(copytext(txt,ta.start,ta.succ-1))

This can also be written as follows:

writeln(copytext(txt,ta))

I/O drivers

The mmsystem module provides two IO drivers: the first one allows to use a string or text object as a file and the second connects a Mosel input or output stream to a program started in a different process. Using this driver, it is possible to get the output of an external program (for instance the result of a preprocessor to feed the Mosel compiler) or implement a basic bidirectional inter process communication thanks to the openpipe procedure (which relies on this IO driver).

Driver text

text:ident

This driver uses a model variable of type string or text as its input or output media. The ident argument it requires is therefore the name of this variable that must be declared globally public to the model or have been published with publish (such that it can always be found independently of the compiler settings).String objects can only be accessed for reading while text entities can be used for both reading and writing.

In the following example the constant string "T" is used as the initialization file for variable "A":

declarations
 public T="A:123"
 A:integer
end-declarations
initializations from "text:T"
 A
end-initializations

Driver pipe

pipe:program [options...]

The file name for this driver is an external program with its options. Options are separated by spaces or tabulations and may be quoted using either single or double quotes. A quoted option may contain any kind of character except the quote used to delimit the string.

When the system opens a pipe, a new process is started for executing the given program and default input and output streams are directed to system pipes. If the file is open for reading (resp. writing), the default ouput stream (resp. input stream) of the new process becomes the current input stream (resp. output stream) of the model. To locate the program to be executed, the system relies on the PATH environment variable. Detection of error (typically the program cannot be found or is not executable) differs depending on the operating system: under Windows, the error is reported immediately and the pipe is not open. With Posix systems, no error is reported but following IO operations fail.

When the file is closed, both input and output streams of the external process are closed then the system waits for its termination: in order to avoid a lock up of the Mosel program one must make sure that the external program ends its execution when default input and output streams are closed.

Example: the following command could be used with Mosel Console for compiling the model mymod.mos after it has been processed by the C preprocessor. Note that we have to provide an output file name since the compiler cannot deduce it from the source file name.

For a Posix systems:

compile 'mmsystem.pipe:cpp mymod.mos' '' mymod.bim

For Windows (with MSVC):

compile 'mmsystem.pipe:cl /E mymod.mos' '' mymod.bim

When Mosel is running in restricted mode (see Section mosel command: restricted mode), this driver behaves like the system procedure.

© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.