<!-- d function#1 <p><bf>$1</bf>\label{$1}<p><descrip> -->
<!doctype linuxdoc system>
<article>
<title> S-Lang Run-Time Library Reference
<author> John E. Davis, <tt>davis@space.mit.edu</tt>
<date> Sun Jan 25 22:41:27 1998
<toc>
<sect><bf>_traceback</bf><label id="_traceback"><p><descrip>
<tag> Synopsis </tag> Generate a traceback upon error
<tag> Usage </tag> <tt>Integer_Type _traceback</tt>
<tag> Description </tag>
<tt>_traceback</tt> is an intrinsic integer variable whose value
controls whether or not a traceback of the call stack is to be
generated upon error. If <tt>_traceback</tt> is greater than zero, a
full traceback will be generated, which includes the values of local
variables. If the value is less than zero, a traceback will be
generated without local variable information, and if
<tt>_traceback</tt> is zero the traceback will not be generated.
Local variables are represented in the form <tt>$n</tt> where <tt>n</tt> is an
integer numbered from zero. More explicitly, <tt>$0</tt> represents the
first local variable, <tt>$1</tt> represents the second, and so on.
Please note that function parameters are local variables and that the
first parameter corresponds to <tt>$0</tt>.
<tag> See Also </tag> <tt>_slangtrace, error</tt>
</descrip><p>
<sect><bf>_slangtrace</bf><label id="_slangtrace"><p><descrip>
<tag> Synopsis </tag> Turn function tracing on or off.
<tag> Usage </tag> <tt>Integer_Type _slangtrace</tt>
<tag> Description </tag>
The <tt>_slangtrace</tt> variable is a debugging aid that when set to a
non-zero value enables tracing when function declared by
<tt>_trace_function</tt> is entered. If the value is greater than
zero, both intrinsic and user defined functions will get traced.
However, if set to a value less than zero, intrinsic functions will
not get traced.
<tag> See Also </tag> <tt>_trace_function, _traceback, _print_stack</tt>
</descrip><p>
<sect><bf>errno</bf><label id="errno"><p><descrip>
<tag> Synopsis </tag> Error code set by system functions.
<tag> Usage </tag> <tt>Integer_Type errno</tt>
<tag> Description </tag>
A system function can fail for a variety of reasons. For example, a
file operation may fail because lack of disk space, or the process
does not have permission to perform the operation. Such functions
will return <tt>-1</tt> and set the variable <tt>errno</tt> to an error
code describing the reason for failure.
Particular values of <tt>errno</tt> may be specified by the following
symbolic constants (read-only variables) and the corresponding
<tt>errno_string</tt> value:
<tscreen><verb>
EPERM "Not owner"
ENOENT "No such file or directory"
ESRCH "No such process"
ENXIO "No such device or address"
ENOEXEC "Exec format error"
EBADF "Bad file number"
ECHILD "No children"
ENOMEM "Not enough core"
EACCES "Permission denied"
EFAULT "Bad address"
ENOTBLK "Block device required"
EBUSY "Mount device busy"
EEXIST "File exists"
EXDEV "Cross-device link"
ENODEV "No such device"
ENOTDIR "Not a directory"
EISDIR "Is a directory"
EINVAL "Invalid argument"
ENFILE "File table overflow"
EMFILE "Too many open files"
ENOTTY "Not a typewriter"
ETXTBSY "Text file busy"
EFBIG "File too large"
ENOSPC "No space left on device"
ESPIPE "Illegal seek"
EROFS "Read-only file system"
EMLINK "Too many links"
EPIPE "Broken pipe"
ELOOP "Too many levels of symbolic links"
ENAMETOOLONG "File name too long"
</verb></tscreen>
<tag> Example </tag>
The <tt>mkdir</tt> function will attempt to create a directory. If
that directory already exists, the function will fail and set
<tt>errno</tt> to <tt>EEXIST</tt>.
<tscreen><verb>
define create_dir (dir)
{
if (0 == mkdir (dir)) return;
if (errno != EEXIST)
error ("mkdir %s failied: %s", dir, errno_string);
}
</verb></tscreen>
<tag> See Also </tag> <tt>errno_string, error, mkdir</tt>
</descrip><p>
<sect><bf>where</bf><label id="where"><p><descrip>
<tag> Synopsis </tag> Get indices where an integer array is non-zero
<tag> Usage </tag> <tt>Array_Type where (Array_Type a)</tt>
<tag> Description </tag>
The <tt>where</tt> function examines an integer array <tt>a</tt> and
returns a 2-d integer array whose rows are the indices of <tt>a</tt>
where the corresponding element of <tt>a</tt> is non-zero.
<tag> Example </tag>
Consider the following:
<tscreen><verb>
variable X = [0.0:10.0:0.01];
variable A = sin (X);
variable I = where (A < 0.0);
A[I] = cos (X) [I];
</verb></tscreen>
Here the variable <tt>X</tt> has been assigned an array of doubles
whose elements range from <tt>0.0</tt> through <tt>10.0</tt> in
increments of <tt>0.01</tt>. The second statement assigns <tt>A</tt> to
an array whose elements are the <tt>sin</tt> of the elements of <tt>X</tt>.
The third statement uses the where function to get the indices of
the elements of <tt>A</tt> that are less than <tt>0.0</tt>. Finally, the
last statement substitutes into <tt>A</tt> the <tt>cos</tt> of the
elements of <tt>X</tt> at the positions of <tt>A</tt> where the
corresponding <tt>sin</tt> is less than <tt>0</tt>. The end result is
that the elements of <tt>A</tt> are a mixture of sines and cosines.
<tag> See Also </tag> <tt>array_info, sin, cos</tt>
</descrip><p>
<sect><bf>vmessage</bf><label id="vmessage"><p><descrip>
<tag> Synopsis </tag> Print a formatted string onto the message device
<tag> Usage </tag> <tt>vmessage (String_Type fmt, ...)</tt>
<tag> Description </tag>
The <tt>vmessage</tt> function formats a sprintf style argument list
and displays the resulting string onto the message device.
<tag> Notes </tag>
In the current implementation, strictly speaking, the <tt>vmessage</tt>
function is not an intrinsic function. Rather it is a predefined
<bf>S-lang</bf> function using a combination of <tt>Sprintf</tt> and
<tt>message</tt>.
<tag> See Also </tag> <tt>message, Sprintf, verror</tt>
</descrip><p>
<sect><bf>_apropos</bf><label id="_apropos"><p><descrip>
<tag> Synopsis </tag> Generate a list of functions and variable
<tag> Usage </tag> <tt>Integer_Type _apropos (String_Type s, Integer_Type flags)</tt>
<tag> Description </tag>
The <tt>_apropos</tt> function may be used to get a list of all defined
objects whose name consists of the substring <tt>s</tt> and whose type
matches those specified by <tt>flags</tt>. It returns the number of
matches. If the number returned is non-zero, that number of strings
which represent the names of the matched objects will also be
present on the stack.
The second parameter <tt>flags</tt> is a bit mapped value whose bits
are defined according to the following table
<tscreen><verb>
1 Intrinsic Function
2 User-defined Function
4 Intrinsic Variable
8 User-defined Variable
</verb></tscreen>
<tag> Example </tag>
<tscreen><verb>
define apropos (s)
{
variable n, name;
n = _apropos (s, 0xF);
if (n) vmessage ("Found %d matches:", n);
else message ("No matches.");
loop (n)
{
name = ();
message (name);
}
}
</verb></tscreen>
prints a list of all matches.
<tag> Notes </tag>
Since the function returns the matches to the stack, it is possible
that a stack overfow error could result if there are two many
matches. If this happens, the interpreter should be recompiled to
use a larger stack size.
<tag> See Also </tag> <tt>is_defined, sprintf</tt>
</descrip><p>
<sect><bf>_clear_error</bf><label id="_clear_error"><p><descrip>
<tag> Synopsis </tag> Clear an error condition
<tag> Usage </tag> <tt>_clear_error ()</tt>
<tag> Description </tag>
This function may be used in error-blocks to clear the error that
triggered execution of the error block. Execution resumes following
the statement, in the scope of the error-block, that triggered the
error.
<tag> Example </tag>
Consider the following wrapper around the <tt>putenv</tt> function:
<tscreen><verb>
define try_putenv (name, value)
{
variable status;
ERROR_BLOCK
{
_clear_error ();
status = -1;
}
status = 0;
putenv (sprintf ("%s=%s", name, value);
return status;
}
</verb></tscreen>
If <tt>putenv</tt> fails, it generates an error condition, which the
<tt>try_putenv</tt> function catches and clears. Thus <tt>try_putenv</tt>
is a function that returns <tt>-1</tt> upon failure and <tt>0</tt> upon
success.
<tag> See Also </tag> <tt>_trace_function, _slangtrace, _traceback</tt>
</descrip><p>
<sect><bf>_function_name</bf><label id="_function_name"><p><descrip>
<tag> Synopsis </tag> Returns the name of the currently executing function
<tag> Usage </tag> <tt>String _function_name ();</tt>
<tag> Description </tag>
This function returns the name of the currently executing function.
If called from top-level, it returns the empty string.
<tag> See Also </tag> <tt>_trace_function, is_defined</tt>
</descrip><p>
<sect><bf>_pop_n</bf><label id="_pop_n"><p><descrip>
<tag> Synopsis </tag> Remove objects from the stack
<tag> Usage </tag> <tt>_pop_n (Integer_Type n);</tt>
<tag> Description </tag>
The <tt>_pop_n</tt> function pops <tt>n</tt> objects from the top of the
stack.
<tag> Example </tag>
<tscreen><verb>
define add3 ()
{
variable x, y, z;
if (_NARGS != 3)
{
_pop_n (_NARGS);
error ("add3: Expecting 3 arguments");
}
(x, y, z) = ();
return x + y + z;
}
</verb></tscreen>
<tag> See Also </tag> <tt>_stkdepth, pop</tt>
</descrip><p>
<sect><bf>_print_stack</bf><label id="_print_stack"><p><descrip>
<tag> Synopsis </tag> print the values on the stack.
<tag> Usage </tag> <tt>_print_stack ()</tt>
<tag> Description </tag>
This function dumps out what is currently on the <bf>S-lang</bf>. It does not
alter the stack and it is usually used for debugging purposes.
<tag> See Also </tag> <tt>_stkdepth, string</tt>
</descrip><p>
<sect><bf>_slang_guess_type</bf><label id="_slang_guess_type"><p><descrip>
<tag> Synopsis </tag> Guess the data type that a string represents.
<tag> Usage </tag> <tt>DataType_Type _slang_guess_type (String_Type s)</tt>
<tag> Description </tag>
This function tries to determine whether its argument <tt>s</tt> represents
an integer or a floating point number. If it appears to be neither,
then a string is assumed. It returns one of three values depending on
the format of the string <tt>s</tt>:
<tscreen><verb>
Integer_Type : If it appears to be an integer
Double_Type : If it appears to be a double
String_Type : Anything else.
</verb></tscreen>
For example, <tt>_slang_guess_type("1e2")</tt> returns
<tt>Double_Type</tt> but <tt>_slang_guess_type("e12")</tt> returns
<tt>String_Type</tt>.
<tag> See Also </tag> <tt>integer, string, double</tt>
</descrip><p>
<sect><bf>_stk_reverse</bf><label id="_stk_reverse"><p><descrip>
<tag> Synopsis </tag> Reverse the order of the objects on the stack.
<tag> Usage </tag> <tt>_stk_reverse (Integer_Type n)</tt>
<tag> Description </tag>
The <tt>_stk_reverse</tt> function reverses the order of the top
<tt>n</tt> items on the stack.
<tag> See Also </tag> <tt>_stkdepth, _stk_roll</tt>
</descrip><p>
<sect><bf>_stk_roll</bf><label id="_stk_roll"><p><descrip>
<tag> Synopsis </tag> Roll items on the stack
<tag> Usage </tag> <tt>_stk_roll (Integer_Type n);</tt>
<tag> Description </tag>
This function may be used to alter the arrangement of objects on the
stack. Specifically, if the integer <tt>n</tt> is positive, the top
<tt>n</tt> items on the stack are rotated up. If
<tt>n</tt> is negative, the top <tt>abs(n)</tt> items on the stack are
rotated down.
<tag> Example </tag>
If the stack looks like:
<tscreen><verb>
item-0
item-1
item-2
item-3
</verb></tscreen>
where <tt>item-0</tt> is at the top of the stack, then
<tt>_stk_roll(-3)</tt> will change the stack to:
<tscreen><verb>
item-2
item-0
item-1
item-3
</verb></tscreen>
<tag> Notes </tag>
This function only has an effect for <tt>abs(n) > 1</tt>.
<tag> See Also </tag> <tt>_stkdepth, _stk_reverse, _pop_n, _print_stack</tt>
</descrip><p>
<sect><bf>_stkdepth</bf><label id="_stkdepth"><p><descrip>
<tag> Usage </tag> <tt>Get the number of objects currently on the stack.</tt>
<tag> Synopsis </tag> Integer_Type _stkdepth ()
<tag> Description </tag>
The <tt>_stkdepth</tt> function returns number of items on stack prior
to the call of <tt>_stkdepth</tt>.
<tag> See Also </tag> <tt>_print_stack, _stk_reverse, _stk_roll</tt>
</descrip><p>
<sect><bf>_trace_function</bf><label id="_trace_function"><p><descrip>
<tag> Synopsis </tag> Set the function to trace
<tag> Usage </tag> <tt>_trace_function (String_Type f)</tt>
<tag> Description </tag>
<tt>_trace_function</tt> declares that the <bf>S-lang</bf> function with name
<tt>f</tt> is to be traced when it is called. Calling
<tt>_trace_function</tt> does not in itself turn tracing on. Tracing
is turned on only when the variable <tt>_slangtrace</tt> is non-zero.
<tag> See Also </tag> <tt>_slangtrace, _traceback</tt>
</descrip><p>
<sect><bf>array_info</bf><label id="array_info"><p><descrip>
<tag> Synopsis </tag> Returns information about an array
<tag> Usage </tag> <tt>(Array_Type, Integer_Type, DataType_Type) array_info (Array_Type a)</tt>
<tag> Description </tag>
The <tt>array_info</tt> function returns information about the array <tt>a</tt>.
It returns three values: an 1-d integer array array specifying the
size of each dimension of <tt>a</tt>, the number of dimensions of
<tt>a</tt>, and the data type of <tt>a</tt>.
<tag> Example </tag>
The <tt>array_info</tt> function may be used to find the number of rows
of an array:
<tscreen><verb>
define num_rows (a)
{
variable dims, num_dims, data_type;
(dims, num_dims, data_type) = array_info (a);
return dims [0];
}
</verb></tscreen>
<tag> See Also </tag> <tt>typeof, reshape</tt>
</descrip><p>
<sect><bf>array_sort</bf><label id="array_sort"><p><descrip>
<tag> Synopsis </tag> Sort an array
<tag> Usage </tag> <tt>Array_Type array_sort (Array_Type a, String_Type f)</tt>
<tag> Description </tag>
<tt>array_sort</tt> sorts the array <tt>a</tt> into ascending order
according to the function specified by the name <tt>f</tt> and returns
an integer array that represents the result of the sort.
The sort function represented by <tt>f</tt> must be a <bf>S-lang</bf>
user-defined function that takes two arguments. The function must
return an integer that is less than zero if the first parameter is
considered to be less than the second, zero if they are equal, and a
value greater than zero if the first is greater than the second.
The integer array returned by this function is simply an index that
indicates the order of the sorted array. The input array <tt>a</tt> is
not changed.
<tag> Example </tag>
An array of strings may be sorted using the <tt>strcmp</tt> function
since it fits the specification for the sorting function described
above:
<tscreen><verb>
variable A = String_Type [3];
A[0] = "gamma"; A[1] = "alpha"; A[2] = "beta";
variable I = array_sort (A, "strcmp");
</verb></tscreen>
After the <tt>array_sort</tt> has executed, the variable <tt>I</tt> will
have the values <tt>[2, 0, 1]</tt>. This array can be used to
re-shuffle the elements of <tt>A</tt> into the sorted order via the
array index expression <tt>A = A[I]</tt>.
<tag> Notes </tag>
The current sorting algorithm is a heap-sort.
<tag> See Also </tag> <tt>strcmp</tt>
</descrip><p>
<sect><bf>atof</bf><label id="atof"><p><descrip>
<tag> Synopsis </tag> Convert a string to a double precision number
<tag> Usage </tag> <tt>Double_Type atof (String_Type s)</tt>
<tag> Description </tag>
This function converts a string <tt>s</tt> to a double precision value
and returns the result. It performs no error checking on the format
of the string. The function <tt>_slang_guess_type</tt> may be used to
check the syntax of the string.
<tag> Example </tag>
<tscreen><verb>
define error_checked_atof (s)
{
switch (_slang_guess_type (s))
{
case Double_Type:
return atof (s);
}
{
case Integer_Type:
return double (integer (s));
}
verror ("%s is is not a double", s);
}
</verb></tscreen>
<tag> See Also </tag> <tt>typecast, double, _slang_guess_type</tt>
</descrip><p>
<sect><bf>autoload</bf><label id="autoload"><p><descrip>
<tag> Synopsis </tag> Load a function from a file
<tag> Usage </tag> <tt>autoload (String_Type funct, String_Type file)</tt>
<tag> Description </tag>
The <tt>autoload</tt> function is used to declare <tt>funct</tt> to the
interpreter and indicate that it should be loaded from <tt>file</tt> when
it is actually used.
<tag> Example </tag>
Suppose <tt>bessel_j0</tt> is a function defined in the file
<tt>bessel.sl</tt>. Then the statement
<tscreen><verb>
autoload ("bessel_j0", "bessel.sl");
</verb></tscreen>
will cause <tt>bessel.sl</tt> to be loaded prior to the execution of
<tt>bessel_j0</tt>
<tag> See Also </tag> <tt>evalfile</tt>
<tag> Keywords </tag> file function
</descrip><p>
<sect><bf>byte_compile_file</bf><label id="byte_compile_file"><p><descrip>
<tag> Synopsis </tag> Compile a file to byte-code for faster loading.
<tag> Usage </tag> <tt>byte_compile_file (String_Type file, Integer_Type method)</tt>
<tag> Description </tag>
The <tt>byte_compile_file</tt> function byte-compiles <tt>file</tt>
producing a new file with the same name except a <tt>'c'</tt> is added
to the output file name. For example, <tt>file</tt> is
<tt>"site.sl"</tt>, then the function produces a new file named
<tt>site.slc</tt>.
<tag> Notes </tag>
The <tt>method</tt> parameter is not used in the current
implementation. Its use is reserved for the future. For now, set
it to <tt>0</tt>.
<tag> See Also </tag> <tt>evalfile</tt>
</descrip><p>
<sect><bf>char</bf><label id="char"><p><descrip>
<tag> Synopsis </tag> Convert an ascii value into a string
<tag> Usage </tag> <tt>String_Type char (Integer_Type c)</tt>
<tag> Description </tag>
The <tt>char</tt> function converts an integer ascii value <tt>c</tt> to a string
of unit length such that the first character of the string is <tt>c</tt>.
For example, <tt>char('a')</tt> returns the string <tt>"a"</tt>.
<tag> See Also </tag> <tt>integer, string, typedef</tt>
</descrip><p>
<sect><bf>chdir</bf><label id="chdir"><p><descrip>
<tag> Synopsis </tag> Change the current working directory.
<tag> Usage </tag> <tt>Integer_Type chdir (String_Type dir)</tt>
<tag> Description </tag>
The <tt>chdir</tt> function may be used to changed the current working
directory to the directory specified by <tt>dir</tt>. Upon sucess it
returns zero; however, upon failure it returns <tt>-1</tt> and sets
<tt>errno</tt> accordingly.
<tag> See Also </tag> <tt>mkdir, stat_file</tt>
</descrip><p>
<sect><bf>chmod</bf><label id="chmod"><p><descrip>
<tag> Synopsis </tag> Change the mode of a file
<tag> Usage </tag> <tt>Integer_Type chmod (String_Type file, Integer_Type mode)</tt>
<tag> Description </tag>
The <tt>chmod</tt> function changes the permissions of <tt>file</tt> to those
specified by <tt>mode</tt>. It returns <tt>0</tt> upon success, or
<tt>-1</tt> upon failure setting <tt>errno</tt> accordingly.
See the system specific documentation for the C library
function <tt>chmod</tt> for a discussion of the <tt>mode</tt> parameter.
<tag> See Also </tag> <tt>chown, stat_file</tt>
</descrip><p>
<sect><bf>chown</bf><label id="chown"><p><descrip>
<tag> Synopsis </tag> Change the owner of a file
<tag> Usage </tag> <tt>Integer_Type chown (String_Type file, Integer_Type uid, Integer_Type gid)</tt>
<tag> Description </tag>
The <tt>chown</tt> function is used to change the user-id and group-id of
<tt>file</tt> to <tt>uid</tt> and <tt>gid</tt>, respectively. It returns
<tt>zero</tt> upon success and <tt>-1</tt> upon failure, with <tt>errno</tt>
set accordingly.
<tag> Notes </tag>
On most systems, only the super user can change the ownership of a
file.
Some systems do not support this function.
<tag> See Also </tag> <tt>chmod, stat_file</tt>
</descrip><p>
<sect><bf>create_delimited_string</bf><label id="create_delimited_string"><p><descrip>
<tag> Synopsis </tag> Concatenate strings using a delimiter
<tag> Usage </tag> <tt>String_Type create_delimited_string (delim, s_1, s_2, ..., s_n, n)</tt>
<tscreen><verb>
String_Type delim, s_1, ..., s_n
Integer_Type n
</verb></tscreen>
<tag> Description </tag>
<tt>create_delimited_string</tt> performs a concatenation operation on
the <tt>n</tt> strings <tt>s_1</tt>, ...,<tt>s_n</tt>, using the string
<tt>delim</tt> as a delimiter. The resulting string is equivalent to
one obtained via
<tscreen><verb>
s_1 + delim + s_2 + delim + ... + s_n
</verb></tscreen>
<tag> Example </tag>
One use for this function is to construct path names, e.g.,
<tscreen><verb>
create_delimited_string ("/", "user", "local", "bin", 3);
</verb></tscreen>
will produce <tt>"usr/local/bin"</tt>.
<tag> Notes </tag>
The expression <tt>strcat(a,b)</tt> is equivalent to
<tt>create_delimited_string("", a, b, 2)</tt>.
<tag> See Also </tag> <tt>is_list_element, extract_element, strchop, strcat</tt>
</descrip><p>
<sect><bf>define_case</bf><label id="define_case"><p><descrip>
<tag> Synopsis </tag> Define upper-lower case conversion.
<tag> Usage </tag> <tt>define_case (Integer_Type ch_up, Integer_Type ch_low);</tt>
<tag> Description </tag>
This function defines an upper and lowercase relationship between two
characters specified by the arguments. This relationship is used by
routines which perform uppercase and lowercase conversions.
The first integer <tt>ch_up</tt> is the ascii value of the uppercase character
and the second parameter <tt>ch_low</tt> is the ascii value of its
lowercase counterpart.
<tag> See Also </tag> <tt>strlow, strup</tt>
</descrip><p>
<sect><bf>double</bf><label id="double"><p><descrip>
<tag> Synopsis </tag> Convert an object to double precision
<tag> Usage </tag> <tt>result = double (x)</tt>
<tag> Description </tag>
The <tt>double</tt> function typecasts an object <tt>x</tt> to double
precision. For example, if <tt>x</tt> is an array of integers, an
array of double types will be returned. If an object cannot be
converted to <tt>Double_Type</tt>, a type-mismatch error will result.
<tag> Notes </tag>
The <tt>double</tt> function is equivalent to the typecast operation
<tscreen><verb>
typecast (x, Double_Type)
</verb></tscreen>
To convert a string to a double precision number, use <tt>atoi</tt>
function.
<tag> See Also </tag> <tt>typecast, atoi, int</tt>
</descrip><p>
<sect><bf>dup</bf><label id="dup"><p><descrip>
<tag> Synopsis </tag> Duplicate the value at the top of the stack
<tag> Usage </tag> <tt>dup ()</tt>
<tag> Description </tag>
This function returns an exact duplicate of the object on top of the
stack. For some objects such as arrays or structures, it creates a
new reference to the array. However, for simple scalar S-Lang types such
as strings, integers, and doubles, it creates a new copy of the
object.
<tag> See Also </tag> <tt>pop, typeof</tt>
</descrip><p>
<sect><bf>errno_string</bf><label id="errno_string"><p><descrip>
<tag> Synopsis </tag> Return a string describing an errno.
<tag> Usage </tag> <tt>String_Type errno_string (Integer_Type err)</tt>
<tag> Description </tag>
The <tt>errno_string</tt> function returns a string describing the
integer error code <tt>err</tt>. The variable <tt>err</tt> usually
corresponds to the <tt>errno</tt> intrinsic function. See the
description for <tt>errno</tt> for more information.
<tag> Example </tag>
The <tt>errno_string</tt> function may be used as follows:
<tscreen><verb>
define sizeof_file (file)
{
variable st = stat (file);
if (st == NULL)
verror ("%s: %s", file, errno_string (errno);
return st.st_size;
}
</verb></tscreen>
<tag> See Also </tag> <tt>errno, stat, verror</tt>
</descrip><p>
<sect><bf>error</bf><label id="error"><p><descrip>
<tag> Synopsis </tag> Generate an error condition
<tag> Usage </tag> <tt>error (String_Type msg</tt>
<tag> Description </tag>
The <tt>error</tt> function generates a <bf>S-lang</bf> error condition causing
the interpreter to start unwinding to top-level. It takes a single
string parameter which is displayed on the stderr output device.
The error condition may be cleared via an <tt>ERROR_BLOCK</tt> with the
<tt>_clear_error</tt> function. Consult <bf>A Guide to the S-Lang Language</bf> for more
information.
<tag> Example </tag>
<tscreen><verb>
define add_txt_extension (file)
{
if (typeof (file) != String_Type)
error ("add_extension: parameter must be a string");
file += ".txt";
return file;
}
</verb></tscreen>
<tag> See Also </tag> <tt>verror, _clear_error, message</tt>
</descrip><p>
<sect><bf>evalfile</bf><label id="evalfile"><p><descrip>
<tag> Synopsis </tag> Interpret a file containing <bf>S-lang</bf> code.
<tag> Usage </tag> <tt>Integer_Type evalfile (String_Type file)</tt>
<tag> Description </tag>
The <tt>evalfile</tt> function loads <tt>file</tt> into the interpreter.
If no errors were encountered, <tt>1</tt> will be returned; otherwise,
a <bf>S-lang</bf> error will be generated and the function will return zero.
<tag> Example </tag>
<tscreen><verb>
define load_file (file)
{
ERROR_BLOCK { _clear_error (); }
() = evalfile (file);
}
</verb></tscreen>
<tag> See Also </tag> <tt>eval, autoload</tt>
</descrip><p>
<sect><bf>eval</bf><label id="eval"><p><descrip>
<tag> Synopsis </tag> Interpret a string as <bf>S-lang</bf> code
<tag> Usage </tag> <tt>eval (String_Type expression)</tt>
<tag> Description </tag>
The <tt>eval</tt> function parses a string as S-Lang code and executes the
result. This is a useful function in many contexts such as dynamically
generating function definitions where there is no way to generate
them otherwise.
<tag> Example </tag>
<tscreen><verb>
if (0 == is_defined ("my_function"))
eval ("define my_function () { message (\"my_function\"); }");
</verb></tscreen>
<tag> See Also </tag> <tt>is_defined, autoload, evalfile</tt>
</descrip><p>
<sect><bf>extract_element</bf><label id="extract_element"><p><descrip>
<tag> Synopsis </tag> Extract the nth element of a string with delimiters
<tag> Usage </tag> <tt>String_Type extract_element (String_Type list, Integer_Type nth, Integer_Type delim);</tt>
<tag> Description </tag>
The <tt>extract_element</tt> function may be used to extract the
<tt>nth</tt> element of the <tt>delim</tt> delimited list of strings
<tt>list</tt>. The function will return the <tt>nth</tt> element of the
list, unless <tt>nth</tt> specifies more elements than the list
contains, in which case <tt>NULL</tt> will be returned.
Elements in the list are numbered from <tt>0</tt>.
<tag> Example </tag>
The expression
<tscreen><verb>
extract_element ("element 0, element 1, element 2", 1, ',')
</verb></tscreen>
returns the string <tt>" element 1"</tt>, whereas
<tscreen><verb>
extract_element ("element 0, element 1, element 2", 1, ' ')
</verb></tscreen>
returns <tt>"0,"</tt>.
The following function may be used to compute the number of elements
in the list:
<tscreen><verb>
define num_elements (list, delim)
{
variable nth = 0;
while (NULL != extract_element (list, nth, delim))
nth++;
return nth;
}
</verb></tscreen>
<tag> See Also </tag> <tt>is_list_element, is_substr, strchop, create_delimited_string</tt>
</descrip><p>
<sect><bf>fclose</bf><label id="fclose"><p><descrip>
<tag> Synopsis </tag> Close a file
<tag> Usage </tag> <tt>Integer_Type fclose (File_Type fp)</tt>
<tag> Description </tag>
The <tt>fclose</tt> function may be used to close an open file pointer
<tt>fp</tt>. Upon success it returns zero, and upon failure it sets
<tt>errno</tt> and returns <tt>-1</tt>. Failure usually indicates a that
the file system is full or that <tt>fp</tt> does not refer to an open file.
<tag> Notes </tag>
Many C programmers call <tt>fclose</tt> without checking the return
value. The <bf>S-lang</bf> language requires the programmer to explicitly
handle any value returned by a <bf>S-lang</bf> function. The simplest way to
handle the return value from <tt>fclose</tt> is to use it as:
<tscreen><verb>
() = fclose (fp);
</verb></tscreen>
<tag> See Also </tag> <tt>fopen, fgets, fflush, errno</tt>
</descrip><p>
<sect><bf>fflush</bf><label id="fflush"><p><descrip>
<tag> Synopsis </tag> Flush an output stream
<tag> Usage </tag> <tt>Integer_Type fflush (File_Type fp)</tt>
<tag> Description </tag>
The <tt>fflush</tt> function may be used to update the <em>output</em>
stream specified by <tt>fp</tt>. It returns <tt>0</tt> upon success, or
<tt>-1</tt> upon failure and sets <tt>errno</tt> accordingly. In
particular, this function will fail if <tt>fp</tt> does not represent
an output stream, or if <tt>fp</tt> is associated with a disk file and
there is insufficient disk space.
<tag> Example </tag>
This example illustrates how to use the <tt>fflush</tt> function
without regard to the return value:
<tscreen><verb>
() = fputs ("Enter value> ", stdout);
() = fflush (stdout);
</verb></tscreen>
<tag> Notes </tag>
Many C programmers disregard the return value from the <tt>fflush</tt>
function. The above example illustrates how to properly do this in
the <bf>S-lang</bf> langauge.
<tag> See Also </tag> <tt>fopen, fclose</tt>
</descrip><p>
<sect><bf>fgets</bf><label id="fgets"><p><descrip>
<tag> Synopsis </tag> Read a line from a file.
<tag> Usage </tag> <tt>Integer_Type fgets (SLang_Ref_Type ref, File_Type fp)</tt>
<tag> Description </tag>
<tt>fgets</tt> reads a line from the open file specified by <tt>fp</tt>
and places the characters in the variable whose reference is
specified by <tt>ref</tt>.
It returns <tt>-1</tt> if <tt>fp</tt> is not associated with an open file
or an attempt was made to read at the end the file; otherwise, it
returns the number of characters read.
<tag> Example </tag>
The following example returns the lines of a file via a linked list:
<tscreen><verb>
define read_file (file)
{
variable buf, fp, root, tail;
variable list_type = struct { text, next };
root = NULL;
fp = fopen(file, "r");
if (fp == NULL)
error("fopen %s failed." file);
while (-1 != fgets (&buf, fp))
{
if (root == NULL)
{
root = @list_type;
tail = root;
}
else
{
tail.next = @list_type;
tail = tail.next;
}
tail.text = buf;
tail.next = NULL;
}
() = fclose (fp);
return root;
}
</verb></tscreen>
<tag> See Also </tag> <tt>fopen, fclose, fputs, error</tt>
</descrip><p>
<sect><bf>fopen</bf><label id="fopen"><p><descrip>
<tag> Synopsis </tag> Open a file
<tag> Usage </tag> <tt>File_Type fopen (String_Type f, String_Type m)</tt>
<tag> Description </tag>
The <tt>fopen</tt> function opens a file <tt>f</tt> according to the mode
string <tt>m</tt>. Allowed values for <tt>m</tt> are:
<tscreen><verb>
"r" Read only
"w" Write only
"a" Append
"r+" Reading and writing at the beginning of the file.
"w+" Reading and writing. The file is created if it does not
exist; otherwise, it is truncated.
"a+" Reading and writing at the end of the file. The file is created
if it does not already exist.
<tscreen><verb>
In addition, the mode string can also include the letter \var{'b'}
as the last character to indicate that the file is to be opened in
binary mode.
Upon success, \var{fopen} a \var{File_Type} object which is meant to
be used in other operations that require an open file. Upon
failure, the function returns \var{NULL}.
\example
The following function opens a file in append mode and writes a
string to it:
<tscreen><verb>
define append_string_to_file (file, str)
{
variable fp = fopen (file, "a");
if (fp == NULL) verror ("%s could not be opened", file);
() = fputs (string, fp);
() = fclose (fp);
}
</verb></tscreen>
Note that the return values from <tt>fputs</tt> and <tt>fclose</tt> are
ignored.
<tag> Notes </tag>
There is no need to explicitly close a file opened with <tt>fopen</tt>.
If the returned <tt>File_Type</tt> object goes out of scope, <bf>S-lang</bf>
will automatically close the file. However, explicitly closing a
file after use is recommended.
<tag> See Also </tag> <tt>fclose, fgets, fputs</tt>
</descrip><p>
<sect><bf>fputs</bf><label id="fputs"><p><descrip>
<tag> Synopsis </tag> Write a string to an open stream
<tag> Usage </tag> <tt>Integer_Type fputs (String_Type s, File_Type fp);</tt>
<tag> Description </tag>
The <tt>fputs</tt> function writes the string <tt>s</tt> to the open file
pointer <tt>fp</tt>. It returns -1 upon failure and sets <tt>errno</tt>,
otherwise it returns the length of the string.
<tag> Example </tag>
The following function opens a file in append mode and uses the
<tt>fputs</tt> function to write to it.
<tscreen><verb>
define append_string_to_file (str, file)
{
variable fp;
fp = fopen (file, "a");
if (fp == NULL) verror ("Unable to open %s", file);
if ((-1 == fputs (s, fp))
or (-1 == fclose (fp)))
verror ("Error writing to %s", file);
}
</verb></tscreen>
<tag> Notes </tag>
One must not disregard the return value from the <tt>fputs</tt>
function, as many C programmers do. Doing so may lead to a stack
overflow error.
<tag> See Also </tag> <tt>fclose, fopen, fgets</tt>
</descrip><p>
<sect><bf>getcwd</bf><label id="getcwd"><p><descrip>
<tag> Synopsis </tag> Get the current working directory
<tag> Usage </tag> <tt>String_Type getcwd ()</tt>
<tag> Description </tag>
The <tt>getcwd</tt> function returns the absolute pathname of the
current working directory. If an error occurs or it cannot
determine the working directory, it returns <tt>NULL</tt> and sets
<tt>errno</tt> accordingly.
<tag> Notes </tag>
Under Unix, OS/2, and MSDOS, the pathname returned by this function
includes the trailing slash character. Some versions also include
the drive specifier.
<tag> See Also </tag> <tt>mkdir, chdir, errno</tt>
</descrip><p>
<sect><bf>get_doc_string_from_file</bf><label id="get_doc_string_from_file"><p><descrip>
<tag> Synopsis </tag> Read documentation from a file
<tag> Usage </tag> <tt>String_Type get_doc_string_from_file (String_Type f, String_Type t)</tt>
<tag> Description </tag>
<tt>get_doc_string_from_file</tt> opens the documentation file <tt>f</tt>
and searches it for topic <tt>t</tt>. It returns the documentation for
<tt>t</tt> upon success, otherwise it returns <tt>NULL</tt> upon error.
It will fail if <tt>f</tt> could not be opened or does not contain
documentation for the topic.
<tag> See Also </tag> <tt>stat_file</tt>
</descrip><p>
<sect><bf>getenv</bf><label id="getenv"><p><descrip>
<tag> Synopsis </tag> Get the value of an environment variable
<tag> Usage </tag> <tt>String_Type getenv(String_Type var)</tt>
<tag> Description </tag>
The <tt>getenv</tt> function returns a string that represents the
value of an environment variable <tt>var</tt>. It will return
<tt>NULL</tt> if there is no environment variable whose name is given
by <tt>var</tt>.
<tag> Example </tag>
<tscreen><verb>
if (NULL != getenv ("USE_COLOR"))
{
set_color ("normal", "white", "blue");
set_color ("status", "black", "gray");
USE_ANSI_COLORS = 1;
}
</verb></tscreen>
<tag> See Also </tag> <tt>putenv, strlen, is_defined</tt>
</descrip><p>
<sect><bf>init_char_array</bf><label id="init_char_array"><p><descrip>
<tag> Synopsis </tag> Initialize an array of characters
<tag> Usage </tag> <tt>init_char_array (Array_Type a, String_Type s)</tt>
<tag> Description </tag>
The <tt>init_char_array</tt> function may be used to initialize a
character array <tt>a</tt> by settting the elements of the array
<tt>a</tt> to the corresponding characters of the string <tt>s</tt>.
<tag> Example </tag>
The statements
<tscreen><verb>
variable a = Char_Type [10];
init_char_array (a, "HelloWorld");
</verb></tscreen>
creates an character array and initializes its elements to the
characters in the string <tt>"HelloWorld"</tt>.
<tag> Notes </tag>
The character array must be large enough to hold all the characters
of the initialization string.
<tag> See Also </tag> <tt>strlen, strcat</tt>
</descrip><p>
<sect><bf>integer</bf><label id="integer"><p><descrip>
<tag> Synopsis </tag> Convert a string to an integer
<tag> Usage </tag> <tt>Integer_Type integer (String_Type s)</tt>
<tag> Description </tag>
The <tt>integer</tt> function converts a string representation of an
integer back to an integer. If the string does not form a valid
integer, a type-mismatch error will be generated.
<tag> Example </tag>
<tt>integer ("1234")</tt> returns the integer value <tt>1234</tt>.
<tag> Notes </tag>
This function operates only on strings and is not the same as the
more general <tt>typecast</tt> operator.
<tag> See Also </tag> <tt>typecast, _slang_guess_type, string, sprintf, char</tt>
</descrip><p>
<sect><bf>int</bf><label id="int"><p><descrip>
<tag> Synopsis </tag> Typecast an object to an integer
<tag> Usage </tag> <tt>int (s)</tt>
<tag> Description </tag>
This function performs a typecast of <tt>s</tt> from its data type to
an object of <tt>Integer_Type</tt>. If <tt>s</tt> is a string, it returns
returns the ascii value value of the first character of the string
<tt>s</tt>. If <tt>s</tt> is <tt>Double_Type</tt>, <tt>int</tt> truncates the
number to an integer and returns it.
<tag> Example </tag>
<tt>int</tt> can be used to convert single character strings to
integers. As an example, the intrinsic function <tt>isdigit</tt> may
be defined as
<tscreen><verb>
define isdigit (s)
{
if ((int (s) >= '0') and (int (s) <= '9')) return 1;
return 0;
}
</verb></tscreen>
<tag> Notes </tag>
This function is equalent to <tt>typecast (s, Integer_Type)</tt>;
<tag> See Also </tag> <tt>typecast, double, integer, char, isdigit</tt>
</descrip><p>
<sect><bf>is_defined</bf><label id="is_defined"><p><descrip>
<tag> Synopsis </tag> Indicate whether a variable or function defined.
<tag> Usage </tag> <tt>Integer_Type is_defined (String_Type obj)</tt>
<tag> Description </tag>
This function is used to determine whether or not a function or
variable whose name is <tt>obj</tt> has been defined. If <tt>obj</tt> is not
defined, the function returns 0. Otherwise, it returns a non-zero
value that defpends on the type of object <tt>obj</tt> represents.
Specifically, it returns one of the following values:
<tscreen><verb>
+1 if an intrinsic function
+2 if user defined function
-1 if intrinsic variable
-2 if user defined variable
0 if undefined
</verb></tscreen>
<tag> Example </tag>
For example, consider the function:
<tscreen><verb>
define runhooks (hook)
{
if (2 == is_defined(hook)) eval(hook);
}
</verb></tscreen>
This function could be called from another <bf>S-lang</bf> function to
allow customization of that function, e.g., if the function
represents a mode, the hook could be called to setup keybindings
for the mode.
<tag> See Also </tag> <tt>typeof, eval, autoload</tt>
</descrip><p>
<sect><bf>is_list_element</bf><label id="is_list_element"><p><descrip>
<tag> Synopsis </tag> Test whether a delimited string contains a specific element
<tag> Usage </tag> <tt>Integer_Type is_list_element (String_Type list, String_Type elem, Integer_Type delim)</tt>
<tag> Description </tag>
The <tt>is_list_element</tt> function may be used to determine whether
or not a delimited list of strings, <tt>list</tt>, contains the element
<tt>elem</tt>. If <tt>elem</tt> is not an element of <tt>list</tt>, the function
will return zero, otherwise, it returns 1 plus the matching element
number.
<tag> Example </tag>
The expression
<tscreen><verb>
is_list_element ("element 0, element 1, element 2", "0,", ' ');
</verb></tscreen>
returns <tt>2</tt> since <tt>"0,"</tt> is element number one of the list
(numbered from zero).
<tag> See Also </tag> <tt>extract_element, is_substr, create_delimited_string</tt>
</descrip><p>
<sect><bf>is_substr</bf><label id="is_substr"><p><descrip>
<tag> Synopsis </tag> Test for a specified substring within a string.
<tag> Usage </tag> <tt>Integer_Type is_substr (String_Type a, String_Type b)</tt>
<tag> Description </tag>
This function may be used to determine if <tt>a</tt> contains the
string <tt>b</tt>. If it does not, the function returns 0; otherwise it
returns the position of the first occurance of <tt>b</tt> in <tt>a</tt>.
<tag> Notes </tag>
It is important to remember that the first character of a string
corresponds to a position value of <tt>1</tt>.
<tag> See Also </tag> <tt>substr, string_match, str_replace</tt>
</descrip><p>
<sect><bf>isdigit</bf><label id="isdigit"><p><descrip>
<tag> Synopsis </tag> Tests for a decimal digit character
<tag> Usage </tag> <tt>Integer_Type isdigit (String_Type s)</tt>
<tag> Description </tag>
This function returns a non-zero value if the first character in the
string <tt>s</tt> is a digit; otherwise, it returns zero.
<tag> Example </tag>
A simple, user defined implementation of <tt>isdigit</tt> is
<tscreen><verb>
define isdigit (s)
{
return ((s[0] <= '9') and (s[0] >= '0'));
}
</verb></tscreen>
However, the intrinsic function <tt>isdigit</tt> executes many times faster
than the equivalent representation defined above.
<tag> Notes </tag>
Unlike the C function with the same name, the <bf>S-lang</bf> function takes
a string argument.
<tag> See Also </tag> <tt>int, integer</tt>
</descrip><p>
<sect><bf>lstat_file</bf><label id="lstat_file"><p><descrip>
<tag> Synopsis </tag> Get information about a symbolic link
<tag> Usage </tag> <tt>Struct_Type lstat_file (String_Type file)</tt>
<tag> Description </tag>
The <tt>lstat_file</tt> function behaves identically to <tt>stat_file</tt>
but if <tt>file</tt> is a symbolic link, <tt>lstat_file</tt> returns
information about the link itself, and not the file that it
references.
See the documentation for <tt>stat_file</tt> for more information.
<tag> Notes </tag>
On systems that do not support symbolic links, there is no
difference between this function and the <tt>stat_file</tt> function.
<tag> See Also </tag> <tt>stat_file</tt>
</descrip><p>
<sect><bf>make_printable_string</bf><label id="make_printable_string"><p><descrip>
<tag> Synopsis </tag> Format a string suitable for parsing
<tag> Usage </tag> <tt>String_Type make_printable_string(String_Type str)</tt>
<tag> Description </tag>
This function formats a string in such a way that it may be used as
an argument to the <tt>eval</tt> function. The resulting string is
identical to <tt>str</tt> except that it is enclosed in double quotes and the
backslash, newline, and double quote characters are expanded.
<tag> See Also </tag> <tt>eval, str_quote_string</tt>
</descrip><p>
<sect><bf>message</bf><label id="message"><p><descrip>
<tag> Synopsis </tag> Print a string onto the message device
<tag> Usage </tag> <tt>message (String_Type s</tt>
<tag> Description </tag>
The <tt>message</tt> function will print the string specified by
<tt>s</tt> onto the message device.
<tag> Example </tag>
<tscreen><verb>
define print_current_time ()
{
message (time ());
}
</verb></tscreen>
<tag> Notes </tag>
The message device will depend upon the application. For example,
the output message device for the <tt>jed</tt> editor correspond to the
line at the bottom of the display window. The default message
device is the standard output device.
<tag> See Also </tag> <tt>vmessage, sprintf, error</tt>
</descrip><p>
<sect><bf>mkdir</bf><label id="mkdir"><p><descrip>
<tag> Synopsis </tag> Create a new directory
<tag> Usage </tag> <tt>Integer_Type mkdir (String_Type dir, Integer_Type mode)</tt>
<tag> Description </tag>
The <tt>mkdir</tt> function creates a directory whose name is specified
by the <tt>dir</tt> parameter with permissions specified by <tt>mode</tt>.
Upon success <tt>mkdir</tt> returns zero, or it returns <tt>-1</tt> and
sets <tt>errno</tt> accordingly. In particular, if the directory
already exists, the function will fail and set errno to
<tt>EEXIST</tt>.
<tag> Example </tag>
define my_mkdir (dir)
{
if (0 == mkdir (dir, 0777)) return;
if (errno == EEXIST) return;
verror ("mkdir %s failed: %s", dir, errno_string (errno));
}
<tag> Notes </tag>
The <tt>mode</tt> parameter may not be meaningful on all systems. On
systems where it is meaningful, the actual permissions on the newly
created directory are modified by the process's umask.
<tag> See Also </tag> <tt>rmdir, getcwd, chdir, fopen, errno</tt>
</descrip><p>
<sect><bf>polynom</bf><label id="polynom"><p><descrip>
<tag> Synopsis </tag> Evaluate a polynomial
<tag> Usage </tag> <tt>Double_Type polynom(Double_Type a, b, ...c, Integer_Type n, Double_Type x)</tt>
<tag> Description </tag>
The <tt>polynom</tt> function returns the value of the polynomial expression:
<tscreen><verb>
ax^n + bx^(n - 1) + ... c
</verb></tscreen>
<tag> Notes </tag>
The <tt>polynom</tt> function should be extended to work with complex
and array data types. The current implementation is limited to
<tt>Double_Type</tt> quantities.
<tag> See Also </tag> <tt>exp</tt>
</descrip><p>
<sect><bf>putenv</bf><label id="putenv"><p><descrip>
<tag> Synopsis </tag> Add or change an environment variable
<tag> Usage </tag> <tt>putenv (String_Type s)</tt>
<tag> Description </tag>
This functions adds string <tt>s</tt> to the environment. Typically,
<tt>s</tt> should of the form <tt>"name=value"</tt>. The function
signals a <bf>S-lang</bf> error upon failure.
<tag> Notes </tag>
This function is not available on all systems.
<tag> See Also </tag> <tt>getenv, sprintf</tt>
</descrip><p>
<sect><bf>reshape</bf><label id="reshape"><p><descrip>
<tag> Synopsis </tag> Reshape an array
<tag> Usage </tag> <tt>reshape (Array_Type A, Array_Type I</tt>
<tag> Description </tag>
The <tt>reshape</tt> function changes the size of a to have the size
specified by the 1-d integer array <tt>I</tt>. The elements of <tt>I</tt>
specify the new dimensions of <tt>A</tt> and must be consistent with
the number of elements <tt>A</tt>.
<tag> Example </tag>
If <tt>A</tt> is a <tt>100</tt> element 1-d array, it can be changed to a
2-d <tt>20</tt> by <tt>5</tt> array via
<tscreen><verb>
reshape (A, [20, 5]);
</verb></tscreen>
However, <tt>reshape(A, [11,5])</tt> will result in an error because
the the <tt>[11,5]</tt> array specifies <tt>55</tt> elements.
<tag> See Also </tag> <tt>array_info</tt>
</descrip><p>
<sect><bf>set_float_format</bf><label id="set_float_format"><p><descrip>
<tag> Synopsis </tag> Set the format for printing floating point values.
<tag> Usage </tag> <tt>set_float_format (String_Type fmt)</tt>
<tag> Description </tag>
The <tt>set_float_format</tt> function is used to set the floating
point format to be used when floating point numbers are printed.
The routines that use this are the traceback routines and the
<tt>string</tt> function. The default value is <tt>"%f"</tt>
<tag> Example </tag>
<tscreen><verb>
s = string (PI); % --> s = "3.14159"
set_float_format ("%16.10f");
s = string (PI); % --> s = "3.1415926536"
set_float_format ("%10.6e");
s = string (PI); % --> s = "3.141593e+00"
</verb></tscreen>
<tag> See Also </tag> <tt>string, sprintf, double</tt>
</descrip><p>
<sect><bf>Sprintf</bf><label id="Sprintf"><p><descrip>
<tag> Synopsis </tag> Format objects into a string
<tag> Usage </tag> <tt>String_Type Sprintf (String_Type format, ..., Integer_Type n)</tt>
<tag> Description </tag>
<tt>Sprintf</tt> formats a string from <tt>n</tt> objects according to
<tt>format</tt>. Unlike <tt>sprintf</tt>, the <tt>Sprintf</tt> function
requires the number of items to format.
<tag> Example </tag>
<tscreen><verb>
s = Sprintf("%f is greater than %f but %s is better than %s\n",
PI, E, "Cake" "Pie", 4);
</verb></tscreen>
The final argument to <tt>Sprintf</tt> is the number of items to format; in
this case, there are 4 items.
<tag> See Also </tag> <tt>sprintf, string</tt>
</descrip><p>
<sect><bf>sprintf</bf><label id="sprintf"><p><descrip>
<tag> Synopsis </tag> Format objects into a string
<tag> Usage </tag> <tt>String sprintf (String format, ...);</tt>
<tag> Description </tag>
This function performs a similar task as the C function with the same
name. It differs from the <bf>S-lang</bf> function <tt>Sprintf</tt> in that it
does not require the number of items to format.
See the documentation for <tt>Sprintf</tt> for more information.
<tag> See Also </tag> <tt>Sprintf, string, vmessage</tt>
</descrip><p>
<sect><bf>stat_file</bf><label id="stat_file"><p><descrip>
<tag> Synopsis </tag> Get information about a file
<tag> Usage </tag> <tt>Struct_Type stat_file (String_Type file)</tt>
<tag> Description </tag>
The <tt>stat_file</tt> function returns information about <tt>file</tt>
through the use of the system <tt>stat</tt> call. If the stat call
fails, the function returns <tt>NULL</tt> and sets errno accordingly.
If it is successful, it returns a stat structure with the following
integer fields:
<tscreen><verb>
st_dev
st_ino
st_mode
st_nlink
st_uid
st_gid
st_rdev
st_size
st_atime
st_mtime
st_ctime
</verb></tscreen>
See the man page for <tt>stat</tt> for a discussion of these fields.
<tag> Example </tag>
The following example shows how the <tt>stat_file</tt> function may be
used to get the size of a file:
<tscreen><verb>
define file_size (file)
{
variable st;
st = stat_file(file);
if (st == NULL) verror ("Unable to stat %s", file);
return st.st_size;
}
</verb></tscreen>
<tag> See Also </tag> <tt>lstat_file, stat_is</tt>
</descrip><p>
<sect><bf>stat_is</bf><label id="stat_is"><p><descrip>
<tag> Synopsis </tag> Parse the <tt>st_mode</tt> field of a stat structure
<tag> Usage </tag> <tt>Integer_Type stat_is (String_Type type, Integer_Type st_mode</tt>}
<tag> Description </tag>
The <tt>stat_is</tt> function returns an integer value about the type of file
specified by <tt>st_mode</tt>. Specifically, <tt>type</tt> must be one of the
strings:
<tscreen><verb>
"sock" (socket)
"fifo" (fifo)
"blk" (block device)
"chr" (character device)
"reg" (regular file)
"lnk" (link)
"dir" (dir)
</verb></tscreen>
It returns a non-zero value if <tt>st_mode</tt> corresponds to
<tt>type</tt>.
<tag> Example </tag>
The following example illustrates how to use the <tt>stat_is</tt>
function to determine whether or not a file is a directory:
<tscreen><verb>
define is_directory (file)
{
variable st;
st = stat_file (file);
if (st == NULL) return 0;
return stat_is ("dir", st.st_mode);
}
</verb></tscreen>
<tag> See Also </tag> <tt>stat_file, lstat_file</tt>
</descrip><p>
<sect><bf>str_quote_string</bf><label id="str_quote_string"><p><descrip>
<tag> Synopsis </tag> Escape characters in a string.
<tag> Usage </tag> <tt>String_Type str_quote_string(String_Type str, String_Type qlis, Integer_Type quote)</tt>
<tag> Description </tag>
The <tt>str_quote_string</tt> returns a string identical to <tt>str</tt>
except that all characters in the set specified by the string
<tt>qlis</tt> are escaped with the <tt>quote</tt> character, including the
quote character itself. This function is useful for making a
string that can be used in a regular expression.
<tag> Example </tag>
Execution of the statements
<tscreen><verb>
node = "Is it [the coat] really worth $100?";
tag = str_quote_string (node, "\\^$[]*.+?", '\\');
</verb></tscreen>
will result in <tt>tag</tt> having the value:
<tscreen><verb>
Is it \[the coat\] really worth \$100\?
</verb></tscreen>
<tag> See Also </tag> <tt>str_uncomment_string, make_printable_string</tt>
</descrip><p>
<sect><bf>str_replace</bf><label id="str_replace"><p><descrip>
<tag> Synopsis </tag> Replace a substring of a string
<tag> Usage </tag> <tt>Integer_Type str_replace (String_Type a, String_Type b, String_Type c)</tt>
<tag> Description </tag>
The <tt>str_replace</tt> function replaces the first occurance of <tt>b</tt> in
<tt>a</tt> with <tt>c</tt> and returns an integer that indicates whether a
replacement was made or not. If <tt>b</tt> does not occur in <tt>a</tt>, zero is
returned. However, if <tt>b</tt> occurs in <tt>a</tt>, a non-zero integer is
returned as well as the new string resulting from the replacement.
<tag> Example </tag>
<tscreen><verb>
define str_replace_all (orig, match, replacement)
{
while (str_replace (orig, match, replacement))
orig = ();
return orig;
}
</verb></tscreen>
is a function that replaces all occurances in a string.
<tag> See Also </tag> <tt>is_substr, strsub, strtrim</tt>
</descrip><p>
<sect><bf>str_uncomment_string</bf><label id="str_uncomment_string"><p><descrip>
<tag> Synopsis </tag> Remove comments from a string
<tag> Usage </tag> <tt>String_Type str_uncomment_string(String_Type s, String_Type beg, String_Type end)</tt>
<tag> Description </tag>
This function may be used to remove comments from a string <tt>s</tt>.
The parameters, <tt>beg</tt> and <tt>end</tt>, are strings of equal length
whose corresponding characters specify the begin and end comment
characters, respectively. It returns the uncommented string.
<tag> Example </tag>
The expression
<tscreen><verb>
str_uncomment_string ("Hello (testing) 'example' World", "'(", "')")
</verb></tscreen>
returns the string <tt>"Hello World"</tt>.
<tag> Notes </tag>
This routine does not handle multicharacter comment delimiters and it
assumes that comments are not nested.
<tag> See Also </tag> <tt>str_quote_string</tt>
</descrip><p>
<sect><bf>strcat</bf><label id="strcat"><p><descrip>
<tag> Synopsis </tag> Concatenate two strings
<tag> Usage </tag> <tt>String_Type strcat (String_Type a, String_Type b)</tt>
<tag> Description </tag>
The <tt>strcat</tt> function takes two string valued quantities, <tt>a</tt> and
<tt>b</tt>, concatenates them together and returns the result.
<tag> Example </tag>
<tscreen><verb>
strcat ("Hello ", "World");
</verb></tscreen>
produces the string <tt>"Hello World"</tt>.
<tag> Notes </tag>
This function is equivalent to the binary operation <tt>a+b</tt>.
<tag> See Also </tag> <tt>sprintf, create_delimited_string</tt>
</descrip><p>
<sect><bf>strchopr</bf><label id="strchopr"><p><descrip>
<tag> Synopsis </tag> Chop or split a string into substrings.
<tag> Usage </tag> <tt>Integer_Type strchopr (String_Type str, String_Type delim, String_Type quote)</tt>
<tag> Description </tag>
This routine performs exactly the same function as <tt>strchop</tt> except
that it returns the substrings in the reverse order. See the
documentation for <tt>strchop</tt> for more information.
<tag> See Also </tag> <tt>strchop, extract_element</tt>
</descrip><p>
<sect><bf>strchop</bf><label id="strchop"><p><descrip>
<tag> Synopsis </tag> Chop or split a string into substrings.
<tag> Usage </tag> <tt>Integer_Type strchop (String_Type str, Integer_Type delim, Integer_Type quote)</tt>
<tag> Description </tag>
The <tt>strchop</tt> function may be used to split-up a string
<tt>str</tt> that consists of substrings delimited by the character
specified by <tt>delim</tt>. If the integer <tt>quote</tt> is
non-zero, it will be taken as a quote character for the
delimiter. The function returns to the stack a variable number
of objects. The top stack object represents the number of
substrings that are on the stack. For example,
<tscreen><verb>
strchop ("apples,oranges,pears", ',', 0);
</verb></tscreen>
will return the integer <tt>3</tt> to the top of the stack followed
by the three strings: <tt>"apples"</tt>, <tt>"oranges"</tt>, and
<tt>"pears"</tt>.
<tag> Example </tag>
<tscreen><verb>
define list_to_array (list)
{
variable n, i, s, a;
n = strchop (list, ',', '\\');
a = String_Type [n];
for (i = 0; i < n; i++)
a[i] = (); % substring is on stack
return a;
}
</verb></tscreen>
This defines a function that converts a comma-separated list of
strings to string array containing the substrings.
<tag> Notes </tag>
Since this function returns a variable number of values to the
stack, it cannot chop up arbitrarily long strings that consist of
many substrings.
The function <tt>strchopr</tt> should be used if it is desired to have
the string chopped-up in the reverse order.
<tag> See Also </tag> <tt>strchopr, extract_element, create_delimited_string</tt>
</descrip><p>
<sect><bf>strcmp</bf><label id="strcmp"><p><descrip>
<tag> Synopsis </tag> Compare two strings
<tag> Usage </tag> <tt>Interpret strcmp (String_Type a, String_Type b)</tt>
<tag> Description </tag>
The <tt>strcmp</tt> function may be used to perform a case-sensitive
string comparison, in the lexicongraphic sense, on strings <tt>a</tt> and
<tt>b</tt>. It returns 0 if the strings are identical, a negative integer
if <tt>a</tt> is less than <tt>b</tt>, or a positive integer if <tt>a</tt> is greater
than <tt>b</tt>.
<tag> Example </tag>
The <tt>strup</tt> function may be used to perform a case-insensitive
string comparison:
<tscreen><verb>
define case_insensitive_strcmp (a, b)
{
return strcmp (strup(a), strup(b));
}
</verb></tscreen>
<tag> Notes </tag>
One may also use one of the binary comparison operators, e.g.,
<tt>a > b</tt>.
<tag> See Also </tag> <tt>strup, strncmp</tt>
</descrip><p>
<sect><bf>strcompress</bf><label id="strcompress"><p><descrip>
<tag> Synopsis </tag> Remove excess whitespace characters from a string
<tag> Usage </tag> <tt>String_Type strtrim (String_Type s, String_Type white)</tt>
<tag> Description </tag>
The <tt>strcompress</tt> function compresses the string <tt>s</tt> by
removing all repeated characters specified by by the characters of
<tt>white</tt> from the interior of <tt>s</tt>. In addition, it also
removes all leading and trailing characters from <tt>s</tt> that are
part of <tt>white</tt>.
<tag> Example </tag>
The expression
<tscreen><verb>
strcompress (",;apple,,cherry;,banana", ",;");
</verb></tscreen>
returns the string @"apple,cherry;banana"@.
<tag> See Also </tag> <tt>strtrim</tt>
</descrip><p>
<sect><bf>string_match_nth</bf><label id="string_match_nth"><p><descrip>
<tag> Synopsis </tag> Get the result of the last call to <tt>string_match</tt>
<tag> Usage </tag> <tt>(Integer_Type, Integer_Type) string_match_nth(Integer_Type nth)</tt>
<tag> Description </tag>
The <tt>string_match_nth</tt> function returns two integers describing
the result of the last call to <tt>string_match</tt>. It returns both
the offset into the string and the length of characters matches by
the <tt>nth</tt> submatch.
By convention, <tt>nth</tt> equal to zero means the entire match.
Otherwise, <tt>nth</tt> must be an integer with a value 1 through 9,
and refers to the set of characters matched by the <tt>nth</tt> regular
expression enclosed by the pairs <tt>\(, \)</tt>.
<tag> Example </tag>
Consider:
<tscreen><verb>
variable matched, pos, len;
matched = string_match("hello world", "\\([a-z]+\\) \\([a-z]+\\)", 1);
if (matched) (pos, len) = string_match_nth(2);
</verb></tscreen>
This will set <tt>matched</tt> to 1 since a match will be found at the
first position, <tt>pos</tt> to 6 since <tt>w</tt> is offset 6 characters
from the beginning of the string, and <tt>len</tt> to 5 since
<tt>"world"</tt> is 5 characters long.
<tag> Notes </tag>
The position offset is <em>not</em> affected by the value of the offset
parameter to the <tt>string_match</tt> function. For example, if the
value of the last parameter to the <tt>string_match</tt> function had
been 3, <tt>pos</tt> would still have been set to 6.
Note also that <tt>string_match_nth</tt> returns the <em>offset</em> from
the beginning of the string and not the position of the match.
<tag> See Also </tag> <tt>string_match</tt>
</descrip><p>
<sect><bf>string_match</bf><label id="string_match"><p><descrip>
<tag> Synopsis </tag> Match a string against a regular expression
<tag> Usage </tag> <tt>Integer_Type string_match(String_Type str, String_Type pat, Integer_Type pos)</tt>
<tag> Description </tag>
The <tt>string_match</tt> function returns zero if <tt>str</tt> does not
match regular expression specified by <tt>pat</tt>. This function
performs the match starting at position <tt>pos</tt> (numbered from 1) in
<tt>str</tt>. This function returns the position of the start of the
match. To find the exact substring actually matched, use
<tt>string_match_nth</tt>.
<tag> See Also </tag> <tt>string_match_nth, strcmp, strncmp</tt>
</descrip><p>
<sect><bf>string</bf><label id="string"><p><descrip>
<tag> Synopsis </tag> Convert an object to a string representation.
<tag> Usage </tag> <tt>Integer_Type string (obj)</tt>
<tag> Description </tag>
The <tt>string</tt> function may be used to convert an object
<tt>obj</tt> of any type to a string representation.
For example, <tt>string(12.34)</tt> returns <tt>"12.34"</tt>.
<tag> Example </tag>
<tscreen><verb>
define print_anything (anything)
{
message (string (anything));
}
</verb></tscreen>
<tag> Notes </tag>
This function is <em>not</em> the same as typecasting to a <tt>String_Type</tt>
using the <tt>typecast</tt> function.
<tag> See Also </tag> <tt>typecast, sprintf, integer, char</tt>
</descrip><p>
<sect><bf>strlen</bf><label id="strlen"><p><descrip>
<tag> Synopsis </tag> Compute the length of a string
<tag> Usage </tag> <tt>Integer_Type strlen (String_Type a)</tt>
<tag> Description </tag>
The <tt>strlen</tt> function may be used to compute the length of a string.
<tag> Example </tag>
After execution of
<tscreen><verb>
variable len = strlen ("hello");
</verb></tscreen>
<tt>len</tt> will have a value of <tt>5</tt>.
<tag> See Also </tag> <tt>substr</tt>
</descrip><p>
<sect><bf>strlow</bf><label id="strlow"><p><descrip>
<tag> Synopsis </tag> Convert a string to lowercase
<tag> Usage </tag> <tt>String_Type strlow (String_Type s)</tt>
<tag> Description </tag>
The <tt>strlow</tt> function takes a string <tt>s</tt> and returns another
string identical to <tt>s</tt> except that all upper case characters
that comprise <tt>s</tt> will be converted to lower case.
<tag> Example </tag>
The function
<tscreen><verb>
define Strcmp (a, b)
{
return strcmp (strlow (a), strlow (b));
}
</verb></tscreen>
performs a case-insensitive comparison operation of two strings by
converting them to lower case first.
<tag> See Also </tag> <tt>strup, tolower, strcmp, strtrim, define_case</tt>
</descrip><p>
<sect><bf>strncmp</bf><label id="strncmp"><p><descrip>
<tag> Synopsis </tag> Compare the first few characters of two strings
<tag> Usage </tag> <tt>Integer_Type strncmp (String_Type a, String_Type b, Integer_Type n)</tt>
<tag> Description </tag>
This function behaves like <tt>strcmp</tt> except that it compares only the
first <tt>n</tt> characters in the strings <tt>a</tt> and <tt>b</tt>. See
the documentation for <tt>strcmp</tt> for information about the return
value.
<tag> Example </tag>
The expression
<tscreen><verb>
strcmp ("apple", "appliance", 3);
</verb></tscreen>
will return zero since the first three characters match.
<tag> See Also </tag> <tt>strcmp, strlen</tt>
</descrip><p>
<sect><bf>strsub</bf><label id="strsub"><p><descrip>
<tag> Synopsis </tag> Replace a character with another in a string.
<tag> Usage </tag> <tt>String_Type strsub (String_Type s, Integer_Type pos, Integer_Type ch)</tt>
<tag> Description </tag>
The <tt>strsub</tt> character may be used to substitute the character
<tt>ch</tt> for the character at position <tt>pos</tt> of the string
<tt>s</tt>. The resulting string is returned.
<tag> Example </tag>
<tscreen><verb>
define replace_spaces_with_comma (s)
{
variable n;
while (n = is_substr (s, " "), n) s = strsub (s, n, ',');
return s;
}
</verb></tscreen>
<tag> Notes </tag>
The first character in the string <tt>s</tt> is specified by <tt>pos</tt>
equal to 1.
<tag> See Also </tag> <tt>is_substr, str_replace, strlen</tt>
</descrip><p>
<sect><bf>strtrim</bf><label id="strtrim"><p><descrip>
<tag> Synopsis </tag> Remove whitespace from the ends of a string
<tag> Usage </tag> <tt>String_Type strtrim (String_Type s)</tt>
<tag> Description </tag>
The <tt>strtrim</tt> function removes all leading and trailing whitespace
characters from the string <tt>s</tt> and returns the result. Whitespace is
defined to be any combination of spaces, tabs, and newline characters.
<tag> See Also </tag> <tt>int, strlow, strup, strcompress</tt>
</descrip><p>
<sect><bf>strup</bf><label id="strup"><p><descrip>
<tag> Synopsis </tag> Convert a string to uppercase
<tag> Usage </tag> <tt>String_Type strup (String_Type s)</tt>
<tag> Description </tag>
The <tt>strup</tt> function takes a string <tt>s</tt> and returns another
string identical to <tt>s</tt> except that all lower case characters
that comprise <tt>s</tt> will be converted to upper case.
<tag> Example </tag>
The function
<tscreen><verb>
define Strcmp (a, b)
{
return strcmp (strup (a), strup (b));
}
</verb></tscreen>
performs a case-insensitive comparison operation of two strings by
converting them to upper case first.
<tag> See Also </tag> <tt>strlow, toupper, strcmp, strtrim, define_case</tt>
</descrip><p>
<sect><bf>substr</bf><label id="substr"><p><descrip>
<tag> Synopsis </tag> Extract a substring from a string
<tag> Usage </tag> <tt>String_Type substr (String_Type s, Integer_Type n, Integer_Type len)</tt>
<tag> Description </tag>
The <tt>substr</tt> function returns a substring with length <tt>len</tt>
of the string <tt>s</tt> beginning at position <tt>n</tt>. If <tt>len</tt> is
<tt>-1</tt>, the entire length of the string <tt>s</tt> will be used for
<tt>len</tt>. The first character of <tt>s</tt> is given by <tt>n</tt> equal
to 1.
<tag> Example </tag>
<tscreen><verb>
substr ("To be or not to be", 7, 5);
</verb></tscreen>
returns <tt>"or no"</tt>
<tag> Notes </tag>
The expression <tt>substr(s, n, 1)</tt> is equivalent to the array
index expression <tt>s[n-1]</tt>.
<tag> See Also </tag> <tt>is_substr, strlen</tt>
</descrip><p>
<sect><bf>system</bf><label id="system"><p><descrip>
<tag> Synopsis </tag> Execute a shell command
<tag> Usage </tag> <tt>Integer_Type system (String_Type cmd)</tt>
<tag> Description </tag>
The <tt>system</tt> function may be used to execute the string
expression <tt>cmd</tt> in an inferior shell. This function is an
interface to the C <tt>system</tt> function which returns an
implementation-defined result. On Linux, it returns 127 if the
inferior shell could not be invoked, -1 if there was some other
error, otherwise it returns the return code for <tt>cmd</tt>.
<tag> Example </tag>
<tscreen><verb>
define dir ()
{
() = system ("DIR");
}
</verb></tscreen>
displays a directory listing of the current directory under MSDOS or
VMS.
</descrip><p>
<sect><bf>time</bf><label id="time"><p><descrip>
<tag> Synopsis </tag> Return the current data and time as a string
<tag> Usage </tag> <tt>String time ();</tt>
<tag> Description </tag>
This function returns the current time as a string of the form:
<tscreen><verb>
Sun Apr 21 13:34:17 1996
</verb></tscreen>
<tag> See Also </tag> <tt>message, substr</tt>
</descrip><p>
<sect><bf>tolower</bf><label id="tolower"><p><descrip>
<tag> Synopsis </tag> Convert a character to lowercase.
<tag> Usage </tag> <tt>Integer_Type lower (Integer_Type ch)</tt>
<tag> Description </tag>
This function takes an integer <tt>ch</tt> and returns its lowercase
equivalent.
<tag> See Also </tag> <tt>toupper, strup, strlow, int, char, define_case</tt>
</descrip><p>
<sect><bf>toupper</bf><label id="toupper"><p><descrip>
<tag> Synopsis </tag> Convert a character to uppercase.
<tag> Usage </tag> <tt>Integer_Type toupper (Integer_Type ch)</tt>
<tag> Description </tag>
This function takes an integer <tt>ch</tt> and returns its uppercase
equivalent.
<tag> See Also </tag> <tt>tolower, strup, strlow, int, char, define_case</tt>
</descrip><p>
<sect><bf>typecast</bf><label id="typecast"><p><descrip>
<tag> Synopsis </tag> Convert an object from one data type to another.
<tag> Usage </tag> <tt>typecast (x, new_type)</tt>
<tag> Description </tag>
The <tt>typecast</tt> function performs a generic typecast operation on
<tt>x</tt> to convert it to <tt>new_type</tt>. If <tt>x</tt> represents an
array, the function will attempt to convert all elements of <tt>x</tt>
to <tt>new_type</tt>. Not all objects can be converted and a
type-mismatch error will result upon failure.
<tag> Example </tag>
<tscreen><verb>
define to_complex (x)
{
return typecast (x, Complex_Type);
}
</verb></tscreen>
defines a function that converts its argument, <tt>x</tt> to a complex
number.
<tag> See Also </tag> <tt>int, double, typeof</tt>
</descrip><p>
<sect><bf>typeof</bf><label id="typeof"><p><descrip>
<tag> Synopsis </tag> Get the data type of an object.
<tag> Usage </tag> <tt>DataType_Type typeof (x)</tt>
<tag> Description </tag>
This function returns the data type of <tt>x</tt>.
<tag> Example </tag>
<tscreen><verb>
if (Integer_Type == typeof (x)) print ("x is an integer");
</verb></tscreen>
<tag> See Also </tag> <tt>array_info, _slang_guess_type, typecast</tt>
</descrip><p>
<sect><bf>unix_ctime</bf><label id="unix_ctime"><p><descrip>
<tag> Synopsis </tag> Convert a calendar time to a string
<tag> Usage </tag> <tt>String_Type unix_ctime(Integer_Type secs)</tt>
<tag> Description </tag>
This function returns a string representation of the time as given
by <tt>secs</tt> seconds since 1970.
<tag> See Also </tag> <tt>time</tt>
</descrip><p>
<sect><bf>unix_kill</bf><label id="unix_kill"><p><descrip>
<tag> Synopsis </tag> Send a signal to a process
<tag> Usage </tag> <tt>Integer_Type unix_kill (Integer_Type pid, Integer_Type sig)</tt>
<tag> Description </tag>
This function may be used to send a signal given by the integer <tt>sig</tt>
to the process specified by <tt>pid</tt>. The function returns zero upon
sucess and <tt>-1</tt> upon failure setting errno accordingly.
<tag> Example </tag>
The <tt>unix_kill</tt> function may be used to determine whether or not
a specific process exists:
<tscreen><verb>
define process_exists (pid)
{
if (-1 == unix_kill (pid, 0))
return 0; % Process does not exist
return 1;
}
</verb></tscreen>
<tag> Notes </tag>
The <tt>unix_kill</tt> function is not available on all systems.
<tag> See Also </tag> <tt>getpid</tt>
</descrip><p>
<sect><bf>verror</bf><label id="verror"><p><descrip>
<tag> Synopsis </tag> Generate an error condition
<tag> Usage </tag> <tt>verror (String_Type fmt, ...)</tt>
<tag> Description </tag>
The <tt>verror</tt> function performs the same role as the <tt>error</tt>
function. The only difference is that instead of a single string
argument, <tt>verror</tt> takes a sprintf style argument list.
<tag> Example </tag>
<tscreen><verb>
define open_file (file)
{
variable fp;
fp = fopen (file, "r");
if (fp == NULL) verror ("Unable to open %s", file);
return fp;
}
</verb></tscreen>
<tag> Notes </tag>
In the current implementation, strictly speaking, the <tt>verror</tt>
function is not an intrinsic function. Rather it is a predefined
<bf>S-lang</bf> function using a combination of <tt>Sprintf</tt> and
<tt>error</tt>.
<tag> See Also </tag> <tt>error, Sprintf, vmessage</tt>
</descrip><p>
</article>