Functions
Contents:
- Var
- Var Creation
- Arithmetical Operators
- Dynamic Array Creation, Access And Update
- String Creation
- String Scanning
- String Conversion - Non-Mutating - Chainable
- String Mutation - Standalone Commands
- I/O Conversion
- Dynamic Array Functions
- Dynamic Array Filters
- Dynamic Array Mutators Standalone Commands
- Dynamic Array Search
- Database Access
- Database Management
- Database File I/O
- Database Sort/Select
- OS Time/Date
- OS File I/O
- OS Directories
- OS Shell/Environment
- Output
- Input
- Math/Boolean
- I/O Conversion Codes
Var
Use | Function | Description |
---|
Var Creation
Use | Function | Description |
---|---|---|
var v1; | Create an unassigned var. Unassigned variables can be assigned conditionally in if/else statements or used as outbound arguments of function calls. A runtime error is thrown if a var is used before being assigned so silent "use before assign" bugs cannot occur.
| |
var v1 = expression; | Assign a var using a literal or an expression. Use "let" instead of "var" wherever possible as a shorthand way of writing "const var".
| |
if | v1.assigned() | Returns: True if the var is assigned, otherwise false |
if | v1.unassigned() | Returns: True if the var is unassigned, otherwise false |
var= | v2.or_default(defaultvalue) |
Returns: A copy of the var if it is assigned or the default value if it is not. Can be used to handle optional arguments in functions. defaultvalue: Cannot be unassigned.
Mutator: defaulter() |
v1.defaulter(defaultvalue) | If the var is unassigned then assign the default value to it, otherwise do nothing. defaultvalue: Cannot be unassigned.
| |
v1.swap(io v2) | Swap the contents of one var with another. Useful for stashing large strings quickly. They are moved using pointers without making copies or allocating memory. Eiher or both variables may be unassigned.
| |
var= | v2.move() | Force the contents of a var to be moved instead of copied. The moved var becomes an empty string. This allows large strings to be handled efficiently. They are moved using pointers without making copies or allocating memory. The moved var must be assigned otherwise a VarUnassigned error is thrown.
|
var= | v2.clone() | Returns a copy of the var. The cloned var may be unassigned, in which case the copy will be unassigned too.
|
var= | v1.dump() | Return a string describing internal data of a var. If the str is located on the heap then its address is given. typ: 0x01 str is available. 0x02 int is available. 0x04 dbl is available. 0x08 nan: str is not a number. 0x16 osfile: str, int and dbl have special meaning.
|
Arithmetical Operators
Use | Function | Description |
---|---|---|
if | v1.isnum() | Checks if a var is numeric. Returns: True if a var holds a double, an integer, or a string that is defined as numeric. A string is defined as numeric only if it consists of one or more digits 0-9, with an optional decimal point "." placed anywhere, with an optional + or - sign prefix, or it is the empty string "", which is defined to be zero.
|
var= | v1.num() | Returns a copy of the var if it is numeric or 0 otherwise. Returns: A guaranteed numeric var Allows working numerically with data that may be non-numeric.
|
var= | v2 + v3 | Addition Attempts to perform numeric operations on non-numeric strings will throw a runtime error VarNonNumeric. Floating point numbers are implicitly converted to strings with no more than 12 significant digits of precision. This practically eliminates all floatng point rounding errors. Internally, 0.1 + 0.2 looks like this using doubles. 0.10000000000000003 + 0.20000000000000004 -> 0.30000000000000004
|
var= | v2 - v3 | Subtraction |
var= | v2 * v3 | Multiplication |
var= | v2 / v3 | Division |
var= | v2 % v3 | Modulus |
v1 += v2 | Self addition
| |
v1 -= v2 | Self subtraction | |
v1 *= v2 | Self multiplication | |
v1 /= v2 | Self division | |
v1 %= v2 | Self modulus | |
v1 ++ | Post increment
| |
v1 -- | Post decrement
| |
++ v1 | Pre increment
| |
-- v1 | Pre decrement
|
Dynamic Array Creation, Access And Update
Use | Function | Description |
---|---|---|
var= | ""_var | The literal suffix "_var" allows dynamic arrays to be seamlessly embedded in code using a predefined set of visible equivalents of unprintable field mark characters as follows: ` = RM, Record mark ^ = FM, Field mark ] = VM, Value mark } = SM, Subvalue mark | = TM, Text mark ~ = ST, Subtext mark
|
var v1 = {"a", "b", "c" ...}; // Initializer list | Create a dynamic array var from a list. C++ constrains list elements to be all the same type: var, string, double, int, etc. but they all end up as fields of a dynamic array string.
| |
var= | v2(fieldno); v1(fieldno) = v2 | Dynamic array - field extraction, update and append: See also inserter() and remover().
Field access:
It is recommended to use "v1.f(fieldno)" syntax using a ".f(" prefix to access fields in expressions instead of plain "v1(fieldno)". The former syntax (using .f()) will always compile whereas the latter does not compile in all contexts. It will compile only if being called on a constant var or in a location which requires a var. This is due to C++ not making a clear distinction between usage on the left and right side of assignment operator =. Furthermore using plain round brackets without the leading .f can be confused with function call syntax.
|
var= | v2(fieldno, valueno); v1(fieldno, valueno) = v2 | Dynamic array - value update and append See also inserter() and remover().
Value access:
|
String Creation
Use | Function | Description |
---|---|---|
var= | v2 ^ v3 | String concatention operator ^ At least one side must be a var. "aa" ^ "22" will not compile but "aa" "22" will. Floating point numbers are implicitly converted to strings with no more than 12 significant digits of precision. This practically eliminates all floatng point rounding errors.
|
v1 ^= v2 | String self concatention ^= (append)
| |
var= | varnum.round(ndecimals = 0) | Convert a number into a string after rounding it to a given number of decimal places. Trailing zeros are not omitted. A leading "0." is shown where appropriate. 0.5 always rounds away from zero. i.e. 1.5 -> 2 and -2.5 -> -3 var: The number to be converted. ndecimals: Determines how many decimal places are shown to the right of the decimal point or, if ndecimals is negative, how many 0's to the left of it. Returns: A var containing an ASCII string of digits with a leading "-" if negative, and a decimal point "." if ndecimals is > 0.
Negative number of decimals rounds to the left of the decimal point
|
var= | var::chr(num) | Get a char given an integer 0-255. Returns: A string containing a single char 0-127 -> ASCII, 128-255 -> invalid UTF-8 which cannot be written to the database or used in many exodus string operations
|
var= | var::textchr(num) | Get a Unicode character given a Unicode Code Point (Number) Returns: A single Unicode character in UTF8 encoding.
|
var= | var::textchrname(unicode_code_point) | Get a Unicode character name unicode_code_point: 0 - 0x10FFFF. Returns: Text of the name or "" if not a valid Unicode Code Point
|
var= | varstr.str(num) | Get a string of repeated substrings. var: The substring to be repeated num: How many times to repeat the substring Returns: A string
|
var= | var::space(nspaces) | Get a string containing a given number of spaces. nspaces: The number of spaces required. Returns: A string of space chars.
|
var= | varnum.numberinwords(locale = "") |
Returns: A string representing a given number written in words instead of digits. locale: e.g. en_GB, ar_AE, el_CY, es_US, fr_FR etc or a language name e.g. "french".
|
String Scanning
Use | Function | Description |
---|---|---|
var= | strvar.at(pos1) | Get a single char from a string. pos1: First char is 1. Last char is -1. Returns: A single char if pos1 ± the length of the string, or "" if greater. Returns the first char if pos1 is 0 or (-pos1) > length.
|
var= | strvar.ord() | Get the char number of a char Returns: A number between 0 and 255. If given a string, then only the first char is considered. Equivalent to ord() in php
|
var= | strvar.textord() | Get the Unicode Code Point of a Unicode character. var: A UTF-8 string. Only the first Unicode character is considered. Returns: A number 0 to 0x10FFFF. Equivalent to ord() in python and ruby, mb_ord() php.
|
var= | strvar.len() | Get the length of a source string in number of chars Returns: A number
|
if | strvar.empty() | Checks if the var is an empty string. Returns: True if it is empty amd false if not. This is a shorthand and more expressive way of writing 'if (var == "")' or 'if (var.len() == 0)' or 'if (not var.len())' Note that 'if (var.empty())' is not exactly the same as 'if (not var)' because 'if (var("0.0")' is also defined as false. If a string can be converted to 0 then it is considered to be false. Contrast this with common scripting languages where 'if (var("0"))' is defined to be true.
|
var= | strvar.textwidth() | Count the number of output columns required for a given source string. Returns: A number Allows wide multi-column Unicode characters that occupy more than one space in a text file or terminal screen. Reduces combining characters to a single column. e.g. "e" followed by grave accent is multiple bytes but only occupies one output column. Does not properly calculate all possible combining sequences of graphemes e.g. face followed by colour
|
var= | strvar.textlen() | Count the number of Unicode code points in a source string. Returns: A number.
|
var= | strvar.fcount(sepstr) | Count the number of fields in a source string. sepstr: The separator character or substr that delimits individual fields. Returns: The count of the number of fields This is similar to "var.count(sepstr) + 1" but it returns 0 for an empty source string.
|
var= | strvar.count(sepstr) | Count the number of occurrences of a given substr in a source string. substr: The substr to count. Returns: The count of the number of sepstr found. Overlapping substrings are not counted.
|
if | strvar.starts(prefix) | Checks if a source string starts with a given prefix (substr). prefix: The substr to check for. Returns: True if the source string starts with the given prefix. Returns: False if prefix is "". DIFFERS from c++, javascript, python3. See contains() for more info.
|
if | strvar.ends(suffix) | Checks if a source string ends with a given suffix (substr). suffix: The substr to check for. Returns: True if the source string ends with given suffix. Returns: False if suffix is "". DIFFERS from c++, javascript, python3. See contains() for more info.
|
if | strvar.contains(substr) | Checks if a given substr exists in a source string. substr: The substr to check for. Returns: True if the source string starts with, ends with or contains the given substr. Returns: False if suffix is "". DIFFERS from c++, javascript, python3 Human logic: "" is not equal to "x" therefore x does not contain "". Human logic: Check each item (character) in the list for equality with what I am looking for and return success if any are equal. Programmer logic: Compare as many characters as are in the search string for presence in the list of characters and return success if there are no failures.
|
var= | strvar.index(substr, startchar1 = 1) | Find a substr in a source string. substr: The substr to search for. startchar1: The char position (1 based) to start the search at. The default is 1, the first char. Returns: The char position (1 based) that the substr is found at or 0 if not present.
|
var= | strvar.indexn(substr, occurrence) | Find the nth occurrence of a substr in a source string. substr: The string to search for. Returns: char position (1 based) or 0 if not present.
|
var= | strvar.indexr(substr, startchar1 = -1) | Find the position of substr working backwards from the end of the string towards the beginning. substr: The string to search for. Returns: The char position of the substr if found, or 0 if not. startchar1: defaults to -1 meaning start searching from the last char. Positive start1char1 counts from the beginning of the source string and negative startchar1 counts backwards from the last char.
|
var= | strvar.match(regex_str, regex_options = "") | Finds all matches of a given regular expression. Returns: Zero or more matching substrings separated by FMs. Any groups are in VMs.
regex_options:
|
var= | strvar.match(regex) | Ditto |
var= | strvar.search(regex_str, io startchar1, regex_options = "") | Search for the first match of a regular expression. startchar1: [in] char position to start the search from startchar1: [out] char position to start the next search from Returns: The 1st match like match() regex_options as for match()
|
var= | strvar.search(regex_str) | Ditto starting from first char |
var= | strvar.search(regex, io startchar1) | Ditto given a rex |
var= | strvar.search(regex) | Ditto starting from first char. |
var= | strvar.hash(std::uint64_t modulus = 0) | Get a hash of a source string. modulus: The result is limited to [0, modulus) Returns: A 64 bit signed integer. MurmurHash3 is used.
|
String Conversion - Non-Mutating - Chainable
Use | Function | Description |
---|---|---|
var= | strvar.ucase() | Convert to upper case
|
var= | strvar.lcase() | Convert to lower case
|
var= | strvar.tcase() | Convert to title case. Returns: Original source string with the first letter of each word is capitalised.
|
var= | strvar.fcase() | Convert to folded case. Returns the source string standardised in a way to enable consistent indexing and searching, Case folding is the process of converting text to a case independent representation. https://www.w3.org/International/wiki/Case_folding Accents can be significant. As in French cote, coté, côte and côté. Case folding is not locale-dependent.
|
var= | strvar.normalize() | Replace Unicode character sequences with their standardised NFC form. Unicode normalization is the process of converting Unicode strings to a standard form, making them binary comparable and suitable for text processing and comparison. It is an important part of Unicode text processing. For example, Unicode character "é" can be represented by either a single Unicode character, which is Unicode Code Point (\u00E9" - Latin Small Letter E with Acute), or a combination of two Unicode code points i.e. the ASCII letter "e" and a combining acute accent (Unicode Code Point "\u0301"). Unicode NFC definition converts the pair of code points to the single code point. Normalization is not locale-dependent.
|
var= | strvar.invert() | Simple reversible disguising of string text. It works by treating the string as UTF8 encoded Unicode code points and inverting the first 8 bits of their Unicode Code Points. Returns: A string. invert(invert()) returns to the original text. ASCII bytes become multibyte UTF-8 so string sizes increase. Inverted characters remain on their original Unicode Code Page but are jumbled up. Non-existant Unicode Code Points may be created but UTF8 encoding remains valid.
|
var= | strvar.lower() | Reduce all types of field mark chars by one level. Convert all FM to VM, VM to SM etc. Returns: The converted string. Note that subtext ST chars are not converted because they are already the lowest level. String size remains identical.
|
var= | strvar.raise() | Increase all types of field mark chars by one level. Convert all VM to FM, SM to VM etc. Returns: The converted string. The record mark char RM is not converted because it is already the highest level. String size remains identical.
|
var= | strvar.crop() | Remove any redundant FM, VM etc. chars (Trailing FM; VM before FM etc.)
|
var= | strvar.quote() | Wrap in double quotes.
|
var= | strvar.squote() | Wrap in single quotes.
|
var= | strvar.unquote() | Remove one pair of surrounding double or single quotes.
|
var= | strvar.trim(trimchars = " ") | Remove all leading, trailing and excessive inner bytes. trimchars: The chars (bytes) to remove. The default is space.
|
var= | strvar.trimfirst(trimchars = " ") | Ditto but only leading.
|
var= | strvar.trimlast(trimchars = " ") | Ditto but only trailing.
|
var= | strvar.trimboth(trimchars = " ") | Ditto but only leading and trailing, not inner.
|
var= | strvar.first() | Get the first char of a string. Returns: A char, or "" if empty. Equivalent to var.substr(1,length) or var[1, length] in Pick OS
|
var= | strvar.last() | Get the last char of a string. Returns: A char, or "" if empty. Equivalent to var.substr(-1, 1) or var[-1, 1] in Pick OS
|
var= | strvar.first(std::size_t length) | Get the first n chars of a source string. length: The number of chars (bytes) to get. Returns: A string of up to n chars. Equivalent to var.substr(1, length) or var[1, length] in Pick OS
|
var= | strvar.last(std::size_t length) | Extract up to length trailing chars Equivalent to var.substr(-length, length) or var[-length, length] in Pick OS
|
var= | strvar.cut(length) | Remove n chars (bytes) from the source string. length: Positive to remove first n chars or negative to remove the last n chars. If the absolute value of length is >= the number of chars in the source string then all chars will be removed. Equivalent to var.substr(length) or var[1, length] = "" in Pick OS
|
var= | strvar.paste(pos1, length, replacestr) | Insert a substr at an given position after removing a given number of chars. pos1: 0 or 1 : Remove length chars from the beginning and insert at the beginning. pos1: > than the length of the source string. Insert after the last char. pos1: -1 : Remove up to length chars before inserting.Insert on or before the last char. pos1: -2 : Insert on or before the penultimate char. Equivalent to var[pos1, length] = substr in Pick OS
|
var= | strvar.paste(pos1, insertstr) | Insert text at char position without overwriting any following chars Equivalent to var[pos1, 0] = substr in Pick OS
|
var= | strvar.prefix(insertstr) | Insert text at the beginning Equivalent to var[0, 0] = substr in Pick OS
|
var= | strvar.append(appendable, ...) | Append anything at the end of a string
|
var= | strvar.pop() | Remove one trailing char. Equivalent to var[-1, 1] = "" in Pick OS
|
var= | strvar.field(delimiter, fieldnx = 1, nfieldsx = 1) | Copies one or more consecutive fields from a string given a delimiter delimiter: A Unicode character. fieldno: The first field is 1, the last field is -1. Returns: A substring
|
var= | strvar.fieldstore(separator, fieldno, nfields, replacement) | fieldstore() replaces, inserts or deletes subfields in a string. fieldno: The field number to replace or, if not 1, the field number to start at. Negative fieldno counts backwards from the last field. nfields: The number of fields to replace or, if negative, the number of fields to delete first. Can be 0 to cause simple insertion of fields. replacement: A string that is the replacement field or fields. Returns: A modified copy of the original string. There is no way to simply delete n fields because the replacement argument cannot be omitted, however one can achieve the same result by replacing n+1 fields with the n+1th field. The replacement can contain multiple fields itself. If replacing n fields and the replacement contains < n fields then the remaining fields become "". Conversely, if the replacement contains more fields than are required, they are discarded.
If nfields is 0 then insert the replacement field(s) before fieldno
If nfields is negative then delete abs(n) fields before inserting whatever fields the replacement has.
If nfields exceeds the number of fields in the input then additional empty fields are added.
|
var= | strvar.substr(pos1, length) | substr version 1. Copies a substr of length chars from a given a starting char position. Returns: A substr or "". pos1: The char position to start at. If negative then start from a position counting backwards from the last char length: The number of chars to copy. If negative then copy backwards. This reverses the order of the chars in the returned substr. Equivalent to var[start, length] in Pick OS Not Unicode friendly.
If pos1 is negative then start counting backwards from the last char
If length is negative then work backwards and return chars reversed
|
var= | strvar.b(pos1, length) | Abbreviated alias of substr version 1. |
var= | strvar.substr(pos1) | substr version 2. Copies a substr from a given char position up to the end of the source string Returns: A substr or "". pos1: The char position to start at. If negative then start from a position counting backwards from the last char Equivalent to var[pos1, 9999999] in Pick OS Partially Unicode friendly but pos1 is in chars.
|
var= | strvar.b(pos1) | Shorthand alias of substr version 2. |
var= | strvar.substr(pos1, delimiterchars, out pos2) | substr version 3. Copies a substr from a given char position up to (but excluding) any one of some given delimiter chars Returns: A substr or "". pos1: [in] The position of the first char to copy. Negative positions count backwards from the last char of the string. pos2: [out] The position of the next delimiter char, or one char position after the end of the source string if no subsequent delimiter chars are found. COL2: is a predefined variable that can be used for pos2 instead of declaring a variable. An empty string may be returned if pos1 [in] points to one of the delimiter chars or points beyond the end of the source string. Equivalent to var[pos1, ",."] in Pick OS (non-numeric length). Works with any encoding including UTF8 for the source string but the delimiter chars are bytes. Add 1 to pos2 to skip over the next delimiter char to copy the next substr Works with any encoding including UTF8 for the source string but the delimiter chars are bytes. This function is similar to std::string::find_first_of but that function only returns pos2.
|
var= | strvar.b(pos1, delimiterchars, out pos2) | Shorthand alias of substr version 3. |
var= | strvar.substr2(io pos1, out delimiterno) | substr version 4. Copies a substr from a given char position up to (but excluding) the next field mark char (RM, FM, VM, SM, TM, ST). Returns: A substr or "". pos1: [in] The position of the first char to copy. Negative positions count backwards from the last char of the string. pos1: [out] The position of the first char of the next substr after whatever field mark char is found, or one char position after the end of the source string if no subsequent field mark char is found. field_mark_no: [out] A number (1-6) indicating which of the standard field mark chars was found, or 0 if not. An empty string may be returned if the pos1 [in] points to one of the field marks or beyond the end of the source string. pos1 [out] is correctly positioned to copy the next substr. Works with any encoding including UTF8. Was called "remove" in Pick OS. The equivalent in Pick OS was the statement "Remove variable From string At column Setting flag" ... This function is valuable for high performance processing of dynamic arrays. It is notably used in "list" to print parallel columns of mixed combinations of multivalues/subvalues and text marks correctly lined up mv to mv, sv to sv, tm to tm even when particular values, subvalues and text fragments are missing from particular columns. It is similar to version 3 of substr - substr(pos1, delimiterchars, pos2) except that in this version the delimiter chars are hard coded as the standard field mark chars (RM, FM, VM, SM, TM, ST) and it returns the first char position of the next substr, not the char position of the next field mark char.
|
var= | strvar.b2(io pos1, out field_mark_no) | Shorthand alias of substr version 4. |
var= | strvar.convert(fromchars, tochars) | Convert or delete chars one for one to other chars from_chars: chars to convert. If longer than to_chars then delete those characters instead of converting them. to_chars: chars to convert to Not UTF8 compatible.
|
var= | strvar.textconvert(fromchars, tochars) | Ditto for Unicode code points.
|
var= | strvar.replace(fromstr, tostr) | Replace all occurrences of one substr with another. Case sensitive.
|
var= | strvar.replace(regex, replacement_str) | Replace substrings using a regular expression. regex: A regular expression created by rex() or _rex. replacement_str: A literal to replace all matched substrings. The replacement string can include the following special replacement patterns: Pattern Inserts $$ Inserts a "$". $& Inserts the matched substring. Equivalent to $0. $` Inserts the portion of the string that precedes the matched substring. $' Inserts the portion of the string that follows the matched substring. $n Inserts the nth (1-indexed) capturing group where n is a positive integer less than 100.
|
var= | strvar.replace(regex, SomeFunction(match_str)) | Replace substrings using a regular expression and a custom function. Allows very complex string conversions. SomeFunction: Must return a var. Can be an inline anonymous lambda function. e.g. [](auto match_str) {return match_str;} // Does nothing. match_str: Text of a single match. If regex groups are used, match_str.f(1, 1) is the whole match, match_str.f(1, 2) is the first group, etc.
|
var= | strvar.unique() | Remove duplicate fields in an FM or VM etc. separated list
|
var= | strvar.sort(delimiter = FM) | Reorder fields in an FM or VM etc. separated list in ascending order Numeric data:
Alphabetic data:
|
var= | strvar.reverse(delimiter = FM) | Reorder fields in an FM or VM etc. separated list in descending order
|
var= | strvar.shuffle(delimiter = FM) | Randomise the order of fields in an FM, VM separated list
|
var= | strvar.parse(char sepchar = ' ') | Split a delimited string with embedded quotes into a dynamic array. Can be used to process CSV data. Replaces separator chars with FM chars except inside double or single quotes and ignoring escaped quotes \" \'
|
dim= | strvar.split(delimiter = FM) | Split a delimited string into a dim array. The delimiter can be multibyte Unicode. Returns: A dim array.
|
var= | strvar.fieldstore(delimiter, fieldno, nfields, replacement) |
String Mutation - Standalone Commands
Use | Function | Description |
---|---|---|
strvar.ucaser() | Upper case All string mutators follow the same pattern as ucaser.See the non-mutating functions for details.
| |
strvar.lcaser() | ||
strvar.tcaser() | ||
strvar.fcaser() | ||
strvar.normalizer() | ||
strvar.inverter() | ||
strvar.quoter() | ||
strvar.squoter() | ||
strvar.unquoter() | ||
strvar.lowerer() | ||
strvar.raiser() | ||
strvar.cropper() | ||
strvar.trimmer(trimchars = " ") | ||
strvar.trimmerfirst(trimchars = " ") | ||
strvar.trimmerlast(trimchars = " ") | ||
strvar.trimmerboth(trimchars = " ") | ||
strvar.firster() | ||
strvar.laster() | ||
strvar.firster(std::size_t length) | ||
strvar.laster(std::size_t length) | ||
strvar.cutter(length) | ||
strvar.paster(pos1, length, insertstr) | ||
strvar.paster(pos1, insertstr) | ||
strvar.prefixer(insertstr) | ||
strvar.appender(appendable, ...) | ||
strvar.popper() | ||
strvar.fieldstorer(delimiter, fieldno, nfields, replacement) | ||
strvar.substrer(pos1, length) | ||
strvar.substrer(pos1) | ||
strvar.converter(from_chars, to_chars) | ||
strvar.textconverter(from_characters, to_characters) | ||
strvar.replacer(regex, tostr) | ||
strvar.replacer(regex, SomeFunction(match_str)) | ||
strvar.replacer(fromstr, tostr) | ||
strvar.uniquer() | ||
strvar.sorter(delimiter = FM) | ||
strvar.reverser(delimiter = FM) | ||
strvar.shuffler(delimiter = FM) | ||
strvar.parser(char sepchar = ' ') |
I/O Conversion
Use | Function | Description |
---|---|---|
var= | var.oconv(convstr) | Converts internal data to output external display format according to a given conversion code or pattern If the internal data is invalid and cannot be converted then most conversions return the ORIGINAL data unconverted Throws a runtime error VarNotImplemented if convstr is invalid See [[#ICONV/OCONV PATTERNS]]
|
var= | var.iconv(convstr) | Converts external data to internal format according to a given conversion code or pattern If the external data is invalid and cannot be converted then most conversions return the EMPTY STRING "" Throws a runtime error VarNotImplemented if convstr is invalid See [[#ICONV/OCONV PATTERNS]]
|
var= | var.format(fmt_str, args, ...) | Classic format function in printf style vars can be formatted either with C++ format codes e.g. {:_>8.2f} or with exodus oconv codes e.g. {::MD20P|R(_)#8} as in the below example.
|
var= | strvar.from_codepage(codepage) | Converts from codepage encoded text to UTF-8 encoded exodus text e.g. Codepage "CP1124" (Ukrainian). Use Linux command "iconv -l" for complete list of code pages and encodings.
|
var= | strvar.to_codepage(codepage) | Converts to codepage encoded text from exodus UTF-8 encoded text
|
Dynamic Array Functions
Use | Function | Description |
---|---|---|
var= | strvar.f(fieldno, valueno = 0, subvalueno = 0) | f() is a highly abbreviated alias for the Pick OS field/value/subvalue extract() function. "f()" can be thought of as "field" although the function can extract values and subvalues as well. The convenient Pick OS angle bracket syntax for field extraction (e.g. xxx<20>) is not available in C++. The abbreviated exodus field extraction function (e.g. xxx.f(20)) is provided instead since field access is extremely heavily used in source code.
|
var= | strvar.extract(fieldno, valueno = 0, subvalueno = 0) | Extract a specific field, value or subvalue from a dynamic array.
|
var= | strvar.update(fieldno, valueno, subvalueno, replacement) | Same as var.updater() function but returns a new string instead of updating a variable in place. |
var= | strvar.update(fieldno, valueno, replacement) | Ditto for a specific multivalue |
var= | strvar.update(fieldno, replacement) | Ditto for a specific field |
var= | strvar.insert(fieldno, valueno, subvalueno, insertion) | Same as var.inserter() function but returns a new string instead of updating a variable in place. |
var= | strvar.insert(fieldno, valueno, insertion) | Ditto for a specific multivalue |
var= | strvar.insert(fieldno, insertion) | Ditto for a specific field |
var= | strvar.remove(fieldno, valueno = 0, subvalueno = 0) | Same as var.remover() function but returns a new string instead of updating a variable in place. "remove()" was called "delete()" in Pick OS/Basic. |
Dynamic Array Filters
Use | Function | Description |
---|---|---|
var= | strvar.sum() | Sum up multiple values into one higher level
|
var= | strvar.sumall() | Sum up all levels into a single figure
|
var= | strvar.sum(delimiter) | Ditto allowing commas etc.
|
var= | strvar.mv(opcode, var2) | Binary ops (+, -, *, /) in parallel on multiple values
|
Dynamic Array Mutators Standalone Commands
Use | Function | Description |
---|---|---|
strvar.updater(fieldno, replacement) | Replace a specific field in a dynamic array
| |
strvar.updater(fieldno, valueno, replacement) | Replace a specific value of a specific field in a dynamic array.
| |
strvar.updater(fieldno, valueno, subvalueno, replacement) | Replace a specific subvalue of a specific value of a specific field in a dynamic array.
| |
strvar.inserter(fieldno, insertion) | Insert a specific field in a dynamic array, moving all other fields up.
| |
strvar.inserter(fieldno, valueno, insertion) | Ditto for a specific value in a specific field, moving all other values up.
| |
strvar.inserter(fieldno, valueno, subvalueno, insertion) | Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
| |
strvar.remover(fieldno, valueno = 0, subvalueno = 0) | Remove a specific field (or value, or subvalue) from a dynamic array, moving all other fields (or values, or subvalues) down.
|
Dynamic Array Search
Use | Function | Description |
---|---|---|
var= | strvar.locate(target) | locate() with only the target substr argument provided searches unordered values separated by any of the field mark chars. Returns: The field, value, subvalue etc. number if found or 0 if not. Searching for empty fields, values etc. (i.e. "") will work. Locating "" in "]yy" will return 1, in "xx]]zz" 2, and in "xx]yy]" 3, however, locating "" in "xx" will return 0 because there is conceptually no empty value in "xx". Locate "" in "" will return 1.
|
if | strvar.locate(target, out valueno) | locate() with only the target substr provided and setting returned searches unordered values separated by any type of field mark chars. Returns: True if found Setting: Field, value, subvalue etc. number if found or the max number + 1 if not. Suitable for additiom of new values
|
if | strvar.locate(target, out setting, fieldno, valueno = 0) | locate() the target in unordered fields if fieldno is 0, or values if a fieldno is specified, or subvalues if the valueno argument is provided. Returns: True if found and with the field, value or subvalue number in setting. Returns: False if not found and with the max field, value or subvalue number found + 1 in setting. Suitable for replacement of new fields, values or subvalues.
|
if | strvar.locateby(ordercode, target, out valueno) | locateby() without fieldno or valueno arguments searches ordered values separated by VM chars. The order code can be AL, DL, AR, DR meaning Ascending Left, Descending Right, Ascending Right, Ascending Left. Left is used to indicate alphabetic order where 10 < 2. Right is used to indicate numeric order where 10 > 2. Data must be in the correct order for searching to work properly. Returns: True if found. In case the target is not exactly found then the correct value no for inserting the target is returned in setting.
|
if | strvar.locateby(ordercode, target, out setting, fieldno, valueno = 0) | locateby() ordered as above but in fields if fieldno is 0, or values in a specific fieldno, or subvalues in a specific valueno.
|
if | strvar.locateusing(usingchar, target) | locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
|
if | strvar.locateusing(usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0) | locate() the target in a specific field, value or subvalue using a specified delimiter and unordered data Returns: True If found and returns in setting the number of the delimited field found. Returns: False if not found and returns in setting the maximum number of delimited fields + 1 if not found. This is similar to the main locate command but the delimiter char can be specified e.g. a comma or TM etc.
|
if | strvar.locatebyusing(ordercode, usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0) | locatebyusing() supports all the above features in a single function. Returns: True if found. |
Database Access
Use | Function | Description |
---|---|---|
if | conn.connect(conninfo = "") | For all db operations, the operative var can either be a db connection created with dbconnect() or be any var and a default connection will be established on the fly. The db connection string (conninfo) parameters are merged from the following places in descending priority. 1. Provided in connect()'s conninfo argument. See 4. for the complete list of parameters. 2. Any environment variables EXO_HOST EXO_PORT EXO_USER EXO_DATA EXO_PASS EXO_TIME 3. Any parameters found in a configuration file at ~/.config/exodus/exodus.cfg 4. The default conninfo is "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10" Setting environment variable EXO_DBTRACE=1 will cause tracing of db interface including SQL commands.
|
if | conn.attach(filenames) | "attach" causes the given filenames to be associated with a specific connection for the remainder of the session. It is not necessary to attach files before opening them. Attachments can changed by calling attach() or open() on a different connection or they can be removed by calling detach(). var: Defaults to the default connection. filenames: FM separated list. Returns: false if any filename does not exist and cannot be opened on the given connection. All filenames that can be opened on the conneciton are attached even if some cannot. Internally, attach merely opens each filename on the given connection causing them to be added to an internal cache.
|
conn.detach(filenames) | Removes files from the internal cache created by previous open() and attach() calls. var: Defaults to the default connection. filenames: FM separated list. | |
if | conn.begintrans() | Begin a db transaction.
|
if | conn.statustrans() | Check if a db transaction is in progress.
|
if | conn.rollbacktrans() | Rollback a db transaction.
|
if | conn.committrans() | Commit a db transaction. Returns: True if successfully committed or if there was no transaction in progress, otherwise false.
|
if | conn.sqlexec(sqlcmd) | Execute an sql command. Returns: True if there was no sql error otherwise lasterror() returns a detailed error message.
|
if | conn.sqlexec(sqlcmd, io response) | Execute an SQL command and capture the response. Returns: True if there was no sql error otherwise response contains a detailed error message. response: Any rows and columns returned are separated by RM and FM respectively. The first row is the column names. Recommended: Don't use sql directly unless you must to manage or configure a database.
|
conn.disconnect() | Closes db connection and frees process resources both locally and in the database server.
| |
conn.disconnectall() | Closes all connections and frees process resources both locally and in the database server(s). All connections are closed automatically when a process terminates.
| |
var= | var::lasterror() |
Returns: The last os or db error message.
|
var::loglasterror(source = "") | Log the last os or db error message. Output: to stdlog Prefixes the output with source if provided.
|
Database Management
Use | Function | Description |
---|---|---|
if | conn.dbcreate(new_dbname, old_dbname = "") | Create a named database on a particular connection. The target database cannot already exist. Optionally copies an existing database from the same connection and which cannot have any current connections.
|
if | conn.dbcopy(from_dbname, to_dbname) | Create a named database as a copy of an existing database. The target database cannot already exist. The source database must exist on the same connection and cannot have any current connections.
|
var= | conn.dblist() |
Returns: A list of available databases on a particular connection.
|
if | conn.dbdelete(dbname) | Delete (drop) a named database. The target database must exist and cannot have any current connections.
|
if | conn.createfile(filename) | Create a named db file. filenames ending with "_temp" only last until the connection is closed.
|
if | conn.renamefile(filename, newfilename) | Rename a db file.
|
var= | conn.listfiles() |
Returns: A list of all files in a database
|
if | conn.clearfile(filename) | Delete all records in a db file
|
if | conn.deletefile(filename) | Delete a db file
|
var= | conn_or_file.reccount(filename = "") |
Returns: The approx. number of records in a db file. Might return -1 if not known. Not very accurate inside transactions.
|
if | conn_or_file.flushindex(filename = "") | Calls db maintenance function for a file or all files. This doesnt actually flush any indexes but does make sure that reccount() function is reasonably accurate. Returns: True if successful otherwise false if not and with lasterror() set. |
Database File I/O
Use | Function | Description |
---|---|---|
if | file.open(dbfilename, connection = "") | Opens a db file to a var which can be used in subsequent db function calls to access a specific file using a specific connection. connection: If not specified and the filename is present in an internal cache of filenames and connections created by previous calls to open() or attach() then open() returns true. If it is not present in the cache then the default connection will be checked. Returns: True if the filename was present in the cache OR if the db connection reports that the file is present.
|
file.close() | Closes db file var Does nothing currently since database file vars consume no resources
| |
if | file.createindex(fieldname, dictfile = "") | Creates a secondary index for a given db file and field name. The fieldname must exist in a dictionary file. The default dictionary is "dict." ^ filename. Returns: False if the index cannot be created for any reason. * Index already exists * File does not exist * The dictionary file does not have a record with a key of the given field name. * The dictionary file does not exist. Default is "dict." ^ filename. * The dictionary field defines a calculated field that uses an exodus function. Using a psql function is OK.
|
var= | file|conn.listindex(file_or_filename = "", fieldname = "") | Lists secondary indexes in a database or for a db file Returns: False if the db file or fieldname are given and do not exist
|
if | file.deleteindex(fieldname) | Deletes a secondary index for a db file and field name. Returns: False if the index cannot be deleted for any reason * File does not exist * Index does not already exists
|
var= | file.lock(key) | Places a metaphorical db lock on a particular record given a db file and key. This is a advisory lock, not a physical lock, since it makes no restriction on the access or modification of data by other connections. Neither the db file nor the record key need to actually exist since a lock is just a hash of the db file name and key combined. If another connection attempts to place an identical lock on the same database it will be denied. Locks can be removed by unlock() or unlockall() or will be automatically removed at the end of a transaction or when the connection is closed. If the same process attempts to place an identical lock more than once it may be denied (if not in a transaction) or succeed but be ignored (if in a transaction). Locks can be used to avoid processing a transaction simultaneously with another connection only to have one of them fail due to mutually updating the same records. Returns:: * 0: Failure: Another connection has already placed the same lock. * "" Failure: The lock has already been placed. * 1: Success: A new lock has been placed. * 2: Success: The lock has already been placed and the connection is in a transaction.
|
if | file.unlock(key) | Removes a db lock placed by the lock function. Only locks placed on the specified connection can be removed. Locks cannot be removed while a connection is in a transaction. Returns: False if the lock is not present in a connection.
|
if | file.unlockall() | Removes all db locks placed by the lock function in the specified connection. Locks cannot be removed while in a transaction.
|
record.write(file, key) | Writes a record into a db file given a unique primary key. Either inserts a new record or updates an existing record. Returns: Nothing since writes always succeed. Throws: VarDBException if the file does not exist. Like most db functions. Any memory cached record is deleted.
| |
if | record.read(file, key) | Reads a record from a db file for a given key. file: A db filename or a var opened to a db file. key: The key of the record to be read. Returns: False if the key doesnt exist var: Contains the record if it exists or is unassigned if not. A special case of the key being "%RECORDS%" results in a fictitious "record" being returned as an FM separated list of all the keys in the db file up to a maximum size of 4Mib, sorted in natural order.
|
if | file.deleterecord(key) | Deletes a record from a db file given a key. Returns: False if the key doesnt exist Any memory cached record is deleted. deleterecord(in file), a one argument free function, is available that deletes multiple records using the currently active select list.
|
if | record.insertrecord(file, key) | Inserts a new record in a db file. Returns: False if the key already exists Any memory cached record is deleted.
|
if | record.updaterecord(file, key) | Updates an existing record in a db file. Returns: False if no record with the given key exists. Any memory cached record is deleted.
|
if | record.updatekey(key, newkey) | Updates the key of an existing record in a db file. Returns: True if successful or false if no record with the given key exists, or a record with newkey already exists Any memory cached records of either key are deleted.
|
if | strvar.readf(file, key, fieldno) | "Read field" Same as read() but only returns a specific field number from the record.
|
strvar.writef(file, key, fieldno) | "write field" Same as write() but only writes to a specific field number in the record
| |
record.writec(file, key) | "Write cache" Writes a record and key into a memory cached "db file". The actual database file is NOT updated. writec() either updates an existing cache record if the key already exists or otherwise inserts a new record into the cache. It always succeeds so no result code is returned. Neither the db file nor the record key need to actually exist in the actual db.
| |
if | record.readc(file, key) | "Read cache" Same as "read() but first reads from a memory cache. 1. Tries to read from a memory cache. Returns true if successful. 2a. Tries to read from the actual db file and returns false if unsuccessful. 2b. Writes the record and key to the memory cache and returns true. Cached db file data lives in exodus process memory and is lost when the process terminates or clearcache() is called.
|
if | dbfile.deletec(key) | Deletes a record and key from a memory cached "file". The actual database file is NOT updated. Returns: False if the key doesnt exist
|
conn.clearcache() | Clears the memory cache of all records for the given connection All future cache readc() function calls will be forced to obtain records from the actual database and refresh the cache.
| |
var= | strvar.xlate(filename, fieldno, mode) | The xlate ("translate") function is similar to readf() but, when called as an exodus program member function, it can be used efficiently with exodus file dictionaries using column names and functions and multivalued data. Arguments: strvar: Used as the primary key to lookup a field in a given file and field no or field name. filename: The db file in which to look up data. If var key is multivalued then a multivalued field is returned. fieldno: Determines which field of the record is returned. * Integer returns that field number * 0 means return the key unchanged. * "" means return the whole record. mode: Determines what is returned if the record does not exist for the given key and file. * "X" returns "" * "C" returns the key unconverted.
|
Database Sort/Select
Use | Function | Description |
---|---|---|
if | dbfile.select(sort_select_command = "") | Create an active select list of keys of a database file. The select(command) function searches and orders database records for subsequent processing given an English language-like command. The primary job of a database, beyond mere storage and retrieval of information, is to allow rapid searching and ordering of information on demand. In Exodus, searching and ordering of information is known as "sort/select" and is performed by the select() function. Executing the select() function creates an "active select list" which can then be consumed by the readnext() function. dbfile: A opened database file or file name, or an open connection or an empty var for default connections. Subsequent readnext calls must use the same. sort_select_command: A natural language command using dictionary field names. The command can be blank if a dbfile or filename is given in dbfile or just a file name and all keys will be selected in undefined order. Example: "select xo_clients with type 'B' and with balance ge 100 by type by name" Option: "(R)" appended to the sort_select_command acquires the database records as well. Returns: True if any records are selected or false if none. Throws: VarDBException in case of any syntax error in the command. Active select lists created using var.select()'s member function syntax cannot be consumed by the free function form of readnext() and vice versa.
|
if | dbfile.selectkeys(keys) | Create an active select list from a string of keys. Similar to select() but creates the list directly from a var. keys: An FM separated list of keys or key^VM^valueno pairs. Returns: True if any keys are provided or false if not.
|
if | dbfile.hasnext() | Checks if a select list is active. dbfile: A file or connection var used in a prior select, selectkeys or getlist function call. Returns: True if a select list is active and false if not. If it returns true then a call to readnext() will return a database record key, otherwise not.
|
if | dbfile.readnext(out key) | Acquires and consumes one key from an active select list of database record keys. dbfile: A file or connection var used in a prior select, selectkeys or getlist function call. key: Returns the first (next) key present in an active select list or "" if no select list is active. Returns: True if a list is active and a key is available, false if not. Each call to readnext consumes one key from the list. Once all the keys in an active select list have been consumed by calls to readnext, the list becomes inactive. See select() for example code. |
if | dbfile.readnext(out key, out valueno) | Similar to readnext(key) but multivalued. If the active list was ordered by multivalued database fields then pairs of key and multivalue number will be available to the readnext function. |
if | dbfile.readnext(out record, out key, out valueno) | Similar to readnext(key) but acquires the database record as well. record: Returns the next database record from the select list assuming that the select list was created with the (R) option otherwise "" if not. key: Returns the next database record key in the select list. valueno: The multivalue number if the select list was ordered on multivalued database record fields or 1 if not.
|
dbfile.clearselect() | Deactivates an active select list. dbfile: A file or connection var used in a prior select, selectkeys or getlist function call. Returns: Nothing Has no effect if no select list is active for dbfile.
| |
if | dbfile.savelist(listname) | Stores an active select list for later retrieval. dbfile: A file or connection var used in a prior select, selectkeys or getlist function call. listname: A suitable name that will be required for later retrieval. Returns: True if saved successfully or false if there was no active list to be saved. Any existing list with the same name will be overwritten. Only the remaining unconsumed part of the active select list is saved. Saved lists are stand-alone and are not tied to specific database files although they usually hold keys related to specific files. Saved lists can be created from one file and used to access another. savelist() merely writes an FM separated string of keys as a record in the "lists" database file using the list name as the key of the record. If a saved list is very long, additional blocks of keys for the same list may be stored with keys like listname*2, listname*3 etc. Select lists saved in the lists database file may be created, deleted and listed like database records in any other database file.
|
if | dbfile.getlist(listname) | Retrieve and reactivate a saved select list. dbfile: A file or connection var to be used by subsequent readnext function calls. listname: The name of an existing list in the "lists" database file, either created by savelist or manually. Returns: True if the list was successfully retrieved and activated, or false if the list name doesnt exist. Any currently active select list is replaced. Retrieving a list does not delete it and a list can be retrieved more than once until specifically deleted.
|
if | dbfile.deletelist(listname) | Delete a saved select list. dbfile: A file or connection to the desired database. listname: The name of an existing list in the "lists" database file. Returns: True if successful or false if the list name doesnt exist.
|
OS Time/Date
Use | Function | Description |
---|---|---|
var= | var::date() | Number of whole days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before. e.g. was 20821 from 2025-01-01 00:00:00 UTC for 24 hours
|
var= | var::time() | Number of whole seconds since last 00:00:00 (UTC). e.g. 43200 if time is 12:00 Range 0 - 86399 since there are 24*60*60 (86400) seconds in a day.
|
var= | var::ostime() | Number of fractional seconds since last 00:00:00 (UTC). A floating point with approx. nanosecond resolution depending on hardware. e.g. 23343.704387955 approx. 06:29:03 UTC
|
var= | var::ostimestamp() | Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before. A floating point with approx. nanosecond resolution depending on hardware. e.g. Was 20821.99998842593 around 2025-01-01 23:59:59 UTC
|
var= | vardate.ostimestamp(ostime) | Construct a timestamp from a date and time
|
var::ossleep(milliseconds) | Sleep/pause/wait for a number of milliseconds Releases the processor if not needed for a period of time or a delay is required.
| |
var= | file_dir_list.oswait(milliseconds) | Sleep/pause/wait up to a given number of milliseconds or until any changes occur in an FM delimited list of directories and/or files. Any terminal input (e.g. a key press) will also terminate the wait. An FM array of event information is returned. See below. Multiple events are returned in multivalues.
Returned array fields
1. Event type codes 2. dirpaths 3. filenames 4. d=dir, f=file
|
OS File I/O
Use | Function | Description |
---|---|---|
if | osfilevar.osopen(osfilename, utf8 = true) | Initialises an os file handle var that can be used for random read and write osfilename: The name of an existing os file name including path. utf8: Defaults to true which causes trimming of partial UTF-8 Unicode byte sequences from the end of osbreads. For raw untrimmed osbreads pass tf8 = false; osfilevar: [out] To be used in subsequent calls to osbread() and osbwrite() Returns: True if successful or false if not possible for any reason. e.g. Target doesnt exist, permissions etc. The file will be opened for writing if possible otherwise for reading.
|
if | osfilevar.osbwrite(osfilevar, io offset) | Writes data to an existing os file starting at a given byte offset (0 based). See osbread for more info.
|
if | osfilevar.osbread(osfilevar, io offset, length) | Reads length bytes from an existing os file starting at a given byte offset (0 based). The osfilevar file handle may either be initialised by osopen or be just be a normal string variable holding the path and name of the os file. After reading, the offset is updated to point to the correct offset for a subsequent sequential read. If reading UTF8 data (the default) then the length of data actually returned may be a few bytes shorter than requested in order to be a complete number of UTF-8 code points.
|
osfilevar.osclose() | Removes an osfilevar handle from the internal memory cache of os file handles. This frees up both exodus process memory and operating system resources. It is advisable to osclose any file handles after use, regardless of whether they were specifically opened using osopen or not, especially in long running programs. Exodus performs caching of internal os file handles per thread and os file. If not closed, then the operating system will probably not flush deleted files from storage until the process is terminated. This can potentially create an memory issue or file system resource issue especially if osopening/osreading/oswriting many perhaps temporary files in a long running process.
| |
if | strvar.oswrite(osfilename, codepage = "") | Create a complete os file from a var. strvar: The text or data to be used to create the file. osfilename: Absolute or relative path and filename to be written. Any existing os file is removed first. codepage: If specified then output is converted from UTF-8 to that codepage before being written. Otherwise no conversion is done. Returns: True if successful or false if not possible for any reason. e.g. Path is not writeable, permissions etc.
|
if | strvar.osread(osfilename, codepage = "") | Read a complete os file into a var. osfilename: Absolute or relative path and filename to be read. codepage: If specified then input is converted from that codepage to UTF-8 after being read. Otherwise no conversion is done. strvar: [out] is currently set to "" in case of any failure but this is may be changed in a future release to either force var to be unassigned or to leave it untouched. To guarantee future behaviour either add a line 'xxxx.defaulter("")' or set var manually in case osread() returns false. Or use the one argument free function version of osread() which always returns "" in case of failure to read. Returns: True if successful or false if not possible for any reason. e.g. File doesnt exist, insufficient permissions etc.
|
if | osfile_or_dirname.osrename(new_dirpath_or_filepath) | Renames an os file or dir in the OS file system. The source and target must exist in the same storage device. osfile_or_dirname: Absolute or relative path and file or dir name to be renamed. new_dirpath_or_filepath: Will not overwrite an existing os file or dir. Returns: True if successful or false if not possible for any reason. e.g. Target already exists, path is not writeable, permissions etc. Uses std::filesystem::rename internally.
|
if | osfile_or_dirname.osmove(to_osfilename) | "Moves" an os file or dir within the os file system. Attempts osrename first, then oscopy followed by osremove original. osfile_or_dirname: Absolute or relative path and file or dir name to be moved. to_osfilename: Will not overwrite an existing os file or dir. Returns: True if successful or false if not possible for any reason. e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions, storage space etc.
|
if | osfile_or_dirname.oscopy(to_osfilename) | Copies an os file or directory recursively within the os file system. osfile_or_dirname: Absolute or relative path and file or dir name to be copied. to_osfilename: Will overwrite an existing os file or merge into an existing dir. Returns: True if successful or false if not possible for any reason. e.g. Source doesnt exist or cannot be accessed, target is not writeable, permissions, storage space, etc. Uses std::filesystem::copy internally with recursive and overwrite options
|
if | osfilename.osremove() | Removes/deletes an os file from the OS file system. Will not remove directories. Use osrmdir() to remove directories osfilename: Absolute or relative path and file name to be removed. Returns: True if successful or false if not possible for any reason. e.g. Target doesnt exist, path is not writeable, permissions etc.
|
OS Directories
Use | Function | Description |
---|---|---|
var= | dirpath.oslist(globpattern = "", mode = 0) | Get a list of os files and/or dirs. dirpath: Absolute or relative dir path. globpattern: e.g. *.conf to be appended to the dirpath or a complete path plus glob pattern e.g. /etc/ *.conf. mode: 0: default - Any regular files or dirs. 1 - Only regular os files. 2 - Only dirs. Returns: An FM delimited string containing all matching dir entries given a dir path
|
var= | dirpath.oslistf(globpattern = "") | Same as oslist for files only |
var= | dirpath.oslistd(globpattern = "") | Same as oslist for files only |
var= | osfile_or_dirpath.osinfo(mode = 0) | Get dir info about an os file or dir. Returns: A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time or "" if not a regular file or dir. mode: 0: default. 1: Must be a regular os file. 2: Must be an os dir. See also osfile() and osdir()
|
var= | osfilename.osfile() | Get dir info of an os file. osfilename: Absolute or relative path and file name. Returns: A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time or "" if not a regular file. Alias for osinfo(1)
|
var= | dirpath.osdir() | Get dir info of an os dir. dirpath: Absolute or relative path and dir name. Returns: A short string containing FM ^ modified_time ^ FM ^ modified_time or "" if not a dir. Alias for osinfo(2)
|
if | dirpath.osmkdir() | Create a new os file system directory. Parent dirs wil be created if necessary. dirpath: Absolute or relative path and dir name. Returns: True if successful.
|
if | var::oscwd(newpath) | Changes the current working dir. newpath: An absolute or relative dir path and name. Returns: True if successful or false if not. e.g. Invalid dirpath, insufficient permission etc.
|
var= | var::oscwd() | Gets the current dir path and name. Returns: The current working dir path and name. e.g. "/root/exodus/cli/src/xo_test/aaa"
|
if | dirpath.osrmdir(evenifnotempty = false) | Removes (deletes) an os dir, eventifnotempty: If true any subdirs will also be removed/deleted recursively, otherwise the function will fail and return false. Returns: Returns true if successful or false if not. e.g dir doesnt exist, insufficient permission, not empty etc.
|
OS Shell/Environment
Use | Function | Description |
---|---|---|
if | command.osshell() | Execute a shell command. command: An executable command to be interpreted by the default os shell. Returns: True if the process terminates with error status 0 and false otherwise. Append "&>/dev/null" to the command to suppress terminal output.
|
if | instr.osshellread(oscmd) | Same as osshell but captures and returns stdout Returns: The stout of the shell command. Append "2>&1" to the command to capture stderr/stdlog output as well.
|
if | outstr.osshellwrite(oscmd) | Same as osshell but provides stdin to the process Returns: True if the process terminates with error status 0 and false otherwise. Append "&> somefile" to the command to suppress and/or capture output.
|
var= | var::ostempdir() | Get the tmp dir path and name. Returns: A string e.g. "/tmp/"
|
var= | var::ostempfile() | Create a temporary file Returns: The name of new temporary file e.g. "/tmp/~exoEcLj3C"
|
envvalue.ossetenv(envcode) | Set the value of an environment variable envcode: The code of the env variable to set. envvalue: The new value to set the env code to.
| |
if | envvalue.osgetenv(envcode) | Get the value of an environment variable. envcode: The code of the env variable to get or "" for all. envvalue: [out] Set to the value of the env variable if set otherwise "". If envcode is "" then envvalue is set to a dynamic array of all environment variables LIKE CODE1=VALUE1^CODE2=VALUE2... Returns: True if the envcode is set or false if not. osgetenv and ossetenv work with a per thread copy of the os process environment. This avoids multithreading issues but does not change the process environment. Child processes created by var::osshell() will not inherit any env variables set using ossetenv() so the oscommand will need to be prefixed to achieve the desired result. For the actual system environment, see "man environ". extern char **environ; // environ is a pointer to an array of pointers to char* env pairs like xxx=yyy and the last pointer in the array is nullptr.
|
var= | var::ospid() | Get the current os process id Returns: A number e.g. 663237.
|
var= | var::ostid() | Get the current os thread process id Returns: A number e.g. 663237.
|
var= | var::version() | Get the exodus library version info. Returns: The git commit details as at the time the library was built.
|
if | strvar.setxlocale(newlocalecode) | Sets the current thread's default locale. strvar: The new locale codepage code. True if successful
|
var= | var.getxlocale() | Gets the current thread's default locale. Returns: A locale codepage code string.
|
Output
Use | Function | Description |
---|---|---|
expr | varstr.outputl(prefix = "") | Output to stdout with optional prefix. Appends an NL char. Is FLUSHED, not buffered. The raw string bytes are output. No character or byte conversion is performed.
|
expr | varstr.output(prefix = "") | Same as outputl() but doesnt append an NL char and is BUFFERED, not flushed. |
expr | varstr.outputt(prefix = "") | Same as outputl() but appends a tab char instead of an NL char and is BUFFERED, not flushed. |
expr | varstr.logputl(prefix = "") | Output to stdlog with optional prefix. Appends an NL char. Is BUFFERED not flushed. Any of the six types of field mark chars present are converted to their visible versions,
|
expr | varstr.logput(prefix = "") | Same as logputl() but doesnt append an NL char. |
expr | varstr.errputl(prefix = "") | Output to stderr with optional prefix. Appends an NL char. Is FLUSHED not buffered. Any of the six types of field mark chars present are converted to their visible versions,
|
expr | varstr.errput(prefix = "") | Same as errputl() but doesnt append an NL char and is BUFFERED not flushed. |
expr | varstr.put(std::ostream& ostream1) | Output to a given stream. Is BUFFERED not flushed. The raw string bytes are output. No character or byte conversion is performed. |
var().osflush() | Flush any and all buffered output to stdout and stdlog.
|
Input
Use | Function | Description |
---|---|---|
if | var.input(prompt = "") | Returns one line of input from stdin. Returns: True if successful or false if EOF or user pressed Esc or Ctrl+X in a terminal. var: [in] The default value for terminal input and editing. Ignored if not a terminal. var: [out] Raw bytes up to but excluding the first new line char. In case of EOF or user pressed Esc or Ctrl+X in a terminal it will be changed to "". Prompt: If provided, it will be displayed on the terminal. Multibyte/UTF8 friendly.
|
expr | var.inputn(nchars) | Get raw bytes from standard input. Any new line chars are treated like any other bytes. Care must be taken to handle incomplete UTF8 byte sequences at the end of one block and the beginning of the next block. Returns: The requested number of bytes or fewer if not available. nchars: 99 : Get up to 99 bytes or fewer if not available. Caution required with UTF8. ⋅0 : Get all bytes presently available. ⋅1 : Same as keypressed(true). Deprecated. -1 : Same as keypressed(). Deprecated. |
expr | var.keypressed(wait = false) | Return the code of the current terminal key pressed. wait: Defaults to false. True means wait for a key to be pressed if not already pressed. Returns: ASCII or key code defined according to terminal protocol. Returns: "" if stdin is not a terminal. e.g. The PgDn key if pressed might return an escape sequence like "\x1b[6~" It only takes a few µsecs to return false if no key is pressed.
|
if | var().isterminal(arg = 1) | Checks if one of stdin, stdout, stderr is a terminal or a file/pipe. arg: 0 - stdin, 1 - stdout (Default), 2 - stderr. Returns: True if it is a terminal or false if it is a file or pipe. Note that if the process is at the start or end of a pipeline, then only stdin or stdout will be a terminal. The type of stdout terminal can be obtained from the TERM environment variable.
|
if | var().hasinput(milliseconds = 0) | Checks if stdin has any bytes available for input. If no bytes are immediately available, the process sleeps for up to the given number of milliseconds, returning true immediately any bytes become available or false if the period expires without any bytes becoming available. Returns: True if any bytes are available otherwise false. It only takes a few µsecs to return false if no bytes are available and no wait time has been requested. |
if | var().eof() | True if stdin is at end of file |
if | var().echo(on_off = true) | Sets terminal echo on or off. "On" causes all stdin data to be reflected to stdout if stdin is a terminal. Turning terminal echo off can be used to prevent display of confidential information. Returns: True if successful. |
var().breakon() | Install various interrupt handlers. Automatically called in program/thread initialisation by exodus_main. SIGINT - Ctrl+C -> "Interrupted. (C)ontinue (Q)uit (B)acktrace (D)ebug (A)bort ?" SIGHUP - Sets a variable "RELOAD_req" which may be handled or ignored by the program. SIGTERM - Sets a variable "TERMINATE_req" which may be handled or ignored by the program. | |
var().breakoff() | Disable keyboard interrupt. Ctrl+C becomes inactive in terminal. |
Math/Boolean
Use | Function | Description |
---|---|---|
var= | varnum.abs() | Absolute value
|
var= | varnum.pwr(exponent) | Power
|
varnum.initrnd() | Initialise the seed for rnd() Allows the stream of pseudo random numbers generated by rnd() to be reproduced. Seeded from std::chrono::high_resolution_clock::now() if the argument is 0;
| |
var= | varnum.rnd() | Pseudo random number generator Returns: a pseudo random integer between 0 and the provided maximum minus 1. Uses std::mt19937 and std::uniform_int_distribution
|
var= | varnum.exp() | Power of e
|
var= | varnum.sqrt() | Square root
|
var= | varnum.sin() | Sine of degrees
|
var= | varnum.cos() | Cosine of degrees
|
var= | varnum.tan() | Tangent of degrees
|
var= | varnum.atan() | Arctangent of degrees
|
var= | varnum.loge() | Natural logarithm Returns: Floating point ver (double)
|
var= | varnum.integer() | Truncate decimal numbers towards zero Returns: An integer var
|
var= | varnum.floor() | Truncate decimal numbers towards negative Returns: An integer var
|
var= | varnum.mod(modulus) | Modulus function Identical to C++ % operator only for positive numbers and modulus Negative denominators are considered as periodic with positiive numbers Result is between [0, modulus) if modulus is positive Result is between (modulus, 0] if modulus is negative (symmetric) Throws: VarDivideByZero if modulus is zero. Floating point works.
|
int= | var::setprecision(newprecision) | Set the maximum floating point precision. This is the number of post-decimal point digits to consider for floating point comparison and implicit conversion to strings. The default precision is 4 which is 0.0001. NUMBERS AND DIFFERENCES SMALLER THAN 0.0001 ARE TREATED AS ZERO UNLESS PRECISION IS INCREASED. newprecision: New precision between -307 and 308 inclusive. Returns: The new precision if successful or the old precision if not. Not required if using common numbers or using the explicit rounding and formatting functions to convert numbers to strings. Increasing the precision allows comparing and outputting smaller numbers but creates errors handling large numbers. Setting precision inside a perform, execute or dictionary function lasts until termination of the function. See cli/demo_precision for more info.
|
int= | var::getprecision() |
Returns: The current precision setting. See setprecision() for more info.
|
I/O Conversion Codes
Use | Function | Description |
---|---|---|
var= | vardate.oconv("D") | Date output: Convert internal date format to human readable date or calendar info in text format. Returns: Human readable date or calendar info, or the original value unconverted if non-numeric. Flags: See examples below. Any Dynamic array structure is preserved.
|
var= | varstr.iconv("D") | Date input: Convert human readable date to internal date format. Returns: Internal date or "" if the input is an invalid date. Internal date format is whole days since 1967-12-31 00:00:00 which is day 0. Any Dynamic array structure is preserved.
|
var= | vartime.oconv("MT") | Time output: Convert internal time format to human readable time e.g. "10:30:59". Returns: Human readable time or the original value unconverted if non-numeric. Conversion code (e.g. "MTHS") is "MT" + flags ... Flags: "H" - Show AM/PM otherwise 24 hour clock is used. "S" - Output seconds "2" = Ignored (used in iconv) ":" - Any other flag is used as the separator char instead of ":" Any Dynamic array structure is preserved.
|
var= | varstr.iconv("MT") | Time input: Convert human readable time (e.g. "10:30:59") to internal time format. Returns: Internal time or "" if the input is an invalid time. Internal time format is whole seconds since midnight. Accepts: Two or three groups of digits surrounded and separated by any non-digits char(s). Any Dynamic array structure is preserved.
|
var= | varnum.oconv("MD") | Number output: Convert internal numbers to external text format after rounding and optional scaling. Returns: A string or, if the value is not numeric, then no conversion is performed and the original value is returned. Conversion code (e.g. "MD20") is "MD" or "MC", 1st digit, 2nd digit, flags ... MD outputs like 123.45 (International) MC outputs like 123,45 (European) 1st digit = Decimal places to display. Also decimal places to move if 2nd digit not present and no P flag present. 2nd digit = Optional decimal places to move left if P flag not present. Flags: "P" - Preserve decimal places. Same as 2nd digit = 0; "Z" - Zero flag - return "" if zero. "X" - No conversion - return as is. "." or "," - Separate thousands depending on MD or MC. "-" means suffix negatives with "-" and positives with " " (space). "<" means wrap negatives in "<" and ">" chars. "C" means suffix negatives with "CR" and positives or zero with "DB". "D" means suffix negatives with "DB" and positives or zero with "CR". Any Dynamic array structure is preserved.
|
var= | var.oconv("LRC") | Text justification: Left, right and center. Padding and truncating. See Procrustes. e.g. "L#10", "R#10", "C#10" Useful when outputting to terminal devices where spaces are used for alignment. Dynamic array structure is preserved. ASCII only.
|
var= | varstr.oconv("T") | Text folding and justification. e.g. T#20 Useful when outputting to terminal devices where spaces are used for alignment. Splits text into multiple fixed length lines by inserting spaces and TM chars. ASCII only.
|
expr | varnum.oconv("MR") | Character replacement e.g. MRU
|
var= | varstr.oconv("HEX") | Convert the chars of a string to a string of pairs of hexadecimal digits. varstr: A string. Numbers will be converted to strings for conversion. 1.2 -> "1.2" -> hex "312E32" Dynamic array structure is not preserved. Field marks are converted to HEX as for all other bytes. The size of the output is always precisely double that of the input. This function is the exact inverse of iconv("HEX").
|
var= | varstr.iconv("HEX") | Convert a string of pairs of hexadecimal digits to a string of chars. varstr: Must be a string of only hex digits 0-9, a-f or A-F. Returns: A string if all input was hex digits otherwise "". Dynamic array structure is not preserved. Any field marks prevent conversion. This function is the exact inverse of oconv("HEX"). After prefixing a "0" to an odd sized input, the size of the output is always precisely half that of the input. |
var= | varnum.oconv("MX") | Convert number to hexadecimal string. "MX": Convert and trim leading zeros e.g. oconv(1025, "MX") -> "401" "MXn": Pad with up to n leading zeros but do not truncate. e.g. oconv(1025, "MX8") -> "00000401" "MXnT": Pad and truncate to n characters. e.g. oconv(1025, "MX2") -> "01" "n": Width. 0-9, A-G = 10 - 16. varnum: A number or dynamic array of numbers. Floating point numbers are rounded to integers before conversion. Returns: A string of hexadecimal digits or a dynamic array of the same. Elements that are not numeric are left untouched and unconverted. Dynamic array structure is preserved. Negative numbers are treated as unsigned 8 byte integers (uint64). 0 -> "00" 1 -> "01" 15 -> "0F" -1 -> "FFFF" "FFFF" "FFFF" "FFFF" (8 x "FF") This function is a near inverse of iconv("MX").
|
var= | varstr.iconv("MX") | Convert hexadecimal string to number. varstr: A string or dynamic array of up to 16 hex digits: 0-9, a-f, A-F. Returns: An integer or dynamic array of integers. Invalid elements are converted to "". Dynamic array structure is preserved. Hex strings are converted to unsigned 8 byte integers (uint64) Leading zeros are ignored. "0" -> 0 "00"-> 0 "1" -> 1 Hex "FFFFFFFFFFFFFFFF" (8 x "FF") -> -1. Hex "7FFFFFFFFFFFFFFF" is the maximum positive integer: 9223372036854775805. Hex "8000000000000000" is the maximum negative integer: -9223372036854775808. This function is the exact inverse of oconv("MX").
|
var= | varnum.oconv("MB") | Number to binary format: Convert number to strings of 1s and 0s varnum: If not numeric then no conversion is performed and the original value is returned.
|
var= | varstr.oconv("TX") | Convert dynamic arrays to standard text format. Useful for using text editors on dynamic arrays. FMs -> \n after escaping any embedded NL VMs -> literal "\" \n SMs -> literal "\\" \n etc.
|
var= | varstr.iconv("TX") | Convert standard text format to dynamic array. Reverse of oconv("TX") above. |
</html>
Contents:
Dim
Use | Function | Description |
---|
Dimensioned Array Construction
Use | Function | Description |
---|---|---|
dim d1; | Create an undimensioned array of vars pending actual dimensions.
| |
dim d1(nrows, ncols = 1); | Create an array of vars with a fixed number of columns and rows. All vars are unassigned.
| |
dim d1 = d2; // Copy | Create a copy of an array.
| |
dim d1 = dim(); // Move | Save an array created elsewhere. Uses C++ "move" semantics.
| |
dim d1 = {"a", "b", "c" ...}; // Initializer list | Create an array from a list. All elements must be the same type, var, string, double, int, etc.. but all end up as vars which are a flexible type.
| |
dim d1 = v1; | Initialise all elements of an array to some single value or constant. A var, "", 0 etc.
| |
d1.redim(nrows, ncols = 1) | Resize an array to a different number of rows and columns. Existing data will be retained as far as possible. Any additional elements are unassigned. Resizing rows to 0 clears all data. Resizing cols to 0 clears all data and changes its status to "undimensioned".
| |
d1.swap(d2) | Swap one array with another. Either or both may be undimensioned.
|
Array Access
Use | Function | Description |
---|---|---|
var v1 = d1[rowno]; d1[rowno] = v1; | Access and update elements of a one dimensional array using [] brackets
| |
var v1 = d1[rowno, colno]; d1[rowno, colno] = v1; | Access and update elements of an two dimensional array using [] brackets
| |
var= | d1.rows() | Get the number of rows in the dimensioned array Returns: A count. Can be zero, indicating an empty array.
|
var= | d1.cols() | Get the number of columns in the dimensioned array Returns: A count. 0 if the array is undimensioned.
|
var= | d1.join(delimiter = FM) | Joins all elements into a single delimited string delimiter: Default is FM. Returns: A string var.
|
Array Mutation
Use | Function | Description |
---|---|---|
d1.splitter(str1, delimiter = FM) | Creates or updates the array from a given string. If the dim array is undimensioned it will be dimensioned with the number of elements that the string has fields. If the dim array is dimensioned and has more elements than there are fields in the string, the excess array elements are initialised to "". If the record has more fields than there are elements in the array, the excess fields are all left unsplit in the final element of the array. Predimensioning arrays allows the efficient reuse of arrays in loops and ensures that all elements are assigned values, useful when reading records from db files. Using undimensioned arrays allows the efficient handling of arrays with a very variable number of elements. e.g. os text files.
| |
d1.sorter(reverse = false) | Sort the elements of the array in place. reverse: Defaults to false. If true, then the order is reversed.
| |
d1.reverser() | Reverse the elements of the array in place.
| |
d1.shuffler() | Randomly shuffle the order of the elements of the array in place.
|
Array Conversion
Use | Function | Description |
---|---|---|
dim= | d1.sort(reverse = false) | Same as sorter() but returns a new array leaving the original untouched. |
dim= | d1.reverse() | Same as reverser() but returns a new array leaving the original untouched. |
dim= | d1.shuffle() | Same as shuffler() but returns a new array leaving the original untouched. |
Array DB I/O
Use | Function | Description |
---|---|---|
d1.write(dbfile, key) | Writes a db file record created from an array. Each element in the array becomes a separate field in the db record. Any redundant trailing FMs are suppressed.
| |
if | d1.read(dbfile, key) | Read a db file record into an array. Each field in the database record becomes a single element in the array. Returns: True if the record exists or false if not, If the array is predimensioned then any excess array elements are initialised to "" and any excess record fields are left unsplit in the final array element. See dim splitter for more info. If the array is not predimensioned (rows and cols = 0) then it will be dimensioned to have exactly the same number of rows as there are fields in the record being read.
|
Array OS I/O
Use | Function | Description |
---|---|---|
if | d1.oswrite(osfilename, codepage = "") | Creates an entire os text file from an array Each element of the array becomes one line in the os file delimited by \n Any existing os file is overwritten and replaced. codepage: Optional: Data is converted from UTF8 to the required codepage/encoding before output. If the conversion cannot be performed then return false. Returns: True if successful or false if not.
|
if | d1.osread(osfilename, codepage = "") | Read an entire os text file into an array. Each line in the os file, delimited by \n or \r\n, becomes a separate element in the array. Existing data in the array is lost and the array is redimensioned to the number of lines in the input data. codepage: Optional. Data will be converted from the specified codepage/encoding to UTF8 after being read. If the conversion cannot be performed then return false. Returns: True if successful or false if not. If the first \n in the file is \r\n then the whole file will be split using \r\n as delimiter.
|
</html>
Contents:
Exodus Program
Use | Function | Description |
---|
Select Lists
Use | Function | Description |
---|---|---|
if | select(sortselectclause_or_filehandle = "") | Create an active select list using a natural language sort/select command. This and all the following exoprog member functions work on an environment variable CURSOR. Identical functions are available directly on plain var objects but vars have less functionality regarding dictionaries and environment variables which are built-in to exoprog. Returns: True if an active select list was created, false otherwise. In the following examples, various environment variables like RECORD, ID and MV are used instead of declaring and using named vars. In actual code, either may be freely used.
|
if | selectkeys(keys) | Create an active select list from some given keys.
|
if | hasnext() | Check if a select list is active.
|
if | readnext(out key) | Get the next key from an active select list. key: [out] A string. Typically the key of a db file record. Returns: True if an active select list was available and the next key in the list was obtained.
|
if | readnext(out key, out valueno) | Get the next key and value number pair from an active select list. key: [out] A string. Typically the key of a db file record. valueno: [out] Is only available in select lists that have been created by sort/select commands that refer to multi-valued db dictionary fields where db records have multiple values for a specific field. In this case, a record key will appear multiple times in the select list since each multivalue is exploded for the purpose of sorting and selecting. This can be viewed as a process of "normalising" multivalues so they appear as multiple records instead of being held in a single record. Returns: True if an active select list was available and the next key in the list was obtained.
|
if | readnext(out record, out key, out valueno) | Get the next record, key and value no from an active select list. record: [out] Is only available in select lists that have been created with the final (R) option. Otherwise the record will be returned as an empty string and must be obtained using a db read() function. key: [out] A string. Typically the key of a db file record. valueno: [out] Is only available in select lists that have been created by sort/select commands that refer to multi-valued db dictionary fields where db records have multiple values for a specific field. Returns: True if an active select list was available and the next key in the list was obtained.
|
pushselect(out cursor) | Saves a pointer to the currently active select list. This allows another select list to be activated and used temporarily before the original select list is reactivated. cursor: [out] A var that can be passed later on to the popselect() function to reactivate the saved list.
| |
popselect(cursor) | Re-establish an active select list saved by pushselect(). cursor: A var created by the pushselect() function. See pushselect() for more info. | |
clearselect() | Deactivate an active select list. If no select list is active then nothing is done.
| |
if | deleterecord(filename) | Use an active select list to delete db records. Returns: False if any records could not be deleted. Contrast this function with the two argument "deleterecord(file, key)" function that deletes a single record.
|
if | deleterecord(dbfile, key) | Delete a single database file record.
|
if | savelist(listname) | Save a currently active select list under a given name. After saving, the list is no longer active and hasnext() will return false. Returns: True if an active select list was saved, false if there was no active select list. Lists are saved as a record in the "lists" file.
|
if | getlist(listname) | Reactivate a saved select list of a given name. A saved list is obtained from the "lists" file and activated. Returns: True if an active select list was successfully reactivated, otherwise false.
|
if | deletelist(listname) | Remove a saved select list by name. A saved list is deleted from the "lists" file.
|
Perform/Execute
Use | Function | Description |
---|---|---|
var= | perform(command_line) | Run an exodus program/library's main function using a command like syntax similar to that of executable programs. A "command line" is passed to the program/library in the usual COMMAND, SENTENCE and OPTIONS environment variables instead of function arguments. The program/library's main function should have zero arguments. Performing a program/library function with main arguments results in them being unassigned and in some case core dump may occur. The following environment variables are initialised on entry to the main function of the program/library. They are preserved untouched in the calling program. SENTENCE, COMMAND, OPTIONS: Initialised from the argument "command_line". RECUR0, RECUR1, RECUR2, RECUR3, RECUR4 to "". ID, RECORD, MV, DICT initialised to "". LEVEL is incremented by one. All other environment variables are shared between the caller and callee. There is essentially only one environment in any one process or thread. Any active select list is passed to the performed program/library and can be consumed by it. Conversely any active select list created by the performed program/library will be returned to the calling program. In other words, both the performing and the performed programs/libraries share a single active select list environment. This is different from execute() which gets its own private active select list, initially inactive. command_line: The first word of this argument is used as the name of the program/library to be loaded and run. command_line is used to initialise the SENTENCE, COMMAND and OPTIONS environment variables. Returns: Whatever var the program/library returns, or "" if it calls stop() or abort(()". The return value can be ignored and discarded without any compiler warning. Exodus program/libraries may also be called directly using conventional function calling syntax. To call an exodus program/library called progname using either the syntax "call progname(args...);" or "var v1 = progname(args...);" you must "#include |
var= | execute(command_line) | Run an exodus program/library's main function. Identical to perform() but any currently active select list in the calling program/library is not accessible to the executed program/library and is preserved in the calling [program as is. Any select list created by the executed library is discarded when it terminates. |
chain(command_line) | Run an exodus program/library's main function after closing the current program. Identical to perform() except that the current program closes first. | |
var= | libinfo(libname) | Check if a lib exists to be performed/executed or called. |
Program Termination
Use | Function | Description |
---|---|---|
stop(message = "") | Stop the current exodus program/library normally and return to the parent exodus program/library, or return to the operating system if none. Calling stop() in an exodus OS command line executable program, or in a function called from the same, will terminate the OS process with an error status of 0 which is generally considered to indicate success. Calling stop() in a performed or executed exodus program/library, or in a function called from the same, will terminate the program/library being executed and return to the exodus program that performed or executed it. | |
abort(message = "") | Abort the current exodus program/library abnormally and return to the parent exodus program/library, or return to the operating system if none. Similar to stop() but, if terminating the OS process, then return an error status of 1 which is generally considered to be an indication of failure. | |
abortall(message = "") | Abort the current exodus program/library abnormally and return to the parent exodus program/library, or return to the operating system if none. Similar to abort() but, if terminating the OS process, then return an error status of 2 which is generally considered to be an indication of failure. | |
logoff(message = "") |
DB File Dictionaries
Use | Function | Description |
---|---|---|
var= | calculate(dictid) | given dictid reads dictrec from DICT file and extracts from RECORD/ID or calls library called dict+DICT function dictid not const so we can mess with the library? |
var= | calculate(dictid, dictfile, id, record, mv = 0) | |
var= | xlate(filename, key, fieldno_or_name, mode) |
I/O Conversion
Use | Function | Description |
---|---|---|
var= | oconv(input, conversion) | iconv/oconv with access to exoprogram's environment variables. exoprog's iconv/oconv have the ability to call custom functions like "[funname,args...]" [NUMBER] // built-in. See doc below. [DATE] // built-in. See doc below. [DATEPERIOD] e.g. [DATEPERIOD,1] [DATEPERIOD,1,12] [DATETIME] e.g. [DATETIME,4*,DOS] [DATETIME,4*,MTS] [DATETIME,4*] [TIME2] e.g. [TIME2,MT] [TIME2,MTS] [TIME2,MTS48] |
var= | iconv(input, conversion) |
Ioconv Date/Time
Use | Function | Description |
---|---|---|
var= | iconv|oconv(var, "[DATE]") | Use iconv/oconv code "[DATE,args]" when you want date conversion to depend on the environment variable DATEFMT, particularly its American/International setting. Otherwise use ordinary "D" conversion codes directly for slightly greater performance. var: [oconv] An internal date (a number). Returns: [oconv] A readable date in text format depending on "[DATE,args]" e.g. "31 DEC 2020" "31/12/2020" "12/31/2020" var: [iconv] A date in text format as above. Returns: [iconv] An internal date (a number) or "" if the input could not be understood as a valid date. args: If args is empty then DATEFMT is used as the conversion code. If args starts with "D" then args is used as the conversion codes but any E option in DATEFMT is appended. If args does not start with "D" then args are appended to DATEFMT, a "Z" option is appended, and the result used as the conversion code. A "*" option is equivalent to a second "Z" option. If you are calling iconv/oconv in code and DATEFMT is adequate for your needs then pass it directly as a function argument e.g. 'var v1 = iconv|oconv(v2, DATEFORMAT);' instead of indirectly like 'var v1 = iconv|oconv(v2, "[DATE]");'.
|
var= | iconv|oconv(var, "[NUMBER]") | Use iconv/oconv "[NUMBER,args]" either when your numbers have currency or unit code suffixes or when you want number conversion to depend on the environment variable BASEFMT to determine thousands separator and decimal point. Otherwise use ordinary "MD" conversion codes directly for slightly greater performance. Formatting for numbers with optional currency code/unit suffix and is sensitive to the International or European setting in BASEFMT regarding use of commas or dots for thousands separators and decimal points. Primarily used for oconv() but can be used in reverse for iconv. var: A number with an optional currency code or unit suffix. e.g. "12345.67USD" Returns: A formatted number with thousands separated conventionally e.g. "12.345.67USD". iconv/oconv("[NUMBER]") oconv leaves ndecimals untouched as in the input. iconv see below. iconv/oconv("[NUMBER,2]") Specified number of decimal places iconv/oconv("[NUMBER,BASE]") Decimal places as per BASEFMT iconv/oconv("[NUMBER,*]") Leave decimal places untouched as in the input iconv/oconv("[NUMBER,X]") Leave decimal places untouched as in the input iconv/oconv("[NUMBER,2Z]") Z (suppress zero) combined with any other code for oconv results in empty output "" instead of "0.00" in case of zero input. Empty input "" gives empty output "". All leading, trailing and internal spaces are removed from the input. A trailing currency or unit code is ignored and returned on output. An exodus number is an optional leading + or - followed by one or more decimal digits 0-9 with a single optional decimal point placed anywhere. If the input is non-numeric then "" is returned and STATUS set to 2. In the case of oconv with multiple fields or values each field or value is processed separately but STATUS is set to 2 if any are non-numeric. iconv removes and oconv adds thousand separator chars. The thousands separator is "," if BASEFMT starts with "MD" or "." if it starts with "MC". oconv: Add thousands separator chars and optionally standardise the number of decimal places. Multiple numbers in fields, values, subvalues etc. can be processed in one string. Any leading + character is preserved on output. Z suppresses zeros and returns empty string "" instead. Special format "[NUMBER,ndecs,move_ndecs]": move_ndecs causes decimal point to be shifted left if positive or right if negative.
iconv: Remove all thousands separator chars and optionally standardise the number of decimal places. If ndecs is not specified in the "[NUMBER]" pattern then ndecs is taken from the current RECORD using dictionary code NDECS if DICT is available otherwise it uses ndecs from BASEFMT. iconv only handles a single field/value. Optional prefix of "1/" or "/" causes the reciprocal of the number to be used. e.g. "1/100" or "/100" -> "0.01".
|
var= | amountunit(input0, out unitx) | Split amount+currency code/unit string into number and currency code/unit. var: "123.45USD" Returns: e.g. "123.45" unitx: [out] e.g. "USD" |
var= | amountunit(input0) |
Time/Date Utilities
Use | Function | Description |
---|---|---|
var= | timedate2() |
Returns: Text of date and time in users time zone e.g. "2MAR2025 11:52AM" Offset from UTC by TZ seconds. |
getdatetime(out user_date, out user_time, out system_date, out system_time, out UTC_date, out UTC_time) |
Returns: User, server and UTC date and time User date and time is determined by adding the environment variable TZ.f(1)'s TZ offset (in seconds) to UTC date/time obtained from the operating system. "system" date and time is normally the same as UTC date/time and is determined by adding the environment variable TZ.f(2)'s TZ offset (in seconds) to UTC date/time obtained from the operating system. | |
var= | elapsedtimetext() | Get text of elapsed time since environment variable TIMESTAMP was initialised with ostimestamp() at program/thread startup. TIMESTAMP can be updated using ostimestamp() as and when desired.
|
var= | elapsedtimetext(timestamp1, timestamp2) | Get text of elapsed time between two timestamps
|
Terminal I/O Utilities
Use | Function | Description |
---|---|---|
note(msg, options, io response) | If stdin is a terminal, output a message to stdout and optionally pause processing and request a response from the user, otherwise set the response to "" and continue. options: R = Response requested. C upper case response.
| |
note(msg) | Output a message to stdin and continue.
| |
var= | decide(question, options = "") | If stdin is a terminal, pause processing, list some given options to stdout and request the user to make a choice, otherwise set the response to "" and continue. Returns: The chosen option (value not number) or "" if the user cancelled. |
var= | decide(question, options, out reply, defaultreply = 1) | Same as decide() above but extended. defaultreply: A default option if the user presses Enter. reply: [out] The option number that the user chose or "" if they cancelled. |
if | esctoexit() | If stdin is a terminal, check if a key has been pressed and, if so, pause execution and ask the user to confirm if they want to escape/cancel or resume processing. Returns: True if a key has been pressed and the user confirms to escape/cancel. False if no key has been pressed or the user chooses to resume and not escape/cancel. |
var= | AT(code) | Get a string to control terminal operation. Returns: A string to be output to the terminal in order to accomplish the desired operation. The terminal protocol is xterminal. code: n Position the cursor at column number n 0 Position the cursor at column number 0 -1 Clear the screen and home the cursor -2 Position the cursor at the top left home (x,y = 0,0) -3 Clear from the cursor at the end of screen -4 Clear from cursor to end of line -40 Position the cursor at columnno 0 and clear to end of line |
var= | AT(x, y) | Get a terminal cursor positioning string. Returns: A string to be output to the terminal to position the cursor at the desired screen x and y position. The terminal protocol is xterminal. |
if | getcursor(out cursor, delayms = 3000, max_errors = 0) | Get the position of the terminal cursor. cursor: [out] If stdin is a terminal, an FM delimited string containing the x and y coordinates of the current terminal cursor. If stdin is not a terminatl then an empty string "" is returned. The cursor additionally contains a third field which contains the delay in ms from the terminal. The FM delimited string returned can be later passed to setcursor() to reposition the cursor back to its original position or it can be parsed and used accordingly. delayms: Default 3000ms. The maximum time to wait for terminal response. max_errors: Default is 0. If not zero, reset the number of times to error before automatically disabling getcursor(). max_errors is initialised to 3. If negative then max_errors has the the effect of disabling all future calls to getcursor(). In case the terminal fails to respond correctly within the required timeout, or is currently disabled due to too many failures, or has been specifically disabled then the returned "cursor" var contains a 4th field: TIMEOUT - The terminal failed to respond within the timeout. READ_ERROR - Failed to read terminal response. INVALID_RESPONSE - Terminal response invalid. SETUP_ERROR - Terminal setup failed. DISABLED - Terminal is disabled due to more errors than the maximum currently set.
|
var= | getcursor() | Get the position of the terminal cursor. For more info see the main getcursor() function above.
|
setcursor(cursor_coordinates) | If stdin is a terminal, position the cursor at x and y as per the given coordinates. cursor_coordinates: An FM delimited string containing the x and y coordinates of the terminal cursor as can be obtained by getcursor().
|
Array Utilities
Use | Function | Description |
---|---|---|
var= | invertarray(input, pad = false) | Dynamic array fields become values and vice versa Returns: The inverted dynamic array. pad: If true then on return, all fields will have the same number of values with superfluous trailing VMs where necessary.
|
sortarray(io array, fns = "", order = "") | Sorts fields of multivalues of dynamic arrays in parallel fns: VM separated list of field numbers to sort in parallel based on the first field number order: AL Ascending - Left Justified - Alphabetic DL Descending - Left Justfiied - Alphabetic AR Ascending - Right Justified - Numeric DR Descending - Right Justified - Numeric
|
Record Locking
Use | Function | Description |
---|---|---|
if | lockrecord(filename, io file, keyx, recordx, waitsecs = 0, allowduplicate = false) | Does not actually return record |
if | lockrecord(filename, io file, keyx) | |
if | unlockrecord(filename, io file, key) | |
if | unlockrecord() |
</html>