home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / doc / libslang2 / slangfun.txt < prev    next >
Encoding:
Text File  |  2006-02-05  |  204.6 KB  |  8,286 lines

  1. all
  2.  
  3.  SYNOPSIS
  4.   Tests if all elements of an array are non-zero
  5.  
  6.  USAGE
  7.   Char_Type all (Array_Type a [,Int_Type dim])
  8.  
  9.  DESCRIPTION
  10.   The `all' function examines the elements of a numeric array and
  11.   returns 1 if all elements are non-zero, otherwise it returns 0. If a
  12.   second argument is given, then it specifies the dimension of the
  13.   array over which the function is to be applied.  In this case, the
  14.   result will be an array with the same shape as the input array minus
  15.   the specified dimension.
  16.  
  17.  EXAMPLE
  18.   Consider the 2-d array
  19.  
  20.       1       2       3       4        5
  21.       6       7       8       9       10
  22.  
  23.   generated by
  24.  
  25.       a = _reshape ([1:10], [2, 5]);
  26.  
  27.   Then `all(a)' will return 1, and `all(a>3, 0)' will return
  28.   a 1-d array
  29.  
  30.       [0, 0, 0, 1, 1]
  31.  
  32.   Similarly, `all(a>3, 1)' will return the 1-d array
  33.  
  34.       [0,1]
  35.  
  36.  
  37.  SEE ALSO
  38.   where, any
  39.  
  40. --------------------------------------------------------------
  41.  
  42. any
  43.  
  44.  SYNOPSIS
  45.   Test if any element of an array is non-zero
  46.  
  47.  USAGE
  48.   Char_Type any (Array_Type a [,Int_Type dim])
  49.  
  50.  DESCRIPTION
  51.   The `any' function examines the elements of a numeric array and
  52.   returns 1 if any element is both non-zero and not a NaN, otherwise
  53.   it returns 0.  If a second argument is given, then it specifies
  54.   the dimension of the array to be tested.
  55.  
  56.  EXAMPLE
  57.   Consider the 2-d array
  58.  
  59.       1       2       3       4        5
  60.       6       7       8       9       10
  61.  
  62.   generated by
  63.  
  64.       a = _reshape ([1:10], [2, 5]);
  65.  
  66.   Then `any(a==3)' will return 1, and `any(a==3, 0)'
  67.   will return a 1-d array with elements:
  68.  
  69.       0        0       1       0       0
  70.  
  71.  
  72.  SEE ALSO
  73.   where, all
  74.  
  75. --------------------------------------------------------------
  76.  
  77. array_info
  78.  
  79.  SYNOPSIS
  80.   Returns information about an array
  81.  
  82.  USAGE
  83.   (Array_Type, Integer_Type, DataType_Type) array_info (Array_Type a)
  84.  
  85.  DESCRIPTION
  86.   The `array_info' function returns information about the array `a'.
  87.   It returns three values: an 1-d integer array specifying the
  88.   size of each dimension of `a', the number of dimensions of
  89.   `a', and the data type of `a'.
  90.  
  91.  EXAMPLE
  92.   The `array_info' function may be used to find the number of rows
  93.   of an array:
  94.  
  95.     define num_rows (a)
  96.     {
  97.        variable dims, num_dims, data_type;
  98.  
  99.        (dims, num_dims, data_type) = array_info (a);
  100.        return dims [0];
  101.     }
  102.  
  103.  
  104.  SEE ALSO
  105.   typeof, array_info, array_shape, length, reshape, _reshape
  106.  
  107. --------------------------------------------------------------
  108.  
  109. array_map
  110.  
  111.  SYNOPSIS
  112.   Apply a function to each element of an array
  113.  
  114.  USAGE
  115.   Array_Type array_map (type, func, arg0, ...)
  116.  
  117.     DataType_Type type;
  118.     Ref_Type func;
  119.  
  120.  
  121.  DESCRIPTION
  122.   The `array_map' function may be used to apply a function to each
  123.   element of an array and returns the resulting values as an array of
  124.   the specified type.  The `type' parameter indicates what kind of
  125.   array should be returned and generally corresponds to the return
  126.   type of the function.  The `arg0' parameter should be an array
  127.   and is used to determine the dimensions of the resulting array.  If
  128.   any subsequent arguments correspond to an array of the same size,
  129.   then those array elements will be passed in parallel with the first
  130.   arrays arguments.
  131.  
  132.  EXAMPLE
  133.   The first example illustrates how to apply the `strlen' function
  134.   to an array of strings:
  135.  
  136.      S = ["", "Train", "Subway", "Car"];
  137.      L = array_map (Integer_Type, &strlen, S);
  138.  
  139.   This is equivalent to:
  140.  
  141.      S = ["", "Train", "Subway", "Car"];
  142.      L = Integer_Type [length (S)];
  143.      for (i = 0; i < length (S); i++) L[i] = strlen (S[i]);
  144.  
  145.  
  146.   Now consider an example involving the `strcat' function:
  147.  
  148.      files = ["slang", "slstring", "slarray"];
  149.  
  150.      exts = ".c";
  151.      cfiles = array_map (String_Type, &strcat, files, exts);
  152.      % ==> cfiles = ["slang.c", "slstring.c", "slarray.c"];
  153.  
  154.      exts =  [".a",".b",".c"];
  155.      xfiles = array_map (String_Type, &strcat, files, exts);
  156.      % ==> xfiles = ["slang.a", "slstring.b", "slarray.c"];
  157.  
  158.  
  159.  NOTES
  160.   Many mathematical functions already work transparantly on arrays.
  161.   For example, the following two statements produce identical results:
  162.  
  163.      B = sin (A);
  164.      B = array_map (Double_Type, &sin, A);
  165.  
  166.  
  167.  SEE ALSO
  168.   array_info, strlen, strcat, sin
  169.  
  170. --------------------------------------------------------------
  171.  
  172. array_reverse
  173.  
  174.  SYNOPSIS
  175.   Reverse the elements of an array
  176.  
  177.  USAGE
  178.   array_reverse (Array_Type a [,Int_Type i0, Int_Type i1] [,Int_Type dim])
  179.  
  180.  DESCRIPTION
  181.   In its simplest form, the `array_reverse' function reverses the
  182.   elements of an array.  If passed 2 or 4 arguments,
  183.   `array_reverse' reverses the elements of the specified
  184.   dimension of a multi-dimensional array.  If passed 3 or 4 arguments,
  185.   the parameters `i0' and `i1' specify a range of elements
  186.   to reverse.
  187.  
  188.  EXAMPLE
  189.   If `a' is a one dimensional array, then
  190.  
  191.     array_reverse (a, i, j);
  192.     a[[i:j]] = a[[j:i:-1]];
  193.  
  194.   are equivalent to one another.  However, the form using
  195.   `array_reverse' is about 10 times faster than the version that
  196.   uses explicit array indexing.
  197.  
  198.  SEE ALSO
  199.   array_swap, transpose
  200.  
  201. --------------------------------------------------------------
  202.  
  203. array_shape
  204.  
  205.  SYNOPSIS
  206.   Get the shape or dimensions of an array
  207.  
  208.  USAGE
  209.   dims = array_shape (Array_Type a)
  210.  
  211.  DESCRIPTION
  212.    This function returns an array representing the dimensionality or
  213.    shape of a specified array.  The `array_info' function also
  214.    returns this information but for many purposes the
  215.    `array_shape' function is more convenient.
  216.  
  217.  SEE ALSO
  218.   array_info, reshape
  219.  
  220. --------------------------------------------------------------
  221.  
  222. array_sort
  223.  
  224.  SYNOPSIS
  225.   Sort an array
  226.  
  227.  USAGE
  228.   Array_Type array_sort (Array_Type a [, String_Type or Ref_Type f])
  229.  
  230.  DESCRIPTION
  231.   `array_sort' sorts the array `a' into ascending order and
  232.   returns an integer array that represents the result of the sort. If
  233.   the optional second parameter `f' is present, the function
  234.   specified by `f' will be used to compare elements of `a';
  235.   otherwise, a built-in sorting function will be used.
  236.  
  237.   If `f' is present, then it must be either a string representing
  238.   the name of the comparison function, or a reference to the function.
  239.   The sort function represented by `f' must be a S-Lang function
  240.   that takes two arguments.  The function must return an integer that
  241.   is less than zero if the first parameter is considered to be less
  242.   than the second, zero if they are equal, and a value greater than
  243.   zero if the first is greater than the second.
  244.  
  245.   If the comparison function is not specified, then a built-in comparison
  246.   function appropriate for the data type will be used.  For example,
  247.   if `a' is an array of character strings, then the sort will be
  248.   performed using the `strcmp' function.
  249.  
  250.   The integer array returned by this function is simply an index array
  251.   that indicates the order of the sorted array.  The input array
  252.   `a' is not changed.
  253.  
  254.  EXAMPLE
  255.   An array of strings may be sorted using the `strcmp' function
  256.   since it fits the specification for the sorting function described
  257.   above:
  258.  
  259.      A = ["gamma", "alpha", "beta"];
  260.      I = array_sort (A, &strcmp);
  261.  
  262.   Alternatively, one may use
  263.  
  264.      variable I = array_sort (A);
  265.  
  266.   to use the built-in comparison function.
  267.  
  268.   After the `array_sort' has executed, the variable `I' will
  269.   have the values `[2, 0, 1]'.  This array can be used to
  270.   re-shuffle the elements of `A' into the sorted order via the
  271.   array index expression `A = A[I]'.  This operation may also be
  272.   written:
  273.  
  274.      A = A[array_sort(A)];
  275.  
  276.  
  277.  SEE ALSO
  278.   strcmp
  279.  
  280. --------------------------------------------------------------
  281.  
  282. array_swap
  283.  
  284.  SYNOPSIS
  285.   Swap elements of an array
  286.  
  287.  USAGE
  288.   array_swap (Array_Type a, Int_Type i, Int_Type j)
  289.  
  290.  DESCRIPTION
  291.   The `array_swap' function swaps the specified elements of an
  292.   array.  It is equivalent to
  293.  
  294.     (a[i], a[j]) = (a[j], a[i]);
  295.  
  296.   except that it executes several times faster than the above construct.
  297.  
  298.  SEE ALSO
  299.   array_reverse, transpose
  300.  
  301. --------------------------------------------------------------
  302.  
  303. cumsum
  304.  
  305.  SYNOPSIS
  306.   Compute the cumulative sum of an array
  307.  
  308.  USAGE
  309.   result = cumsum (Array_Type a [, Int_Type dim])
  310.  
  311.  DESCRIPTION
  312.   The `cumsum' function performs a cumulative sum over the
  313.   elements of a numeric array and returns the result.  If a second
  314.   argument is given, then it specifies the dimension of the array to
  315.   be summed over.  For example, the cumulative sum of
  316.   `[1,2,3,4]', is the array `[1,1+2,1+2+3,1+2+3+4]', i.e.,
  317.   `[1,3,6,10]'.
  318.  
  319.  SEE ALSO
  320.   sum
  321.  
  322. --------------------------------------------------------------
  323.  
  324. init_char_array
  325.  
  326.  SYNOPSIS
  327.   Initialize an array of characters
  328.  
  329.  USAGE
  330.   init_char_array (Array_Type a, String_Type s)
  331.  
  332.  DESCRIPTION
  333.   The `init_char_array' function may be used to initialize a
  334.   character array `a' by setting the elements of the array
  335.   `a' to the corresponding characters of the string `s'.
  336.  
  337.  EXAMPLE
  338.   The statements
  339.  
  340.      variable a = Char_Type [10];
  341.      init_char_array (a, "HelloWorld");
  342.  
  343.    creates an character array and initializes its elements to the
  344.    characters in the string `"HelloWorld"'.
  345.  
  346.  NOTES
  347.    The character array must be large enough to hold all the characters
  348.    of the initialization string.
  349.  
  350.  SEE ALSO
  351.   bstring_to_array, strlen, strcat
  352.  
  353. --------------------------------------------------------------
  354.  
  355. _isnull
  356.  
  357.  SYNOPSIS
  358.   Check an array for NULL elements
  359.  
  360.  USAGE
  361.   Char_Type[] = _isnull (a[])
  362.  
  363.  DESCRIPTION
  364.   This function may be used to test for the presence of NULL elements
  365.   of an array.   Specifically, it returns a Char_Type array of
  366.   with the same number of elements and dimensionality of the input
  367.   array.  If an element of the input array is NULL, then the
  368.   corresponding element of the output array will be set to 1,
  369.   otherwise it will be set to 0.
  370.  
  371.  EXAMPLE
  372.   Set all NULL elements of a string array `A' to the empty
  373.   string `""':
  374.  
  375.      A[where(_isnull(A))] = "";
  376.  
  377.  
  378.  NOTES
  379.   It is important to understand the difference between `A==NULL'
  380.   and `_isnull(A)'.  The latter tests all elements of `A'
  381.   against NULL, whereas the former only tests `A' itself.
  382.  
  383.  SEE ALSO
  384.   where, array_map
  385.  
  386. --------------------------------------------------------------
  387.  
  388. length
  389.  
  390.  SYNOPSIS
  391.   Get the length of an object
  392.  
  393.  USAGE
  394.   Integer_Type length (obj)
  395.  
  396.  DESCRIPTION
  397.   The `length' function may be used to get information about the
  398.   length of an object.  For simple scalar data-types, it returns 1.
  399.   For arrays, it returns the total number of elements of the array.
  400.  
  401.  NOTES
  402.   If `obj' is a string, `length' returns 1 because a
  403.   String_Type object is considered to be a scalar.  To get the
  404.   number of characters in a string, use the `strlen' function.
  405.  
  406.  SEE ALSO
  407.   array_info, array_shape, typeof, strlen
  408.  
  409. --------------------------------------------------------------
  410.  
  411. max
  412.  
  413.  SYNOPSIS
  414.   Get the maximum value of an array
  415.  
  416.  USAGE
  417.   result = max (Array_Type a [,Int_Type dim])
  418.  
  419.  DESCRIPTION
  420.   The `max' function examines the elements of a numeric array and
  421.   returns the value of the largest element.  If a second argument is
  422.   given, then it specifies the dimension of the array to be searched.
  423.   In this case, an array of dimension one less than that of the input array
  424.   will be returned with the corresponding elements in the specified
  425.   dimension replaced by the maximum value in that dimension.
  426.  
  427.  EXAMPLE
  428.   Consider the 2-d array
  429.  
  430.       1       2       3       4        5
  431.       6       7       8       9       10
  432.  
  433.   generated by
  434.  
  435.       a = _reshape ([1:10], [2, 5]);
  436.  
  437.   Then `max(a)' will return `10', and `max(a,0)' will return
  438.   a 1-d array with elements
  439.  
  440.       6       7       8       9       10
  441.  
  442.  
  443.  NOTES
  444.   This function ignores NaNs in the input array.
  445.  
  446.  SEE ALSO
  447.   min, sum, reshape
  448.  
  449. --------------------------------------------------------------
  450.  
  451. min
  452.  
  453.  SYNOPSIS
  454.   Get the minimum value of an array
  455.  
  456.  USAGE
  457.   result = min (Array_Type a [,Int_Type dim])
  458.  
  459.  DESCRIPTION
  460.   The `min' function examines the elements of a numeric array and
  461.   returns the value of the smallest element.  If a second argument is
  462.   given, then it specifies the dimension of the array to be searched.
  463.   In this case, an array of dimension one less than that of the input array
  464.   will be returned with the corresponding elements in the specified
  465.   dimension replaced by the minimum value in that dimension.
  466.  
  467.  EXAMPLE
  468.   Consider the 2-d array
  469.  
  470.       1       2       3       4       5
  471.       6       7       8       9       10
  472.  
  473.   generated by
  474.  
  475.       a = _reshape ([1:10], [2, 5]);
  476.  
  477.   Then `min(a)' will return `1', and `min(a,0)' will return
  478.   a 1-d array with elements
  479.  
  480.       1        2       3       4       5
  481.  
  482.  
  483.  NOTES
  484.   This function ignores NaNs in the input array.
  485.  
  486.  SEE ALSO
  487.   max, sum, reshape
  488.  
  489. --------------------------------------------------------------
  490.  
  491. _reshape
  492.  
  493.  SYNOPSIS
  494.   Copy an array to a new shape
  495.  
  496.  USAGE
  497.   Array_Type _reshape (Array_Type A, Array_Type I)
  498.  
  499.  DESCRIPTION
  500.   The `_reshape' function creates a copy of an array `A',
  501.   reshapes it to the form specified by `I' and returns the result.
  502.   The elements of `I' specify the new dimensions of the copy of
  503.   `A' and must be consistent with the number of elements `A'.
  504.  
  505.  EXAMPLE
  506.   If `A' is a `100' element 1-d array, a new 2-d array of
  507.   size `20' by `5' may be created from the elements of `A'
  508.   by
  509.  
  510.       B = _reshape (A, [20, 5]);
  511.  
  512.  
  513.  NOTES
  514.   The `reshape' function performs a similar function to
  515.   `_reshape'.  In fact, the `_reshape' function could have been
  516.   implemented via:
  517.  
  518.      define _reshape (a, i)
  519.      {
  520.         a = @a;     % Make a new copy
  521.         reshape (a, i);
  522.         return a;
  523.      }
  524.  
  525.  
  526.  SEE ALSO
  527.   reshape, array_shape, array_info
  528.  
  529. --------------------------------------------------------------
  530.  
  531. reshape
  532.  
  533.  SYNOPSIS
  534.   Reshape an array
  535.  
  536.  USAGE
  537.   reshape (Array_Type A, Array_Type I)
  538.  
  539.  DESCRIPTION
  540.   The `reshape' function changes the shaper of `A' to have the
  541.   shape specified by the 1-d integer array `I'.  The elements of `I'
  542.   specify the new dimensions of `A' and must be consistent with
  543.   the number of elements `A'.
  544.  
  545.  EXAMPLE
  546.   If `A' is a `100' element 1-d array, it can be changed to a
  547.   2-d `20' by `5' array via
  548.  
  549.       reshape (A, [20, 5]);
  550.  
  551.   However, `reshape(A, [11,5])' will result in an error because
  552.   the `[11,5]' array specifies `55' elements.
  553.  
  554.  NOTES
  555.   Since `reshape' modifies the shape of an array, and arrays are
  556.   treated as references, then all references to the array will
  557.   reference the new shape.  If this effect is unwanted, then use the
  558.   `_reshape' function instead.
  559.  
  560.  SEE ALSO
  561.   _reshape, array_info, array_shape
  562.  
  563. --------------------------------------------------------------
  564.  
  565. sum
  566.  
  567.  SYNOPSIS
  568.   Sum over the elements of an array
  569.  
  570.  USAGE
  571.   result = sum (Array_Type a [, Int_Type dim])
  572.  
  573.  DESCRIPTION
  574.   The `sum' function sums over the elements of a numeric array and
  575.   returns its result.  If a second argument is given, then it
  576.   specifies the dimension of the array to be summed over.  In this
  577.   case, an array of dimension one less than that of the input array
  578.   will be returned.
  579.  
  580.   If the input array is an integer type, then the resulting value will
  581.   be a Double_Type.  If the input array is a Float_Type,
  582.   then the result will be a Float_Type.
  583.  
  584.  EXAMPLE
  585.   The mean of an array `a' of numbers is
  586.  
  587.     sum(a)/length(a)
  588.  
  589.  
  590.  SEE ALSO
  591.   cumsum, transpose, reshape
  592.  
  593. --------------------------------------------------------------
  594.  
  595. transpose
  596.  
  597.  SYNOPSIS
  598.   Transpose an array
  599.  
  600.  USAGE
  601.   Array_Type transpose (Array_Type a)
  602.  
  603.  DESCRIPTION
  604.   The `transpose' function returns the transpose of a specified
  605.   array.  By definition, the transpose of an array, say one with
  606.   elements `a[i,j,...k]' is an array whose elements are
  607.   `a[k,...,j,i]'.
  608.  
  609.  SEE ALSO
  610.   _reshape, reshape, sum, array_info, array_shape
  611.  
  612. --------------------------------------------------------------
  613.  
  614. where
  615.  
  616.  SYNOPSIS
  617.   Get indices where a numeric array is non-zero
  618.  
  619.  USAGE
  620.   Array_Type where (Array_Type a)
  621.  
  622.  DESCRIPTION
  623.   The `where' function examines a numeric array `a' and
  624.   returns an integer array giving the indices of `a'
  625.   where the corresponding element of `a' is non-zero.
  626.  
  627.   Although this function may appear to be simple or even trivial, it
  628.   is arguably one of the most important and powerful functions for
  629.   manipulating arrays.
  630.  
  631.  EXAMPLE
  632.   Consider the following:
  633.  
  634.     variable X = [0.0:10.0:0.01];
  635.     variable A = sin (X);
  636.     variable I = where (A < 0.0);
  637.     A[I] = cos (X) [I];
  638.  
  639.   Here the variable `X' has been assigned an array of doubles
  640.   whose elements range from `0.0' through `10.0' in
  641.   increments of `0.01'.  The second statement assigns `A' to
  642.   an array whose elements are the `sin' of the elements of `X'.
  643.   The third statement uses the `where' function to get the indices of
  644.   the elements of `A' that are less than 0.  Finally, the
  645.   last statement replaces those elements of `A' by the cosine of the
  646.   corresponding elements of `X'.
  647.  
  648.  SEE ALSO
  649.   wherefirst, wherelast, array_info, array_shape, _isnull
  650.  
  651. --------------------------------------------------------------
  652.  
  653. wherefirst
  654.  
  655.  SYNOPSIS
  656.   Get the index of the first non-zero array element
  657.  
  658.  USAGE
  659.   Int_Type wherefirst (Array_Type a [,start_index])
  660.  
  661.  DESCRIPTION
  662.   The `wherefirst' function returns the index of the first
  663.   non-zero element of a specified array.  If the optional parameter
  664.   `start_index' is given, the search will take place starting
  665.   from that index.  If a non-zero element is not found, the function
  666.   will return NULL.
  667.  
  668.  NOTES
  669.   The single parameter version of this function is equivalent to
  670.  
  671.      define wherefirst (a)
  672.      {
  673.         variable i = where (a);
  674.         if (length(i))
  675.           return i[0];
  676.         else
  677.           return NULL;
  678.      }
  679.  
  680.  
  681.  SEE ALSO
  682.   where, wherelast
  683.  
  684. --------------------------------------------------------------
  685.  
  686. wherelast
  687.  
  688.  SYNOPSIS
  689.   Get the index of the last non-zero array element
  690.  
  691.  USAGE
  692.   Int_Type wherelast (Array_Type a [,start_index])
  693.  
  694.  DESCRIPTION
  695.   The `wherelast' function returns the index of the last
  696.   non-zero element of a specified array.  If the optional parameter
  697.   `start_index' is given, the backward search will take place starting
  698.   from that index.  If a non-zero element is not found, the function
  699.   will return NULL.
  700.  
  701.  NOTES
  702.   The single parameter version of this function is equivalent to
  703.  
  704.      define wherefirst (a)
  705.      {
  706.         variable i = where (a);
  707.         if (length(i))
  708.           return i[-1];
  709.         else
  710.           return NULL;
  711.      }
  712.  
  713.  
  714.  SEE ALSO
  715.   where, wherefirst
  716.  
  717. --------------------------------------------------------------
  718.  
  719. assoc_delete_key
  720.  
  721.  SYNOPSIS
  722.   Delete a key from an Associative Array
  723.  
  724.  USAGE
  725.   assoc_delete_key (Assoc_Type a, String_Type k)
  726.  
  727.  DESCRIPTION
  728.   The `assoc_delete_key' function deletes a key given by `k'
  729.   from the associative array `a'.  If the specified key does not
  730.   exist in `a', then this function has no effect.
  731.  
  732.  SEE ALSO
  733.   assoc_key_exists, assoc_get_keys
  734.  
  735. --------------------------------------------------------------
  736.  
  737. assoc_get_keys
  738.  
  739.  SYNOPSIS
  740.   Return all the key names of an Associative Array
  741.  
  742.  USAGE
  743.   String_Type[] assoc_get_keys (Assoc_Type a)
  744.  
  745.  DESCRIPTION
  746.   This function returns all the key names of an associative array
  747.   `a' as an ordinary one dimensional array of strings.  If the
  748.   associative array contains no keys, an empty array will be returned.
  749.  
  750.  SEE ALSO
  751.   assoc_get_values, assoc_key_exists, assoc_delete_key, length
  752.  
  753. --------------------------------------------------------------
  754.  
  755. assoc_get_values
  756.  
  757.  SYNOPSIS
  758.   Return all the values of an Associative Array
  759.  
  760.  USAGE
  761.   Array_Type assoc_get_keys (Assoc_Type a)
  762.  
  763.  DESCRIPTION
  764.   This function returns all the values in the associative array
  765.   `a' as an array of proper type.  If the associative array
  766.   contains no keys, an empty array will be returned.
  767.  
  768.  EXAMPLE
  769.   Suppose that `a' is an associative array of type
  770.   Integer_Type, i.e., it was created via
  771.  
  772.       variable a = Assoc_Type[Integer_Type];
  773.  
  774.   The the following may be used to print the values of the array in
  775.   ascending order:
  776.  
  777.       static define int_sort_fun (x, y)
  778.       {
  779.          return sign (x - y);
  780.       }
  781.       define sort_and_print_values (a)
  782.       {
  783.          variable v = assoc_get_values (a);
  784.          variable i = array_sort (v, &int_sort_fun);
  785.          v = v[i];
  786.          foreach (v)
  787.            {
  788.               variable vi = ();
  789.               () = fprintf (stdout, "%d\n", vi);
  790.            }
  791.       }
  792.  
  793.  
  794.  SEE ALSO
  795.   assoc_get_values, assoc_key_exists, assoc_delete_key, array_sort
  796.  
  797. --------------------------------------------------------------
  798.  
  799. assoc_key_exists
  800.  
  801.  SYNOPSIS
  802.   Check to see whether a key exists in an Associative Array
  803.  
  804.  USAGE
  805.   Integer_Type assoc_key_exists (Assoc_Type a, String_Type k)
  806.  
  807.  DESCRIPTION
  808.   The `assoc_key_exists' function may be used to determine whether
  809.   or not a specified key `k' exists in an associative array `a'.
  810.   It returns 1 if the key exists, or 0 if it does not.
  811.  
  812.  SEE ALSO
  813.   assoc_get_keys, assoc_get_values, assoc_delete_key
  814.  
  815. --------------------------------------------------------------
  816.  
  817. array_to_bstring
  818.  
  819.  SYNOPSIS
  820.   Convert an array to a binary string
  821.  
  822.  USAGE
  823.   BString_Type array_to_bstring (Array_Type a)
  824.  
  825.  DESCRIPTION
  826.    The `array_to_bstring' function returns the elements of an
  827.    array `a' as a binary string.
  828.  
  829.  SEE ALSO
  830.   bstring_to_array, init_char_array
  831.  
  832. --------------------------------------------------------------
  833.  
  834. bstring_to_array
  835.  
  836.  SYNOPSIS
  837.   Convert a binary string to an array of characters
  838.  
  839.  USAGE
  840.   UChar_Type[] bstring_to_array (BString_Type b)
  841.  
  842.  DESCRIPTION
  843.    The `bstring_to_array' function returns an array of unsigned
  844.    characters whose elements correspond to the characters in the
  845.    binary string.
  846.  
  847.  SEE ALSO
  848.   array_to_bstring, init_char_array
  849.  
  850. --------------------------------------------------------------
  851.  
  852. bstrlen
  853.  
  854.  SYNOPSIS
  855.   Get the length of a binary string
  856.  
  857.  USAGE
  858.   UInt_Type bstrlen (BString_Type s)
  859.  
  860.  DESCRIPTION
  861.   The `bstrlen' function may be used to obtain the length of a
  862.   binary string.  A binary string differs from an ordinary string (a C
  863.   string) in that a binary string may include null chracters.
  864.  
  865.  EXAMPLE
  866.  
  867.     s = "hello\0";
  868.     len = bstrlen (s);      % ==> len = 6
  869.     len = strlen (s);       % ==> len = 5
  870.  
  871.  
  872.  SEE ALSO
  873.   strlen, length
  874.  
  875. --------------------------------------------------------------
  876.  
  877. pack
  878.  
  879.  SYNOPSIS
  880.   Pack objects into a binary string
  881.  
  882.  USAGE
  883.   BString_Type pack (String_Type fmt, ...)
  884.  
  885.  DESCRIPTION
  886.   The `pack' function combines zero or more objects (represented
  887.   by the ellipses above) into a binary string according to the format
  888.   string `fmt'.
  889.  
  890.   The format string consists of one or more data-type specification
  891.   characters defined by the following table:
  892.  
  893.      c     char
  894.      C     unsigned char
  895.      h     short
  896.      H     unsigned short
  897.      i     int
  898.      I     unsigned int
  899.      l     long
  900.      L     unsigned long
  901.      m     long long
  902.      M     unsigned long long
  903.      j     16 bit int
  904.      J     16 bit unsigned int
  905.      k     32 bit int
  906.      K     32 bit unsigned int
  907.      q     64 bit int
  908.      Q     64 bit unsigned int
  909.      f     float
  910.      d     double
  911.      F     32 bit float
  912.      D     64 bit float
  913.      s     character string, null padded
  914.      S     character string, space padded
  915.      z     character string, null padded
  916.      x     a null pad character
  917.  
  918.   A decimal length specifier may follow the data-type specifier.  With
  919.   the exception of the `s' and `S' specifiers, the length
  920.   specifier indicates how many objects of that data type are to be
  921.   packed or unpacked from the string.  When used with the `s',
  922.   `S', or `z' specifiers, it indicates the field width to be
  923.   used.  If the length specifier is not present, the length defaults
  924.   to one.
  925.  
  926.   When packing, unlike the `s' specifier, the `z' specifier
  927.   guarantees that at least one null byte will be written even if the
  928.   field has to be truncated to do so.
  929.  
  930.   With the exception of `c', `C', `s', `S', and
  931.   `x', each of these may be prefixed by a character that indicates
  932.   the byte-order of the object:
  933.  
  934.      >    big-endian order (network order)
  935.      <    little-endian order
  936.      =    native byte-order
  937.  
  938.   The default is to use native byte order.
  939.  
  940.   When unpacking via the `unpack' function, if the length
  941.   specifier is greater than one, then an array of that length will be
  942.   returned.  In addition, trailing whitespace and null characters are
  943.   stripped when unpacking an object given by the `S' specifier.
  944.   Trailing null characters will be stripped from an object represented
  945.   by the `z' specifier.  No such stripping is performed by the `s'
  946.   specifier.
  947.  
  948.  EXAMPLE
  949.  
  950.      a = pack ("cc", 'A', 'B');         % ==> a = "AB";
  951.      a = pack ("c2", 'A', 'B');         % ==> a = "AB";
  952.      a = pack ("xxcxxc", 'A', 'B');     % ==> a = "\0\0A\0\0B";
  953.      a = pack ("h2", 'A', 'B');         % ==> a = "\0A\0B" or "\0B\0A"
  954.      a = pack (">h2", 'A', 'B');        % ==> a = "\0\xA\0\xB"
  955.      a = pack ("<h2", 'A', 'B');        % ==> a = "\0B\0A"
  956.      a = pack ("s4", "AB", "CD");       % ==> a = "AB\0\0"
  957.      a = pack ("s4s2", "AB", "CD");     % ==> a = "AB\0\0CD"
  958.      a = pack ("S4", "AB", "CD");       % ==> a = "AB  "
  959.      a = pack ("S4S2", "AB", "CD");     % ==> a = "AB  CD"
  960.      a = pack ("z4", "AB");             % ==> a = "AB\0\0"
  961.      a = pack ("s4", "ABCDEFG");        % ==> a = "ABCD"
  962.      a = pack ("z4", "ABCDEFG");        % ==> a = "ABC\0"
  963.  
  964.  
  965.  SEE ALSO
  966.   unpack, sizeof_pack, pad_pack_format, sprintf
  967.  
  968. --------------------------------------------------------------
  969.  
  970. pad_pack_format
  971.  
  972.  SYNOPSIS
  973.   Add padding to a pack format
  974.  
  975.  USAGE
  976.   BString_Type pad_pack_format (String_Type fmt)
  977.  
  978.  DESCRIPTION
  979.   The `pad_pack_format' function may be used to add the
  980.   appropriate padding characters to the format `fmt' such that the
  981.   data types specified by the format will be properly aligned on word
  982.   boundaries.  This is especially important when reading or writing files
  983.   that assume the native alignment.
  984.  
  985.  SEE ALSO
  986.   pack, unpack, sizeof_pack
  987.  
  988. --------------------------------------------------------------
  989.  
  990. sizeof_pack
  991.  
  992.  SYNOPSIS
  993.   Compute the size implied by a pack format string
  994.  
  995.  USAGE
  996.   UInt_Type sizeof_pack (String_Type fmt)
  997.  
  998.  DESCRIPTION
  999.   The `sizeof_pack' function returns the size of the binary string
  1000.   represented by the format string `fmt'.  This information may be
  1001.   needed when reading a structure from a file.
  1002.  
  1003.  SEE ALSO
  1004.   pack, unpack, pad_pack_format
  1005.  
  1006. --------------------------------------------------------------
  1007.  
  1008. unpack
  1009.  
  1010.  SYNOPSIS
  1011.   Unpack Objects from a Binary String
  1012.  
  1013.  USAGE
  1014.   (...) = unpack (String_Type fmt, BString_Type s)
  1015.  
  1016.  DESCRIPTION
  1017.   The `unpack' function unpacks objects from a binary string
  1018.   `s' according to the format `fmt' and returns the objects to
  1019.   the stack in the order in which they were unpacked.  See the
  1020.   documentation of the `pack' function for details about the
  1021.   format string.
  1022.  
  1023.  EXAMPLE
  1024.  
  1025.     (x,y) = unpack ("cc", "AB");          % ==> x = 'A', y = 'B'
  1026.     x = unpack ("c2", "AB");              % ==> x = ['A', 'B']
  1027.     x = unpack ("x<H", "\0\xAB\xCD");     % ==> x = 0xCDABuh
  1028.     x = unpack ("xxs4", "a b c\0d e f");  % ==> x = "b c\0"
  1029.     x = unpack ("xxS4", "a b c\0d e f");  % ==> x = "b c"
  1030.  
  1031.  
  1032.  SEE ALSO
  1033.   pack, sizeof_pack, pad_pack_format
  1034.  
  1035. --------------------------------------------------------------
  1036.  
  1037. Assoc_Type
  1038.  
  1039.  SYNOPSIS
  1040.   An associative array or hash type
  1041.  
  1042.  DESCRIPTION
  1043.   An Assoc_Type object is like an array except that it is
  1044.   indexed using strings and not integers.  Unlike an Array_Type
  1045.   object, the size of an associative array is not fixed, but grows as
  1046.   objects are added to the array.  Another difference is that ordinary
  1047.   arrays represent ordered object; however, the ordering of the
  1048.   elements of an `Assoc_Type' object is unspecified.
  1049.  
  1050.   An Assoc_Type object whose elements are of some data-type
  1051.   `d' may be created using using
  1052.  
  1053.     A = Assoc_Type[d];
  1054.  
  1055.   For example,
  1056.  
  1057.     A = Assoc_Type[Int_Type];
  1058.  
  1059.   will create an associative array of integers.  To create an
  1060.   associative array capable of storing an arbitrary type, use the form
  1061.  
  1062.     A = Assoc_Type[];
  1063.  
  1064.  
  1065.   An optional parameter may be used to specify a default value for
  1066.   array elements.  For example,
  1067.  
  1068.    A = Assoc_Type[Int_Type, -1];
  1069.  
  1070.   creates an integer-valued associative array with a default element
  1071.   value of -1.  Then `A["foo"]' will return -1 if the key
  1072.   `"foo"' does not exist in the array.  Default values are
  1073.   available only if the type was specified when the associative array
  1074.   was created.
  1075.  
  1076.   The following functions may be used with associative arrays:
  1077.  
  1078.     assoc_get_keys
  1079.     assoc_get_values
  1080.     assoc_key_exists
  1081.     assoc_delete_key
  1082.  
  1083.   The `length' function may be used to obtain the number of
  1084.   elements in the array.
  1085.  
  1086.   The `foreach' construct may be used with associative arrays via
  1087.   on of the following forms:
  1088.  
  1089.       foreach k,v (A) {...}
  1090.       foreach k (A) using ("keys") { ... }
  1091.       foreach v (A) using ("values") { ... }
  1092.       foreach k,v (A) using ("keys", "values") { ... }
  1093.  
  1094.   In all the above forms, the loop is over all elements of the array
  1095.   such that `v=A[k]'.
  1096.  
  1097.  SEE ALSO
  1098.   List_Type, Array_Type, Struct_Type
  1099.  
  1100. --------------------------------------------------------------
  1101.  
  1102. List_Type
  1103.  
  1104.  SYNOPSIS
  1105.   A list object
  1106.  
  1107.  DESCRIPTION
  1108.   An object of type `List_Type' represents a list, which is
  1109.   defined as an ordered heterogeneous collection of objects.
  1110.   A list may be created using, e.g.,
  1111.  
  1112.     empty_list = {};
  1113.     list_with_4_items = {[1:10], "three", 9, {1,2,3}};
  1114.  
  1115.   Note that the last item of the list in the last example is also a
  1116.   list.  A List_Type object may be manipulated by the following
  1117.   functions:
  1118.  
  1119.     list_new
  1120.     list_insert
  1121.     list_append
  1122.     list_delete
  1123.     list_reverse
  1124.     list_pop
  1125.  
  1126.   A `List_Type' object may be indexed using an array syntax with
  1127.   the first item on the list given by an index of 0.  The
  1128.   `length' function may be used to obtain the number of elements
  1129.   in the list.
  1130.  
  1131.   A copy of the list may be created using the @ operator, e.g.,
  1132.   `copy = @list'.
  1133.  
  1134.   The `foreach' statement may be used with a List_Type
  1135.   objects to loop over its elements:
  1136.  
  1137.     foreach elem (list) {....}
  1138.  
  1139.  
  1140.  SEE ALSO
  1141.   Array_Type, Assoc_Type, Struct_Type
  1142.  
  1143. --------------------------------------------------------------
  1144.  
  1145. Struct_Type
  1146.  
  1147.  SYNOPSIS
  1148.   A structure datatype
  1149.  
  1150.  DESCRIPTION
  1151.   A Struct_Type object with fields `f1', `f2',...,
  1152.   `fN' may be created using
  1153.  
  1154.     s = struct { f1, f2, ..., fN };
  1155.  
  1156.   The fields may be accessed via the "dot" operator, e.g.,
  1157.  
  1158.      s.f1 = 3;
  1159.      if (s12.f1 == 4) s.f1++;
  1160.  
  1161.   By default, all fields will be initialized to NULL.
  1162.  
  1163.   A structure may also be created using the dereference operator (@):
  1164.  
  1165.     s = @Struct_Type ("f1", "f2", ..., "fN");
  1166.     s = @Struct_Type ( ["f1", "f2", ..., "fN"] );
  1167.  
  1168.   Functions for manipulating structure fields include:
  1169.  
  1170.      _push_struct_field_values
  1171.      get_struct_field
  1172.      get_struct_field_names
  1173.      set_struct_field
  1174.      set_struct_fields
  1175.  
  1176.  
  1177.   The `foreach' loop may be used to loop over elements of a linked
  1178.   list.  Suppose that first structure in the list is called
  1179.   `root', and that the `child' field is used to form the
  1180.   chain.  Then one may walk the list using:
  1181.  
  1182.      foreach s (root) using ("child")
  1183.       {
  1184.          % s will take on successive values in the list
  1185.           .
  1186.           .
  1187.       }
  1188.  
  1189.   The loop will terminate when the last elements `child' field is
  1190.   NULL.  If no ``linking'' field is specified, the field name will
  1191.   default to `next'.
  1192.  
  1193.   User-defined data types are similar to the `Struct_Type'.  A
  1194.   type, e.g., `Vector_Type' may be created using:
  1195.  
  1196.     typedef struct { x, y, z } Vector_Type;
  1197.  
  1198.   Objects of this type may be created via the @ operator, e.g.,
  1199.  
  1200.     v = @Vector_Type;
  1201.  
  1202.   It is recommended that this be used in a function for creating such
  1203.   types, e.g.,
  1204.  
  1205.     define vector (x, y, z)
  1206.     {
  1207.        variable v = @Vector_Type;
  1208.        v.x = x;
  1209.        v.y = y;
  1210.        v.z = z;
  1211.        return v;
  1212.     }
  1213.  
  1214.   The action of the binary and unary operators may be defined for such
  1215.   types.  Consider the "+" operator.  First define a function for
  1216.   adding two `Vector_Type' objects:
  1217.  
  1218.     static define vector_add (v1, v2)
  1219.     {
  1220.        return vector (v1.x+v2.x, v1.y+v2.y, v1.z, v2.z);
  1221.     }
  1222.  
  1223.   Then use
  1224.  
  1225.     __add_binary ("+", Vector_Type, &vector_add, Vector_Type, Vector_Type);
  1226.  
  1227.   to indicate that the function is to be called whenever the "+"
  1228.   binary operation between two `Vector_Type' objects takes place,
  1229.   e.g.,
  1230.  
  1231.     V1 = vector (1, 2, 3);
  1232.     V2 = vector (8, 9, 1);
  1233.     V3 = V1 + V2;
  1234.  
  1235.   will assigned the vector (9, 11, 4) to `V3'.  Similarly, the
  1236.   `"*"' operator between scalars and vectors may be defined using:
  1237.  
  1238.     static define vector_scalar_mul (v, a)
  1239.     {
  1240.        return vector (a*v.x, a*v.y, a*v.z);
  1241.     }
  1242.     static define scalar_vector_mul (a, v)
  1243.     {
  1244.        return vector_scalar_mul (v, a);
  1245.     }
  1246.     __add_binary ("*", Vector_Type, &scalar_vector_mul, Any_Type, Vector_Type);
  1247.     __add_binary ("*", Vector_Type, &vector_scalar_mul, Vector_Type, Any_Type);
  1248.  
  1249.   Related functions include:
  1250.  
  1251.     __add_unary
  1252.     __add_string
  1253.     __add_destroy
  1254.  
  1255.  
  1256.  SEE ALSO
  1257.   List_Type, Assoc_Type
  1258.  
  1259. --------------------------------------------------------------
  1260.  
  1261. _boseos_info
  1262.  
  1263.  SYNOPSIS
  1264.   Control the generation of BOS/EOS callback code
  1265.  
  1266.  USAGE
  1267.   Int_Type _boseos_info
  1268.  
  1269.  DESCRIPTION
  1270.  This value of this variable dictates whether or not the S-Lang
  1271.  interpeter will generate code to call the beginning and end of
  1272.  statement callback handlers.  The value of this variable is local to
  1273.  the compilation unit, but is inherited by other units loaded by the
  1274.  current unit.
  1275.  
  1276.  The value of `_boseos_info' controls the generation of code for
  1277.  callbacks as follows:
  1278.  
  1279.    Value      Description
  1280.    -----------------------------------------------------------------
  1281.      0        No code for making callbacks will be produced.
  1282.      1        Callback generation will take place for all non-branching
  1283.               statements.
  1284.      2        Same as for 1 with the addition that code will also be
  1285.               generated for branching statements.
  1286.  
  1287.  A non-branching statement is one that does not effect chain of
  1288.  execution.  Branching statements include all looping statements,
  1289.  conditional statement, `break', `continue', and `return'.
  1290.  
  1291.  EXAMPLE
  1292.  Consider the following:
  1293.  
  1294.    _boseos_info = 1;
  1295.    define foo ()
  1296.    {
  1297.       if (some_expression)
  1298.         some_statement;
  1299.    }
  1300.    _boseos_info = 2;
  1301.    define bar ()
  1302.    {
  1303.       if (some_expression)
  1304.         some_statement;
  1305.    }
  1306.  
  1307.  The function `foo' will be compiled with code generated to call the
  1308.  BOS and EOS handlers when `some_statement' is executed.  The
  1309.  function `bar' will be compiled with code to call the handlers
  1310.  for both `some_expression' and `some_statement'.
  1311.  
  1312.  NOTES
  1313.  The `sldb' debugger and `slsh''s `stkcheck.sl' make use of this
  1314.  facility.
  1315.  
  1316.  SEE ALSO
  1317.   _set_bos_handler, _set_eos_handler, _debug_info
  1318.  
  1319. --------------------------------------------------------------
  1320.  
  1321. _clear_error
  1322.  
  1323.  SYNOPSIS
  1324.   Clear an error condition (deprecated)
  1325.  
  1326.  USAGE
  1327.   _clear_error ()
  1328.  
  1329.  DESCRIPTION
  1330.   This function has been deprecated.  New code should make use of
  1331.   try-catch exception handling.
  1332.  
  1333.   This function may be used in error-blocks to clear the error that
  1334.   triggered execution of the error block.  Execution resumes following
  1335.   the statement, in the scope of the error-block, that triggered the
  1336.   error.
  1337.  
  1338.  EXAMPLE
  1339.   Consider the following wrapper around the `putenv' function:
  1340.  
  1341.     define try_putenv (name, value)
  1342.     {
  1343.        variable status;
  1344.        ERROR_BLOCK
  1345.         {
  1346.           _clear_error ();
  1347.           status = -1;
  1348.         }
  1349.        status = 0;
  1350.        putenv (sprintf ("%s=%s", name, value);
  1351.        return status;
  1352.     }
  1353.  
  1354.   If `putenv' fails, it generates an error condition, which the
  1355.   `try_putenv' function catches and clears.  Thus `try_putenv'
  1356.   is a function that returns -1 upon failure and 0 upon
  1357.   success.
  1358.  
  1359.  SEE ALSO
  1360.   _trace_function, _slangtrace, _traceback
  1361.  
  1362. --------------------------------------------------------------
  1363.  
  1364. _debug_info
  1365.  
  1366.  SYNOPSIS
  1367.   Configure debugging information
  1368.  
  1369.  USAGE
  1370.   Integer_Type _debug_info
  1371.  
  1372.  DESCRIPTION
  1373.   The `_debug_info' variable controls whether or not extra code
  1374.   should be generated for additional debugging and traceback
  1375.   information.  Currently, if `_debug_info' is zero, no extra code
  1376.   will be generated; otherwise extra code will be inserted into the
  1377.   compiled bytecode for additional debugging data.
  1378.  
  1379.   The value of this variable is local to each compilation unit and
  1380.   setting its value in one unit has no effect upon its value in other
  1381.   units.
  1382.  
  1383.  EXAMPLE
  1384.  
  1385.     _debug_info = 1;   % Enable debugging information
  1386.  
  1387.  
  1388.  NOTES
  1389.   Setting this variable to a non-zero value may slow down the
  1390.   interpreter somewhat.
  1391.  
  1392.   The value of this variable is not currently used.
  1393.  
  1394.  SEE ALSO
  1395.   _traceback, _slangtrace
  1396.  
  1397. --------------------------------------------------------------
  1398.  
  1399. _set_bos_handler
  1400.  
  1401.  SYNOPSIS
  1402.   Set the beginning of statement callback handler
  1403.  
  1404.  USAGE
  1405.   _set_bos_handler (Ref_Type func)
  1406.  
  1407.  DESCRIPTION
  1408.  This function is used to set the function to be called prior to the
  1409.  beginning of a statement.  The function will be passed two
  1410.  parameters: the name of the file and the line number of the statement
  1411.  to be executed.  It should return nothing.
  1412.  
  1413.  EXAMPLE
  1414.  
  1415.     static define bos_handler (file, line)
  1416.     {
  1417.       () = fputs ("About to execute $file:$line\n"$, stdout);
  1418.     }
  1419.     _set_bos_handler (&bos_handler);
  1420.  
  1421.  
  1422.  NOTES
  1423.  The beginning and end of statement handlers will be called for
  1424.  statements in a file only if that file was compiled with the variable
  1425.  `_boseos_info' set to a non-zero value.
  1426.  
  1427.  SEE ALSO
  1428.   _set_eos_handler, _boseos_info
  1429.  
  1430. --------------------------------------------------------------
  1431.  
  1432. _set_eos_handler
  1433.  
  1434.  SYNOPSIS
  1435.   Set the beginning of statement callback handler
  1436.  
  1437.  USAGE
  1438.   _set_eos_handler (Ref_Type func)
  1439.  
  1440.  DESCRIPTION
  1441.  This function is used to set the function to be called at the end of
  1442.  a statement.  The function will be passed no parameters and it should
  1443.  return nothing.
  1444.  
  1445.  EXAMPLE
  1446.  
  1447.    static define eos_handler ()
  1448.    {
  1449.      () = fputs ("Done executing the statement\n", stdout);
  1450.    }
  1451.    _set_eos_handler (&bos_handler);
  1452.  
  1453.  
  1454.  NOTES
  1455.  The beginning and end of statement handlers will be called for
  1456.  statements in a file only if that file was compiled with the variable
  1457.  `_boseos_info' set to a non-zero value.
  1458.  
  1459.  SEE ALSO
  1460.   _set_eos_handler, _boseos_info
  1461.  
  1462. --------------------------------------------------------------
  1463.  
  1464. _slangtrace
  1465.  
  1466.  SYNOPSIS
  1467.   Turn function tracing on or off
  1468.  
  1469.  USAGE
  1470.   Integer_Type _slangtrace
  1471.  
  1472.  DESCRIPTION
  1473.   The `_slangtrace' variable is a debugging aid that when set to a
  1474.   non-zero value enables tracing when function declared by
  1475.   `_trace_function' is entered.  If the value is greater than
  1476.   zero, both intrinsic and user defined functions will get traced.
  1477.   However, if set to a value less than zero, intrinsic functions will
  1478.   not get traced.
  1479.  
  1480.  SEE ALSO
  1481.   _trace_function, _traceback, _print_stack
  1482.  
  1483. --------------------------------------------------------------
  1484.  
  1485. _traceback
  1486.  
  1487.  SYNOPSIS
  1488.   Generate a traceback upon error
  1489.  
  1490.  USAGE
  1491.   Integer_Type _traceback
  1492.  
  1493.  DESCRIPTION
  1494.   `_traceback' is an intrinsic integer variable whose value
  1495.   controls whether or not a traceback of the call stack is to be
  1496.   generated upon error.  If `_traceback' is greater than zero, a
  1497.   full traceback will be generated, which includes the values of local
  1498.   variables.  If the value is less than zero, a traceback will be
  1499.   generated without local variable information, and if
  1500.   `_traceback' is zero the traceback will not be generated.
  1501.  
  1502.   Running `slsh' with the `-g' option causes this variable to be
  1503.   set to 1.
  1504.  
  1505.  SEE ALSO
  1506.   _boseos_info
  1507.  
  1508. --------------------------------------------------------------
  1509.  
  1510. _trace_function
  1511.  
  1512.  SYNOPSIS
  1513.   Set the function to trace
  1514.  
  1515.  USAGE
  1516.   _trace_function (String_Type f)
  1517.  
  1518.  DESCRIPTION
  1519.   `_trace_function' declares that the S-Lang function with name
  1520.   `f' is to be traced when it is called.  Calling
  1521.   `_trace_function' does not in itself turn tracing on.  Tracing
  1522.   is turned on only when the variable `_slangtrace' is non-zero.
  1523.  
  1524.  SEE ALSO
  1525.   _slangtrace, _traceback
  1526.  
  1527. --------------------------------------------------------------
  1528.  
  1529. chdir
  1530.  
  1531.  SYNOPSIS
  1532.   Change the current working directory
  1533.  
  1534.  USAGE
  1535.   Int_Type chdir (String_Type dir)
  1536.  
  1537.  DESCRIPTION
  1538.   The `chdir' function may be used to change the current working
  1539.   directory to the directory specified by `dir'.  Upon success it
  1540.   returns zero.  Upon failure it returns `-1' and sets
  1541.   `errno' accordingly.
  1542.  
  1543.  SEE ALSO
  1544.   mkdir, stat_file
  1545.  
  1546. --------------------------------------------------------------
  1547.  
  1548. chmod
  1549.  
  1550.  SYNOPSIS
  1551.   Change the mode of a file
  1552.  
  1553.  USAGE
  1554.   Int_Type chmod (String_Type file, Int_Type mode)
  1555.  
  1556.  DESCRIPTION
  1557.   The `chmod' function changes the permissions of the specified
  1558.   file to those given by `mode'.  It returns `0' upon
  1559.   success, or `-1' upon failure setting `errno' accordingly.
  1560.  
  1561.   See the system specific documentation for the C library
  1562.   function `chmod' for a discussion of the `mode' parameter.
  1563.  
  1564.  SEE ALSO
  1565.   chown, stat_file
  1566.  
  1567. --------------------------------------------------------------
  1568.  
  1569. chown
  1570.  
  1571.  SYNOPSIS
  1572.   Change the owner of a file
  1573.  
  1574.  USAGE
  1575.   Int_Type chown (String_Type file, Int_Type uid, Int_Type gid)
  1576.  
  1577.  DESCRIPTION
  1578.   The `chown' function is used to change the user-id and group-id of
  1579.   `file' to `uid' and `gid', respectively.  It returns
  1580.   0 upon success and -1 upon failure, with `errno'
  1581.   set accordingly.
  1582.  
  1583.  NOTES
  1584.   On most systems, only the superuser can change the ownership of a
  1585.   file.
  1586.  
  1587.   Some systems do not support this function.
  1588.  
  1589.  SEE ALSO
  1590.   chmod, stat_file
  1591.  
  1592. --------------------------------------------------------------
  1593.  
  1594. getcwd
  1595.  
  1596.  SYNOPSIS
  1597.   Get the current working directory
  1598.  
  1599.  USAGE
  1600.   String_Type getcwd ()
  1601.  
  1602.  DESCRIPTION
  1603.   The `getcwd' function returns the absolute pathname of the
  1604.   current working directory.  If an error occurs or it cannot
  1605.   determine the working directory, it returns NULL and sets
  1606.   `errno' accordingly.
  1607.  
  1608.  NOTES
  1609.   Under Unix, OS/2, and MSDOS, the pathname returned by this function
  1610.   includes the trailing slash character.  It may also include
  1611.   the drive specifier for systems where that is meaningful.
  1612.  
  1613.  SEE ALSO
  1614.   mkdir, chdir, errno
  1615.  
  1616. --------------------------------------------------------------
  1617.  
  1618. hardlink
  1619.  
  1620.  SYNOPSIS
  1621.   Create a hard-link
  1622.  
  1623.  USAGE
  1624.   Int_Type hardlink (String_Type oldpath, String_Type newpath)
  1625.  
  1626.  DESCRIPTION
  1627.   The `hardlink' function creates a hard-link called
  1628.   `newpath' to the existing file `oldpath'.  If the link was
  1629.   sucessfully created, the function will return 0.  Upon error, the
  1630.   function returns -1 and sets `errno' accordingly.
  1631.  
  1632.  NOTES
  1633.   Not all systems support the concept of a hard-link.
  1634.  
  1635.  SEE ALSO
  1636.   symlink
  1637.  
  1638. --------------------------------------------------------------
  1639.  
  1640. listdir
  1641.  
  1642.  SYNOPSIS
  1643.   Get a list of the files in a directory
  1644.  
  1645.  USAGE
  1646.   String_Type[] listdir (String_Type dir)
  1647.  
  1648.  DESCRIPTION
  1649.   The `listdir' function returns the directory listing of all the
  1650.   files in the specified directory `dir' as an array of strings.
  1651.   It does not return the special files `".."' and `"."' as
  1652.   part of the list.
  1653.  
  1654.  SEE ALSO
  1655.   stat_file, stat_is, length
  1656.  
  1657. --------------------------------------------------------------
  1658.  
  1659. lstat_file
  1660.  
  1661.  SYNOPSIS
  1662.   Get information about a symbolic link
  1663.  
  1664.  USAGE
  1665.   Struct_Type lstat_file (String_Type file)
  1666.  
  1667.  DESCRIPTION
  1668.   The `lstat_file' function behaves identically to `stat_file'
  1669.   but if `file' is a symbolic link, `lstat_file' returns
  1670.   information about the link itself, and not the file that it
  1671.   references.
  1672.  
  1673.   See the documentation for `stat_file' for more information.
  1674.  
  1675.  NOTES
  1676.   On systems that do not support symbolic links, there is no
  1677.   difference between this function and the `stat_file' function.
  1678.  
  1679.  SEE ALSO
  1680.   stat_file, readlink
  1681.  
  1682. --------------------------------------------------------------
  1683.  
  1684. mkdir
  1685.  
  1686.  SYNOPSIS
  1687.   Create a new directory
  1688.  
  1689.  USAGE
  1690.   Int_Type mkdir (String_Type dir [,Int_Type mode])
  1691.  
  1692.  DESCRIPTION
  1693.   The `mkdir' function creates a directory whose name is specified
  1694.   by the `dir' parameter with permissions given by the optional
  1695.   `mode' parameter.  Upon success `mkdir' returns 0, or it
  1696.   returns `-1' upon failure setting `errno' accordingly.  In
  1697.   particular, if the directory already exists, the function will fail
  1698.   and set errno to EEXIST.
  1699.  
  1700.  EXAMPLE
  1701.  
  1702.      define my_mkdir (dir)
  1703.      {
  1704.         if (0 == mkdir (dir)) return;
  1705.         if (errno == EEXIST) return;
  1706.         throw IOError,
  1707.            sprintf ("mkdir %s failed: %s", dir, errno_string (errno));
  1708.      }
  1709.  
  1710.  
  1711.  NOTES
  1712.   The `mode' parameter may not be meaningful on all systems.  On
  1713.   systems where it is meaningful, the actual permissions on the newly
  1714.   created directory are modified by the process's umask.
  1715.  
  1716.  SEE ALSO
  1717.   rmdir, getcwd, chdir, fopen, errno
  1718.  
  1719. --------------------------------------------------------------
  1720.  
  1721. readlink
  1722.  
  1723.  SYNOPSIS
  1724.   String_Type readlink (String_Type path)
  1725.  
  1726.  USAGE
  1727.   Get the value of a symbolic link
  1728.  
  1729.  DESCRIPTION
  1730.   The `readlink' function returns the value of a symbolic link.
  1731.   Upon failure, NULL is returned and `errno' set accordingly.
  1732.  
  1733.  NOTES
  1734.   Not all systems support this function.
  1735.  
  1736.  SEE ALSO
  1737.   symlink, lstat_file, stat_file, stat_is
  1738.  
  1739. --------------------------------------------------------------
  1740.  
  1741. remove
  1742.  
  1743.  SYNOPSIS
  1744.   Delete a file
  1745.  
  1746.  USAGE
  1747.   Int_Type remove (String_Type file)
  1748.  
  1749.  DESCRIPTION
  1750.   The `remove' function deletes a file.  It returns 0 upon
  1751.   success, or -1 upon error and sets `errno' accordingly.
  1752.  
  1753.  SEE ALSO
  1754.   rename, rmdir
  1755.  
  1756. --------------------------------------------------------------
  1757.  
  1758. rename
  1759.  
  1760.  SYNOPSIS
  1761.   Rename a file
  1762.  
  1763.  USAGE
  1764.   Int_Type rename (String_Type old, String_Type new)
  1765.  
  1766.  DESCRIPTION
  1767.   The `rename' function renames a file from `old' to `new'
  1768.   moving it between directories if necessary.  This function may fail
  1769.   if the directories are not on the same file system.  It returns
  1770.   0 upon success, or -1 upon error and sets `errno' accordingly.
  1771.  
  1772.  SEE ALSO
  1773.   remove, errno
  1774.  
  1775. --------------------------------------------------------------
  1776.  
  1777. rmdir
  1778.  
  1779.  SYNOPSIS
  1780.   Remove a directory
  1781.  
  1782.  USAGE
  1783.   Int_Type rmdir (String_Type dir)
  1784.  
  1785.  DESCRIPTION
  1786.   The `rmdir' function deletes the specified directory.  It returns
  1787.   0 upon success or -1 upon error and sets `errno' accordingly.
  1788.  
  1789.  NOTES
  1790.   The directory must be empty before it can be removed.
  1791.  
  1792.  SEE ALSO
  1793.   rename, remove, mkdir
  1794.  
  1795. --------------------------------------------------------------
  1796.  
  1797. stat_file
  1798.  
  1799.  SYNOPSIS
  1800.   Get information about a file
  1801.  
  1802.  USAGE
  1803.   Struct_Type stat_file (String_Type file)
  1804.  
  1805.  DESCRIPTION
  1806.   The `stat_file' function returns information about `file'
  1807.   through the use of the system `stat' call.  If the stat call
  1808.   fails, the function returns NULL and sets errno accordingly.
  1809.   If it is successful, it returns a stat structure with the following
  1810.   integer-value fields:
  1811.  
  1812.     st_dev
  1813.     st_ino
  1814.     st_mode
  1815.     st_nlink
  1816.     st_uid
  1817.     st_gid
  1818.     st_rdev
  1819.     st_size
  1820.     st_atime
  1821.     st_mtime
  1822.     st_ctime
  1823.  
  1824.   See the C library documentation of `stat' for a discussion of the
  1825.   meanings of these fields.
  1826.  
  1827.  EXAMPLE
  1828.   The following example shows how the `stat_file' function may be
  1829.   used to get the size of a file:
  1830.  
  1831.      define file_size (file)
  1832.      {
  1833.         variable st;
  1834.         st = stat_file(file);
  1835.         if (st == NULL)
  1836.           throw IOError, "Unable to stat $file"$;
  1837.         return st.st_size;
  1838.      }
  1839.  
  1840.  
  1841.  SEE ALSO
  1842.   lstat_file, stat_is
  1843.  
  1844. --------------------------------------------------------------
  1845.  
  1846. stat_is
  1847.  
  1848.  SYNOPSIS
  1849.   Parse the st_mode field of a stat structure
  1850.  
  1851.  USAGE
  1852.   Char_Type stat_is (String_Type type, Int_Type st_mode)
  1853.  
  1854.  DESCRIPTION
  1855.   The `stat_is' function returns a boolean value according to
  1856.   whether or not the `st_mode' parameter is of the specified type.
  1857.   Specifically, `type' must be one of the strings:
  1858.  
  1859.      "sock"     (socket)
  1860.      "fifo"     (fifo)
  1861.      "blk"      (block device)
  1862.      "chr"      (character device)
  1863.      "reg"      (regular file)
  1864.      "lnk"      (link)
  1865.      "dir"      (dir)
  1866.  
  1867.   It returns a non-zero value if `st_mode' corresponds to
  1868.   `type'.
  1869.  
  1870.  EXAMPLE
  1871.   The following example illustrates how to use the `stat_is'
  1872.   function to determine whether or not a file is a directory:
  1873.  
  1874.      define is_directory (file)
  1875.      {
  1876.         variable st;
  1877.  
  1878.         st = stat_file (file);
  1879.         if (st == NULL) return 0;
  1880.         return stat_is ("dir", st.st_mode);
  1881.      }
  1882.  
  1883.  
  1884.  SEE ALSO
  1885.   stat_file, lstat_file
  1886.  
  1887. --------------------------------------------------------------
  1888.  
  1889. symlink
  1890.  
  1891.  SYNOPSIS
  1892.   Create a symbolic link
  1893.  
  1894.  USAGE
  1895.   status = symlink (String_Type oldpath, String_Type new_path)
  1896.  
  1897.  DESCRIPTION
  1898.   The `symlink' function may be used to create a symbolic link
  1899.   named `new_path' for  `oldpath'.  If successful, the function
  1900.   returns 0, otherwise it returns -1 and sets `errno' appropriately.
  1901.  
  1902.  NOTES
  1903.   This function is not supported on all systems and even if supported,
  1904.   not all file systems support the concept of a symbolic link.
  1905.  
  1906.  SEE ALSO
  1907.   readlink, hardlink
  1908.  
  1909. --------------------------------------------------------------
  1910.  
  1911. autoload
  1912.  
  1913.  SYNOPSIS
  1914.   Load a function from a file
  1915.  
  1916.  USAGE
  1917.   autoload (String_Type funct, String_Type file)
  1918.  
  1919.  DESCRIPTION
  1920.   The `autoload' function is used to declare `funct' to the
  1921.   interpreter and indicate that it should be loaded from `file'
  1922.   when it is actually used.  If `func' contains a namespace
  1923.   prefix, then the file will be loaded into the corresponding
  1924.   namespace.  Otherwise, if the `autoload' function is called
  1925.   from an execution namespace that is not the Global namespace nor an
  1926.   anonymous namespace, then the file will be loaded into the execution
  1927.   namespace.
  1928.  
  1929.  EXAMPLE
  1930.     Suppose `bessel_j0' is a function defined in the file
  1931.     `bessel.sl'.  Then the statement
  1932.  
  1933.       autoload ("bessel_j0", "bessel.sl");
  1934.  
  1935.     will cause `bessel.sl' to be loaded prior to the execution of
  1936.     `bessel_j0'.
  1937.  
  1938.  SEE ALSO
  1939.   evalfile, import
  1940.  
  1941. --------------------------------------------------------------
  1942.  
  1943. byte_compile_file
  1944.  
  1945.  SYNOPSIS
  1946.   Compile a file to byte-code for faster loading.
  1947.  
  1948.  USAGE
  1949.   byte_compile_file (String_Type file, Int_Type method)
  1950.  
  1951.  DESCRIPTION
  1952.   The `byte_compile_file' function byte-compiles `file'
  1953.   producing a new file with the same name except a `'c'' is added
  1954.   to the output file name.  For example, `file' is
  1955.   `"site.sl"', then this function produces a new file named
  1956.   `site.slc'.
  1957.  
  1958.  NOTES
  1959.   The `method' parameter is not used in the current
  1960.   implementation, but may be in the future.  For now, set
  1961.   it to `0'.
  1962.  
  1963.  SEE ALSO
  1964.   evalfile
  1965.  
  1966. --------------------------------------------------------------
  1967.  
  1968. eval
  1969.  
  1970.  SYNOPSIS
  1971.   Interpret a string as S-Lang code
  1972.  
  1973.  USAGE
  1974.   eval (String_Type expression [,String_Type namespace])
  1975.  
  1976.  DESCRIPTION
  1977.   The `eval' function parses a string as S-Lang code and executes the
  1978.   result.  If called with the optional namespace argument, then the
  1979.   string will be evaluated in the specified namespace.  If that
  1980.   namespace does not exist it will be created first.
  1981.  
  1982.   This is a useful function in many contexts including those where
  1983.   it is necessary to dynamically generate function definitions.
  1984.  
  1985.  EXAMPLE
  1986.  
  1987.     if (0 == is_defined ("my_function"))
  1988.       eval ("define my_function () { message (\"my_function\"); }");
  1989.  
  1990.  
  1991.  SEE ALSO
  1992.   is_defined, autoload, evalfile
  1993.  
  1994. --------------------------------------------------------------
  1995.  
  1996. evalfile
  1997.  
  1998.  SYNOPSIS
  1999.   Interpret a file containing S-Lang code
  2000.  
  2001.  USAGE
  2002.   Int_Type evalfile (String_Type file [,String_Type namespace])
  2003.  
  2004.  DESCRIPTION
  2005.   The `evalfile' function loads `file' into the interpreter
  2006.   and executes it.  If called with the optional namespace argument,
  2007.   the file will be loaded into the specified namespace, which will be
  2008.   created if necessary.  If given no namespace argument and the file
  2009.   has already been loaded, then it will be loaded again into an
  2010.   anonymous namespace.  A namespace argument given by the empty string
  2011.   will also cause the file to be loaded into a new anonymous namespace.
  2012.  
  2013.   If no errors were encountered, 1 will be returned; otherwise,
  2014.   a S-Lang exception will be thrown and the function will return zero.
  2015.  
  2016.  EXAMPLE
  2017.  
  2018.     define load_file (file)
  2019.     {
  2020.        try
  2021.        {
  2022.          () = evalfile (file);
  2023.        }
  2024.        catch AnyError;
  2025.     }
  2026.  
  2027.  
  2028.  NOTES
  2029.   For historical reasons, the return value of this function is not
  2030.   really useful.
  2031.  
  2032.   The file is searched along an application-defined load-path.  The
  2033.   `get_slang_load_path' and `set_slang_load_path' functions
  2034.   may be used to set and query the path.
  2035.  
  2036.  SEE ALSO
  2037.   eval, autoload, set_slang_load_path, get_slang_load_path
  2038.  
  2039. --------------------------------------------------------------
  2040.  
  2041. get_slang_load_path
  2042.  
  2043.  SYNOPSIS
  2044.   Get the value of the interpreter's load-path
  2045.  
  2046.  USAGE
  2047.   String_Type get_slang_load_path ()
  2048.  
  2049.  DESCRIPTION
  2050.   This function retrieves the value of the delimiter-separated search
  2051.   path used for loading files.  The delimiter is OS-specific and may
  2052.   be queried using the `path_get_delimiter' function.
  2053.  
  2054.  NOTES
  2055.   Some applications may not support the built-in load-path searching
  2056.   facility provided by the underlying library.
  2057.  
  2058.  SEE ALSO
  2059.   set_slang_load_path, path_get_delimiter
  2060.  
  2061. --------------------------------------------------------------
  2062.  
  2063. set_slang_load_path
  2064.  
  2065.  SYNOPSIS
  2066.   Set the value of the interpreter's load-path
  2067.  
  2068.  USAGE
  2069.   set_slang_load_path (String_Type path)
  2070.  
  2071.  DESCRIPTION
  2072.   This function may be used to set the value of the
  2073.   delimiter-separated search path used by the `evalfile' and
  2074.   `autoload' functions for locating files.  The delimiter is
  2075.   OS-specific and may be queried using the `path_get_delimiter'
  2076.   function.
  2077.  
  2078.  EXAMPLE
  2079.  
  2080.     public define prepend_to_slang_load_path (p)
  2081.     {
  2082.        variable s = stat_file (p);
  2083.        if (s == NULL) return;
  2084.        if (0 == stat_is ("dir", s.st_mode))
  2085.          return;
  2086.  
  2087.        variable d = path_get_delimiter ();
  2088.        set_slang_load_path (strcat (p, d, get_slang_load_path ()));
  2089.     }
  2090.  
  2091.  
  2092.  NOTES
  2093.   Some applications may not support the built-in load-path searching
  2094.   facility provided by the underlying library.
  2095.  
  2096.  SEE ALSO
  2097.   get_slang_load_path, path_get_delimiter, evalfile, autoload
  2098.  
  2099. --------------------------------------------------------------
  2100.  
  2101. get_import_module_path
  2102.  
  2103.  SYNOPSIS
  2104.   Get the search path for dynamically loadable objects
  2105.  
  2106.  USAGE
  2107.   String_Type get_import_module_path ()
  2108.  
  2109.  DESCRIPTION
  2110.   The `get_import_module_path' may be used to get the search path
  2111.   for dynamically shared objects.  Such objects may be made accessible
  2112.   to the application via the `import' function.
  2113.  
  2114.  SEE ALSO
  2115.   import, set_import_module_path
  2116.  
  2117. --------------------------------------------------------------
  2118.  
  2119. import
  2120.  
  2121.  SYNOPSIS
  2122.   Dynamically link to a specified module
  2123.  
  2124.  USAGE
  2125.   import (String_Type module [, String_Type namespace])
  2126.  
  2127.  DESCRIPTION
  2128.   The `import' function causes the run-time linker to dynamically
  2129.   link to the shared object specified by the `module' parameter.
  2130.   It searches for the shared object as follows: First a search is
  2131.   performed along all module paths specified by the application.  Then
  2132.   a search is made along the paths defined via the
  2133.   `set_import_module_path' function.  If not found, a search is
  2134.   performed along the paths given by the `SLANG_MODULE_PATH'
  2135.   environment variable.  Finally, a system dependent search is
  2136.   performed (e.g., using the `LD_LIBRARY_PATH' environment
  2137.   variable).
  2138.  
  2139.   The optional second parameter may be used to specify a namespace
  2140.   for the intrinsic functions and variables of the module.  If this
  2141.   parameter is not present, the intrinsic objects will be placed into
  2142.   the active namespace, or global namespace if the active namespace is
  2143.   anonymous.
  2144.  
  2145.   This function throws an `ImportError' if the specified module is
  2146.   not found.
  2147.  
  2148.  NOTES
  2149.   The `import' function is not available on all systems.
  2150.  
  2151.  SEE ALSO
  2152.   set_import_module_path, use_namespace, current_namespace, getenv, evalfile
  2153.  
  2154. --------------------------------------------------------------
  2155.  
  2156. set_import_module_path
  2157.  
  2158.  SYNOPSIS
  2159.   Set the search path for dynamically loadable objects
  2160.  
  2161.  USAGE
  2162.   set_import_module_path (String_Type path_list)
  2163.  
  2164.  DESCRIPTION
  2165.   The `set_import_module_path' may be used to set the search path
  2166.   for dynamically shared objects.  Such objects may be made accessible
  2167.   to the application via the `import' function.
  2168.  
  2169.   The actual syntax for the specification of the set of paths will
  2170.   vary according to the operating system.  Under Unix, a colon
  2171.   character is used to separate paths in `path_list'.  For win32
  2172.   systems a semi-colon is used.  The `path_get_delimiter'
  2173.   function may be used to get the value of the delimiter.
  2174.  
  2175.  SEE ALSO
  2176.   import, get_import_module_path, path_get_delimiter
  2177.  
  2178. --------------------------------------------------------------
  2179.  
  2180. add_doc_file
  2181.  
  2182.  SYNOPSIS
  2183.   Make a documentation file known to the help system
  2184.  
  2185.  USAGE
  2186.   add_doc_file (String_Type file)
  2187.  
  2188.  DESCRIPTION
  2189.   The `add_doc_file' is used to add a documentation file to the
  2190.   system.  Such files are searched by the
  2191.   `get_doc_string_from_file' function.  The `file' must be
  2192.   specified using the full path.
  2193.  
  2194.  SEE ALSO
  2195.   set_doc_files, get_doc_files, get_doc_string_from_file
  2196.  
  2197. --------------------------------------------------------------
  2198.  
  2199. _apropos
  2200.  
  2201.  SYNOPSIS
  2202.   Generate a list of functions and variables
  2203.  
  2204.  USAGE
  2205.   Array_Type _apropos (String_Type ns, String_Type s, Integer_Type flags)
  2206.  
  2207.  DESCRIPTION
  2208.   The `_apropos' function may be used to get a list of all defined
  2209.   objects in the namespace `ns' whose name matches the regular
  2210.   expression `s' and whose type matches those specified by
  2211.   `flags'.  It returns an array of strings containing the names
  2212.   matched.
  2213.  
  2214.   The second parameter `flags' is a bit mapped value whose bits
  2215.   are defined according to the following table
  2216.  
  2217.      1          Intrinsic Function
  2218.      2          User-defined Function
  2219.      4          Intrinsic Variable
  2220.      8          User-defined Variable
  2221.  
  2222.  
  2223.  EXAMPLE
  2224.  
  2225.     define apropos (s)
  2226.     {
  2227.       variable n, name, a;
  2228.       a = _apropos ("Global", s, 0xF);
  2229.  
  2230.       vmessage ("Found %d matches:", length (a));
  2231.       foreach name (a)
  2232.         message (name);
  2233.     }
  2234.  
  2235.   prints a list of all matches.
  2236.  
  2237.  NOTES
  2238.   If the namespace specifier `ns' is the empty string `""',
  2239.   then the namespace will default to the static namespace of the
  2240.   current compilation unit.
  2241.  
  2242.  SEE ALSO
  2243.   is_defined, sprintf, _get_namespaces
  2244.  
  2245. --------------------------------------------------------------
  2246.  
  2247. _function_name
  2248.  
  2249.  SYNOPSIS
  2250.   Returns the name of the currently executing function
  2251.  
  2252.  USAGE
  2253.   String_Type _function_name ()
  2254.  
  2255.  DESCRIPTION
  2256.   This function returns the name of the currently executing function.
  2257.   If called from top-level, it returns the empty string.
  2258.  
  2259.  SEE ALSO
  2260.   _trace_function, is_defined
  2261.  
  2262. --------------------------------------------------------------
  2263.  
  2264. __get_defined_symbols
  2265.  
  2266.  SYNOPSIS
  2267.   Get the symbols defined by the preprocessor
  2268.  
  2269.  USAGE
  2270.   Int_Type __get_defined_symbols ()
  2271.  
  2272.  DESCRIPTION
  2273.   The `__get_defined_symbols' functions is used to get the list of
  2274.   all the symbols defined by the S-Lang preprocessor.  It pushes each
  2275.   of the symbols on the stack followed by the number of items pushed.
  2276.  
  2277.  SEE ALSO
  2278.   is_defined, _apropos, _get_namespaces
  2279.  
  2280. --------------------------------------------------------------
  2281.  
  2282. get_doc_files
  2283.  
  2284.  SYNOPSIS
  2285.   Get the list of documentation files
  2286.  
  2287.  USAGE
  2288.   String_Type[] = get_doc_files ()
  2289.  
  2290.  DESCRIPTION
  2291.   The `get_doc_files' function returns the internal list of
  2292.   documentation files as an array of strings.
  2293.  
  2294.  SEE ALSO
  2295.   set_doc_files, add_doc_file, get_doc_string_from_file
  2296.  
  2297. --------------------------------------------------------------
  2298.  
  2299. get_doc_string_from_file
  2300.  
  2301.  SYNOPSIS
  2302.   Read documentation from a file
  2303.  
  2304.  USAGE
  2305.   String_Type get_doc_string_from_file ([String_Type f,] String_Type t)
  2306.  
  2307.  DESCRIPTION
  2308.   If called with two arguments, `get_doc_string_from_file' opens
  2309.   the documentation file `f' and searches it for topic `t'.
  2310.   Otherwise, it will search an internal list of documentation files
  2311.   looking for the documentation associated with the topic `t'.  If
  2312.   found, the documentation for `t' will be returned, otherwise the
  2313.   function will return NULL.
  2314.  
  2315.   Files may be added to the internal list via the `add_doc_file'
  2316.   or `set_doc_files' functions.
  2317.  
  2318.  SEE ALSO
  2319.   add_doc_file, set_doc_files, get_doc_files, _slang_doc_dir
  2320.  
  2321. --------------------------------------------------------------
  2322.  
  2323. _get_namespaces
  2324.  
  2325.  SYNOPSIS
  2326.   Returns a list of namespace names
  2327.  
  2328.  USAGE
  2329.   String_Type[] _get_namespaces ()
  2330.  
  2331.  DESCRIPTION
  2332.   This function returns a string array containing the names of the
  2333.   currently defined namespaces.
  2334.  
  2335.  SEE ALSO
  2336.   _apropos, use_namespace, implements, __get_defined_symbols
  2337.  
  2338. --------------------------------------------------------------
  2339.  
  2340. is_defined
  2341.  
  2342.  SYNOPSIS
  2343.   Determine if a variable or function is defined
  2344.  
  2345.  USAGE
  2346.   Integer_Type is_defined (String_Type name)
  2347.  
  2348.  DESCRIPTION
  2349.    This function is used to determine whether or not a function or
  2350.    variable of the given name has been defined.  If the specified name
  2351.    has not been defined, the function returns 0.  Otherwise, it
  2352.    returns a non-zero value that depends on the type of object
  2353.    attached to the name. Specifically, it returns one of the following
  2354.    values:
  2355.  
  2356.      +1     intrinsic function
  2357.      +2     slang function
  2358.      -1     intrinsic variable
  2359.      -2     slang variable
  2360.       0     undefined
  2361.  
  2362.  
  2363.  EXAMPLE
  2364.     Consider the function:
  2365.  
  2366.     define runhooks (hook)
  2367.     {
  2368.        if (2 == is_defined(hook)) eval(hook);
  2369.     }
  2370.  
  2371.     This function could be called from another S-Lang function to
  2372.     allow customization of that function, e.g., if the function
  2373.     represents a mode, the hook could be called to setup keybindings
  2374.     for the mode.
  2375.  
  2376.  SEE ALSO
  2377.   typeof, eval, autoload, __get_reference, __is_initialized
  2378.  
  2379. --------------------------------------------------------------
  2380.  
  2381. __is_initialized
  2382.  
  2383.  SYNOPSIS
  2384.   Determine whether or not a variable has a value
  2385.  
  2386.  USAGE
  2387.   Integer_Type __is_initialized (Ref_Type r)
  2388.  
  2389.  DESCRIPTION
  2390.    This function returns non-zero of the object referenced by `r'
  2391.    is initialized, i.e., whether it has a value.  It returns 0 if the
  2392.    referenced object has not been initialized.
  2393.  
  2394.  EXAMPLE
  2395.    The function:
  2396.  
  2397.     define zero ()
  2398.     {
  2399.        variable f;
  2400.        return __is_initialized (&f);
  2401.     }
  2402.  
  2403.   will always return zero, but
  2404.  
  2405.     define one ()
  2406.     {
  2407.        variable f = 0;
  2408.        return __is_initialized (&f);
  2409.     }
  2410.  
  2411.   will return one.
  2412.  
  2413.  SEE ALSO
  2414.   __get_reference, __uninitialize, is_defined, typeof, eval
  2415.  
  2416. --------------------------------------------------------------
  2417.  
  2418. _NARGS
  2419.  
  2420.  SYNOPSIS
  2421.   The number of parameters passed to a function
  2422.  
  2423.  USAGE
  2424.   Integer_Type _NARGS
  2425.    The value of the `_NARGS' variable represents the number of
  2426.    arguments passed to the function.  This variable is local to each
  2427.    function.
  2428.  
  2429.  EXAMPLE
  2430.    This example uses the `_NARGS' variable to print the list of
  2431.    values passed to the function:
  2432.  
  2433.      define print_values ()
  2434.      {
  2435.         variable arg;
  2436.  
  2437.         if (_NARGS == 0)
  2438.           {
  2439.              message ("Nothing to print");
  2440.              return;
  2441.           }
  2442.         foreach arg (__pop_args (_NARGS))
  2443.           vmessage ("Argument value is: %S", arg.value);
  2444.      }
  2445.  
  2446.  
  2447.  SEE ALSO
  2448.   __pop_args, __push_args, typeof
  2449.  
  2450. --------------------------------------------------------------
  2451.  
  2452. set_doc_files
  2453.  
  2454.  SYNOPSIS
  2455.   Set the internal list of documentation files
  2456.  
  2457.  USAGE
  2458.   set_doc_files (String_Type[] list)
  2459.  
  2460.  DESCRIPTION
  2461.   The `set_doc_files' function may be used to set the internal
  2462.   list of documentation files.  It takes a single parameter, which is
  2463.   required to be an array of strings.  The internal file list is set
  2464.   to the files specified by the elements of the array.
  2465.  
  2466.  EXAMPLE
  2467.   The following example shows how to add all the files in a specified
  2468.   directory to the internal list.  It makes use of the `glob'
  2469.   function that is distributed as part of `slsh'.
  2470.  
  2471.      files = glob ("/path/to/doc/files/*.sld");
  2472.      set_doc_files ([files, get_doc_files ()]);
  2473.  
  2474.  
  2475.  SEE ALSO
  2476.   get_doc_files, add_doc_file, get_doc_string_from_file
  2477.  
  2478. --------------------------------------------------------------
  2479.  
  2480. _slang_doc_dir
  2481.  
  2482.  SYNOPSIS
  2483.   Installed documentation directory
  2484.  
  2485.  USAGE
  2486.   String_Type _slang_doc_dir
  2487.  
  2488.  DESCRIPTION
  2489.    The `_slang_doc_dir' variable is a read-only variable that
  2490.    specifies the compile-time installation location of the S-Lang
  2491.    documentation.
  2492.  
  2493.  SEE ALSO
  2494.   get_doc_string_from_file
  2495.  
  2496. --------------------------------------------------------------
  2497.  
  2498. _slang_version
  2499.  
  2500.  SYNOPSIS
  2501.   The S-Lang library version number
  2502.  
  2503.  USAGE
  2504.   Integer_Type _slang_version
  2505.  
  2506.  DESCRIPTION
  2507.    `_slang_version' is a read-only variable that gives the version
  2508.    number of the S-Lang library.
  2509.  
  2510.  SEE ALSO
  2511.   _slang_version_string
  2512.  
  2513. --------------------------------------------------------------
  2514.  
  2515. _slang_version_string
  2516.  
  2517.  SYNOPSIS
  2518.   The S-Lang library version number as a string
  2519.  
  2520.  USAGE
  2521.   String_Type _slang_version_string
  2522.  
  2523.  DESCRIPTION
  2524.   `_slang_version_string' is a read-only variable that gives a
  2525.   string representation of the version number of the S-Lang library.
  2526.  
  2527.  SEE ALSO
  2528.   _slang_version
  2529.  
  2530. --------------------------------------------------------------
  2531.  
  2532. list_append
  2533.  
  2534.  SYNOPSIS
  2535.   Append an object to a list
  2536.  
  2537.  USAGE
  2538.   list_append (List_Type object, Int_Type nth)
  2539.  
  2540.  DESCRIPTION
  2541.   The `list_append' function is like `list_insert' except
  2542.   this function inserts the object into the list after the `nth'
  2543.   item.  See the documentation on `list_insert' for more details.
  2544.  
  2545.  SEE ALSO
  2546.   list_insert, list_delete, list_pop, list_new, list_reverse
  2547.  
  2548. --------------------------------------------------------------
  2549.  
  2550. list_delete
  2551.  
  2552.  SYNOPSIS
  2553.   Remove an item from a list
  2554.  
  2555.  USAGE
  2556.   list_delete (List_Type list, Int_Type nth)
  2557.  
  2558.  DESCRIPTION
  2559.   This function removes the `nth' item in the specified list.
  2560.   The first item in the list corresponds to a value of `nth'
  2561.   equal to zero.  If `nth' is negative, then the indexing is with
  2562.   respect to the end of the list with the last item corresponding to
  2563.   `nth' equal to -1.
  2564.  
  2565.  SEE ALSO
  2566.   list_insert, list_append, list_pop, list_new, list_reverse
  2567.  
  2568. --------------------------------------------------------------
  2569.  
  2570. list_insert
  2571.  
  2572.  SYNOPSIS
  2573.   Insert an item into a list
  2574.  
  2575.  USAGE
  2576.   list_insert (List_Type list, object, Int_Type nth)
  2577.  
  2578.  DESCRIPTION
  2579.   This function may be used to insert an object before the `nth'
  2580.   position in a list.  The first item in the list corresponds to a
  2581.   value of `nth' equal to zero.  If `nth' is negative, then
  2582.   the indexing is with respect to the end of the list with the last
  2583.   item given by a value of `nth' equal to -1.
  2584.  
  2585.  NOTES
  2586.   It is important to note that
  2587.  
  2588.     list_insert (list, object, 0);
  2589.  
  2590.   is not the same as
  2591.  
  2592.     list = {object, list}
  2593.  
  2594.   since the latter creates a new list with two items, `object'
  2595.   and the old list.
  2596.  
  2597.  SEE ALSO
  2598.   list_append, list_pop, list_delete, list_new, list_reverse
  2599.  
  2600. --------------------------------------------------------------
  2601.  
  2602. list_new
  2603.  
  2604.  SYNOPSIS
  2605.   Create a new list
  2606.  
  2607.  USAGE
  2608.   List_Type list_new ()
  2609.  
  2610.  DESCRIPTION
  2611.   This function creates a new empty List_Type object.  Such a
  2612.   list may also be created using the syntax
  2613.  
  2614.      list = {};
  2615.  
  2616.  
  2617.  SEE ALSO
  2618.   list_delete, list_insert, list_append, list_reverse, list_pop
  2619.  
  2620. --------------------------------------------------------------
  2621.  
  2622. list_pop
  2623.  
  2624.  SYNOPSIS
  2625.   Extract an item from a list
  2626.  
  2627.  USAGE
  2628.   object = list_pop (List_Type list [, Int_Type nth])
  2629.  
  2630.  DESCRIPTION
  2631.   The `list_pop' function returns a object from a list deleting
  2632.   the item from the list in the process.  If the second argument is
  2633.   present, then it may be used to specify the position in the list
  2634.   where the item is to be obtained.  If called with a single argument,
  2635.   the first item in the list will be used.
  2636.  
  2637.  SEE ALSO
  2638.   list_delete, list_insert, list_append, list_reverse, list_new
  2639.  
  2640. --------------------------------------------------------------
  2641.  
  2642. list_reverse
  2643.  
  2644.  SYNOPSIS
  2645.   Reverse a list
  2646.  
  2647.  USAGE
  2648.   list_reverse (List_Type list)
  2649.  
  2650.  DESCRIPTION
  2651.   This function may be used to reverse the items in list.
  2652.  
  2653.  NOTES
  2654.   This function does not create a new list.  The list passed to the
  2655.   function will be reversed upon return from the function.  If it is
  2656.   desired to create a separate reversed list, then a separate copy
  2657.   should be made, e.g.,
  2658.  
  2659.      rev_list = @list;
  2660.      list_reverse (rev_list);
  2661.  
  2662.  
  2663.  SEE ALSO
  2664.   list_new, list_insert, list_append, list_delete, list_pop
  2665.  
  2666. --------------------------------------------------------------
  2667.  
  2668. abs
  2669.  
  2670.  SYNOPSIS
  2671.   Compute the absolute value of a number
  2672.  
  2673.  USAGE
  2674.   y = abs(x)
  2675.  
  2676.  DESCRIPTION
  2677.   The `abs' function returns the absolute value of an arithmetic
  2678.   type.  If its argument is a complex number (Complex_Type),
  2679.   then it returns the modulus.  If the argument is an array, a new
  2680.   array will be created whose elements are obtained from the original
  2681.   array by using the `abs' function.
  2682.  
  2683.  SEE ALSO
  2684.   sign, sqr
  2685.  
  2686. --------------------------------------------------------------
  2687.  
  2688. acos
  2689.  
  2690.  SYNOPSIS
  2691.   Compute the arc-cosine of a number
  2692.  
  2693.  USAGE
  2694.   y = acos (x)
  2695.  
  2696.  DESCRIPTION
  2697.   The `acos' function computes the arc-cosine of a number and
  2698.   returns the result.  If its argument is an array, the
  2699.   `acos' function will be applied to each element and the result returned
  2700.   as an array.
  2701.  
  2702.  SEE ALSO
  2703.   cos, atan, acosh, cosh
  2704.  
  2705. --------------------------------------------------------------
  2706.  
  2707. acosh
  2708.  
  2709.  SYNOPSIS
  2710.   Compute the inverse cosh of a number
  2711.  
  2712.  USAGE
  2713.   y = acosh (x)
  2714.  
  2715.  DESCRIPTION
  2716.   The `acosh' function computes the inverse hyperbolic cosine of a number and
  2717.   returns the result.  If its argument is an array, the
  2718.   `acosh' function will be applied to each element and the result returned
  2719.   as an array.
  2720.  
  2721.  SEE ALSO
  2722.   cos, atan, acosh, cosh
  2723.  
  2724. --------------------------------------------------------------
  2725.  
  2726. asin
  2727.  
  2728.  SYNOPSIS
  2729.   Compute the arc-sine of a number
  2730.  
  2731.  USAGE
  2732.   y = asin (x)
  2733.  
  2734.  DESCRIPTION
  2735.   The `asin' function computes the arc-sine of a number and
  2736.   returns the result.  If its argument is an array, the
  2737.   `asin' function will be applied to each element and the result returned
  2738.   as an array.
  2739.  
  2740.  SEE ALSO
  2741.   cos, atan, acosh, cosh
  2742.  
  2743. --------------------------------------------------------------
  2744.  
  2745. asinh
  2746.  
  2747.  SYNOPSIS
  2748.   Compute the inverse-sinh of a number
  2749.  
  2750.  USAGE
  2751.   y = asinh (x)
  2752.  
  2753.  DESCRIPTION
  2754.   The `asinh' function computes the inverse hyperbolic sine of a number and
  2755.   returns the result.  If its argument is an array, the
  2756.   `asinh' function will be applied to each element and the result returned
  2757.   as an array.
  2758.  
  2759.  SEE ALSO
  2760.   cos, atan, acosh, cosh
  2761.  
  2762. --------------------------------------------------------------
  2763.  
  2764. atan
  2765.  
  2766.  SYNOPSIS
  2767.   Compute the arc-tangent of a number
  2768.  
  2769.  USAGE
  2770.   y = atan (x)
  2771.  
  2772.  DESCRIPTION
  2773.   The `atan' function computes the arc-tangent of a number and
  2774.   returns the result.  If its argument is an array, the
  2775.   `atan' function will be applied to each element and the result returned
  2776.   as an array.
  2777.  
  2778.  SEE ALSO
  2779.   atan2, cos, acosh, cosh
  2780.  
  2781. --------------------------------------------------------------
  2782.  
  2783. atan2
  2784.  
  2785.  SYNOPSIS
  2786.   Compute the arc-tangent of the ratio of two variables
  2787.  
  2788.  USAGE
  2789.   z = atan2 (y, x)
  2790.  
  2791.  DESCRIPTION
  2792.   The `atan2' function computes the arc-tangent of the ratio
  2793.   `y/x' and returns the result as a value that has the
  2794.   proper sign for the quadrant where the point (x,y) is located.  The
  2795.   returned value `z' will satisfy (-PI < z <= PI).  If either of the
  2796.   arguments is an array, an array of the corresponding values will be returned.
  2797.  
  2798.  SEE ALSO
  2799.   hypot, cos, atan, acosh, cosh
  2800.  
  2801. --------------------------------------------------------------
  2802.  
  2803. atanh
  2804.  
  2805.  SYNOPSIS
  2806.   Compute the inverse-tanh of a number
  2807.  
  2808.  USAGE
  2809.   y = atanh (x)
  2810.  
  2811.  DESCRIPTION
  2812.   The `atanh' function computes the inverse hyperbolic tangent of a number and
  2813.   returns the result.  If its argument is an array, the
  2814.   `atanh' function will be applied to each element and the result returned
  2815.   as an array.
  2816.  
  2817.  SEE ALSO
  2818.   cos, atan, acosh, cosh
  2819.  
  2820. --------------------------------------------------------------
  2821.  
  2822. ceil
  2823.  
  2824.  SYNOPSIS
  2825.   Round x up to the nearest integral value
  2826.  
  2827.  USAGE
  2828.   y = ceil (x)
  2829.  
  2830.  DESCRIPTION
  2831.   This function rounds its numeric argument up to the nearest integral
  2832.   value. If the argument is an array, the corresponding array will be
  2833.   returned.
  2834.  
  2835.  SEE ALSO
  2836.   floor, round
  2837.  
  2838. --------------------------------------------------------------
  2839.  
  2840. Conj
  2841.  
  2842.  SYNOPSIS
  2843.   Compute the complex conjugate of a number
  2844.  
  2845.  USAGE
  2846.   z1 = Conj (z)
  2847.  
  2848.  DESCRIPTION
  2849.   The `Conj' function returns the complex conjugate of a number.
  2850.   If its argument is an array, the `Conj' function will be applied to each
  2851.   element and the result returned as an array.
  2852.  
  2853.  SEE ALSO
  2854.   Real, Imag, abs
  2855.  
  2856. --------------------------------------------------------------
  2857.  
  2858. cos
  2859.  
  2860.  SYNOPSIS
  2861.   Compute the cosine of a number
  2862.  
  2863.  USAGE
  2864.   y = cos (x)
  2865.  
  2866.  DESCRIPTION
  2867.   The `cos' function computes the cosine of a number and
  2868.   returns the result.  If its argument is an array, the
  2869.   `cos' function will be applied to each element and the result returned
  2870.   as an array.
  2871.  
  2872.  SEE ALSO
  2873.   cos, atan, acosh, cosh
  2874.  
  2875. --------------------------------------------------------------
  2876.  
  2877. cosh
  2878.  
  2879.  SYNOPSIS
  2880.   Compute the hyperbolic cosine of a number
  2881.  
  2882.  USAGE
  2883.   y = cosh (x)
  2884.  
  2885.  DESCRIPTION
  2886.   The `cosh' function computes the hyperbolic cosine of a number and
  2887.   returns the result.  If its argument is an array, the
  2888.   `cosh' function will be applied to each element and the result returned
  2889.   as an array.
  2890.  
  2891.  SEE ALSO
  2892.   cos, atan, acosh, cosh
  2893.  
  2894. --------------------------------------------------------------
  2895.  
  2896. _diff
  2897.  
  2898.  SYNOPSIS
  2899.   Compute the absolute difference between two values
  2900.  
  2901.  USAGE
  2902.   y = _diff (x, y)
  2903.  
  2904.  DESCRIPTION
  2905.   The `_diff' function returns a floating point number equal to
  2906.   the absolute value of the difference between its two arguments.
  2907.   If either argument is an array, an array of the corresponding values
  2908.   will be returned.
  2909.  
  2910.  SEE ALSO
  2911.   abs
  2912.  
  2913. --------------------------------------------------------------
  2914.  
  2915. exp
  2916.  
  2917.  SYNOPSIS
  2918.   Compute the exponential of a number
  2919.  
  2920.  USAGE
  2921.   y = exp (x)
  2922.  
  2923.  DESCRIPTION
  2924.   The `exp' function computes the exponential of a number and
  2925.   returns the result.  If its argument is an array, the
  2926.   `exp' function will be applied to each element and the result returned
  2927.   as an array.
  2928.  
  2929.  SEE ALSO
  2930.   cos, atan, acosh, cosh
  2931.  
  2932. --------------------------------------------------------------
  2933.  
  2934. floor
  2935.  
  2936.  SYNOPSIS
  2937.   Round x down to the nearest integer
  2938.  
  2939.  USAGE
  2940.   y = floor (x)
  2941.  
  2942.  DESCRIPTION
  2943.   This function rounds its numeric argument down to the nearest
  2944.   integral value. If the argument is an array, the corresponding array
  2945.   will be returned.
  2946.  
  2947.  SEE ALSO
  2948.   ceil, round, nint
  2949.  
  2950. --------------------------------------------------------------
  2951.  
  2952. hypot
  2953.  
  2954.  SYNOPSIS
  2955.   Compute sqrt(x^2+y^2)
  2956.  
  2957.  USAGE
  2958.   r = hypot (x, y)
  2959.  
  2960.  DESCRIPTION
  2961.   The `hypot' function computes the quantity `sqrt(x^2+y^2)'
  2962.   except that it employs an algorithm that tries to avoid arithmetic
  2963.   overflow when `x' or `y' are large.  If either argument is
  2964.   an array, an array of the corresponding values will be returned.
  2965.  
  2966.  SEE ALSO
  2967.   atan2, cos, atan, acosh, cosh
  2968.  
  2969. --------------------------------------------------------------
  2970.  
  2971. Imag
  2972.  
  2973.  SYNOPSIS
  2974.   Compute the imaginary part of a number
  2975.  
  2976.  USAGE
  2977.   i = Imag (z)
  2978.  
  2979.  DESCRIPTION
  2980.   The `Imag' function returns the imaginary part of a number.
  2981.   If its argument is an array, the `Imag' function will be applied to each
  2982.   element and the result returned as an array.
  2983.  
  2984.  SEE ALSO
  2985.   Real, Conj, abs
  2986.  
  2987. --------------------------------------------------------------
  2988.  
  2989. isinf
  2990.  
  2991.  SYNOPSIS
  2992.   Test for infinity
  2993.  
  2994.  USAGE
  2995.   y = isinf (x)
  2996.  
  2997.  DESCRIPTION
  2998.   This function returns 1 if x corresponds to an IEEE infinity, or 0
  2999.   otherwise. If the argument is an array, an array of the
  3000.   corresponding values will be returned.
  3001.  
  3002.  SEE ALSO
  3003.   isnan, _Inf
  3004.  
  3005. --------------------------------------------------------------
  3006.  
  3007. isnan
  3008.  
  3009.  SYNOPSIS
  3010.   isnan
  3011.  
  3012.  USAGE
  3013.   y = isnan (x)
  3014.  
  3015.  DESCRIPTION
  3016.   This function returns 1 if x corresponds to an IEEE NaN (Not a Number),
  3017.   or 0 otherwise.  If the argument is an array, an array of
  3018.   the corresponding values will be returned.
  3019.  
  3020.  SEE ALSO
  3021.   isinf, _NaN
  3022.  
  3023. --------------------------------------------------------------
  3024.  
  3025. log
  3026.  
  3027.  SYNOPSIS
  3028.   Compute the logarithm of a number
  3029.  
  3030.  USAGE
  3031.   y = log (x)
  3032.  
  3033.  DESCRIPTION
  3034.   The `log' function computes the natural logarithm of a number and
  3035.   returns the result.  If its argument is an array, the
  3036.   `log' function will be applied to each element and the result returned
  3037.   as an array.
  3038.  
  3039.  SEE ALSO
  3040.   cos, atan, acosh, cosh
  3041.  
  3042. --------------------------------------------------------------
  3043.  
  3044. log10
  3045.  
  3046.  SYNOPSIS
  3047.   Compute the base-10 logarithm of a number
  3048.  
  3049.  USAGE
  3050.   y = log10 (x)
  3051.  
  3052.  DESCRIPTION
  3053.   The `log10' function computes the base-10 logarithm of a number and
  3054.   returns the result.  If its argument is an array, the
  3055.   `log10' function will be applied to each element and the result returned
  3056.   as an array.
  3057.  
  3058.  SEE ALSO
  3059.   cos, atan, acosh, cosh
  3060.  
  3061. --------------------------------------------------------------
  3062.  
  3063. _max
  3064.  
  3065.  SYNOPSIS
  3066.   Compute the maximum of two values
  3067.  
  3068.  USAGE
  3069.   z = _max (x,y)
  3070.  
  3071.  DESCRIPTION
  3072.   The `_max' function returns a floating point number equal to the
  3073.   maximum value of its two arguments.
  3074.   If either argument is an array, an array of the corresponding values
  3075.   will be returned.
  3076.  
  3077.  NOTES
  3078.   This function returns a floating point result even when both
  3079.   arguments are integers.
  3080.  
  3081.  SEE ALSO
  3082.   max, _min, min
  3083.  
  3084. --------------------------------------------------------------
  3085.  
  3086. _min
  3087.  
  3088.  SYNOPSIS
  3089.   Compute the minimum of two values
  3090.  
  3091.  USAGE
  3092.   z = _min (x,y)
  3093.  
  3094.  DESCRIPTION
  3095.   The `_min' function returns a floating point number equal to the
  3096.   minimum value of its two arguments.
  3097.   If either argument is an array, an array of the corresponding values
  3098.   will be returned.
  3099.  
  3100.  NOTES
  3101.   This function returns a floating point result even when both
  3102.   arguments are integers.
  3103.  
  3104.  SEE ALSO
  3105.   min, _max, max
  3106.  
  3107. --------------------------------------------------------------
  3108.  
  3109. mul2
  3110.  
  3111.  SYNOPSIS
  3112.   Multiply a number by 2
  3113.  
  3114.  USAGE
  3115.   y = mul2(x)
  3116.  
  3117.  DESCRIPTION
  3118.   The `mul2' function multiplies an arithmetic type by two and
  3119.   returns the result.  If its argument is an array, a new array will
  3120.   be created whose elements are obtained from the original array by
  3121.   using the `mul2' function.
  3122.  
  3123.  SEE ALSO
  3124.   sqr, abs
  3125.  
  3126. --------------------------------------------------------------
  3127.  
  3128. nint
  3129.  
  3130.  SYNOPSIS
  3131.   Round to the nearest integer
  3132.  
  3133.  USAGE
  3134.   i = nint(x)
  3135.  
  3136.  DESCRIPTION
  3137.   The `nint' rounds its argument to the nearest integer and
  3138.   returns the result.  If its argument is an array, a new array will
  3139.   be created whose elements are obtained from the original array
  3140.   elements by using the `nint' function.
  3141.  
  3142.  SEE ALSO
  3143.   round, floor, ceil
  3144.  
  3145. --------------------------------------------------------------
  3146.  
  3147. polynom
  3148.  
  3149.  SYNOPSIS
  3150.   Evaluate a polynomial
  3151.  
  3152.  USAGE
  3153.   Double_Type polynom(Double_Type a, b, ...c, Integer_Type n, Double_Type x)
  3154.  
  3155.  DESCRIPTION
  3156.   The `polynom' function returns the value of the polynomial expression:
  3157.  
  3158.      ax^n + bx^(n - 1) + ... c
  3159.  
  3160.  
  3161.  NOTES
  3162.   The `polynom' function should be extended to work with complex
  3163.   and array data types.  The current implementation is limited to
  3164.   Double_Type quantities.
  3165.  
  3166.  SEE ALSO
  3167.   exp
  3168.  
  3169. --------------------------------------------------------------
  3170.  
  3171. Real
  3172.  
  3173.  SYNOPSIS
  3174.   Compute the real part of a number
  3175.  
  3176.  USAGE
  3177.   r = Real (z)
  3178.  
  3179.  DESCRIPTION
  3180.   The `Real' function returns the real part of a number. If its
  3181.   argument is an array, the `Real' function will be applied to
  3182.   each element and the result returned as an array.
  3183.  
  3184.  SEE ALSO
  3185.   Imag, Conj, abs
  3186.  
  3187. --------------------------------------------------------------
  3188.  
  3189. round
  3190.  
  3191.  SYNOPSIS
  3192.   Round to the nearest integral value
  3193.  
  3194.  USAGE
  3195.   y = round (x)
  3196.  
  3197.  DESCRIPTION
  3198.   This function rounds its argument to the nearest integral value and
  3199.   returns it as a floating point result. If the argument is an array,
  3200.   an array of the corresponding values will be returned.
  3201.  
  3202.  SEE ALSO
  3203.   floor, ceil, nint
  3204.  
  3205. --------------------------------------------------------------
  3206.  
  3207. set_float_format
  3208.  
  3209.  SYNOPSIS
  3210.   Set the format for printing floating point values.
  3211.  
  3212.  USAGE
  3213.   set_float_format (String_Type fmt)
  3214.  
  3215.  DESCRIPTION
  3216.   The `set_float_format' function is used to set the floating
  3217.   point format to be used when floating point numbers are printed.
  3218.   The routines that use this are the traceback routines and the
  3219.   `string' function, any anything based upon the `string'
  3220.   function. The default value is `"%g"'
  3221.  
  3222.  EXAMPLE
  3223.  
  3224.      s = string (PI);                %  --> s = "3.14159"
  3225.      set_float_format ("%16.10f");
  3226.      s = string (PI);                %  --> s = "3.1415926536"
  3227.      set_float_format ("%10.6e");
  3228.      s = string (PI);                %  --> s = "3.141593e+00"
  3229.  
  3230.  
  3231.  SEE ALSO
  3232.   string, sprintf, double
  3233.  
  3234. --------------------------------------------------------------
  3235.  
  3236. sign
  3237.  
  3238.  SYNOPSIS
  3239.   Compute the sign of a number
  3240.  
  3241.  USAGE
  3242.   y = sign(x)
  3243.  
  3244.  DESCRIPTION
  3245.   The `sign' function returns the sign of an arithmetic type.  If
  3246.   its argument is a complex number (Complex_Type), the
  3247.   `sign' will be applied to the imaginary part of the number.  If
  3248.   the argument is an array, a new array will be created whose elements
  3249.   are obtained from the original array by using the `sign'
  3250.   function.
  3251.  
  3252.   When applied to a real number or an integer, the `sign' function
  3253.   returns -1, 0, or `+1' according to whether the number is
  3254.   less than zero, equal to zero, or greater than zero, respectively.
  3255.  
  3256.  SEE ALSO
  3257.   abs
  3258.  
  3259. --------------------------------------------------------------
  3260.  
  3261. sin
  3262.  
  3263.  SYNOPSIS
  3264.   Compute the sine of a number
  3265.  
  3266.  USAGE
  3267.   y = sin (x)
  3268.  
  3269.  DESCRIPTION
  3270.   The `sin' function computes the sine of a number and
  3271.   returns the result.  If its argument is an array, the
  3272.   `sin' function will be applied to each element and the result returned
  3273.   as an array.
  3274.  
  3275.  SEE ALSO
  3276.   cos, atan, acosh, cosh
  3277.  
  3278. --------------------------------------------------------------
  3279.  
  3280. sinh
  3281.  
  3282.  SYNOPSIS
  3283.   Compute the hyperbolic sine of a number
  3284.  
  3285.  USAGE
  3286.   y = sinh (x)
  3287.  
  3288.  DESCRIPTION
  3289.   The `sinh' function computes the hyperbolic sine of a number and
  3290.   returns the result.  If its argument is an array, the
  3291.   `sinh' function will be applied to each element and the result returned
  3292.   as an array.
  3293.  
  3294.  SEE ALSO
  3295.   cos, atan, acosh, cosh
  3296.  
  3297. --------------------------------------------------------------
  3298.  
  3299. sqr
  3300.  
  3301.  SYNOPSIS
  3302.   Compute the square of a number
  3303.  
  3304.  USAGE
  3305.   y = sqr(x)
  3306.  
  3307.  DESCRIPTION
  3308.   The `sqr' function returns the square of an arithmetic type.  If its
  3309.   argument is a complex number (Complex_Type), then it returns
  3310.   the square of the modulus.  If the argument is an array, a new array
  3311.   will be created whose elements are obtained from the original array
  3312.   by using the `sqr' function.
  3313.  
  3314.  NOTES
  3315.   For real scalar numbers, using `x*x' instead of `sqr(x)'
  3316.   will result in faster executing code.  However, if `x' is an
  3317.   array, then `sqr(x)' will execute faster.
  3318.  
  3319.  SEE ALSO
  3320.   abs, mul2
  3321.  
  3322. --------------------------------------------------------------
  3323.  
  3324. sqrt
  3325.  
  3326.  SYNOPSIS
  3327.   Compute the square root of a number
  3328.  
  3329.  USAGE
  3330.   y = sqrt (x)
  3331.  
  3332.  DESCRIPTION
  3333.   The `sqrt' function computes the square root of a number and
  3334.   returns the result.  If its argument is an array, the
  3335.   `sqrt' function will be applied to each element and the result returned
  3336.   as an array.
  3337.  
  3338.  SEE ALSO
  3339.   sqr, cos, atan, acosh, cosh
  3340.  
  3341. --------------------------------------------------------------
  3342.  
  3343. tan
  3344.  
  3345.  SYNOPSIS
  3346.   Compute the tangent of a number
  3347.  
  3348.  USAGE
  3349.   y = tan (x)
  3350.  
  3351.  DESCRIPTION
  3352.   The `tan' function computes the tangent of a number and
  3353.   returns the result.  If its argument is an array, the
  3354.   `tan' function will be applied to each element and the result returned
  3355.   as an array.
  3356.  
  3357.  SEE ALSO
  3358.   cos, atan, acosh, cosh
  3359.  
  3360. --------------------------------------------------------------
  3361.  
  3362. tanh
  3363.  
  3364.  SYNOPSIS
  3365.   Compute the hyperbolic tangent of a number
  3366.  
  3367.  USAGE
  3368.   y = tanh (x)
  3369.  
  3370.  DESCRIPTION
  3371.   The `tanh' function computes the hyperbolic tangent of a number and
  3372.   returns the result.  If its argument is an array, the
  3373.   `tanh' function will be applied to each element and the result returned
  3374.   as an array.
  3375.  
  3376.  SEE ALSO
  3377.   cos, atan, acosh, cosh
  3378.  
  3379. --------------------------------------------------------------
  3380.  
  3381. errno
  3382.  
  3383.  SYNOPSIS
  3384.   Error code set by system functions
  3385.  
  3386.  USAGE
  3387.   Int_Type errno
  3388.  
  3389.  DESCRIPTION
  3390.   A system function can fail for a variety of reasons.  For example, a
  3391.   file operation may fail because lack of disk space, or the process
  3392.   does not have permission to perform the operation.  Such functions
  3393.   will return -1 and set the variable `errno' to an error
  3394.   code describing the reason for failure.
  3395.  
  3396.   Particular values of `errno' may be specified by the following
  3397.   symbolic constants (read-only variables) and the corresponding
  3398.   `errno_string' value:
  3399.  
  3400.      EPERM            "Not owner"
  3401.      ENOENT           "No such file or directory"
  3402.      ESRCH            "No such process"
  3403.      ENXIO            "No such device or address"
  3404.      ENOEXEC          "Exec format error"
  3405.      EBADF            "Bad file number"
  3406.      ECHILD           "No children"
  3407.      ENOMEM           "Not enough core"
  3408.      EACCES           "Permission denied"
  3409.      EFAULT           "Bad address"
  3410.      ENOTBLK          "Block device required"
  3411.      EBUSY            "Mount device busy"
  3412.      EEXIST           "File exists"
  3413.      EXDEV            "Cross-device link"
  3414.      ENODEV           "No such device"
  3415.      ENOTDIR          "Not a directory"
  3416.      EISDIR           "Is a directory"
  3417.      EINVAL           "Invalid argument"
  3418.      ENFILE           "File table overflow"
  3419.      EMFILE           "Too many open files"
  3420.      ENOTTY           "Not a typewriter"
  3421.      ETXTBSY          "Text file busy"
  3422.      EFBIG            "File too large"
  3423.      ENOSPC           "No space left on device"
  3424.      ESPIPE           "Illegal seek"
  3425.      EROFS            "Read-only file system"
  3426.      EMLINK           "Too many links"
  3427.      EPIPE            "Broken pipe"
  3428.      ELOOP            "Too many levels of symbolic links"
  3429.      ENAMETOOLONG     "File name too long"
  3430.  
  3431.  
  3432.  EXAMPLE
  3433.   The `mkdir' function will attempt to create a directory.  If
  3434.   that directory already exists, the function will fail and set
  3435.   `errno' to EEXIST.
  3436.  
  3437.     define create_dir (dir)
  3438.     {
  3439.        if (0 == mkdir (dir)) return;
  3440.        if (errno != EEXIST)
  3441.          throw IOError, sprintf ("mkdir %s failed: %s",
  3442.                                   dir, errno_string (errno));
  3443.     }
  3444.  
  3445.  
  3446.  SEE ALSO
  3447.   errno_string, error, mkdir
  3448.  
  3449. --------------------------------------------------------------
  3450.  
  3451. errno_string
  3452.  
  3453.  SYNOPSIS
  3454.   Return a string describing an errno.
  3455.  
  3456.  USAGE
  3457.   String_Type errno_string ( [Int_Type err ])
  3458.  
  3459.  DESCRIPTION
  3460.   The `errno_string' function returns a string describing the
  3461.   integer errno code `err'.  If the `err' parameter is
  3462.   omitted, the current value of `errno' will be used. See the
  3463.   description for `errno' for more information.
  3464.  
  3465.  EXAMPLE
  3466.   The `errno_string' function may be used as follows:
  3467.  
  3468.     define sizeof_file (file)
  3469.     {
  3470.        variable st = stat_file (file);
  3471.        if (st == NULL)
  3472.          throw IOError, sprintf ("%s: %s", file, errno_string (errno));
  3473.        return st.st_size;
  3474.     }
  3475.  
  3476.  
  3477.  SEE ALSO
  3478.   errno, stat_file
  3479.  
  3480. --------------------------------------------------------------
  3481.  
  3482. error
  3483.  
  3484.  SYNOPSIS
  3485.   Generate an error condition (deprecated)
  3486.  
  3487.  USAGE
  3488.   error (String_Type msg
  3489.  
  3490.  DESCRIPTION
  3491.   This function has been deprecated in favor of `throw'.
  3492.  
  3493.   The `error' function generates a S-Lang `RunTimeError'
  3494.   exception. It takes a single string parameter which is displayed on
  3495.   the stderr output device.
  3496.  
  3497.  EXAMPLE
  3498.  
  3499.     define add_txt_extension (file)
  3500.     {
  3501.        if (typeof (file) != String_Type)
  3502.          error ("add_extension: parameter must be a string");
  3503.        file += ".txt";
  3504.        return file;
  3505.     }
  3506.  
  3507.  
  3508.  SEE ALSO
  3509.   verror, message
  3510.  
  3511. --------------------------------------------------------------
  3512.  
  3513. message
  3514.  
  3515.  SYNOPSIS
  3516.   Print a string onto the message device
  3517.  
  3518.  USAGE
  3519.   message (String_Type s
  3520.  
  3521.  DESCRIPTION
  3522.   The `message' function will print the string specified by
  3523.   `s' onto the message device.
  3524.  
  3525.  EXAMPLE
  3526.  
  3527.      define print_current_time ()
  3528.      {
  3529.        message (time ());
  3530.      }
  3531.  
  3532.  
  3533.  NOTES
  3534.   The message device will depend upon the application.  For example,
  3535.   the output message device for the jed editor corresponds to the
  3536.   line at the bottom of the display window.  The default message
  3537.   device is the standard output device.
  3538.  
  3539.  SEE ALSO
  3540.   vmessage, sprintf, error
  3541.  
  3542. --------------------------------------------------------------
  3543.  
  3544. new_exception
  3545.  
  3546.  SYNOPSIS
  3547.   Create a new exception
  3548.  
  3549.  USAGE
  3550.   new_exception (String_Type name, Int_Type baseclass, String_Type descr)
  3551.  
  3552.  DESCRIPTION
  3553.   This function creates a new exception called `name' subclassed
  3554.   upon `baseclass'.  The description of the exception is
  3555.   specified by `descr'.
  3556.  
  3557.  EXAMPLE
  3558.  
  3559.   new_exception ("MyError", RunTimeError, "My very own error");
  3560.   try
  3561.     {
  3562.        if (something_is_wrong ())
  3563.          throw MyError;
  3564.     }
  3565.   catch RunTimeError;
  3566.  
  3567.   In this case, catching `RunTimeError' will also catch
  3568.   `MyError' since it is a subclass of `RunTimeError'.
  3569.  
  3570.  SEE ALSO
  3571.   error, verror
  3572.  
  3573. --------------------------------------------------------------
  3574.  
  3575. usage
  3576.  
  3577.  SYNOPSIS
  3578.   Generate a usage error
  3579.  
  3580.  USAGE
  3581.   usage (String_Type msg)
  3582.  
  3583.  DESCRIPTION
  3584.   The `usage' function generates a `UsageError' exception and
  3585.   displays `msg' to the message device.
  3586.  
  3587.  EXAMPLE
  3588.   Suppose that a function called `plot' plots an array of `x' and
  3589.   `y' values.  Then such a function could be written to issue a
  3590.   usage message if the wrong number of arguments was passed:
  3591.  
  3592.     define plot ()
  3593.     {
  3594.        variable x, y;
  3595.  
  3596.        if (_NARGS != 2)
  3597.          usage ("plot (x, y)");
  3598.  
  3599.        (x, y) = ();
  3600.        % Now do the hard part
  3601.           .
  3602.           .
  3603.     }
  3604.  
  3605.  
  3606.  SEE ALSO
  3607.   error, message
  3608.  
  3609. --------------------------------------------------------------
  3610.  
  3611. verror
  3612.  
  3613.  SYNOPSIS
  3614.   Generate an error condition (deprecated)
  3615.  
  3616.  USAGE
  3617.   verror (String_Type fmt, ...)
  3618.  
  3619.  DESCRIPTION
  3620.   This function has been deprecated in favor or `throw'.
  3621.  
  3622.   The `verror' function performs the same role as the `error'
  3623.   function.  The only difference is that instead of a single string
  3624.   argument, `verror' takes a sprintf style argument list.
  3625.  
  3626.  EXAMPLE
  3627.  
  3628.     define open_file (file)
  3629.     {
  3630.        variable fp;
  3631.  
  3632.        fp = fopen (file, "r");
  3633.        if (fp == NULL) verror ("Unable to open %s", file);
  3634.        return fp;
  3635.     }
  3636.  
  3637.  
  3638.  NOTES
  3639.   In the current implementation, the `verror' function is not an
  3640.   intrinsic function.  Rather it is a predefined S-Lang function using
  3641.   a combination of `sprintf' and `error'.
  3642.  
  3643.   To generate a specific exception, a `throw' statement should be
  3644.   used.  In fact, a `throw' statement such as:
  3645.  
  3646.      if (fp == NULL)
  3647.        throw OpenError, "Unable to open $file"$;
  3648.  
  3649.   is preferable to the use of `verror' in the above example.
  3650.  
  3651.  SEE ALSO
  3652.   error, Sprintf, vmessage
  3653.  
  3654. --------------------------------------------------------------
  3655.  
  3656. vmessage
  3657.  
  3658.  SYNOPSIS
  3659.   Print a formatted string onto the message device
  3660.  
  3661.  USAGE
  3662.   vmessage (String_Type fmt, ...)
  3663.  
  3664.  DESCRIPTION
  3665.   The `vmessage' function formats a sprintf style argument list
  3666.   and displays the resulting string onto the message device.
  3667.  
  3668.  NOTES
  3669.   In the current implementation, the `vmessage' function is not an
  3670.   intrinsic function.  Rather it is a predefined S-Lang function using
  3671.   a combination of `Sprintf' and `message'.
  3672.  
  3673.  SEE ALSO
  3674.   message, sprintf, Sprintf, verror
  3675.  
  3676. --------------------------------------------------------------
  3677.  
  3678. _auto_declare
  3679.  
  3680.  SYNOPSIS
  3681.   Set automatic variable declaration mode
  3682.  
  3683.  USAGE
  3684.   Integer_Type _auto_declare
  3685.  
  3686.  DESCRIPTION
  3687.   The `_auto_declare' variable may be used to have undefined
  3688.   variable implicitly declared.  If set to zero, any
  3689.   variable must be declared with a `variable' declaration before it
  3690.   can be used.  If set to one, then any undeclared variable will be
  3691.   declared as a `static' variable.
  3692.  
  3693.   The `_auto_declare' variable is local to each compilation unit and
  3694.   setting its value in one unit has no effect upon its value in other
  3695.   units.   The value of this variable has no effect upon the variables
  3696.   in a function.
  3697.  
  3698.  EXAMPLE
  3699.   The following code will not compile if `X' not been
  3700.   declared:
  3701.  
  3702.     X = 1;
  3703.  
  3704.   However,
  3705.  
  3706.     _auto_declare = 1;   % declare variables as static.
  3707.     X = 1;
  3708.  
  3709.   is equivalent to
  3710.  
  3711.     static variable X = 1;
  3712.  
  3713.  
  3714.  NOTES
  3715.   This variable should be used sparingly and is intended primarily for
  3716.   interactive applications where one types S-Lang commands at a
  3717.   prompt.
  3718.  
  3719. --------------------------------------------------------------
  3720.  
  3721. __class_id
  3722.  
  3723.  SYNOPSIS
  3724.   Return the class-id of a specified type
  3725.  
  3726.  USAGE
  3727.   Int_Type __class_id (DataType_Type type)
  3728.  
  3729.  DESCRIPTION
  3730.   This function returns the internal class-id of a specified data type.
  3731.  
  3732.  SEE ALSO
  3733.   typeof, _typeof, __class_type, __datatype
  3734.  
  3735. --------------------------------------------------------------
  3736.  
  3737. __class_type
  3738.  
  3739.  SYNOPSIS
  3740.   Return the class-type of a specified type
  3741.  
  3742.  USAGE
  3743.   Int_Type __class_type (DataType_Type type))
  3744.  
  3745.  DESCRIPTION
  3746.   Internally S-Lang objects are classified according to four types:
  3747.   scalar, vector, pointer, and memory managed types.  For example, an
  3748.   integer is implemented as a scalar, a complex number as a vector,
  3749.   and a string is represented as a pointer.  The `__class_type'
  3750.   function returns an integer representing the class-type associated
  3751.   with the specified data type. Specifically, it returns:
  3752.  
  3753.        0    memory-managed
  3754.        1    scalar
  3755.        2    vector
  3756.        3    pointer
  3757.  
  3758.  
  3759.  SEE ALSO
  3760.   typeof, _typeof, __class_id, __datatype
  3761.  
  3762. --------------------------------------------------------------
  3763.  
  3764. current_namespace
  3765.  
  3766.  SYNOPSIS
  3767.   Get the name of the current namespace
  3768.  
  3769.  USAGE
  3770.   String_Type current_namespace ()
  3771.  
  3772.  DESCRIPTION
  3773.    The `current_namespace' function returns the name of the
  3774.    static namespace associated with the compilation unit.  If there is
  3775.    no such namespace associated with the compilation unit, then the
  3776.    empty string `""' will be returned.
  3777.  
  3778.  SEE ALSO
  3779.   implements, use_namespace, import, evalfile
  3780.  
  3781. --------------------------------------------------------------
  3782.  
  3783. _eqs
  3784.  
  3785.  SYNOPSIS
  3786.   Test for equality of two objects
  3787.  
  3788.  USAGE
  3789.   Int_Type _eqs (a, b)
  3790.  
  3791.  DESCRIPTION
  3792.   This function tests its two arguments for equality and returns 1 if
  3793.   they are equal or 0 otherwise. What it means to be equal depends
  3794.   upon the data types of the objects being compared.  If the types are
  3795.   numeric, they are regarded as equal if their numerical values are
  3796.   equal.  If they are arrays, then they are equal if they have the
  3797.   same shape with equal elements. If they are structures, then they
  3798.   are equal if they contain identical fields, and the corresponding
  3799.   values are equal.
  3800.  
  3801.  EXAMPLE
  3802.    _eqs (1, 1)             ===> 1
  3803.    _eqs (1, 1.0)           ===> 1
  3804.    _eqs ("a", 1)           ===> 0
  3805.    _eqs ([1,2], [1.0,2.0]) ===> 1
  3806.  
  3807.  SEE ALSO
  3808.   typeof, _eqs, __get_reference, __is_callable
  3809.  
  3810.  NOTES
  3811.    For testing sameness, use `__is_same'.
  3812.  
  3813. --------------------------------------------------------------
  3814.  
  3815. getenv
  3816.  
  3817.  SYNOPSIS
  3818.   Get the value of an environment variable
  3819.  
  3820.  USAGE
  3821.   String_Type getenv(String_Type var)
  3822.  
  3823.  DESCRIPTION
  3824.    The `getenv' function returns a string that represents the
  3825.    value of an environment variable `var'.  It will return
  3826.    NULL if there is no environment variable whose name is given
  3827.    by `var'.
  3828.  
  3829.  EXAMPLE
  3830.  
  3831.     if (NULL != getenv ("USE_COLOR"))
  3832.       {
  3833.         set_color ("normal", "white", "blue");
  3834.         set_color ("status", "black", "gray");
  3835.         USE_ANSI_COLORS = 1;
  3836.       }
  3837.  
  3838.  
  3839.  SEE ALSO
  3840.   putenv, strlen, is_defined
  3841.  
  3842. --------------------------------------------------------------
  3843.  
  3844. __get_reference
  3845.  
  3846.  SYNOPSIS
  3847.   Get a reference to a global object
  3848.  
  3849.  USAGE
  3850.   Ref_Type __get_reference (String_Type nm)
  3851.  
  3852.  DESCRIPTION
  3853.   This function returns a reference to a global variable or function
  3854.   whose name is specified by `nm'.  If no such object exists, it
  3855.   returns NULL, otherwise it returns a reference.
  3856.  
  3857.  EXAMPLE
  3858.    Consider the function:
  3859.  
  3860.     define runhooks (hook)
  3861.     {
  3862.        variable f;
  3863.        f = __get_reference (hook);
  3864.        if (f != NULL)
  3865.          @f ();
  3866.     }
  3867.  
  3868.    This function could be called from another S-Lang function to allow
  3869.    customization of that function, e.g., if the function represents a
  3870.    jed editor mode, the hook could be called to setup keybindings for
  3871.    the mode.
  3872.  
  3873.  SEE ALSO
  3874.   is_defined, typeof, eval, autoload, __is_initialized, __uninitialize
  3875.  
  3876. --------------------------------------------------------------
  3877.  
  3878. implements
  3879.  
  3880.  SYNOPSIS
  3881.   Create a new static namespace
  3882.  
  3883.  USAGE
  3884.   implements (String_Type name)
  3885.  
  3886.  DESCRIPTION
  3887.   The `implements' function may be used to create a new static
  3888.   namespace and have it associated with the current compilation unit.
  3889.   If a namespace with the specified name already exists, a
  3890.   `NamespaceError' exception will be thrown.
  3891.  
  3892.   In addition to creating a new static namespace and associating it
  3893.   with the compilation unit, the function will also create a new
  3894.   private namespace.  As a result, any symbols in the previous private
  3895.   namespace will be no longer be accessable.  For this reason, it is
  3896.   recommended that this function should be used before any private
  3897.   symbols have been created.
  3898.  
  3899.  EXAMPLE
  3900.   Suppose that some file `t.sl' contains:
  3901.  
  3902.      implements ("My");
  3903.      define message (x)
  3904.      {
  3905.         Global->message ("My's message: $x"$);
  3906.      }
  3907.      message ("hello");
  3908.  
  3909.   will produce `"My's message: hello"'.  This `message'
  3910.   function may be accessed from outside the namespace via:
  3911.  
  3912.     My->message ("hi");
  3913.  
  3914.  
  3915.  NOTES
  3916.   Since `message' is an intrinsic function, it is public and may
  3917.   not be redefined in the public namespace.
  3918.  
  3919.   The `implements' function should rarely be used.  It is
  3920.   preferable to allow a static namespace to be associated with a
  3921.   compilation unit using, e.g., `evalfile'.
  3922.  
  3923.  SEE ALSO
  3924.   use_namespace, current_namespace, import
  3925.  
  3926. --------------------------------------------------------------
  3927.  
  3928. __is_callable
  3929.  
  3930.  SYNOPSIS
  3931.   Determine whether or not an object is callable
  3932.  
  3933.  USAGE
  3934.   Int_Type __is_callable (obj)
  3935.  
  3936.  DESCRIPTION
  3937.   This function may be used to determine if an object is callable.  It
  3938.   returns 1 if the argument is callable, or zero otherwise.
  3939.  
  3940.  EXAMPLE
  3941.    __is_callable (7) ==> 0
  3942.    __is_callable (&sin) ==> 1
  3943.  
  3944.  SEE ALSO
  3945.   __is_numeric, is_defined
  3946.  
  3947. --------------------------------------------------------------
  3948.  
  3949. __is_numeric
  3950.  
  3951.  SYNOPSIS
  3952.   Determine whether or not an object is a numeric type
  3953.  
  3954.  USAGE
  3955.   Int_Type __is_numeric (obj)
  3956.  
  3957.  DESCRIPTION
  3958.   This function may be used to determine if an object represents a
  3959.   numeric type.  It returns 1 if the argument is numeric, or zero
  3960.   otherwise.  If the argument is an array, then the array type will be
  3961.   used for the test.
  3962.  
  3963.  EXAMPLE
  3964.    __is_numeric ("foo");  ==> 0
  3965.    __is_numeric ("0");    ==> 0
  3966.    __is_numeric (0);      ==> 1
  3967.    __is_numeric (PI);     ==> 1
  3968.    __is_numeric ([1,2]);  ==> 1
  3969.    __is_numeric ({1,2});  ==> 0
  3970.  
  3971.  SEE ALSO
  3972.   typeof
  3973.  
  3974. --------------------------------------------------------------
  3975.  
  3976. __is_same
  3977.  
  3978.  SYNOPSIS
  3979.   Test for sameness of two objects
  3980.  
  3981.  USAGE
  3982.   Int_Type __is_same (a, b)
  3983.  
  3984.  DESCRIPTION
  3985.   This function tests its two arguments for sameness and returns 1
  3986.   if they are the same, or 0 otherwise.  To be the same, the data type of
  3987.   the arguments must match and the values of the objects must
  3988.   reference the same underlying object.
  3989.  
  3990.  EXAMPLE
  3991.    __is_same (1, 1)         ===> 1
  3992.    __is_same (1, 1.0)       ===> 0
  3993.    __is_same ("a", 1)       ===> 0
  3994.    __is_same ([1,2], [1,2]) ===> 0
  3995.  
  3996.  SEE ALSO
  3997.   typeof, _eqs, __get_reference, __is_callable
  3998.  
  3999.  NOTES
  4000.    For testing equality, use `_eqs'.
  4001.  
  4002. --------------------------------------------------------------
  4003.  
  4004. putenv
  4005.  
  4006.  SYNOPSIS
  4007.   Add or change an environment variable
  4008.  
  4009.  USAGE
  4010.   putenv (String_Type s)
  4011.  
  4012.  DESCRIPTION
  4013.     This functions adds string `s' to the environment.  Typically,
  4014.     `s' should of the form `"name=value"'.  The function
  4015.     throws an `OSError' upon failure.
  4016.  
  4017.  NOTES
  4018.     This function may not be available on all systems.
  4019.  
  4020.  SEE ALSO
  4021.   getenv, sprintf
  4022.  
  4023. --------------------------------------------------------------
  4024.  
  4025. _slang_install_prefix
  4026.  
  4027.  SYNOPSIS
  4028.   S-Lang's installation prefix
  4029.  
  4030.  USAGE
  4031.   String_Type _slang_install_prefix
  4032.  
  4033.  DESCRIPTION
  4034.   The value of this variable is set at the S-Lang library's
  4035.   compilation time.  On Unix systems, the value corresponds to the
  4036.   value of the `prefix' variable in the Makefile.  For normal
  4037.   installations, the library itself will be located in the `lib'
  4038.   subdirectory of the `prefix' directory.
  4039.  
  4040.  NOTES
  4041.   The value of this variable may or may not have anything to do with
  4042.   where the slang library is located.  As such, it should be regarded
  4043.   as a hint.  A standard installation will have the `slsh'
  4044.   library files located in the `share/slsh' subdirectory of the
  4045.   installation prefix.
  4046.  
  4047.  SEE ALSO
  4048.   _slang_doc_dir
  4049.  
  4050. --------------------------------------------------------------
  4051.  
  4052. _slang_utf8_ok
  4053.  
  4054.  SYNOPSIS
  4055.   Test if the interpreter running in UTF-8 mode
  4056.  
  4057.  USAGE
  4058.   Int_Type _slang_utf8_ok
  4059.  
  4060.  DESCRIPTION
  4061.   If the value of this variable is non-zero, then the interpreter is
  4062.   running in UTF-8 mode.  In this mode, characters in strings are
  4063.   interpreted as variable length byte sequences according to the
  4064.   semantics of the UTF-8 encoding.
  4065.  
  4066.  NOTES
  4067.   When running in UTF-8 mode, one must be careful not to confuse a
  4068.   character with a byte.  For example, in this mode the `strlen'
  4069.   function returns the number of characters in a string which may be
  4070.   different than the number of bytes.  The latter information may be
  4071.   obtained by the `strbytelen' function.
  4072.  
  4073.  SEE ALSO
  4074.   strbytelen, strlen, strcharlen
  4075.  
  4076. --------------------------------------------------------------
  4077.  
  4078. __uninitialize
  4079.  
  4080.  SYNOPSIS
  4081.   Uninitialize a variable
  4082.  
  4083.  USAGE
  4084.   __uninitialize (Ref_Type x)
  4085.  
  4086.  DESCRIPTION
  4087.   The `__uninitialize' function may be used to uninitialize the
  4088.   variable referenced by the parameter `x'.
  4089.  
  4090.  EXAMPLE
  4091.   The following two lines are equivalent:
  4092.  
  4093.      () = __tmp(z);
  4094.      __uninitialize (&z);
  4095.  
  4096.  
  4097.  SEE ALSO
  4098.   __tmp, __is_initialized
  4099.  
  4100. --------------------------------------------------------------
  4101.  
  4102. use_namespace
  4103.  
  4104.  SYNOPSIS
  4105.   Change to another namespace
  4106.  
  4107.  USAGE
  4108.   use_namespace (String_Type name)
  4109.  
  4110.  DESCRIPTION
  4111.    The `use_namespace' function changes the current static namespace to
  4112.    the one specified by the parameter.  If the specified namespace
  4113.    does not exist, a `NamespaceError' exception will be generated.
  4114.  
  4115.  SEE ALSO
  4116.   implements, current_namespace, import
  4117.  
  4118. --------------------------------------------------------------
  4119.  
  4120. path_basename
  4121.  
  4122.  SYNOPSIS
  4123.   Get the basename part of a filename
  4124.  
  4125.  USAGE
  4126.   String_Type path_basename (String_Type filename)
  4127.  
  4128.  DESCRIPTION
  4129.    The `path_basename' function returns the basename associated
  4130.    with the `filename' parameter.  The basename is the non-directory
  4131.    part of the filename, e.g., on unix `c' is the basename of
  4132.    `/a/b/c'.
  4133.  
  4134.  SEE ALSO
  4135.   path_dirname, path_extname, path_concat, path_is_absolute
  4136.  
  4137. --------------------------------------------------------------
  4138.  
  4139. path_basename_sans_extname
  4140.  
  4141.  SYNOPSIS
  4142.   Get the basename part of a filename but without the extension
  4143.  
  4144.  USAGE
  4145.   String_Type path_basename_sans_extname (String_Type path)
  4146.  
  4147.  DESCRIPTION
  4148.    The `path_basename_sans_extname' function returns the basename
  4149.    associated with the `filename' parameter, omitting the
  4150.    extension if present.  The basename is the non-directory part of
  4151.    the filename, e.g., on unix `c' is the basename of
  4152.    `/a/b/c'.
  4153.  
  4154.  SEE ALSO
  4155.   path_dirname, path_basename, path_extname, path_concat, path_is_absolute
  4156.  
  4157. --------------------------------------------------------------
  4158.  
  4159. path_concat
  4160.  
  4161.  SYNOPSIS
  4162.   Combine elements of a filename
  4163.  
  4164.  USAGE
  4165.   String_Type path_concat (String_Type dir, String_Type basename)
  4166.  
  4167.  DESCRIPTION
  4168.    The `path_concat' function combines the arguments `dir' and
  4169.    `basename' to produce a filename.  For example, on Unix if
  4170.    `dir' is `x/y' and `basename' is `z', then the
  4171.    function will return `x/y/z'.
  4172.  
  4173.  SEE ALSO
  4174.   path_dirname, path_basename, path_extname, path_is_absolute
  4175.  
  4176. --------------------------------------------------------------
  4177.  
  4178. path_dirname
  4179.  
  4180.  SYNOPSIS
  4181.   Get the directory name part of a filename
  4182.  
  4183.  USAGE
  4184.   String_Type path_dirname (String_Type filename)
  4185.  
  4186.  DESCRIPTION
  4187.    The `path_dirname' function returns the directory name
  4188.    associated with a specified filename.
  4189.  
  4190.  NOTES
  4191.    On systems that include a drive specifier as part of the filename,
  4192.    the value returned by this function will also include the drive
  4193.    specifier.
  4194.  
  4195.  SEE ALSO
  4196.   path_basename, path_extname, path_concat, path_is_absolute
  4197.  
  4198. --------------------------------------------------------------
  4199.  
  4200. path_extname
  4201.  
  4202.  SYNOPSIS
  4203.   Return the extension part of a filename
  4204.  
  4205.  USAGE
  4206.   String_Type path_extname (String_Type filename)
  4207.  
  4208.  DESCRIPTION
  4209.    The `path_extname' function returns the extension portion of the
  4210.    specified filename.  If an extension is present, this function will
  4211.    also include the dot as part of the extension, e.g., if `filename'
  4212.    is `"file.c"', then this function will return `".c"'.  If no
  4213.    extension is present, the function returns an empty string `""'.
  4214.  
  4215.  NOTES
  4216.    Under VMS, the file version number is not returned as part of the
  4217.    extension.
  4218.  
  4219.  SEE ALSO
  4220.   path_sans_extname, path_dirname, path_basename, path_concat, path_is_absolute
  4221.  
  4222. --------------------------------------------------------------
  4223.  
  4224. path_get_delimiter
  4225.  
  4226.  SYNOPSIS
  4227.   Get the value of a search-path delimiter
  4228.  
  4229.  USAGE
  4230.   Char_Type path_get_delimiter ()
  4231.  
  4232.  DESCRIPTION
  4233.   This function returns the value of the character used to delimit
  4234.   fields of a search-path.
  4235.  
  4236.  SEE ALSO
  4237.   set_slang_load_path, get_slang_load_path
  4238.  
  4239. --------------------------------------------------------------
  4240.  
  4241. path_is_absolute
  4242.  
  4243.  SYNOPSIS
  4244.   Determine whether or not a filename is absolute
  4245.  
  4246.  USAGE
  4247.   Int_Type path_is_absolute (String_Type filename)
  4248.  
  4249.  DESCRIPTION
  4250.    The `path_is_absolute' function will return non-zero is
  4251.    `filename' refers to an absolute filename, otherwise it returns zero.
  4252.  
  4253.  SEE ALSO
  4254.   path_dirname, path_basename, path_extname, path_concat
  4255.  
  4256. --------------------------------------------------------------
  4257.  
  4258. path_sans_extname
  4259.  
  4260.  SYNOPSIS
  4261.   Strip the extension from a filename
  4262.  
  4263.  USAGE
  4264.   String_Type path_sans_extname (String_Type filename)
  4265.  
  4266.  DESCRIPTION
  4267.   The `path_sans_extname' function removes the file name extension
  4268.   (including the dot) from the filename and returns the result.
  4269.  
  4270.  SEE ALSO
  4271.   path_basename_sans_extname, path_extname, path_basename, path_dirname, path_concat
  4272.  
  4273. --------------------------------------------------------------
  4274.  
  4275. close
  4276.  
  4277.  SYNOPSIS
  4278.   Close an open file descriptor
  4279.  
  4280.  USAGE
  4281.   Int_Type close (FD_Type fd)
  4282.  
  4283.  DESCRIPTION
  4284.   The `close' function is used to close and open file descriptor
  4285.   created by the `open' function.  Upon success 0 is returned,
  4286.   otherwise the function returns -1 and sets `errno' accordingly.
  4287.  
  4288.  SEE ALSO
  4289.   open, fclose, read, write
  4290.  
  4291. --------------------------------------------------------------
  4292.  
  4293. dup_fd
  4294.  
  4295.  SYNOPSIS
  4296.   Duplicate a file descriptor
  4297.  
  4298.  USAGE
  4299.   FD_Type dup_fd (FD_Type fd)
  4300.  
  4301.  DESCRIPTION
  4302.   The `dup_fd' function duplicates a specified file descriptor and
  4303.   returns the duplicate.  If the function fails, NULL will be
  4304.   returned and `errno' set accordingly.
  4305.  
  4306.  NOTES
  4307.   This function is essentially a wrapper around the POSIX `dup'
  4308.   function.
  4309.  
  4310.  SEE ALSO
  4311.   open, close
  4312.  
  4313. --------------------------------------------------------------
  4314.  
  4315. fileno
  4316.  
  4317.  SYNOPSIS
  4318.   Convert a stdio File_Type object to a FD_Type descriptor
  4319.  
  4320.  USAGE
  4321.   FD_Type fileno (File_Type fp)
  4322.  
  4323.  DESCRIPTION
  4324.   The `fileno' function returns the FD_Type descriptor
  4325.   associated with the stdio File_Type file pointer.  Upon failure,
  4326.   NULL is returned.
  4327.  
  4328.  SEE ALSO
  4329.   fopen, open, fclose, close, dup_fd
  4330.  
  4331. --------------------------------------------------------------
  4332.  
  4333. isatty
  4334.  
  4335.  SYNOPSIS
  4336.   Determine if an open file descriptor refers to a terminal
  4337.  
  4338.  USAGE
  4339.   Int_Type isatty (FD_Type or File_Type fd)
  4340.  
  4341.  DESCRIPTION
  4342.   This function returns 1 if the file descriptor `fd' refers to a
  4343.   terminal; otherwise it returns 0.  The object `fd' may either
  4344.   be a File_Type stdio descriptor or a lower-level FD_Type
  4345.   object.
  4346.  
  4347.  SEE ALSO
  4348.   fopen, fclose, fileno
  4349.  
  4350. --------------------------------------------------------------
  4351.  
  4352. lseek
  4353.  
  4354.  SYNOPSIS
  4355.   Reposition a file descriptor's file pointer
  4356.  
  4357.  USAGE
  4358.   Long_Type lseek (FD_Type fd, LLong_Type ofs, int mode)
  4359.    The `lseek' function repositions the file pointer associated
  4360.    with the open file descriptor `fd' to the offset `ofs'
  4361.    according to the mode parameter.  Specifically, `mode' must be
  4362.    one of the values:
  4363.  
  4364.      SEEK_SET   Set the offset to ofs from the beginning of the file
  4365.      SEEK_CUR   Add ofs to the current offset
  4366.      SEEK_END   Add ofs to the current file size
  4367.  
  4368.    Upon error, `lseek' returns -1 and sets `errno'.  If
  4369.    successful, it returns the new filepointer offset.
  4370.  
  4371.  NOTES
  4372.    Not all file descriptors are capable of supporting the seek
  4373.    operation, e.g., a descriptor associated with a pipe.
  4374.  
  4375.    By using SEEK_END with a positive value of the `ofs'
  4376.    parameter, it is possible to position the file pointer beyond the
  4377.    current size of the file.
  4378.  
  4379.  SEE ALSO
  4380.   fseek, ftell, open, close
  4381.  
  4382. --------------------------------------------------------------
  4383.  
  4384. open
  4385.  
  4386.  SYNOPSIS
  4387.   Open a file
  4388.  
  4389.  USAGE
  4390.   FD_Type open (String_Type filename, Int_Type flags [,Int_Type mode])
  4391.  
  4392.  DESCRIPTION
  4393.   The `open' function attempts to open a file specified by the
  4394.   `filename' parameter according to the `flags' parameter,
  4395.   which must be one of the following values:
  4396.  
  4397.      O_RDONLY   (read-only)
  4398.      O_WRONLY   (write-only)
  4399.      O_RDWR     (read/write)
  4400.  
  4401.   In addition, `flags' may also be bitwise-or'd with any of the
  4402.   following:
  4403.  
  4404.      O_BINARY   (open the file in binary mode)
  4405.      O_TEXT     (open the file in text mode)
  4406.      O_CREAT    (create the file if it does not exist)
  4407.      O_EXCL     (fail if the file already exists)
  4408.      O_NOCTTY   (do not make the device the controlling terminal)
  4409.      O_TRUNC    (truncate the file if it exists)
  4410.      O_APPEND   (open the file in append mode)
  4411.      O_NONBLOCK (open the file in non-blocking mode)
  4412.  
  4413.    Some of these flags make sense only when combined with other flags.
  4414.    For example, if O_EXCL is used, then O_CREAT must also be
  4415.    specified, otherwise unpredictable behavior may result.
  4416.  
  4417.    If O_CREAT is used for the `flags' parameter then the
  4418.    `mode' parameter must be present. `mode' specifies the
  4419.    permissions to use if a new file is created. The actual file
  4420.    permissions will be affected by the process's `umask' via
  4421.    `mode&~umask'.  The `mode' parameter's value is
  4422.    constructed via bitwise-or of the following values:
  4423.  
  4424.      S_IRWXU    (Owner has read/write/execute permission)
  4425.      S_IRUSR    (Owner has read permission)
  4426.      S_IWUSR    (Owner has write permission)
  4427.      S_IXUSR    (Owner has execute permission)
  4428.      S_IRWXG    (Group has read/write/execute permission)
  4429.      S_IRGRP    (Group has read permission)
  4430.      S_IWGRP    (Group has write permission)
  4431.      S_IXGRP    (Group has execute permission)
  4432.      S_IRWXO    (Others have read/write/execute permission)
  4433.      S_IROTH    (Others have read permission)
  4434.      S_IWOTH    (Others have write permission)
  4435.      S_IXOTH    (Others have execute permission)
  4436.  
  4437.    Upon success `open' returns a file descriptor object
  4438.    (FD_Type), otherwise NULL is returned and `errno'
  4439.    is set.
  4440.  
  4441.  NOTES
  4442.    If you are not familiar with the `open' system call, then it
  4443.    is recommended that you use `fopen' instead and use the higher
  4444.    level stdio interface.
  4445.  
  4446.  SEE ALSO
  4447.   fopen, close, read, write, stat_file
  4448.  
  4449. --------------------------------------------------------------
  4450.  
  4451. read
  4452.  
  4453.  SYNOPSIS
  4454.   Read from an open file descriptor
  4455.  
  4456.  USAGE
  4457.   UInt_Type read (FD_Type fd, Ref_Type buf, UInt_Type num)
  4458.  
  4459.  DESCRIPTION
  4460.   The `read' function attempts to read at most `num' bytes
  4461.   into the variable indicated by `buf' from the open file
  4462.   descriptor `fd'.  It returns the number of bytes read, or -1
  4463.   upon failure and sets `errno'.  The number of bytes
  4464.   read may be less than `num', and will be zero if an attempt is
  4465.   made to read past the end of the file.
  4466.  
  4467.  NOTES
  4468.   `read' is a low-level function and may return -1 for a variety
  4469.   of reasons.  For example, if non-blocking I/O has been specified for
  4470.   the open file descriptor and no data is available for reading then
  4471.   the function will return -1 and set `errno' to EAGAIN.
  4472.  
  4473.  SEE ALSO
  4474.   fread, open, close, write
  4475.  
  4476. --------------------------------------------------------------
  4477.  
  4478. write
  4479.  
  4480.  SYNOPSIS
  4481.   Write to an open file descriptor
  4482.  
  4483.  USAGE
  4484.   UInt_Type write (FD_Type fd, BString_Type buf)
  4485.  
  4486.  DESCRIPTION
  4487.    The `write' function attempts to write the bytes specified by
  4488.    the `buf' parameter to the open file descriptor `fd'.  It
  4489.    returns the number of bytes successfully written, or -1 and sets
  4490.    `errno' upon failure.  The number of bytes written may be less
  4491.    than `length(buf)'.
  4492.  
  4493.  SEE ALSO
  4494.   read, fwrite, open, close
  4495.  
  4496. --------------------------------------------------------------
  4497.  
  4498. getegid
  4499.  
  4500.  SYNOPSIS
  4501.   Get the effective group id of the current process
  4502.  
  4503.  USAGE
  4504.   Int_Type getegid ()
  4505.  
  4506.  DESCRIPTION
  4507.   The `getegid' function returns the effective group ID of the
  4508.   current process.
  4509.  
  4510.  NOTES
  4511.   This function is not supported by all systems.
  4512.  
  4513.  SEE ALSO
  4514.   getgid, geteuid, setgid
  4515.  
  4516. --------------------------------------------------------------
  4517.  
  4518. geteuid
  4519.  
  4520.  SYNOPSIS
  4521.   Get the effective user-id of the current process
  4522.  
  4523.  USAGE
  4524.   Int_Type geteuid ()
  4525.  
  4526.  DESCRIPTION
  4527.   The `geteuid' function returns the effective user-id of the
  4528.   current process.
  4529.  
  4530.  NOTES
  4531.   This function is not supported by all systems.
  4532.  
  4533.  SEE ALSO
  4534.   getuid, setuid, setgid
  4535.  
  4536. --------------------------------------------------------------
  4537.  
  4538. getgid
  4539.  
  4540.  SYNOPSIS
  4541.   Get the group id of the current process
  4542.  
  4543.  USAGE
  4544.   Integer_Type getgid ()
  4545.  
  4546.  DESCRIPTION
  4547.   The `getgid' function returns the real group id of the current
  4548.   process.
  4549.  
  4550.  NOTES
  4551.   This function is not supported by all systems.
  4552.  
  4553.  SEE ALSO
  4554.   getpid, getppid
  4555.  
  4556. --------------------------------------------------------------
  4557.  
  4558. getpid
  4559.  
  4560.  SYNOPSIS
  4561.   Get the current process id
  4562.  
  4563.  USAGE
  4564.   Integer_Type getpid ()
  4565.  
  4566.  DESCRIPTION
  4567.   The `getpid' function returns the current process identification
  4568.   number.
  4569.  
  4570.  SEE ALSO
  4571.   getppid, getgid
  4572.  
  4573. --------------------------------------------------------------
  4574.  
  4575. getppid
  4576.  
  4577.  SYNOPSIS
  4578.   Get the parent process id
  4579.  
  4580.  USAGE
  4581.   Integer_Type getppid ()
  4582.  
  4583.  DESCRIPTION
  4584.   The `getpid' function returns the process identification
  4585.   number of the parent process.
  4586.  
  4587.  NOTES
  4588.   This function is not supported by all systems.
  4589.  
  4590.  SEE ALSO
  4591.   getpid, getgid
  4592.  
  4593. --------------------------------------------------------------
  4594.  
  4595. getuid
  4596.  
  4597.  SYNOPSIS
  4598.   Get the user-id of the current process
  4599.  
  4600.  USAGE
  4601.   Int_Type getuid ()
  4602.  
  4603.  DESCRIPTION
  4604.   The `getuid' function returns the user-id of the current
  4605.   process.
  4606.  
  4607.  NOTES
  4608.   This function is not supported by all systems.
  4609.  
  4610.  SEE ALSO
  4611.   getuid, getegid
  4612.  
  4613. --------------------------------------------------------------
  4614.  
  4615. kill
  4616.  
  4617.  SYNOPSIS
  4618.   Send a signal to a process
  4619.  
  4620.  USAGE
  4621.   Integer_Type kill (Integer_Type pid, Integer_Type sig)
  4622.  
  4623.  DESCRIPTION
  4624.   This function may be used to send a signal given by the integer `sig'
  4625.   to the process specified by `pid'.  The function returns zero upon
  4626.   success or `-1' upon failure setting `errno' accordingly.
  4627.  
  4628.  EXAMPLE
  4629.   The `kill' function may be used to determine whether or not
  4630.   a specific process exists:
  4631.  
  4632.     define process_exists (pid)
  4633.     {
  4634.        if (-1 == kill (pid, 0))
  4635.          return 0;     % Process does not exist
  4636.        return 1;
  4637.     }
  4638.  
  4639.  
  4640.  NOTES
  4641.   This function is not supported by all systems.
  4642.  
  4643.  SEE ALSO
  4644.   getpid
  4645.  
  4646. --------------------------------------------------------------
  4647.  
  4648. mkfifo
  4649.  
  4650.  SYNOPSIS
  4651.   Create a named pipe
  4652.  
  4653.  USAGE
  4654.   Int_Type mkfifo (String_Type name, Int_Type mode)
  4655.  
  4656.  DESCRIPTION
  4657.   The `mkfifo' attempts to create a named pipe with the specified
  4658.   name and mode (modified by the process's umask).  The function
  4659.   returns 0 upon success, or -1 and sets `errno' upon failure.
  4660.  
  4661.  NOTES
  4662.   Not all systems support the `mkfifo' function and even on
  4663.   systems that do implement the `mkfifo' system call, the
  4664.   underlying file system may not support the concept of a named pipe,
  4665.   e.g, an NFS filesystem.
  4666.  
  4667.  SEE ALSO
  4668.   stat_file
  4669.  
  4670. --------------------------------------------------------------
  4671.  
  4672. setgid
  4673.  
  4674.  SYNOPSIS
  4675.   Set the group-id of the current process
  4676.  
  4677.  USAGE
  4678.   Int_Type setgid (Int_Type gid)
  4679.  
  4680.  DESCRIPTION
  4681.   The `setgid' function sets the effective group-id of the current
  4682.   process.  It returns zero upon success, or -1 upon error and sets
  4683.   `errno' appropriately.
  4684.  
  4685.  NOTES
  4686.   This function is not supported by all systems.
  4687.  
  4688.  SEE ALSO
  4689.   getgid, setuid
  4690.  
  4691. --------------------------------------------------------------
  4692.  
  4693. setpgid
  4694.  
  4695.  SYNOPSIS
  4696.   Set the process group-id
  4697.  
  4698.  USAGE
  4699.   Int_Type setpgid (Int_Type pid, Int_Type gid)
  4700.  
  4701.  DESCRIPTION
  4702.   The `setpgid' function sets the group-id `gid' of the
  4703.   process whose process-id is `pid'.  If `pid' is 0, then the
  4704.   current process-id will be used.  If `pgid' is 0, then the pid
  4705.   of the affected process will be used.
  4706.  
  4707.   If successful 0 will be returned, otherwise the function will
  4708.   return -1 and set `errno' accordingly.
  4709.  
  4710.  NOTES
  4711.   This function is not supported by all systems.
  4712.  
  4713.  SEE ALSO
  4714.   setgid, setuid
  4715.  
  4716. --------------------------------------------------------------
  4717.  
  4718. setuid
  4719.  
  4720.  SYNOPSIS
  4721.   Set the user-id of the current process
  4722.  
  4723.  USAGE
  4724.   Int_Type setuid (Int_Type id)
  4725.  
  4726.  DESCRIPTION
  4727.   The `setuid' function sets the effective user-id of the current
  4728.   process.  It returns zero upon success, or -1 upon error and sets
  4729.   `errno' appropriately.
  4730.  
  4731.  NOTES
  4732.   This function is not supported by all systems.
  4733.  
  4734.  SEE ALSO
  4735.   setgid, setpgid, getuid, geteuid
  4736.  
  4737. --------------------------------------------------------------
  4738.  
  4739. sleep
  4740.  
  4741.  SYNOPSIS
  4742.   Pause for a specified number of seconds
  4743.  
  4744.  USAGE
  4745.   sleep (Double_Type n)
  4746.  
  4747.  DESCRIPTION
  4748.   The `sleep' function delays the current process for the
  4749.   specified number of seconds.  If it is interrupted by a signal, it
  4750.   will return prematurely.
  4751.  
  4752.  NOTES
  4753.   Not all system support sleeping for a fractional part of a second.
  4754.  
  4755. --------------------------------------------------------------
  4756.  
  4757. system
  4758.  
  4759.  SYNOPSIS
  4760.   Execute a shell command
  4761.  
  4762.  USAGE
  4763.   Integer_Type system (String_Type cmd)
  4764.  
  4765.  DESCRIPTION
  4766.   The `system' function may be used to execute the string
  4767.   expression `cmd' in an inferior shell.  This function is an
  4768.   interface to the C `system' function which returns an
  4769.   implementation-defined result.   On Linux, it returns 127 if the
  4770.   inferior shell could not be invoked, -1 if there was some other
  4771.   error, otherwise it returns the return code for `cmd'.
  4772.  
  4773.  EXAMPLE
  4774.  
  4775.     define dir ()
  4776.     {
  4777.        () = system ("DIR");
  4778.     }
  4779.  
  4780.   displays a directory listing of the current directory under MSDOS or
  4781.   VMS.
  4782.  
  4783.  SEE ALSO
  4784.   popen, listdir
  4785.  
  4786. --------------------------------------------------------------
  4787.  
  4788. umask
  4789.  
  4790.  SYNOPSIS
  4791.   Set the file creation mask
  4792.  
  4793.  USAGE
  4794.   Int_Type umask (Int_Type m)
  4795.  
  4796.  DESCRIPTION
  4797.   The `umask' function sets the file creation mask to the value of
  4798.   `m' and returns the previous mask.
  4799.  
  4800.  SEE ALSO
  4801.   stat_file
  4802.  
  4803. --------------------------------------------------------------
  4804.  
  4805. uname
  4806.  
  4807.  SYNOPSIS
  4808.   Get the system name
  4809.  
  4810.  USAGE
  4811.   Struct_Type uname ()
  4812.  
  4813.  DESCRIPTION
  4814.   The `uname' function returns a structure containing information
  4815.   about the operating system.  The structure contains the following
  4816.   fields:
  4817.  
  4818.        sysname  (Name of the operating system)
  4819.        nodename (Name of the node within the network)
  4820.        release  (Release level of the OS)
  4821.        version  (Current version of the release)
  4822.        machine  (Name of the hardware)
  4823.  
  4824.  
  4825.  NOTES
  4826.   Not all systems support this function.
  4827.  
  4828.  SEE ALSO
  4829.   getenv
  4830.  
  4831. --------------------------------------------------------------
  4832.  
  4833. alarm
  4834.  
  4835.  SYNOPSIS
  4836.   Schedule an alarm signal
  4837.  
  4838.  USAGE
  4839.   alarm (UInt_Type secs [, Ref_Type secs_remaining])
  4840.  
  4841.  DESCRIPTION
  4842.   The `alarm' function schedules the delivery of a SIGALRM
  4843.   signal in `secs' seconds.  Any previously scheduled alarm will
  4844.   be canceled.  If `secs' is zero, then no new alarm will be
  4845.   scheduled.  If the second argument is present, then it must be a
  4846.   reference to a variable whose value will be set upon return to the
  4847.   number of seconds remaining for a previously scheduled alarm to take
  4848.   place.
  4849.  
  4850.  EXAMPLE
  4851.   This example shows demonstrates how the `alarm' function may be
  4852.   used to read from a file within a specified amount of time:
  4853.  
  4854.     define sigalrm_handler (sig)
  4855.     {
  4856.        throw ReadError, "Read timed out";
  4857.     }
  4858.     define read_or_timeout (secs)
  4859.     {
  4860.        variable line, e;
  4861.        variable fp = fopen ("/dev/tty", "r");
  4862.        signal (SIGALRM, &sigalrm_handler);
  4863.        alarm (secs);
  4864.        try (e)
  4865.          {
  4866.             () = fputs ("Enter some text> ", stdout); () = fflush (stdout);
  4867.             if (-1 == fgets (&line, fp))
  4868.               line = NULL;
  4869.          }
  4870.        catch IOError: { message (e.message); line = NULL; }
  4871.        return line;
  4872.     }
  4873.  
  4874.  
  4875.  NOTES
  4876.   Some operating systems may implement the `sleep' function using
  4877.   `alarm'.  As a result, it is not a good idea to mix calls to
  4878.   `alarm' and `sleep'.
  4879.  
  4880.   The default action for SIGALRM is to terminate the process.
  4881.   Hence, if `alarm' is called it is wise to establish a signal
  4882.   handler for `SIGALRM'.
  4883.  
  4884.  SEE ALSO
  4885.   signal, sleep
  4886.  
  4887. --------------------------------------------------------------
  4888.  
  4889. signal
  4890.  
  4891.  SYNOPSIS
  4892.   Establish a signal handler
  4893.  
  4894.  USAGE
  4895.   signal (Int_Type sig, Ref_Type func [,Ref_Type old_func])
  4896.  
  4897.  DESCRIPTION
  4898.   The `signal' function assigns the signal handler represented by
  4899.   `func' to the signal `sig'.  Here `func' is usually
  4900.   reference to a function that takes an integer argument (the signal)
  4901.   and returns nothing, e.g.,
  4902.  
  4903.     define signal_handler (sig)
  4904.     {
  4905.        return;
  4906.     }
  4907.  
  4908.   Alternatively, `func' may be given by one of the symbolic
  4909.   constants SIG_IGN or SIG_DFL to indicate that the
  4910.   signal is to be ignored or given its default action, respectively.
  4911.  
  4912.   The first parameter, `sig', specifies the signal to be handled.
  4913.   The actual supported values vary with the OS.  Common values on Unix
  4914.   include `SIGHUP', `SIGINT', and `SIGTERM'.
  4915.  
  4916.   If a third argument is present, then it must be a reference to a
  4917.   variable whose value will be set to the value of the previously
  4918.   installed handler.
  4919.  
  4920.  EXAMPLE
  4921.   This example establishes a handler for `SIGTSTP'.
  4922.  
  4923.     static define sig_suspend ();  % forward declaration
  4924.     static define sig_suspend (sig)
  4925.     {
  4926.        message ("SIGTSTP received-- stopping");
  4927.        signal (sig, SIG_DFL);
  4928.        () = kill (getpid(), SIGSTOP);
  4929.        message ("Resuming");
  4930.        signal (sig, &sig_suspend);
  4931.     }
  4932.     signal (SIGTSTP, &sig_suspend);
  4933.  
  4934.  
  4935.  NOTES
  4936.   Currently the signal interface is supported only on systems that
  4937.   implement signals according to the POSIX standard.
  4938.  
  4939.   Once a signal has been received, it will remain blocked until after
  4940.   the signal handler has completed.  This is the reason SIGSTOP
  4941.   was used in the above signal handler instead of SIGTSTP.
  4942.  
  4943.  SEE ALSO
  4944.   alarm, sigsuspend, sigprocmask
  4945.  
  4946. --------------------------------------------------------------
  4947.  
  4948. sigprocmask
  4949.  
  4950.  SYNOPSIS
  4951.   Change the list of currently blocked signals
  4952.  
  4953.  USAGE
  4954.   sigprocmask (Int_Type how, Array_Type mask [,Ref_Type old_mask])
  4955.  
  4956.  DESCRIPTION
  4957.   The `sigprocmask' function may be used to change the list of
  4958.   signals that are currently blocked.  The first parameter indicates
  4959.   how this is accomplished.  Specifically, `how' must be one of
  4960.   the following values: SIG_BLOCK, SIG_UNBLOCK, or
  4961.   SIG_SETMASK.
  4962.  
  4963.   If `how' is SIG_BLOCK, then the set of blocked signals
  4964.   will be the union the current set with the values specified in the
  4965.   `mask' argument.
  4966.  
  4967.   If `how' is SIG_UNBLOCK, then the signals specified by
  4968.   the `mask' parameter will be removed from the currently blocked
  4969.   set.
  4970.  
  4971.   If `how' is SIG_SETMASK, then the set of blocked signals
  4972.   will be set to those given by the `mask'.
  4973.  
  4974.   If a third argument is present, then it must be a reference to a
  4975.   variable whose value will be set to the previous signal mask.
  4976.  
  4977.  SEE ALSO
  4978.   signal, sigsuspend, alarm
  4979.  
  4980. --------------------------------------------------------------
  4981.  
  4982. sigsuspend
  4983.  
  4984.  SYNOPSIS
  4985.   Suspend the process until a signal is delivered
  4986.  
  4987.  USAGE
  4988.   sigsuspend ([Array_Type signal_mask])
  4989.  
  4990.  DESCRIPTION
  4991.   The
  4992. sigsuspend
  4993.  function suspends the current process
  4994.   until a signal is received.  An optional array argument may be
  4995.   passed to the function to specify a list of signals that should be
  4996.   temporarily blocked while waiting for a signal.
  4997.  
  4998.  EXAMPLE
  4999.   The following example pauses the current process for 10 seconds
  5000.   while blocking the SIGHUP and SIGINT signals.
  5001.  
  5002.      static variable Tripped;
  5003.      define sigalrm_handler (sig)
  5004.      {
  5005.         Tripped = 1;
  5006.      }
  5007.      signal (SIGALRM, &sigalrm_handler);
  5008.      Tripped = 0;
  5009.      alarm (10);
  5010.      while (Tripped == 0) sigsuspend ([SIGHUP, SIGINT]);
  5011.  
  5012.   Note that in this example the call to `sigsuspend' was wrapped in
  5013.   a while-loop.  This was necessary because there is no guarantee that
  5014.   another signal would not cause `sigsuspend' to return.
  5015.  
  5016.  SEE ALSO
  5017.   signal, alarm, sigprocmask
  5018.  
  5019. --------------------------------------------------------------
  5020.  
  5021. dup
  5022.  
  5023.  SYNOPSIS
  5024.   Duplicate the value at the top of the stack
  5025.  
  5026.  USAGE
  5027.   dup ()
  5028.  
  5029.  DESCRIPTION
  5030.   This function returns an exact duplicate of the object on top of the
  5031.   stack.  For some objects such as arrays or structures, it creates a
  5032.   new reference to the object.  However, for simple scalar S-Lang types such
  5033.   as strings, integers, and doubles, it creates a new copy of the
  5034.   object.
  5035.  
  5036.  SEE ALSO
  5037.   pop, typeof
  5038.  
  5039. --------------------------------------------------------------
  5040.  
  5041. exch
  5042.  
  5043.  SYNOPSIS
  5044.   Exchange two items on the stack
  5045.  
  5046.  USAGE
  5047.   exch ()
  5048.  
  5049.  DESCRIPTION
  5050.   The `exch' swaps the two top items on the stack.
  5051.  
  5052.  SEE ALSO
  5053.   pop, _stk_reverse, _stk_roll
  5054.  
  5055. --------------------------------------------------------------
  5056.  
  5057. pop
  5058.  
  5059.  SYNOPSIS
  5060.   Discard an item from the stack
  5061.  
  5062.  USAGE
  5063.   pop ()
  5064.  
  5065.  DESCRIPTION
  5066.   The `pop' function removes the top item from the stack.
  5067.  
  5068.  SEE ALSO
  5069.   _pop_n, __pop_args
  5070.  
  5071. --------------------------------------------------------------
  5072.  
  5073. __pop_args
  5074.  
  5075.  SYNOPSIS
  5076.   Remove n function arguments from the stack
  5077.  
  5078.  USAGE
  5079.   args = __pop_args(Integer_Type n)
  5080.  
  5081.  DESCRIPTION
  5082.   This function, together with the companion function
  5083.   `__push_args', is useful for creating a function that takes a
  5084.   variable number of arguments, as well as passing the arguments of
  5085.   one function to another function.
  5086.  
  5087.   `__pop_args' removes the specified number of values from the
  5088.   stack and returns them as an array of structures of the corresponding
  5089.   length.  Each structure in the array consists of a single
  5090.   field called `value', which represents the value of the
  5091.   argument.
  5092.  
  5093.  EXAMPLE
  5094.   Consider the following function.  It prints all its arguments to
  5095.   `stdout' separated by spaces:
  5096.  
  5097.     define print_args ()
  5098.     {
  5099.        variable i;
  5100.        variable args = __pop_args (_NARGS);
  5101.  
  5102.        for (i = 0; i < _NARGS; i++)
  5103.          {
  5104.             () = fputs (string (args[i].value), stdout);
  5105.             () = fputs (" ", stdout);
  5106.          }
  5107.        () = fputs ("\n", stdout);
  5108.        () = fflush (stdout);
  5109.     }
  5110.  
  5111.   Now consider the problem of defining a function called `ones'
  5112.   that returns a multi-dimensional array with all the elements set to
  5113.   1.  For example, `ones(10)' should return a 1-d array of 10
  5114.   ones, whereas `ones(10,20)' should return a 10x20 array.
  5115.  
  5116.     define ones ()
  5117.     {
  5118.       !if (_NARGS) return 1;
  5119.       variable a;
  5120.  
  5121.       a = __pop_args (_NARGS);
  5122.       return @Array_Type (Integer_Type, [__push_args (a)]) + 1;
  5123.     }
  5124.  
  5125.   Here, `__push_args' was used to push the arguments passed to
  5126.   the `ones' function onto the stack to be used when dereferencing
  5127.   Array_Type.
  5128.  
  5129.  SEE ALSO
  5130.   __push_args, typeof, _pop_n
  5131.  
  5132. --------------------------------------------------------------
  5133.  
  5134. _pop_n
  5135.  
  5136.  SYNOPSIS
  5137.   Remove objects from the stack
  5138.  
  5139.  USAGE
  5140.   _pop_n (Integer_Type n);
  5141.  
  5142.  DESCRIPTION
  5143.   The `_pop_n' function removes the specified number of objects
  5144.   from the top of the stack.
  5145.  
  5146.  SEE ALSO
  5147.   _stkdepth, pop
  5148.  
  5149. --------------------------------------------------------------
  5150.  
  5151. _print_stack
  5152.  
  5153.  SYNOPSIS
  5154.   Print the values on the stack.
  5155.  
  5156.  USAGE
  5157.   _print_stack ()
  5158.  
  5159.  DESCRIPTION
  5160.   This function dumps out what is currently on the S-Lang stack.  It does not
  5161.   alter the stack and it is usually used for debugging purposes.
  5162.  
  5163.  SEE ALSO
  5164.   _stkdepth, string, message
  5165.  
  5166. --------------------------------------------------------------
  5167.  
  5168. __push_args
  5169.  
  5170.  SYNOPSIS
  5171.   Remove n function arguments onto the stack
  5172.  
  5173.  USAGE
  5174.   __push_args (Struct_Type args);
  5175.  
  5176.  DESCRIPTION
  5177.   This function together with the companion function `__pop_args'
  5178.   is useful for the creation of functions that take a variable number
  5179.   of arguments.  See the description of `__pop_args' for more
  5180.   information.
  5181.  
  5182.  SEE ALSO
  5183.   __pop_args, typeof, _pop_n
  5184.  
  5185. --------------------------------------------------------------
  5186.  
  5187. _stkdepth
  5188.  
  5189.  USAGE
  5190.   Get the number of objects currently on the stack
  5191.  
  5192.  SYNOPSIS
  5193.   Integer_Type _stkdepth ()
  5194.  
  5195.  DESCRIPTION
  5196.   The `_stkdepth' function returns number of items on the stack.
  5197.  
  5198.  SEE ALSO
  5199.   _print_stack, _stk_reverse, _stk_roll
  5200.  
  5201. --------------------------------------------------------------
  5202.  
  5203. _stk_reverse
  5204.  
  5205.  SYNOPSIS
  5206.   Reverse the order of the objects on the stack
  5207.  
  5208.  USAGE
  5209.   _stk_reverse (Integer_Type n)
  5210.  
  5211.  DESCRIPTION
  5212.    The `_stk_reverse' function reverses the order of the top
  5213.    `n' items on the stack.
  5214.  
  5215.  SEE ALSO
  5216.   _stkdepth, _stk_roll
  5217.  
  5218. --------------------------------------------------------------
  5219.  
  5220. _stk_roll
  5221.  
  5222.  SYNOPSIS
  5223.   Roll items on the stack
  5224.  
  5225.  USAGE
  5226.   _stk_roll (Integer_Type n)
  5227.  
  5228.  DESCRIPTION
  5229.   This function may be used to alter the arrangement of objects on the
  5230.   stack.  Specifically, if the integer `n' is positive, the top
  5231.   `n' items on the stack are rotated up.  If
  5232.   `n' is negative, the top `abs(n)' items on the stack are
  5233.   rotated down.
  5234.  
  5235.  EXAMPLE
  5236.   If the stack looks like:
  5237.  
  5238.     item-0
  5239.     item-1
  5240.     item-2
  5241.     item-3
  5242.  
  5243.   where `item-0' is at the top of the stack, then
  5244.   `_stk_roll(-3)' will change the stack to:
  5245.  
  5246.     item-2
  5247.     item-0
  5248.     item-1
  5249.     item-3
  5250.  
  5251.  
  5252.  NOTES
  5253.   This function only has an effect if `abs(n) > 1'.
  5254.  
  5255.  SEE ALSO
  5256.   _stkdepth, _stk_reverse, _pop_n, _print_stack
  5257.  
  5258. --------------------------------------------------------------
  5259.  
  5260. clearerr
  5261.  
  5262.  SYNOPSIS
  5263.   Clear the error of a file stream
  5264.  
  5265.  USAGE
  5266.   clearerr (File_Type fp
  5267.  
  5268.  DESCRIPTION
  5269.   The `clearerr' function clears the error and end-of-file flags
  5270.   associated with the open file stream `fp'.
  5271.  
  5272.  SEE ALSO
  5273.   ferror, feof, fopen
  5274.  
  5275. --------------------------------------------------------------
  5276.  
  5277. fclose
  5278.  
  5279.  SYNOPSIS
  5280.   Close a file
  5281.  
  5282.  USAGE
  5283.   Integer_Type fclose (File_Type fp)
  5284.  
  5285.  DESCRIPTION
  5286.   The `fclose' function may be used to close an open file pointer
  5287.   `fp'.  Upon success it returns zero, and upon failure it sets
  5288.   `errno' and returns `-1'.  Failure usually indicates a that
  5289.   the file system is full or that `fp' does not refer to an open file.
  5290.  
  5291.  NOTES
  5292.   Many C programmers call `fclose' without checking the return
  5293.   value.  The S-Lang language requires the programmer to explicitly
  5294.   handle any value returned by a function.  The simplest way to
  5295.   handle the return value from `fclose' is to call it via:
  5296.  
  5297.      () = fclose (fp);
  5298.  
  5299.  
  5300.  SEE ALSO
  5301.   fopen, fgets, fflush, pclose, errno
  5302.  
  5303. --------------------------------------------------------------
  5304.  
  5305. fdopen
  5306.  
  5307.  SYNOPSIS
  5308.   Convert a FD_Type file descriptor to a stdio File_Type object
  5309.  
  5310.  USAGE
  5311.   File_Type fdopen (FD_Type, String_Type mode)
  5312.  
  5313.  DESCRIPTION
  5314.    The `fdopen' function creates and returns a stdio
  5315.    File_Type object from the open FD_Type
  5316.    descriptor `fd'.  The `mode' parameter corresponds to the
  5317.    `mode' parameter of the `fopen' function and must be
  5318.    consistent with the mode of the descriptor `fd'.  The function
  5319.    returns NULL upon failure and sets `errno'.
  5320.  
  5321.  NOTES
  5322.    The `fclose' function does not close the File_Type object
  5323.    returned from this function.  The underlying file object must be
  5324.    closed by the `close' function.
  5325.  
  5326.  SEE ALSO
  5327.   fileno, fopen, open, close, fclose
  5328.  
  5329. --------------------------------------------------------------
  5330.  
  5331. feof
  5332.  
  5333.  SYNOPSIS
  5334.   Get the end-of-file status
  5335.  
  5336.  USAGE
  5337.   Integer_Type feof (File_Type fp)
  5338.  
  5339.  DESCRIPTION
  5340.   This function may be used to determine the state of the end-of-file
  5341.   indicator of the open file descriptor `fp'.  It returns zero
  5342.   if the indicator is not set, or non-zero if it is.  The end-of-file
  5343.   indicator may be cleared by the `clearerr' function.
  5344.  
  5345.  SEE ALSO
  5346.   ferror, clearerr, fopen
  5347.  
  5348. --------------------------------------------------------------
  5349.  
  5350. ferror
  5351.  
  5352.  SYNOPSIS
  5353.   Determine the error status of an open file descriptor
  5354.  
  5355.  USAGE
  5356.   Integer_Type ferror (File_Type fp)
  5357.  
  5358.  DESCRIPTION
  5359.   This function may be used to determine the state of the error
  5360.   indicator of the open file descriptor `fp'.  It returns zero
  5361.   if the indicator is not set, or non-zero if it is.  The error
  5362.   indicator may be cleared by the `clearerr' function.
  5363.  
  5364.  SEE ALSO
  5365.   feof, clearerr, fopen
  5366.  
  5367. --------------------------------------------------------------
  5368.  
  5369. fflush
  5370.  
  5371.  SYNOPSIS
  5372.   Flush an output stream
  5373.  
  5374.  USAGE
  5375.   Integer_Type fflush (File_Type fp)
  5376.  
  5377.  DESCRIPTION
  5378.   The `fflush' function may be used to update the stdio _output_
  5379.   stream specified by `fp'.  It returns 0 upon success, or
  5380.   -1 upon failure and sets `errno' accordingly.  In
  5381.   particular, this function will fail if `fp' does not represent
  5382.   an open output stream, or if `fp' is associated with a disk file and
  5383.   there is insufficient disk space.
  5384.  
  5385.  EXAMPLE
  5386.   This example illustrates how to use the `fflush' function
  5387.   without regard to the return value:
  5388.  
  5389.     () = fputs ("Enter value> ", stdout);
  5390.     () = fflush (stdout);
  5391.  
  5392.  
  5393.  SEE ALSO
  5394.   fopen, fclose
  5395.  
  5396. --------------------------------------------------------------
  5397.  
  5398. fgets
  5399.  
  5400.  SYNOPSIS
  5401.   Read a line from a file
  5402.  
  5403.  USAGE
  5404.   Integer_Type fgets (SLang_Ref_Type ref, File_Type fp)
  5405.  
  5406.  DESCRIPTION
  5407.   `fgets' reads a line from the open file specified by `fp'
  5408.   and places the characters in the variable whose reference is
  5409.   specified by `ref'.
  5410.   It returns -1 if `fp' is not associated with an open file
  5411.   or an attempt was made to read at the end the file; otherwise, it
  5412.   returns the number of characters read.
  5413.  
  5414.  EXAMPLE
  5415.   The following example returns the lines of a file via a linked list:
  5416.  
  5417.     define read_file (file)
  5418.     {
  5419.        variable buf, fp, root, tail;
  5420.        variable list_type = struct { text, next };
  5421.  
  5422.        root = NULL;
  5423.  
  5424.        fp = fopen(file, "r");
  5425.        if (fp == NULL)
  5426.          error("fopen %s failed." file);
  5427.        while (-1 != fgets (&buf, fp))
  5428.          {
  5429.             if (root == NULL)
  5430.               {
  5431.                  root = @list_type;
  5432.                  tail = root;
  5433.               }
  5434.             else
  5435.               {
  5436.                  tail.next = @list_type;
  5437.                  tail = tail.next;
  5438.               }
  5439.             tail.text = buf;
  5440.             tail.next = NULL;
  5441.          }
  5442.        () = fclose (fp);
  5443.        return root;
  5444.     }
  5445.  
  5446.  
  5447.  SEE ALSO
  5448.   fgetslines, fopen, fclose, fputs, fread, error
  5449.  
  5450. --------------------------------------------------------------
  5451.  
  5452. fgetslines
  5453.  
  5454.  SYNOPSIS
  5455.   Read lines as an array from an open file
  5456.  
  5457.  USAGE
  5458.   String_Type[] fgetslines (File_Type fp [,Int_Type num])
  5459.  
  5460.  DESCRIPTION
  5461.   The `fgetslines' function reads lines a specified number of
  5462.   lines as an array of strings from the file associated with the
  5463.   file pointer `fp'.  If the number of lines to be read is left
  5464.   unspecified, the function will return the rest of the lines in the
  5465.   file.  If the file is empty, an empty string array will be returned.
  5466.   The function returns NULL upon error.
  5467.  
  5468.  EXAMPLE
  5469.   The following function returns the number of lines in a file:
  5470.  
  5471.     define count_lines_in_file (file)
  5472.     {
  5473.        variable fp, lines;
  5474.  
  5475.        fp = fopen (file, "r");
  5476.        if (fp == NULL)
  5477.          return -1;
  5478.  
  5479.        lines = fgetslines (fp);
  5480.        if (lines == NULL)
  5481.          return -1;
  5482.  
  5483.        return length (lines);
  5484.     }
  5485.  
  5486.   Note that the file was implicitly closed when the variable `fp'
  5487.   goes out of scope (in the case, when the function returns).
  5488.  
  5489.  SEE ALSO
  5490.   fgets, fread, fopen, fputslines
  5491.  
  5492. --------------------------------------------------------------
  5493.  
  5494. fopen
  5495.  
  5496.  SYNOPSIS
  5497.   Open a file
  5498.  
  5499.  USAGE
  5500.   File_Type fopen (String_Type f, String_Type m)
  5501.  
  5502.  DESCRIPTION
  5503.   The `fopen' function opens a file `f' according to the mode
  5504.   string `m'.  Allowed values for `m' are:
  5505.  
  5506.      "r"    Read only
  5507.      "w"    Write only
  5508.      "a"    Append
  5509.      "r+"   Reading and writing at the beginning of the file.
  5510.      "w+"   Reading and writing.  The file is created if it does not
  5511.               exist; otherwise, it is truncated.
  5512.      "a+"   Reading and writing at the end of the file.  The file is created
  5513.               if it does not already exist.
  5514.  
  5515.   In addition, the mode string can also include the letter `'b''
  5516.   as the last character to indicate that the file is to be opened in
  5517.   binary mode.
  5518.  
  5519.   Upon success, `fopen' returns a File_Type object which is
  5520.   meant to be used by other operations that require an open file
  5521.   pointer.  Upon failure, the function returns NULL.
  5522.  
  5523.  EXAMPLE
  5524.   The following function opens a file in append mode and writes a
  5525.   string to it:
  5526.  
  5527.     define append_string_to_file (file, str)
  5528.     {
  5529.        variable fp = fopen (file, "a");
  5530.        if (fp == NULL)
  5531.          throw OpenError, "$file could not be opened"$;
  5532.        () = fputs (string, fp);
  5533.        () = fclose (fp);
  5534.     }
  5535.  
  5536.   Note that the return values from `fputs' and `fclose' were
  5537.   ignored.
  5538.  
  5539.  NOTES
  5540.   There is no need to explicitly close a file opened with `fopen'.
  5541.   If the returned File_Type object goes out of scope, the
  5542.   interpreter will automatically close the file.  However, explicitly
  5543.   closing a file with `fclose' and checking its return value is
  5544.   recommended.
  5545.  
  5546.  SEE ALSO
  5547.   fclose, fgets, fputs, popen
  5548.  
  5549. --------------------------------------------------------------
  5550.  
  5551. fprintf
  5552.  
  5553.  SYNOPSIS
  5554.   Create and write a formatted string to a file
  5555.  
  5556.  USAGE
  5557.   Int_Type fprintf (File_Type fp, String_Type fmt, ...)
  5558.  
  5559.  DESCRIPTION
  5560.   `fprintf' formats the objects specified by the variable argument
  5561.   list according to the format `fmt' and write the result to the
  5562.   open file pointer `fp'.
  5563.  
  5564.   The format string obeys the same syntax and semantics as the
  5565.   `sprintf' format string.  See the description of the
  5566.   `sprintf' function for more information.
  5567.  
  5568.   `fprintf' returns the number of bytes written to the file,
  5569.   or -1 upon error.
  5570.  
  5571.  SEE ALSO
  5572.   fputs, printf, fwrite, message
  5573.  
  5574. --------------------------------------------------------------
  5575.  
  5576. fputs
  5577.  
  5578.  SYNOPSIS
  5579.   Write a string to an open stream
  5580.  
  5581.  USAGE
  5582.   Integer_Type fputs (String_Type s, File_Type fp)
  5583.  
  5584.  DESCRIPTION
  5585.   The `fputs' function writes the string `s' to the open file
  5586.   pointer `fp'. It returns -1 upon failure and sets `errno',
  5587.   otherwise it returns the length of the string.
  5588.  
  5589.  EXAMPLE
  5590.   The following function opens a file in append mode and uses the
  5591.   `fputs' function to write to it.
  5592.  
  5593.     define append_string_to_file (str, file)
  5594.     {
  5595.        variable fp;
  5596.        fp = fopen (file, "a");
  5597.        if (fp == NULL)
  5598.          throw OpenError, "Unable to open $file"$;
  5599.        if ((-1 == fputs (s, fp))
  5600.            or (-1 == fclose (fp)))
  5601.          throw WriteError, "Error writing to $file";
  5602.     }
  5603.  
  5604.  
  5605.  NOTES
  5606.   One must not disregard the return value from the `fputs'
  5607.   function.  Doing so may lead to a stack overflow error.
  5608.  
  5609.   To write an object that contains embedded null characters, use the
  5610.   `fwrite' function.
  5611.  
  5612.  SEE ALSO
  5613.   fclose, fopen, fgets, fwrite
  5614.  
  5615. --------------------------------------------------------------
  5616.  
  5617. fputslines
  5618.  
  5619.  SYNOPSIS
  5620.   Write an array of strings to an open file
  5621.  
  5622.  USAGE
  5623.   Int_Type fputslines (String_Type[]a, File_Type fp)
  5624.  
  5625.  DESCRIPTION
  5626.   The `fputslines' function writes an array of strings to the
  5627.   specified file pointer.  It returns the number of elements
  5628.   successfully written.  Any NULL elements in the array will be
  5629.   skipped.
  5630.  
  5631.  EXAMPLE
  5632.  
  5633.     if (length (lines) != fputslines (fp, lines))
  5634.       throw WriteError;
  5635.  
  5636.  
  5637.  SEE ALSO
  5638.   fputs, fgetslines, fopen
  5639.  
  5640. --------------------------------------------------------------
  5641.  
  5642. fread
  5643.  
  5644.  SYNOPSIS
  5645.   Read binary data from a file
  5646.  
  5647.  USAGE
  5648.   UInt_Type fread (Ref_Type b, DataType_Type t, UInt_Type n, File_Type fp)
  5649.  
  5650.  DESCRIPTION
  5651.   The `fread' function may be used to read `n' objects of type
  5652.   `t' from an open file pointer `fp'.  Upon success, it
  5653.   returns the number of objects read from the file and places the
  5654.   objects in variable specified by `b'.  Upon error or
  5655.   end-of-file, it returns -1 and sets `errno' accordingly.
  5656.  
  5657.   If more than one object is read from the file, those objects will be
  5658.   placed in an array of the appropriate size.
  5659.  
  5660.  EXAMPLE
  5661.   The following example illustrates how to read 50 integers from a file:
  5662.  
  5663.      define read_50_ints_from_a_file (file)
  5664.      {
  5665.         variable fp, n, buf;
  5666.  
  5667.         fp = fopen (file, "rb");
  5668.         if (fp == NULL)
  5669.           throw OpenError;
  5670.         n = fread (&buf, Int_Type, 50, fp);
  5671.         if (n == -1)
  5672.           throw ReadError, "fread failed";
  5673.         () = fclose (fp);
  5674.         return buf;
  5675.      }
  5676.  
  5677.  
  5678.  NOTES
  5679.   Use the `pack' and `unpack' functions to read data with a
  5680.   specific byte-ordering.
  5681.  
  5682.   The `fread_bytes' function may be used to read a specified number of
  5683.   bytes in the form of a binary string (`BString_Type').
  5684.  
  5685.  SEE ALSO
  5686.   fread_bytes, fwrite, fgets, fopen, pack, unpack
  5687.  
  5688. --------------------------------------------------------------
  5689.  
  5690. fread_bytes
  5691.  
  5692.  SYNOPSIS
  5693.   Read bytes from a file as a binary-string
  5694.  
  5695.  USAGE
  5696.   UInt_Type fread_bytes (Ref_Type b, UInt_Type n, File_Type fp)
  5697.  
  5698.  DESCRIPTION
  5699.   The `fread_bytes' function may be used to read `n' bytes
  5700.   from from an open file pointer `fp'.  Upon success, it returns
  5701.   the number of bytes read from the file and assigns to the variable
  5702.   attached to the reference `b' a binary string formed from the
  5703.   bytes read.  Upon error or end of file, the function returns
  5704.   -1 and sets `errno' accordingly.
  5705.  
  5706.  NOTES
  5707.   Use the `pack' and `unpack' functions to read data with a
  5708.   specific byte-ordering.
  5709.  
  5710.  SEE ALSO
  5711.   fread, fwrite, fgets, fopen, pack, unpack
  5712.  
  5713. --------------------------------------------------------------
  5714.  
  5715. fseek
  5716.  
  5717.  SYNOPSIS
  5718.   Reposition a stdio stream
  5719.  
  5720.  USAGE
  5721.   Integer_Type fseek (File_Type fp, LLong_Type ofs, Integer_Type whence
  5722.  
  5723.  DESCRIPTION
  5724.   The `fseek' function may be used to reposition the file position
  5725.   pointer associated with the open file stream `fp'. Specifically,
  5726.   it moves the pointer `ofs' bytes relative to the position
  5727.   indicated by `whence'.  If `whence' is set to one of the symbolic
  5728.   constants SEEK_SET, SEEK_CUR, or SEEK_END, the
  5729.   offset is relative to the start of the file, the current position
  5730.   indicator, or end-of-file, respectively.
  5731.  
  5732.   The function returns 0 upon success, or -1 upon failure and sets
  5733.   `errno' accordingly.
  5734.  
  5735.  EXAMPLE
  5736.     define rewind (fp)
  5737.     {
  5738.        if (0 == fseek (fp, 0, SEEK_SET)) return;
  5739.        vmessage ("rewind failed, reason: %s", errno_string (errno));
  5740.     }
  5741.  
  5742.  SEE ALSO
  5743.   ftell, fopen
  5744.  
  5745. --------------------------------------------------------------
  5746.  
  5747. ftell
  5748.  
  5749.  SYNOPSIS
  5750.   Obtain the current position in an open stream
  5751.  
  5752.  USAGE
  5753.   LLong_Type ftell (File_Type fp)
  5754.  
  5755.  DESCRIPTION
  5756.   The ftell function may be used to obtain the current position in the
  5757.   stream associated with the open file pointer `fp'.  It returns
  5758.   the position of the pointer measured in bytes from the beginning of
  5759.   the file.  Upon error, it returns `-1' and sets `errno'
  5760.   accordingly.
  5761.  
  5762.  SEE ALSO
  5763.   fseek, fopen
  5764.  
  5765. --------------------------------------------------------------
  5766.  
  5767. fwrite
  5768.  
  5769.  SYNOPSIS
  5770.   Write binary data to a file
  5771.  
  5772.  USAGE
  5773.   UInt_Type fwrite (b, File_Type fp)
  5774.  
  5775.  DESCRIPTION
  5776.   The `fwrite' function may be used to write the object represented by
  5777.   `b' to an open file.  If `b' is a string or an array, the
  5778.   function will attempt to write all elements of the object to the
  5779.   file.  It returns the number of elements successfully written,
  5780.   otherwise it returns -1 upon error and sets `errno'
  5781.   accordingly.
  5782.  
  5783.  EXAMPLE
  5784.   The following example illustrates how to write an integer array to a
  5785.   file.  In this example, `fp' is an open file descriptor:
  5786.  
  5787.      variable a = [1:50];     % 50 element integer array
  5788.      if (50 != fwrite (a, fp))
  5789.        throw WriteError;
  5790.  
  5791.   Here is how to write the array one element at a time:
  5792.  
  5793.      variable ai, a = [1:50];
  5794.  
  5795.      foreach ai (a)
  5796.        {
  5797.           if (1 != fwrite(ai, fp))
  5798.             throw WriteError;
  5799.        }
  5800.  
  5801.  
  5802.  NOTES
  5803.   Not all data types may be supported the `fwrite' function.  It
  5804.   is supported by all vector, scalar, and string objects.
  5805.  
  5806.  SEE ALSO
  5807.   fread, fputs, fopen, pack, unpack
  5808.  
  5809. --------------------------------------------------------------
  5810.  
  5811. pclose
  5812.  
  5813.  SYNOPSIS
  5814.   Close a process pipe
  5815.  
  5816.  USAGE
  5817.   Integer_Type pclose (File_Type fp)
  5818.  
  5819.  DESCRIPTION
  5820.   The `pclose' function waits for the process associated with
  5821.   `fp' to exit and the returns the exit status of the command.
  5822.  
  5823.  SEE ALSO
  5824.   pclose, fclose
  5825.  
  5826. --------------------------------------------------------------
  5827.  
  5828. popen
  5829.  
  5830.  SYNOPSIS
  5831.   Open a pipe to a process
  5832.  
  5833.  USAGE
  5834.   File_Type popen (String_Type cmd, String_Type mode)
  5835.  
  5836.  DESCRIPTION
  5837.   The `popen' function executes a process specified by `cmd'
  5838.   and opens a unidirectional pipe to the newly created process.  The
  5839.   `mode' indicates whether or not the pipe is open for reading
  5840.   or writing.  Specifically, if `mode' is `"r"', then the
  5841.   pipe is opened for reading, or if `mode' is `"w"', then the
  5842.   pipe will be open for writing.
  5843.  
  5844.   Upon success, a File_Type pointer will be returned, otherwise
  5845.   the function failed and NULL will be returned.
  5846.  
  5847.  NOTES
  5848.   This function is not available on all systems.
  5849.  
  5850.  SEE ALSO
  5851.   pclose, fopen
  5852.  
  5853. --------------------------------------------------------------
  5854.  
  5855. printf
  5856.  
  5857.  SYNOPSIS
  5858.   Create and write a formatted string to stdout
  5859.  
  5860.  USAGE
  5861.   Int_Type printf (String_Type fmt, ...)
  5862.  
  5863.  DESCRIPTION
  5864.   `printf' formats the objects specified by the variable argument
  5865.   list according to the format `fmt' and write the result to
  5866.   `stdout'.  This function is equivalent to `fprintf' used
  5867.   with the `stdout' file pointer.  See `fprintf' for more
  5868.   information.
  5869.  
  5870.   `printf' returns the number of bytes written or -1 upon error.
  5871.  
  5872.  NOTES
  5873.   Many C programmers do not check the return status of the
  5874.   `printf' C library function.  Make sure that if you do not care
  5875.   about whether or not the function succeeds, then code it as in the
  5876.   following example:
  5877.  
  5878.      () = printf ("%s laid %d eggs\n", chicken_name, num_egg);
  5879.  
  5880.  
  5881.  SEE ALSO
  5882.   fputs, printf, fwrite, message
  5883.  
  5884. --------------------------------------------------------------
  5885.  
  5886. create_delimited_string
  5887.  
  5888.  SYNOPSIS
  5889.   Concatenate strings using a delimiter
  5890.  
  5891.  USAGE
  5892.   String_Type create_delimited_string (delim, s_1, s_2, ..., s_n, n)
  5893.  
  5894.     String_Type delim, s_1, ..., s_n
  5895.     Int_Type n
  5896.  
  5897.  
  5898.  DESCRIPTION
  5899.   `create_delimited_string' performs a concatenation operation on
  5900.   the `n' strings `s_1', ...,`s_n', using the string
  5901.   `delim' as a delimiter.  The resulting string is equivalent to
  5902.   one obtained via
  5903.  
  5904.       s_1 + delim + s_2 + delim + ... + s_n
  5905.  
  5906.  
  5907.  EXAMPLE
  5908.  
  5909.     create_delimited_string ("/", "user", "local", "bin", 3);
  5910.  
  5911.   will produce `"usr/local/bin"'.
  5912.  
  5913.  NOTES
  5914.   New code should use the `strjoin' function, which performs a
  5915.   similar task.
  5916.  
  5917.  SEE ALSO
  5918.   strjoin, is_list_element, extract_element, strchop, strcat
  5919.  
  5920. --------------------------------------------------------------
  5921.  
  5922. extract_element
  5923.  
  5924.  SYNOPSIS
  5925.   Extract the nth element of a string with delimiters
  5926.  
  5927.  USAGE
  5928.   String_Type extract_element (String_Type list, Int_Type nth, Int_Type delim)
  5929.  
  5930.  DESCRIPTION
  5931.   The `extract_element' function may be used to extract the
  5932.   `nth' substring of a string delimited by the character given by
  5933.   the `delim' parameter.  If the string contains fewer than the
  5934.   requested substring, the function will return NULL.  Substring
  5935.   elements are numbered from 0.
  5936.  
  5937.  EXAMPLE
  5938.   The expression
  5939.  
  5940.      extract_element ("element 0, element 1, element 2", 1, ',')
  5941.  
  5942.   returns the string `" element 1"', whereas
  5943.  
  5944.      extract_element ("element 0, element 1, element 2", 1, ' ')
  5945.  
  5946.   returns `"0,"'.
  5947.  
  5948.   The following function may be used to compute the number of elements
  5949.   in the list:
  5950.  
  5951.      define num_elements (list, delim)
  5952.      {
  5953.         variable nth = 0;
  5954.         while (NULL != extract_element (list, nth, delim))
  5955.           nth++;
  5956.         return nth;
  5957.      }
  5958.  
  5959.   Alternatively, the `strchop' function may be more useful.  In
  5960.   fact, `extract_element' may be expressed in terms of the
  5961.   function `strchop' as
  5962.  
  5963.     define extract_element (list, nth, delim)
  5964.     {
  5965.        list = strchop(list, delim, 0);
  5966.        if (nth >= length (list))
  5967.          return NULL;
  5968.        else
  5969.          return list[nth];
  5970.     }
  5971.  
  5972.    and the `num_elements' function used above may be recoded more
  5973.    simply as:
  5974.  
  5975.     define num_elements (list, delim)
  5976.     {
  5977.        return length (strchop (length, delim, 0));
  5978.     }
  5979.  
  5980.  
  5981.  NOTES
  5982.   New code should make use of the `List_Type' object for lists.
  5983.  
  5984.  SEE ALSO
  5985.   is_list_element, is_substr, strtok, strchop, create_delimited_string
  5986.  
  5987. --------------------------------------------------------------
  5988.  
  5989. glob_to_regexp
  5990.  
  5991.  SYNOPSIS
  5992.   Convert a globbing expression to a regular expression
  5993.  
  5994.  USAGE
  5995.   String_Type glob_to_regexp (String_Type g)
  5996.  
  5997.  DESCRIPTION
  5998.   This function may be used to convert a so-called globbing expression
  5999.   to a regular expression.  A globbing expression is frequently used
  6000.   for matching filenames where '?' represents a single character and
  6001.   '*' represents 0 or more characters.
  6002.  
  6003.  NOTES
  6004.   The `slsh' program that is distributed with the S-Lang library
  6005.   includes a function called `glob' that is a wrapper around
  6006.   `glob_to_regexp' and `listdir'.  It returns a list of
  6007.   filenames matching a globbing expression.
  6008.  
  6009.  SEE ALSO
  6010.   string_match, listdir
  6011.  
  6012. --------------------------------------------------------------
  6013.  
  6014. is_list_element
  6015.  
  6016.  SYNOPSIS
  6017.   Test whether a delimited string contains a specific element
  6018.  
  6019.  USAGE
  6020.   Int_Type is_list_element (String_Type list, String_Type elem, Int_Type delim)
  6021.  
  6022.  DESCRIPTION
  6023.   The `is_list_element' function may be used to determine whether
  6024.   or not a delimited list of substring, `list', contains the element
  6025.   `elem'.  If `elem' is not an element of `list', the function
  6026.   will return zero, otherwise, it returns 1 plus the matching element
  6027.   number.
  6028.  
  6029.  EXAMPLE
  6030.   The expression
  6031.  
  6032.      is_list_element ("element 0, element 1, element 2", "0,", ' ');
  6033.  
  6034.   returns `2' since `"0,"' is element number one of the list
  6035.   (numbered from zero).
  6036.  
  6037.  SEE ALSO
  6038.   extract_element, is_substr, create_delimited_string
  6039.  
  6040. --------------------------------------------------------------
  6041.  
  6042. is_substr
  6043.  
  6044.  SYNOPSIS
  6045.   Test for a specified substring within a string
  6046.  
  6047.  USAGE
  6048.   Int_Type is_substr (String_Type a, String_Type b)
  6049.  
  6050.  DESCRIPTION
  6051.   This function may be used to determine if `a' contains the
  6052.   string `b'.  If it does not, the function returns 0; otherwise it
  6053.   returns the position of the first occurrence of `b' in `a'
  6054.   expressed in terms of characters, not bytes.
  6055.  
  6056.  NOTES
  6057.   This function regards the first character of a string to be given by
  6058.   a position value of 1.
  6059.  
  6060.   The distinction between characters and bytes is significant in UTF-8
  6061.   mode.
  6062.  
  6063.  SEE ALSO
  6064.   substr, string_match, strreplace
  6065.  
  6066. --------------------------------------------------------------
  6067.  
  6068. make_printable_string
  6069.  
  6070.  SYNOPSIS
  6071.   Format a string suitable for parsing
  6072.  
  6073.  USAGE
  6074.   String_Type make_printable_string(String_Type str)
  6075.  
  6076.  DESCRIPTION
  6077.   This function formats a string in such a way that it may be used as
  6078.   an argument to the `eval' function.  The resulting string is
  6079.   identical to `str' except that it is enclosed in double quotes
  6080.   and the backslash, newline, control, and double quote characters are
  6081.   expanded.
  6082.  
  6083.  SEE ALSO
  6084.   eval, str_quote_string
  6085.  
  6086. --------------------------------------------------------------
  6087.  
  6088. Sprintf
  6089.  
  6090.  SYNOPSIS
  6091.   Format objects into a string (deprecated)
  6092.  
  6093.  USAGE
  6094.   String_Type Sprintf (String_Type format, ..., Int_Type n)
  6095.  
  6096.  DESCRIPTION
  6097.   This function performs a similar task as the `sprintf'
  6098.   function but requires an additional argument that specifies the
  6099.   number of items to format.  For this reason, the `sprintf'
  6100.   function should be used.
  6101.  
  6102.  SEE ALSO
  6103.   sprintf, string, sscanf, vmessage
  6104.  
  6105. --------------------------------------------------------------
  6106.  
  6107. sprintf
  6108.  
  6109.  SYNOPSIS
  6110.   Format objects into a string
  6111.  
  6112.  USAGE
  6113.   String_Type sprintf (String fmt, ...)
  6114.  
  6115.  DESCRIPTION
  6116.   The `sprintf' function formats a string from a variable number
  6117.   of arguments according to according to the format specification
  6118.   string `fmt'.
  6119.  
  6120.   The format string is a C library `sprintf' style format
  6121.   descriptor.  Briefly, the format string may consist of ordinary
  6122.   characters (not including the `%' character), which are copied
  6123.   into the output string as-is, and conversion specification sequences
  6124.   introduced by the `%' character.  The number of additional
  6125.   arguments passed to the `sprintf' function must be consistent
  6126.   with the number required by the format string.
  6127.  
  6128.   The `%' character in the format string starts a conversion
  6129.   specification that indicates how an object is to be formatted.
  6130.   Usually the percent character is followed immediately by a
  6131.   conversion specification character.  However, it may optionally be
  6132.   followed by flag characters, field width characters, and precision
  6133.   modifiers, as described below.
  6134.  
  6135.   The character immediately following the `%' character may be
  6136.   one or more of the following flag characters:
  6137.  
  6138.     -         Use left-justification
  6139.     #         Use alternate form for formatting.
  6140.     0         Use 0 padding
  6141.     +         Preceed a number by a plus or minus sign.
  6142.     (space)   Use a blank instead of a plus sign.
  6143.  
  6144.  
  6145.   The flag characters (if any) may be followed by an optional field
  6146.   width specification string represented by one or more digit
  6147.   characters.  If the size of the formatted object is less than the
  6148.   field width, it will be right-justified in the specified field
  6149.   width, unless the `-' flag was given, in which case it will be
  6150.   left justified.
  6151.  
  6152.   If the next character in the control sequence is a period, then it
  6153.   introduces a precision specification sequence.  The precision is
  6154.   given by the digit characters following the period.  If none are
  6155.   given the precision is taken to be 0.  The meaning of the precision
  6156.   specifier depends upon the type of conversion:  For integer
  6157.   conversions, it gives the minimum number digits to appear in the
  6158.   output.  For `e' and `f' floating point conversions, it
  6159.   gives the number of digits to appear after the decimal point.  For
  6160.   the `g' floating point conversion, it gives the maximum number
  6161.   of significant digits to appear.  Finally for the `s' and
  6162.   `S' conversions it specifies the maximum number of characters
  6163.   to be copied to the output string.
  6164.  
  6165.   The next character in the sequence may be a modifier that controls
  6166.   the size of object to be formatted. It may consist of the following
  6167.   characters:
  6168.  
  6169.      h    This character is ignored in the current implementation.
  6170.      l    The integer is be formatted as a long integer, or a
  6171.           character as a wide character.
  6172.  
  6173.  
  6174.   Finally the conversion specification sequence ends with the
  6175.   conversion specification character that describes how the object is
  6176.   to be
  6177.   formatted:
  6178.  
  6179.      s    as a string
  6180.      f    as a floating point number
  6181.      e    as a float using exponential form, e.g., 2.345e08
  6182.      g    format as e or g, depending upon its value
  6183.      c    as a character
  6184.      %    a literal percent character
  6185.      d    as a signed decimal integer
  6186.      u    as an unsigned decimal integer
  6187.      o    as an octal integer
  6188.      X    as hexadecimal
  6189.      S    convert object to a string and format accordingly
  6190.  
  6191.   The `S' conversion specifier is a S-Lang extension which will
  6192.   cause the corresponding object to be converted to a string using the
  6193.   `string' function, and then converted as `s'. formatted as
  6194.   string.  In fact, `sprintf("%S",x)' is equivalent to
  6195.   `sprintf("%s",string(x))'.
  6196.  
  6197.  EXAMPLE
  6198.  
  6199.     sprintf("%s","hello")               ===> "hello"
  6200.     sprintf("%s %s","hello", "world")   ===> "hello world"
  6201.     sprintf("Agent %.3d",,7)            ===> "Agent 007"
  6202.     sprintf("%S",PI)                    ===> "3.14159"
  6203.     sprintf("%g",PI)                    ===> "3.14159"
  6204.     sprintf("%.2g",PI)                  ===> "3.1"
  6205.     sprintf("%.2e",PI)                  ===> "3.14e+00"
  6206.     sprintf("%.2f",PI)                  ===> "3.14"
  6207.     sprintf("|% 8.2f|",PI)              ===> "|    3.14|"
  6208.     sprintf("|%-8.2f|",PI)              ===> "|3.14    |"
  6209.     sprintf("|%+8.2f|",PI)              ===> "|   +3.14|"
  6210.     sprintf("%S",{1,2,3})               ===> "List_Type with 3 elements"
  6211.     sprintf("%S",1+2i)                  ===> "(1 + 2i)"
  6212.  
  6213.  
  6214.  NOTES
  6215.   The `set_float_format' function controls the format for the
  6216.   `S' conversion of floating point numbers.
  6217.  
  6218.  SEE ALSO
  6219.   string, sscanf, message
  6220.  
  6221. --------------------------------------------------------------
  6222.  
  6223. sscanf
  6224.  
  6225.  SYNOPSIS
  6226.   Parse a formatted string
  6227.  
  6228.  USAGE
  6229.   Int_Type sscanf (s, fmt, r1, ... rN)
  6230.  
  6231.     String_Type s, fmt;
  6232.     Ref_Type r1, ..., rN
  6233.  
  6234.  
  6235.  DESCRIPTION
  6236.  The `sscanf' function parses the string `s' according to the
  6237.  format `fmt' and sets the variables whose references are given by
  6238.  `r1', ..., `rN'.  The function returns the number of
  6239.  references assigned, or throws an exception upon error.
  6240.  
  6241.  The format string `fmt' consists of ordinary characters and
  6242.  conversion specifiers.  A conversion specifier begins with the
  6243.  special character `%' and is described more fully below.  A white
  6244.  space character in the format string matches any amount of whitespace
  6245.  in the input string.  Parsing of the format string stops whenever a
  6246.  match fails.
  6247.  
  6248.  The `%' character is used to denote a conversion specifier whose
  6249.  general form is given by `%[*][width][type]format' where the
  6250.  brackets indicate optional items.  If `*' is present, then the
  6251.  conversion will be performed but no assignment to a reference will be
  6252.  made.  The `width' specifier specifies the maximum field width to
  6253.  use for the conversion.  The `type' modifier is used to indicate
  6254.  the size of the object, e.g., a short integer, as follows.
  6255.  
  6256.  If _type_ is given as the character `h', then if the format
  6257.  conversion is for an integer (`dioux'), the object assigned will
  6258.  be a short integer.  If _type_ is `l', then the conversion
  6259.  will be to a long integer for integer conversions, or to a double
  6260.  precision floating point number for floating point conversions.
  6261.  
  6262.  The format specifier is a character that specifies the conversion:
  6263.  
  6264.        %     Matches a literal percent character.  No assignment is
  6265.              performed.
  6266.        d     Matches a signed decimal integer.
  6267.        D     Matches a long decimal integer (equiv to `ld')
  6268.        u     Matches an unsigned decimal integer
  6269.        U     Matches an unsigned long decimal integer (equiv to `lu')
  6270.        i     Matches either a hexadecimal integer, decimal integer, or
  6271.              octal integer.
  6272.        I     Equivalent to `li'.
  6273.        x     Matches a hexadecimal integer.
  6274.        X     Matches a long hexadecimal integer (same as `lx').
  6275.        e,f,g Matches a decimal floating point number (Float_Type).
  6276.        E,F,G Matches a double precision floating point number, same as `lf'.
  6277.        s     Matches a string of non-whitespace characters (String_Type).
  6278.        c     Matches one character.  If width is given, width
  6279.              characters are matched.
  6280.        n     Assigns the number of characters scanned so far.
  6281.        [...] Matches zero or more characters from the set of characters
  6282.              enclosed by the square brackets.  If '^' is given as the
  6283.              first character, then the complement set is matched.
  6284.  
  6285.  
  6286.  EXAMPLE
  6287.  Suppose that `s' is `"Coffee: (3,4,12.4)"'.  Then
  6288.  
  6289.     n = sscanf (s, "%[a-zA-Z]: (%d,%d,%lf)", &item, &x, &y, &z);
  6290.  
  6291.  will set `n' to 4, `item' to `"Coffee"', `x' to 3,
  6292.  `y' to 4, and `z' to the double precision number
  6293.  `12.4'.  However,
  6294.  
  6295.     n = sscanf (s, "%s: (%d,%d,%lf)", &item, &x, &y, &z);
  6296.  
  6297.  will set `n' to 1, `item' to `"Coffee:"' and the
  6298.  remaining variables will not be assigned.
  6299.  
  6300.  SEE ALSO
  6301.   sprintf, unpack, string, atof, int, integer, string_match
  6302.  
  6303. --------------------------------------------------------------
  6304.  
  6305. strbytelen
  6306.  
  6307.  SYNOPSIS
  6308.   Get the number of bytes in a string
  6309.  
  6310.  USAGE
  6311.   Int_Type strbytelen (String_Type s)
  6312.  
  6313.  DESCRIPTION
  6314.   This function returns the number of bytes in a string.  In UTF-8
  6315.   mode, this value is generally different from the number of
  6316.   characters in a string.  For the latter information, the
  6317.   `strlen' or `strcharlen' functions should be used.
  6318.  
  6319.  SEE ALSO
  6320.   strlen, strcharlen, length
  6321.  
  6322. --------------------------------------------------------------
  6323.  
  6324. strbytesub
  6325.  
  6326.  SYNOPSIS
  6327.   Replace a byte with another in a string.
  6328.  
  6329.  USAGE
  6330.   String_Type strsub (String_Type s, Int_Type pos, UChar_Type b)
  6331.  
  6332.  DESCRIPTION
  6333.   The `strbytesub' function may be be used to substitute the byte
  6334.   `b' for the byte at byte position `pos' of the string
  6335.   `s'.  The resulting string is returned.
  6336.  
  6337.  NOTES
  6338.   The first byte in the string `s' is specified by `pos'
  6339.   equal to 1.  This function uses byte semantics, not character
  6340.   semantics.
  6341.  
  6342.  SEE ALSO
  6343.   strsub, is_substr, strreplace, strbytelen
  6344.  
  6345. --------------------------------------------------------------
  6346.  
  6347. strcat
  6348.  
  6349.  SYNOPSIS
  6350.   Concatenate strings
  6351.  
  6352.  USAGE
  6353.   String_Type strcat (String_Type a_1, ...,  String_Type a_N)
  6354.  
  6355.  DESCRIPTION
  6356.    The `strcat' function concatenates its N string
  6357.    arguments `a_1', ... `a_N' together and returns the result.
  6358.  
  6359.  EXAMPLE
  6360.  
  6361.     strcat ("Hello", " ", "World");
  6362.  
  6363.    produces the string `"Hello World"'.
  6364.  
  6365.  NOTES
  6366.    This function is equivalent to the binary operation `a_1+...+a_N'.
  6367.    However, `strcat' is much faster making it the preferred method
  6368.    to concatenate strings.
  6369.  
  6370.  SEE ALSO
  6371.   sprintf, strjoin
  6372.  
  6373. --------------------------------------------------------------
  6374.  
  6375. strcharlen
  6376.  
  6377.  SYNOPSIS
  6378.   Get the number of characters in a string including combining characters
  6379.  
  6380.  USAGE
  6381.   Int_Type strcharlen (String_Type s)
  6382.  
  6383.  DESCRIPTION
  6384.   The `strcharlen' function returns the number of characters in a
  6385.   string.  If the string contains combining characters, then they are
  6386.   also counted.  Use the `strlen' function to obtain the
  6387.   character count ignoring combining characters.
  6388.  
  6389.  SEE ALSO
  6390.   strlen, strbytelen
  6391.  
  6392. --------------------------------------------------------------
  6393.  
  6394. strchop
  6395.  
  6396.  SYNOPSIS
  6397.   Chop or split a string into substrings.
  6398.  
  6399.  USAGE
  6400.   String_Type[] strchop (String_Type str, Int_Type delim, Int_Type quote)
  6401.  
  6402.  DESCRIPTION
  6403.    The `strchop' function may be used to split-up a string
  6404.    `str' that consists of substrings delimited by the character
  6405.    specified by `delim'.  If the integer `quote' is non-zero,
  6406.    it will be taken as a quote character for the delimiter.  The
  6407.    function returns the substrings as an array.
  6408.  
  6409.  EXAMPLE
  6410.    The following function illustrates how to sort a comma separated
  6411.    list of strings:
  6412.  
  6413.      define sort_string_list (a)
  6414.      {
  6415.         variable i, b, c;
  6416.         b = strchop (a, ',', 0);
  6417.  
  6418.         i = array_sort (b);
  6419.         b = b[i];   % rearrange
  6420.  
  6421.         % Convert array back into comma separated form
  6422.         return strjoin (b, ",");
  6423.      }
  6424.  
  6425.  
  6426.  SEE ALSO
  6427.   strchopr, strjoin, strtok
  6428.  
  6429. --------------------------------------------------------------
  6430.  
  6431. strchopr
  6432.  
  6433.  SYNOPSIS
  6434.   Chop or split a string into substrings.
  6435.  
  6436.  USAGE
  6437.   String_Type[] strchopr (String_Type str, String_Type delim, String_Type quote)
  6438.  
  6439.  DESCRIPTION
  6440.   This routine performs exactly the same function as `strchop' except
  6441.   that it returns the substrings in the reverse order.  See the
  6442.   documentation for `strchop' for more information.
  6443.  
  6444.  SEE ALSO
  6445.   strchop, strtok, strjoin
  6446.  
  6447. --------------------------------------------------------------
  6448.  
  6449. strcmp
  6450.  
  6451.  SYNOPSIS
  6452.   Compare two strings
  6453.  
  6454.  USAGE
  6455.   Int_Type strcmp (String_Type a, String_Type b)
  6456.  
  6457.  DESCRIPTION
  6458.    The `strcmp' function may be used to perform a case-sensitive
  6459.    string comparison, in the lexicographic sense, on strings `a' and
  6460.    `b'.  It returns 0 if the strings are identical, a negative integer
  6461.    if `a' is less than `b', or a positive integer if `a' is greater
  6462.    than `b'.
  6463.  
  6464.  EXAMPLE
  6465.    The `strup' function may be used to perform a case-insensitive
  6466.    string comparison:
  6467.  
  6468.     define case_insensitive_strcmp (a, b)
  6469.     {
  6470.       return strcmp (strup(a), strup(b));
  6471.     }
  6472.  
  6473.  
  6474.  NOTES
  6475.    One may also use one of the binary comparison operators, e.g.,
  6476.    `a > b'.
  6477.  
  6478.  SEE ALSO
  6479.   strup, strncmp
  6480.  
  6481. --------------------------------------------------------------
  6482.  
  6483. strcompress
  6484.  
  6485.  SYNOPSIS
  6486.   Remove excess whitespace characters from a string
  6487.  
  6488.  USAGE
  6489.   String_Type strcompress (String_Type s, String_Type white)
  6490.  
  6491.  DESCRIPTION
  6492.   The `strcompress' function compresses the string `s' by
  6493.   replacing a sequence of one or more characters from the set
  6494.   `white' by the first character of `white'. In addition, it
  6495.   also removes all leading and trailing characters from `s' that
  6496.   are part of `white'.
  6497.  
  6498.  EXAMPLE
  6499.   The expression
  6500.  
  6501.     strcompress (",;apple,,cherry;,banana", ",;");
  6502.  
  6503.   returns the string `"apple,cherry,banana"'.
  6504.  
  6505.  SEE ALSO
  6506.   strtrim, strtrans, str_delete_chars
  6507.  
  6508. --------------------------------------------------------------
  6509.  
  6510. string_match
  6511.  
  6512.  SYNOPSIS
  6513.   Match a string against a regular expression
  6514.  
  6515.  USAGE
  6516.   Int_Type string_match(String_Type str, String_Type pat, Int_Type nth)
  6517.  
  6518.  DESCRIPTION
  6519.   The `string_match' function returns zero if `str' does not
  6520.   match regular expression specified by `pat'.  This function
  6521.   performs the match starting at the `nth' byte in the string
  6522.   `str' (numbered from 1).  This function returns the position in
  6523.   bytes (numbered from 1) of the start of the match in `str'.  If
  6524.   the match fails, the function will return -1. The exact substring
  6525.   matched may be found using `string_match_nth'.
  6526.  
  6527.  NOTES
  6528.   Positions in the string are specified using byte-offsets not
  6529.   character offsets. The value returned by this function is measured
  6530.   from the beginning of the string `str'.
  6531.  
  6532.   The function is not yet UTF-8 aware.  If possible, consider using
  6533.   the `pcre' module for better, more sophisticated regular
  6534.   expressions.
  6535.  
  6536.  SEE ALSO
  6537.   string_match_nth, strcmp, strncmp
  6538.  
  6539. --------------------------------------------------------------
  6540.  
  6541. string_match_nth
  6542.  
  6543.  SYNOPSIS
  6544.   Get the result of the last call to string_match
  6545.  
  6546.  USAGE
  6547.   (Int_Type pos, Int_Type len) = string_match_nth(Int_Type nth)
  6548.  
  6549.  DESCRIPTION
  6550.   The `string_match_nth' function returns two integers describing
  6551.   the result of the last call to `string_match'.  It returns both
  6552.   the zero-based byte-position of the `nth' submatch and
  6553.   the length of the match.
  6554.  
  6555.   By convention, `nth' equal to zero means the entire match.
  6556.   Otherwise, `nth' must be an integer with a value 1 through 9,
  6557.   and refers to the set of characters matched by the `nth' regular
  6558.   expression enclosed by the pairs `\(, \)'.
  6559.  
  6560.  EXAMPLE
  6561.   Consider:
  6562.  
  6563.      variable matched, pos, len;
  6564.      matched = string_match("hello world", "\([a-z]+\) \([a-z]+\)"R, 1);
  6565.      if (matched)
  6566.        (pos, len) = string_match_nth(2);
  6567.  
  6568.   This will set `matched' to 1 since a match will be found at the
  6569.   first byte position, `pos' to 6 since `w' is offset 6 bytes
  6570.   from the beginning of the string, and `len' to 5 since
  6571.   `"world"' is 5 bytes long.
  6572.  
  6573.  NOTES
  6574.   The position offset is _not_ affected by the value of the offset
  6575.   parameter to the `string_match' function. For example, if the
  6576.   value of the last parameter to the `string_match' function had
  6577.   been 3, `pos' would still have been set to 6.
  6578.  
  6579.  SEE ALSO
  6580.   string_match
  6581.  
  6582. --------------------------------------------------------------
  6583.  
  6584. strjoin
  6585.  
  6586.  SYNOPSIS
  6587.   Concatenate elements of a string array
  6588.  
  6589.  USAGE
  6590.   String_Type strjoin (Array_Type a, String_Type delim)
  6591.  
  6592.  DESCRIPTION
  6593.    The `strjoin' function operates on an array of strings by joining
  6594.    successive elements together separated with a delimiter `delim'.
  6595.    If `delim' is the empty string `""', then the result will
  6596.    simply be the concatenation of the elements.
  6597.  
  6598.  EXAMPLE
  6599.    Suppose that
  6600.  
  6601.       days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
  6602.  
  6603.    Then `strjoin (days,"+")' will produce
  6604.    `"Sun+Mon+Tue+Wed+Thu+Fri+Sat+Sun"'.  Similarly,
  6605.    `strjoin (["","",""], "X")' will produce `"XX"'.
  6606.  
  6607.  SEE ALSO
  6608.   strchop, strcat
  6609.  
  6610. --------------------------------------------------------------
  6611.  
  6612. strlen
  6613.  
  6614.  SYNOPSIS
  6615.   Compute the length of a string
  6616.  
  6617.  USAGE
  6618.   Int_Type strlen (String_Type a)
  6619.  
  6620.  DESCRIPTION
  6621.    The `strlen' function may be used to compute the character
  6622.    length of a string ignoring the presence of combining characters.
  6623.    The `strcharlen' function may be used to count combining
  6624.    characters as distinct characters.  For byte-semantics, use the
  6625.    `strbytelen' function.
  6626.  
  6627.  EXAMPLE
  6628.    After execution of
  6629.  
  6630.    variable len = strlen ("hello");
  6631.  
  6632.    `len' will have a value of `5'.
  6633.  
  6634.  SEE ALSO
  6635.   strbytelen, strcharlen, bstrlen, length, substr
  6636.  
  6637. --------------------------------------------------------------
  6638.  
  6639. strlow
  6640.  
  6641.  SYNOPSIS
  6642.   Convert a string to lowercase
  6643.  
  6644.  USAGE
  6645.   String_Type strlow (String_Type s)
  6646.  
  6647.  DESCRIPTION
  6648.   The `strlow' function takes a string `s' and returns another
  6649.   string identical to `s' except that all upper case characters
  6650.   that are contained in `s' are converted converted to lower case.
  6651.  
  6652.  EXAMPLE
  6653.   The function
  6654.  
  6655.     define Strcmp (a, b)
  6656.     {
  6657.       return strcmp (strlow (a), strlow (b));
  6658.     }
  6659.  
  6660.   performs a case-insensitive comparison operation of two strings by
  6661.   converting them to lower case first.
  6662.  
  6663.  SEE ALSO
  6664.   strup, tolower, strcmp, strtrim, define_case
  6665.  
  6666. --------------------------------------------------------------
  6667.  
  6668. strnbytecmp
  6669.  
  6670.  SYNOPSIS
  6671.   Compare the first n bytes of two strings
  6672.  
  6673.  USAGE
  6674.   Int_Type strnbytecmp (String_Type a, String_Type b, Int_Type n)
  6675.  
  6676.  DESCRIPTION
  6677.   This function compares the first `n' bytes of the strings
  6678.   `a' and `b'.  See the documentation for `strcmp' for
  6679.   information about the return value.
  6680.  
  6681.  SEE ALSO
  6682.   strncmp, strncharcmp, strcmp
  6683.  
  6684. --------------------------------------------------------------
  6685.  
  6686. strncharcmp
  6687.  
  6688.  SYNOPSIS
  6689.   Compare the first n characters of two strings
  6690.  
  6691.  USAGE
  6692.   Int_Type strncharcmp (String_Type a, String_Type b, Int_Type n)
  6693.  
  6694.  DESCRIPTION
  6695.   This function compares the first `n' characters of the strings
  6696.   `a' and `b' counting combining characters as distinct
  6697.   characters.  See the documentation for `strcmp' for information
  6698.   about the return value.
  6699.  
  6700.  SEE ALSO
  6701.   strncmp, strnbytecmp, strcmp
  6702.  
  6703. --------------------------------------------------------------
  6704.  
  6705. strncmp
  6706.  
  6707.  SYNOPSIS
  6708.   Compare the first few characters of two strings
  6709.  
  6710.  USAGE
  6711.   Int_Type strncmp (String_Type a, String_Type b, Int_Type n)
  6712.  
  6713.  DESCRIPTION
  6714.   This function behaves like `strcmp' except that it compares only the
  6715.   first `n' characters in the strings `a' and `b'.
  6716.   See the documentation for `strcmp' for information about the return
  6717.   value.
  6718.  
  6719.   In counting characters, combining characters are not counted,
  6720.   although they are used in the comparison.  Use the
  6721.   `strncharcmp' function if you want combining characters to be
  6722.   included in the character count.  The `strnbytecmp' function
  6723.   should be used to compare bytes.
  6724.  
  6725.  EXAMPLE
  6726.   The expression
  6727.  
  6728.      strcmp ("apple", "appliance", 3);
  6729.  
  6730.   will return zero since the first three characters match.
  6731.  
  6732.  NOTES
  6733.   This function uses character semantics.
  6734.  
  6735.  SEE ALSO
  6736.   strcmp, strlen, strncharcmp, strnbytecmp
  6737.  
  6738. --------------------------------------------------------------
  6739.  
  6740. strreplace
  6741.  
  6742.  SYNOPSIS
  6743.   Replace one or more substrings
  6744.  
  6745.  USAGE
  6746.   (new, n) = strreplace (a, b, c, max_n)
  6747.  
  6748.    String_Type a, b, c, rep;
  6749.    Int_Type n, max_n;
  6750.  
  6751.  
  6752.  DESCRIPTION
  6753.   The `strreplace' function may be used to replace one or more
  6754.   occurrences of `b' in `a' with `c'.  If the integer
  6755.   `max_n' is positive, then the first `max_n' occurrences of
  6756.   `b' in `a' will be replaced.  Otherwise, if `max_n' is
  6757.   negative, then the last `abs(max_n)' occurrences will be replaced.
  6758.  
  6759.   The function returns the resulting string and an integer indicating
  6760.   how many replacements were made.
  6761.  
  6762.  EXAMPLE
  6763.   The following function illustrates how `strreplace' may be used
  6764.   to remove all occurrences of a specified substring:
  6765.  
  6766.      define delete_substrings (a, b)
  6767.      {
  6768.         (a, ) = strreplace (a, b, "", strlen (a));
  6769.         return a;
  6770.      }
  6771.  
  6772.  
  6773.  SEE ALSO
  6774.   is_substr, strsub, strtrim, strtrans, str_delete_chars
  6775.  
  6776. --------------------------------------------------------------
  6777.  
  6778. strsub
  6779.  
  6780.  SYNOPSIS
  6781.   Replace a character with another in a string.
  6782.  
  6783.  USAGE
  6784.   String_Type strsub (String_Type s, Int_Type pos, Int_Type ch)
  6785.  
  6786.  DESCRIPTION
  6787.   The `strsub' function may be used to substitute the character
  6788.   `ch' for the character at character position `pos' of the string
  6789.   `s'.  The resulting string is returned.
  6790.  
  6791.  EXAMPLE
  6792.  
  6793.     define replace_spaces_with_comma (s)
  6794.     {
  6795.       variable n;
  6796.       while (n = is_substr (s, " "), n) s = strsub (s, n, ',');
  6797.       return s;
  6798.     }
  6799.  
  6800.   For uses such as this, the `strtrans' function is a better choice.
  6801.  
  6802.  NOTES
  6803.   The first character in the string `s' is specified by `pos'
  6804.   equal to 1.  This function uses character semantics, not byte
  6805.   semantics.
  6806.  
  6807.  SEE ALSO
  6808.   is_substr, strreplace, strlen
  6809.  
  6810. --------------------------------------------------------------
  6811.  
  6812. strtok
  6813.  
  6814.  SYNOPSIS
  6815.   Extract tokens from a string
  6816.  
  6817.  USAGE
  6818.   String_Type[] strtok (String_Type str [,String_Type white])
  6819.  
  6820.  DESCRIPTION
  6821.   `strtok' breaks the string `str' into a series of tokens
  6822.   and returns them as an array of strings.  If the second parameter
  6823.   `white' is present, then it specifies the set of characters
  6824.   that are to be regarded as whitespace when extracting the tokens,
  6825.   and may consist of the whitespace characters or a range of such
  6826.   characters. If the first character of `white' is `'^'',
  6827.   then the whitespace characters consist of all characters except
  6828.   those in `white'.  For example, if `white' is `"
  6829.   \t\n,;."', then those characters specify the whitespace
  6830.   characters.  However, if `white' is given by
  6831.   `"^a-zA-Z0-9_"', then any character is a whitespace character
  6832.   except those in the ranges `a-z', `A-Z', `0-9', and
  6833.   the underscore character.  To specify the hyphen character as a
  6834.   whitespace character, then it should be the first character of the
  6835.   whitespace string.  In addition to ranges, the whitespace specifier
  6836.   may also include character classes:
  6837.  
  6838.     \w matches a unicode "word" character, taken to be alphanumeric.
  6839.     \a alphabetic character, excluding digits
  6840.     \s matches whitespace
  6841.     \l matches lowercase
  6842.     \u matches uppercase
  6843.     \d matches a digit
  6844.     \\ matches a backslash
  6845.  
  6846.  
  6847.   If the second parameter is not present, then it defaults to
  6848.   `"\s"'.
  6849.  
  6850.  EXAMPLE
  6851.   The following example may be used to count the words in a text file:
  6852.  
  6853.     define count_words (file)
  6854.     {
  6855.        variable fp, line, count;
  6856.  
  6857.        fp = fopen (file, "r");
  6858.        if (fp == NULL) return -1;
  6859.  
  6860.        count = 0;
  6861.        while (-1 != fgets (&line, fp))
  6862.          {
  6863.            line = strtok (line, "^\\a");
  6864.            count += length (line);
  6865.          }
  6866.        () = fclose (fp);
  6867.        return count;
  6868.     }
  6869.  
  6870.   Here a word was assumed to consist only of alphabetic characters.
  6871.  
  6872.  SEE ALSO
  6873.   strchop, strcompress, strjoin
  6874.  
  6875. --------------------------------------------------------------
  6876.  
  6877. strtrans
  6878.  
  6879.  SYNOPSIS
  6880.   Replace characters in a string
  6881.  
  6882.  USAGE
  6883.   String_Type strtrans (str, old_set, new_set)
  6884.  
  6885.    String_Type str, old_set, new_set;
  6886.  
  6887.  
  6888.  DESCRIPTION
  6889.   The `strtrans' function may be used to replace all the characters
  6890.   from the set `old_set' with the corresponding characters from
  6891.   `new_set' in the string `str'.  If `new_set' is empty,
  6892.   then the characters in `old_set' will be removed from `str'.
  6893.  
  6894.   If `new_set' is not empty, then `old_set' and
  6895.   `new_set' must be commensurate.  Each set may consist of
  6896.   character ranges such as `A-Z' and character classes:
  6897.  
  6898.     \w matches a unicode "word" character, taken to be alphanumeric.
  6899.     \a alphabetic character, excluding digits
  6900.     \s matches whitespace
  6901.     \l matches lowercase
  6902.     \u matches uppercase
  6903.     \d matches a digit
  6904.     \\ matches a backslash
  6905.  
  6906.   If the first character of a set is `^' then the set is taken to
  6907.   be the complement set.
  6908.  
  6909.  EXAMPLE
  6910.  
  6911.     str = strtrans (str, "\\u", "\\l");   % lower-case str
  6912.     str = strtrans (str, "^0-9", " ");    % Replace anything but 0-9 by space
  6913.  
  6914.  
  6915.  SEE ALSO
  6916.   strreplace, strtrim, strup, strlow
  6917.  
  6918. --------------------------------------------------------------
  6919.  
  6920. strtrim
  6921.  
  6922.  SYNOPSIS
  6923.   Remove whitespace from the ends of a string
  6924.  
  6925.  USAGE
  6926.   String_Type strtrim (String_Type s [,String_Type w])
  6927.  
  6928.  DESCRIPTION
  6929.   The `strtrim' function removes all leading and trailing whitespace
  6930.   characters from the string `s' and returns the result.  The
  6931.   optional second parameter specifies the set of whitespace
  6932.   characters.  If the argument is not present, then the set defaults
  6933.   to `"\s"'.  The whitespace specification may consist of
  6934.   character ranges such as `A-Z' and character classes:
  6935.  
  6936.     \w matches a unicode "word" character, taken to be alphanumeric.
  6937.     \a alphabetic character, excluding digits
  6938.     \s matches whitespace
  6939.     \l matches lowercase
  6940.     \u matches uppercase
  6941.     \d matches a digit
  6942.     \\ matches a backslash
  6943.  
  6944.   If the first character of a set is `^' then the set is taken to
  6945.   be the complement set.
  6946.  
  6947.  SEE ALSO
  6948.   strtrim_beg, strtrim_end, strcompress
  6949.  
  6950. --------------------------------------------------------------
  6951.  
  6952. strtrim_beg
  6953.  
  6954.  SYNOPSIS
  6955.   Remove leading whitespace from a string
  6956.  
  6957.  USAGE
  6958.   String_Type strtrim_beg (String_Type s [,String_Type w])
  6959.  
  6960.  DESCRIPTION
  6961.   The `strtrim_beg' function removes all leading whitespace
  6962.   characters from the string `s' and returns the result.
  6963.   The optional second parameter specifies the set of whitespace
  6964.   characters.  See the documentation for the `strtrim' function
  6965.   form more information about the whitespace parameter.
  6966.  
  6967.  SEE ALSO
  6968.   strtrim, strtrim_end, strcompress
  6969.  
  6970. --------------------------------------------------------------
  6971.  
  6972. strtrim_end
  6973.  
  6974.  SYNOPSIS
  6975.   Remove trailing whitespace from a string
  6976.  
  6977.  USAGE
  6978.   String_Type strtrim_end (String_Type s [,String_Type w])
  6979.  
  6980.  DESCRIPTION
  6981.   The `strtrim_end' function removes all trailing whitespace
  6982.   characters from the string `s' and returns the result.  The
  6983.   optional second parameter specifies the set of whitespace
  6984.   characters.  See the documentation for the `strtrim' function
  6985.   form more information about the whitespace parameter.
  6986.  
  6987.  SEE ALSO
  6988.   strtrim, strtrim_beg, strcompress
  6989.  
  6990. --------------------------------------------------------------
  6991.  
  6992. strup
  6993.  
  6994.  SYNOPSIS
  6995.   Convert a string to uppercase
  6996.  
  6997.  USAGE
  6998.   String_Type strup (String_Type s)
  6999.  
  7000.  DESCRIPTION
  7001.   The `strup' function takes a string `s' and returns another
  7002.   string identical to `s' except that all lower case characters
  7003.   that contained in `s' are converted to upper case.
  7004.  
  7005.  EXAMPLE
  7006.   The function
  7007.  
  7008.     define Strcmp (a, b)
  7009.     {
  7010.       return strcmp (strup (a), strup (b));
  7011.     }
  7012.  
  7013.   performs a case-insensitive comparison operation of two strings by
  7014.   converting them to upper case first.
  7015.  
  7016.  SEE ALSO
  7017.   strlow, toupper, strcmp, strtrim, define_case, strtrans
  7018.  
  7019. --------------------------------------------------------------
  7020.  
  7021. str_delete_chars
  7022.  
  7023.  SYNOPSIS
  7024.   Delete characters from a string
  7025.  
  7026.  USAGE
  7027.   String_Type str_delete_chars (String_Type str, String_Type del_set
  7028.  
  7029.  DESCRIPTION
  7030.   This function may be used to delete the set of characters specified
  7031.   by `del_set' from the string `str'.  The result is returned.
  7032.  
  7033.   The set of characters to be deleted may include ranges such as
  7034.   `A-Z' and characters classes:
  7035.  
  7036.     \w matches a unicode "word" character, taken to be alphanumeric.
  7037.     \a alphabetic character, excluding digits
  7038.     \s matches whitespace
  7039.     \l matches lowercase
  7040.     \u matches uppercase
  7041.     \d matches a digit
  7042.     \\ matches a backslash
  7043.  
  7044.   If the first character of `del_set' is `^', then the set
  7045.   is taken to be the complement of the remaining string.
  7046.  
  7047.  EXAMPLE
  7048.  
  7049.     str = str_delete_chars (str, "^A-Za-z");
  7050.  
  7051.   will remove all characters except `A-Z' and `a-z' from
  7052.   `str'.  Similarly,
  7053.  
  7054.     str = str_delete_chars (str, "^\\a");
  7055.  
  7056.   will remove all but the alphabetic characters.
  7057.  
  7058.  SEE ALSO
  7059.   strtrans, strreplace, strcompress
  7060.  
  7061. --------------------------------------------------------------
  7062.  
  7063. str_quote_string
  7064.  
  7065.  SYNOPSIS
  7066.   Escape characters in a string.
  7067.  
  7068.  USAGE
  7069.   String_Type str_quote_string(String_Type str, String_Type qlis, Int_Type quote)
  7070.  
  7071.  DESCRIPTION
  7072.   The `str_quote_string' returns a string identical to `str'
  7073.   except that all characters contained in the string `qlis' are
  7074.   escaped with the `quote' character, including the quote
  7075.   character itself.  This function is useful for making a string that
  7076.   can be used in a regular expression.
  7077.  
  7078.  EXAMPLE
  7079.   Execution of the statements
  7080.  
  7081.    node = "Is it [the coat] really worth $100?";
  7082.    tag = str_quote_string (node, "\\^$[]*.+?", '\\');
  7083.  
  7084.   will result in `tag' having the value:
  7085.  
  7086.     Is it \[the coat\] really worth \$100\?
  7087.  
  7088.  
  7089.  SEE ALSO
  7090.   str_uncomment_string, make_printable_string
  7091.  
  7092. --------------------------------------------------------------
  7093.  
  7094. str_replace
  7095.  
  7096.  SYNOPSIS
  7097.   Replace a substring of a string (deprecated)
  7098.  
  7099.  USAGE
  7100.   Int_Type str_replace (String_Type a, String_Type b, String_Type c)
  7101.  
  7102.  DESCRIPTION
  7103.   The `str_replace' function replaces the first occurrence of `b' in
  7104.   `a' with `c' and returns an integer that indicates whether a
  7105.   replacement was made.  If `b' does not occur in `a', zero is
  7106.   returned.  However, if `b' occurs in `a', a non-zero integer is
  7107.   returned as well as the new string resulting from the replacement.
  7108.  
  7109.  NOTES
  7110.   This function has been superceded by `strreplace'.  It should no
  7111.   longer be used.
  7112.  
  7113.  SEE ALSO
  7114.   strreplace
  7115.  
  7116. --------------------------------------------------------------
  7117.  
  7118. str_uncomment_string
  7119.  
  7120.  SYNOPSIS
  7121.   Remove comments from a string
  7122.  
  7123.  USAGE
  7124.   String_Type str_uncomment_string(String_Type s, String_Type beg, String_Type end)
  7125.  
  7126.  DESCRIPTION
  7127.   This function may be used to remove simple forms of comments from a
  7128.   string `s'. The parameters, `beg' and `end', are strings
  7129.   of equal length whose corresponding characters specify the begin and
  7130.   end comment characters, respectively.  It returns the uncommented
  7131.   string.
  7132.  
  7133.  EXAMPLE
  7134.   The expression
  7135.  
  7136.      str_uncomment_string ("Hello (testing) 'example' World", "'(", "')")
  7137.  
  7138.   returns the string `"Hello   World"'.
  7139.  
  7140.  NOTES
  7141.   This routine does not handle multicharacter comment delimiters and it
  7142.   assumes that comments are not nested.
  7143.  
  7144.  SEE ALSO
  7145.   str_quote_string, str_delete_chars, strtrans
  7146.  
  7147. --------------------------------------------------------------
  7148.  
  7149. substr
  7150.  
  7151.  SYNOPSIS
  7152.   Extract a substring from a string
  7153.  
  7154.  USAGE
  7155.   String_Type substr (String_Type s, Int_Type n, Int_Type len)
  7156.  
  7157.  DESCRIPTION
  7158.   The `substr' function returns a substring with character length
  7159.   `len' of the string `s' beginning at the character position
  7160.   `n'.  If `len' is `-1', the entire length of the string
  7161.   `s' will be used for `len'.  The first character of `s'
  7162.   is given by `n' equal to 1.
  7163.  
  7164.  EXAMPLE
  7165.  
  7166.      substr ("To be or not to be", 7, 5);
  7167.  
  7168.   returns `"or no"'
  7169.  
  7170.  NOTES
  7171.   In many cases it is more convenient to use array indexing rather
  7172.   than the `substr' function.  In fact, if UTF-8 mode is not in
  7173.   effect, `substr(s,i+1,strlen(s))' is equivalent to
  7174.   `s[[i:]]'.  Array indexing uses byte-semantics, not character
  7175.   semantics assumed by the `substr' function.
  7176.  
  7177.  SEE ALSO
  7178.   is_substr, substrbytes, strlen
  7179.  
  7180. --------------------------------------------------------------
  7181.  
  7182. substrbytes
  7183.  
  7184.  SYNOPSIS
  7185.   Extract a byte sequence from a string
  7186.  
  7187.  USAGE
  7188.   String_Type substrbytes (String_Type s, Int_Type n, Int_Type len)
  7189.  
  7190.  DESCRIPTION
  7191.   The `substrbytes' function returns a substring with byte length
  7192.   `len' of the string `s' beginning at the byte position
  7193.   `n', counting from 1.  If `len' is `-1', the entire
  7194.   byte-length of the string `s' will be used for `len'.  The first
  7195.   byte of `s' is given by `n' equal to 1.
  7196.  
  7197.  EXAMPLE
  7198.  
  7199.      substrbytes ("To be or not to be", 7, 5);
  7200.  
  7201.   returns `"or no"'
  7202.  
  7203.  NOTES
  7204.   In many cases it is more convenient to use array indexing rather
  7205.   than the `substr' function.  In fact
  7206.   `substrbytes(s,i+1,-1)' is equivalent to
  7207.   `s[[i:]]'.
  7208.  
  7209.   The function `substr' may be used if character semantics are
  7210.   desired.
  7211.  
  7212.  SEE ALSO
  7213.   substr, strbytelen
  7214.  
  7215. --------------------------------------------------------------
  7216.  
  7217. __add_binary
  7218.  
  7219.  SYNOPSIS
  7220.   Extend a binary operation to a user defined type
  7221.  
  7222.  USAGE
  7223.   __add_binary(op, return_type, binary_funct, lhs_type, rhs_type)
  7224.  
  7225.    String_Type op;
  7226.    Ref_Type binary_funct;
  7227.    DataType_Type return_type, lhs_type, rhs_type;
  7228.  
  7229.  
  7230.  DESCRIPTION
  7231.   The `__add_binary' function is used to specify a function to be
  7232.   called when a binary operation takes place between specified data
  7233.   types.  The first parameter indicates the binary operator and must
  7234.   be one of the following:
  7235.  
  7236.    "+", "-", "*", "/", "==", "!=", ">", ">=", "<", "<=", "^",
  7237.    "or", "and", "&", "|", "xor", "shl", "shr", "mod"
  7238.  
  7239.   The second parameter (`binary_funct') specifies the function to
  7240.   be called when the binary function takes place between the
  7241.   types `lhs_type' and `rhs_type'.  The `return_type'
  7242.   parameter stipulates the return values of the function and the data
  7243.   type of the result of the binary operation.
  7244.  
  7245.   The data type for `lhs_type' or `rhs_type' may be left
  7246.   unspecified by using Any_Type for either of these values.
  7247.   However, at least one of the parameters must correspond to a
  7248.   user-defined datatype.
  7249.  
  7250.  EXAMPLE
  7251.   This example defines a vector data type and extends the "*" operator
  7252.   to the new type:
  7253.  
  7254.     typedef struct { x, y, z } Vector_Type;
  7255.     define vector (x, y, z)
  7256.     {
  7257.        variable v = @Vector_Type;
  7258.        v.x = x;
  7259.        v.y = y;
  7260.        v.z = z;
  7261.        return v;
  7262.     }
  7263.     static define vector_scalar_mul (v, a)
  7264.     {
  7265.        return vector (a*v.x, a*v.y, a*v.z);
  7266.     }
  7267.     static define scalar_vector_mul (a, v)
  7268.     {
  7269.        return vector_scalar_mul (v, a);
  7270.     }
  7271.     static define dotprod (v1,v2)
  7272.     {
  7273.        return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  7274.     }
  7275.     __add_binary ("*", Vector_Type, &scalar_vector_mul, Any_Type, Vector_Type);
  7276.     __add_binary ("*", Vector_Type, &scalar_vector_mul, Any_Type, Vector_Type);
  7277.     __add_binary ("*", Double_Type, &dotprod, Vector_Type, Vector_Type);
  7278.  
  7279.  
  7280.  SEE ALSO
  7281.   __add_unary, __add_string, __add_destroy
  7282.  
  7283. --------------------------------------------------------------
  7284.  
  7285. __add_string
  7286.  
  7287.  SYNOPSIS
  7288.   Specify a string representation for a user-defined type
  7289.  
  7290.  USAGE
  7291.   __add_string (DataType_Type user_type, Ref_Type func)
  7292.  
  7293.  DESCRIPTION
  7294.   The `__add_string' function specifies a function to be called
  7295.   when a string representation is required for the specified
  7296.   user-defined datatype.
  7297.  
  7298.  EXAMPLE
  7299.   Consider the `Vector_Type' object defined in the example
  7300.   for the `__add_binary' function.
  7301.  
  7302.      static define vector_string (v)
  7303.      {
  7304.         return sprintf ("[%S,%S,%S]", v.x, v.y, v.z);
  7305.      }
  7306.      __add_string (Vector_Type, &vector_string);
  7307.  
  7308.   Then
  7309.  
  7310.      v = vector (3, 4, 5);
  7311.      vmessage ("v=%S", v);
  7312.  
  7313.   will generate the message:
  7314.  
  7315.      v=[3,4,5]
  7316.  
  7317.  
  7318.  SEE ALSO
  7319.   __add_unary, __add_binary, __add_destroy
  7320.  
  7321. --------------------------------------------------------------
  7322.  
  7323. __add_unary
  7324.  
  7325.  SYNOPSIS
  7326.   Extend a unary operator to a user-defined type
  7327.  
  7328.  USAGE
  7329.   __add_unary (op, return_type, unary_func, user_type)
  7330.  
  7331.    String_Type op;
  7332.    Ref_Type unary_func;
  7333.    DataType_Type return_type, user_type;
  7334.  
  7335.  
  7336.  DESCRIPTION
  7337.   The `__add_unary' function is used to define the action of an
  7338.   unary operation on a user-defined type.  The first parameter
  7339.   `op' must be a valid unary operator
  7340.  
  7341.    "-", "not", "~"
  7342.  
  7343.   or one of the following:
  7344.  
  7345.    "++", "--",
  7346.    "abs", "sign", "sqr", "mul2", "_ispos", "_isneg", "_isnonneg",
  7347.  
  7348.   The third parameter, `unary_func' specifies the function to be
  7349.   called to carry out the specified unary operation on the data type
  7350.   `user_type'.  The result of the operation is indicated by the
  7351.   value of the `return_type' parameter and must also be the
  7352.   return type of the unary function.
  7353.  
  7354.  EXAMPLE
  7355.   The example for the `__add_binary' function defined a
  7356.   `Vector_Type' object.  Here, the unary `"-"' and
  7357.   `"abs"' operators are
  7358.   extended to this type:
  7359.  
  7360.    static define vector_chs (v)
  7361.    {
  7362.       variable v1 = @Vector_Type;
  7363.       v1.x = -v.x;
  7364.       v1.y = -v.y;
  7365.       v1.z = -v.z;
  7366.       return v1;
  7367.    }
  7368.    static define vector_abs (v)
  7369.    {
  7370.       return sqrt (v.x*v.x + v.y*v.y + v.z*v.z);
  7371.    }
  7372.    __add_unary ("-", Vector_Type, &vector_chs, Vector_Type);
  7373.    __add_unary ("abs", Double_Type, &vector_abs, Vector_Type);
  7374.  
  7375.  
  7376.  SEE ALSO
  7377.   __add_binary, __add_string, __add_destroy
  7378.  
  7379. --------------------------------------------------------------
  7380.  
  7381. get_struct_field
  7382.  
  7383.  SYNOPSIS
  7384.   Get the value associated with a structure field
  7385.  
  7386.  USAGE
  7387.   x = get_struct_field (Struct_Type s, String field_name)
  7388.  
  7389.  DESCRIPTION
  7390.    The `get_struct_field' function gets the value of the field
  7391.    whose name is specified by `field_name' of the structure `s'.
  7392.  
  7393.  EXAMPLE
  7394.    The following example illustrates how this function may be used to
  7395.    to print the value of a structure.
  7396.  
  7397.       define print_struct (s)
  7398.       {
  7399.          variable name;
  7400.  
  7401.          foreach (get_struct_field_names (s))
  7402.            {
  7403.              name = ();
  7404.              value = get_struct_field (s, name);
  7405.              vmessage ("s.%s = %s\n", name, string(value));
  7406.            }
  7407.       }
  7408.  
  7409.  
  7410.  SEE ALSO
  7411.   set_struct_field, get_struct_field_names, array_info
  7412.  
  7413. --------------------------------------------------------------
  7414.  
  7415. get_struct_field_names
  7416.  
  7417.  SYNOPSIS
  7418.   Retrieve the field names associated with a structure
  7419.  
  7420.  USAGE
  7421.   String_Type[] = get_struct_field_names (Struct_Type s)
  7422.  
  7423.  DESCRIPTION
  7424.    The `get_struct_field_names' function returns an array of
  7425.    strings whose elements specify the names of the fields of the
  7426.    struct `s'.
  7427.  
  7428.  EXAMPLE
  7429.    The following example illustrates how the
  7430.    `get_struct_field_names' function may be used to print the
  7431.    value of a structure.
  7432.  
  7433.       define print_struct (s)
  7434.       {
  7435.          variable name, value;
  7436.  
  7437.          foreach (get_struct_field_names (s))
  7438.            {
  7439.              name = ();
  7440.              value = get_struct_field (s, name);
  7441.              vmessage ("s.%s = %s\n", name, string (value));
  7442.            }
  7443.       }
  7444.  
  7445.  
  7446.  SEE ALSO
  7447.   _push_struct_field_values, get_struct_field
  7448.  
  7449. --------------------------------------------------------------
  7450.  
  7451. is_struct_type
  7452.  
  7453.  SYNOPSIS
  7454.   Determine whether or not an object is a structure
  7455.  
  7456.  USAGE
  7457.   Integer_Type is_struct_type (X)
  7458.  
  7459.  DESCRIPTION
  7460.   The `is_struct_type' function returns 1 if the parameter
  7461.   refers to a structure or a user-defined type.  If the object is
  7462.   neither, 0 will be returned.
  7463.  
  7464.  SEE ALSO
  7465.   typeof, _typeof, _is_struct_type
  7466.  
  7467. --------------------------------------------------------------
  7468.  
  7469. _push_struct_field_values
  7470.  
  7471.  SYNOPSIS
  7472.   Push the values of a structure's fields onto the stack
  7473.  
  7474.  USAGE
  7475.   Integer_Type num = _push_struct_field_values (Struct_Type s)
  7476.  
  7477.  DESCRIPTION
  7478.   The `_push_struct_field_values' function pushes the values of
  7479.   all the fields of a structure onto the stack, returning the
  7480.   number of items pushed.  The fields are pushed such that the last
  7481.   field of the structure is pushed first.
  7482.  
  7483.  SEE ALSO
  7484.   get_struct_field_names, get_struct_field
  7485.  
  7486. --------------------------------------------------------------
  7487.  
  7488. set_struct_field
  7489.  
  7490.  SYNOPSIS
  7491.   Set the value associated with a structure field
  7492.  
  7493.  USAGE
  7494.   set_struct_field (s, field_name, field_value)
  7495.  
  7496.    Struct_Type s;
  7497.    String_Type field_name;
  7498.    Generic_Type field_value;
  7499.  
  7500.  
  7501.  DESCRIPTION
  7502.    The `set_struct_field' function sets the value of the field
  7503.    whose name is specified by `field_name' of the structure
  7504.    `s' to `field_value'.
  7505.  
  7506.  SEE ALSO
  7507.   get_struct_field, get_struct_field_names, set_struct_fields, array_info
  7508.  
  7509. --------------------------------------------------------------
  7510.  
  7511. set_struct_fields
  7512.  
  7513.  SYNOPSIS
  7514.   Set the fields of a structure
  7515.  
  7516.  USAGE
  7517.   set_struct_fields (Struct_Type s, ...)
  7518.  
  7519.  DESCRIPTION
  7520.   The `set_struct_fields' function may be used to set zero or more
  7521.   fields of a structure.  The fields are set in the order in which
  7522.   they were created when the structure was defined.
  7523.  
  7524.  EXAMPLE
  7525.  
  7526.     variable s = struct { name, age, height };
  7527.     set_struct_fields (s, "Bill", 13, 64);
  7528.  
  7529.  
  7530.  SEE ALSO
  7531.   set_struct_field, get_struct_field_names
  7532.  
  7533. --------------------------------------------------------------
  7534.  
  7535. ctime
  7536.  
  7537.  SYNOPSIS
  7538.   Convert a calendar time to a string
  7539.  
  7540.  USAGE
  7541.   String_Type ctime(Long_Type secs)
  7542.  
  7543.  DESCRIPTION
  7544.   This function returns a string representation of the time as given
  7545.   by `secs' seconds since 00:00:00 UTC, Jan 1, 1970.
  7546.  
  7547.  SEE ALSO
  7548.   time, strftime, _time, localtime, gmtime
  7549.  
  7550. --------------------------------------------------------------
  7551.  
  7552. gmtime
  7553.  
  7554.  SYNOPSIS
  7555.   Break down a time in seconds to the GMT timezone
  7556.  
  7557.  USAGE
  7558.   Struct_Type gmtime (Long_Type secs)
  7559.  
  7560.  DESCRIPTION
  7561.    The `gmtime' function is exactly like `localtime' except
  7562.    that the values in the structure it returns are with respect to GMT
  7563.    instead of the local timezone.  See the documentation for
  7564.    `localtime' for more information.
  7565.  
  7566.  NOTES
  7567.    On systems that do not support the `gmtime' C library function,
  7568.    this function is the same as `localtime'.
  7569.  
  7570.  SEE ALSO
  7571.   localtime, _time, mktime
  7572.  
  7573. --------------------------------------------------------------
  7574.  
  7575. localtime
  7576.  
  7577.  SYNOPSIS
  7578.   Break down a time in seconds to the local timezone
  7579.  
  7580.  USAGE
  7581.   Struct_Type localtime (Long_Type secs)
  7582.  
  7583.  DESCRIPTION
  7584.    The `localtime' function takes a parameter `secs'
  7585.    representing the number of seconds since 00:00:00, January 1 1970
  7586.    UTC and returns a structure containing information about `secs'
  7587.    in the local timezone.  The structure contains the following
  7588.    Int_Type fields:
  7589.  
  7590.    `tm_sec' The number of seconds after the minute, normally
  7591.       in the range 0 to 59, but can be up to 61 to allow for
  7592.       leap seconds.
  7593.  
  7594.    `tm_min' The number of minutes after the hour, in the
  7595.       range 0 to 59.
  7596.  
  7597.    `tm_hour' The number of hours past midnight, in the range
  7598.       0 to 23.
  7599.  
  7600.    `tm_mday' The day of the month, in the range 1 to 31.
  7601.  
  7602.    `tm_mon' The number of months since January, in the range
  7603.       0 to 11.
  7604.  
  7605.    `tm_year' The number of years since 1900.
  7606.  
  7607.    `tm_wday' The number of days since Sunday, in the range 0
  7608.       to 6.
  7609.  
  7610.    `tm_yday' The number of days since January 1, in the
  7611.       range 0 to 365.
  7612.  
  7613.    `tm_isdst' A flag that indicates whether daylight saving
  7614.       time is in effect at the time described.  The value is
  7615.       positive if daylight saving time is in effect, zero if it
  7616.       is not, and negative if the information is not available.
  7617.  
  7618.  SEE ALSO
  7619.   gmtime, _time, ctime, mktime
  7620.  
  7621. --------------------------------------------------------------
  7622.  
  7623. mktime
  7624.  
  7625.  SYNOPSIS
  7626.   Convert a time-structure to seconds
  7627.  
  7628.  USAGE
  7629.   secs = mktime (Struct_Type tm)
  7630.  
  7631.  DESCRIPTION
  7632.   The `mktime' function is essentially the inverse of the
  7633.   `localtime' function.  See the documentation for that function
  7634.   for more details.
  7635.  
  7636.  SEE ALSO
  7637.   localtime, gmtime, _time
  7638.  
  7639. --------------------------------------------------------------
  7640.  
  7641. strftime
  7642.  
  7643.  SYNOPSIS
  7644.   Format a date and time string
  7645.  
  7646.  USAGE
  7647.   str = strftime (String_Type format [,Struct_Type tm])
  7648.  
  7649.  DESCRIPTION
  7650.   The `strftime' creates a date and time string according to a
  7651.   specified format.  If called with a single argument, the current
  7652.   local time will be used as the reference time.  If called with two
  7653.   arguments, the second argument specifies the reference time, and
  7654.   must be a structure with the same fields as the structure returned
  7655.   by the `localtime' function.
  7656.  
  7657.   The format string may be composed of one or more of the following
  7658.   format descriptors:
  7659.  
  7660.        %A      full weekday name (Monday)
  7661.        %a      abbreviated weekday name (Mon)
  7662.        %B      full month name (January)
  7663.        %b      abbreviated month name (Jan)
  7664.        %c      standard date and time representation
  7665.        %d      day-of-month (01-31)
  7666.        %H      hour (24 hour clock) (00-23)
  7667.        %I      hour (12 hour clock) (01-12)
  7668.        %j      day-of-year (001-366)
  7669.        %M      minute (00-59)
  7670.        %m      month (01-12)
  7671.        %p      local equivalent of AM or PM
  7672.        %S      second (00-59)
  7673.        %U      week-of-year, first day sunday (00-53)
  7674.        %W      week-of-year, first day monday (00-53)
  7675.        %w      weekday (0-6, sunday is 0)
  7676.        %X      standard time representation
  7677.        %x      standard date representation
  7678.        %Y      year with century
  7679.        %y      year without century (00-99)
  7680.        %Z      timezone name
  7681.        %%      percent sign
  7682.  
  7683.  as well as any others provided by the C library.  The actual values
  7684.  represented by the format descriptors are locale-dependent.
  7685.  
  7686.  EXAMPLE
  7687.  
  7688.     message (strftime ("Today is %A, day %j of the year"));
  7689.     tm = localtime (0);
  7690.     message (strftime ("Unix time 0 was on a %A", tm));
  7691.  
  7692.  
  7693.  SEE ALSO
  7694.   localtime, time
  7695.  
  7696. --------------------------------------------------------------
  7697.  
  7698. _tic
  7699.  
  7700.  SYNOPSIS
  7701.   Reset the CPU timer
  7702.  
  7703.  USAGE
  7704.   _tic ()
  7705.  
  7706.  DESCRIPTION
  7707.   The `_tic' function resets the internal CPU timer.  The
  7708.  `_toc' may be used to read this timer.  See the documentation
  7709.  for the `_toc' function for more information.
  7710.  
  7711.  EXAMPLE
  7712.  
  7713.  SEE ALSO
  7714.   _toc, times, tic, toc
  7715.  
  7716. --------------------------------------------------------------
  7717.  
  7718. tic
  7719.  
  7720.  SYNOPSIS
  7721.   Reset the interval timer
  7722.  
  7723.  USAGE
  7724.   void tic ()
  7725.  
  7726.  DESCRIPTION
  7727.   The `tic' function resets the internal interval timer.  The
  7728.  `toc' may be used to read the interval timer.
  7729.  
  7730.  EXAMPLE
  7731.   The tic/toc functions may be used to measure execution times.  For
  7732.  example, at the `slsh' prompt, they may be used to measure the speed
  7733.  of a loop:
  7734.  
  7735.    slsh> tic; loop (500000); toc;
  7736.    0.06558
  7737.  
  7738.  
  7739.  NOTES
  7740.   On Unix, this timer makes use of the C library `gettimeofday'
  7741.   function.
  7742.  
  7743.  SEE ALSO
  7744.   toc, times
  7745.  
  7746. --------------------------------------------------------------
  7747.  
  7748. _time
  7749.  
  7750.  SYNOPSIS
  7751.   Get the current calendar time in seconds
  7752.  
  7753.  USAGE
  7754.   Long_Type _time ()
  7755.  
  7756.  DESCRIPTION
  7757.   The `_time' function returns the number of elapsed seconds since
  7758.   00:00:00 UTC, January 1, 1970.  A number of functions (`ctime',
  7759.   `gmtime', `localtime', etc.) are able to convert such a
  7760.   value to other representations.
  7761.  
  7762.  SEE ALSO
  7763.   ctime, time, localtime, gmtime
  7764.  
  7765. --------------------------------------------------------------
  7766.  
  7767. time
  7768.  
  7769.  SYNOPSIS
  7770.   Return the current date and time as a string
  7771.  
  7772.  USAGE
  7773.   String_Type time ()
  7774.  
  7775.  DESCRIPTION
  7776.   This function returns the current time as a string of the form:
  7777.  
  7778.     Sun Apr 21 13:34:17 1996
  7779.  
  7780.  
  7781.  SEE ALSO
  7782.   strftime, ctime, message, substr
  7783.  
  7784. --------------------------------------------------------------
  7785.  
  7786. times
  7787.  
  7788.  SYNOPSIS
  7789.   Get process times
  7790.  
  7791.  USAGE
  7792.   Struct_Type times ()
  7793.  
  7794.  DESCRIPTION
  7795.   The `times' function returns a structure containing the
  7796.   following fields:
  7797.  
  7798.     tms_utime     (user time)
  7799.     tms_stime     (system time)
  7800.     tms_cutime    (user time of child processes)
  7801.     tms_cstime    (system time of child processes)
  7802.  
  7803.  
  7804.  NOTES
  7805.   Not all systems support this function.
  7806.  
  7807.  SEE ALSO
  7808.   _tic, _toc, _time
  7809.  
  7810. --------------------------------------------------------------
  7811.  
  7812. _toc
  7813.  
  7814.  SYNOPSIS
  7815.   Get the elapsed CPU time for the current process
  7816.  
  7817.  USAGE
  7818.   Double_Type _toc ()
  7819.  
  7820.  DESCRIPTION
  7821.   The `_toc' function returns the elapsed CPU time in seconds since
  7822.   the last call to `_tic'.  The CPU time is the amount of time the
  7823.   CPU spent running the code of the current process.
  7824.  
  7825.  EXAMPLE
  7826.  
  7827.  NOTES
  7828.   This function may not be available on all systems.
  7829.  
  7830.   The implementation of this function is based upon the `times'
  7831.   system call.  The precision of the clock is system dependent and may
  7832.   not be very accurate for small time intervals.  For this reason, the
  7833.   tic/toc functions may be more useful for small time-intervals.
  7834.  
  7835.  SEE ALSO
  7836.   _tic, _tic, _toc, times, _time
  7837.  
  7838. --------------------------------------------------------------
  7839.  
  7840. toc
  7841.  
  7842.  SYNOPSIS
  7843.   Read the interval timer
  7844.  
  7845.  USAGE
  7846.   Double_Type toc ()
  7847.  
  7848.  DESCRIPTION
  7849.   The `toc' function returns the elapsed time in seconds since
  7850.   the last call to `tic'.  See the documentation for the
  7851.  `tic' function for more information.
  7852.  
  7853.  SEE ALSO
  7854.   tic, _tic, _toc, times, _time
  7855.  
  7856. --------------------------------------------------------------
  7857.  
  7858. atof
  7859.  
  7860.  SYNOPSIS
  7861.   Convert a string to a double precision number
  7862.  
  7863.  USAGE
  7864.   Double_Type atof (String_Type s)
  7865.  
  7866.  DESCRIPTION
  7867.   This function converts a string `s' to a double precision value
  7868.   and returns the result.  It performs no error checking on the format
  7869.   of the string.  The function `_slang_guess_type' may be used to
  7870.   check the syntax of the string.
  7871.  
  7872.  EXAMPLE
  7873.  
  7874.      define error_checked_atof (s)
  7875.      {
  7876.         if (__is_datatype_numeric (_slang_guess_type (x)))
  7877.           return atof (s);
  7878.         throw InvalidParmError, "$s is not a double"$;
  7879.     }
  7880.  
  7881.  
  7882.  SEE ALSO
  7883.   typecast, double, _slang_guess_type
  7884.  
  7885. --------------------------------------------------------------
  7886.  
  7887. atoi
  7888.  
  7889.  SYNOPSIS
  7890.   Convert a string to an integer
  7891.  
  7892.  USAGE
  7893.   Int_Type atoi (String_Type str)
  7894.  
  7895.  DESCRIPTION
  7896.   The `atoi' function converts a string to an `Int_Type'
  7897.   using the standard C library function of the corresponding name.
  7898.  
  7899.  NOTES
  7900.   This function performs no syntax checking upon its argument.
  7901.  
  7902.  SEE ALSO
  7903.   integer, atol, atoll, atof, sscanf
  7904.  
  7905. --------------------------------------------------------------
  7906.  
  7907. atol
  7908.  
  7909.  SYNOPSIS
  7910.   Convert a string to an long integer
  7911.  
  7912.  USAGE
  7913.   Long_Type atol (String_Type str)
  7914.  
  7915.  DESCRIPTION
  7916.   The `atol' function converts a string to a `Long_Type'
  7917.   using the standard C library function of the corresponding name.
  7918.  
  7919.  NOTES
  7920.   This function performs no syntax checking upon its argument.
  7921.  
  7922.  SEE ALSO
  7923.   integer, atoi, atoll, atof, sscanf
  7924.  
  7925. --------------------------------------------------------------
  7926.  
  7927. atoll
  7928.  
  7929.  SYNOPSIS
  7930.   Convert a string to a long long
  7931.  
  7932.  USAGE
  7933.   LLong_Type atoll (String_Type str)
  7934.  
  7935.  DESCRIPTION
  7936.   The `atoll' function converts a string to a `LLong_Type'
  7937.   using the standard C library function of the corresponding name.
  7938.  
  7939.  NOTES
  7940.   This function performs no syntax checking upon its argument.  Not
  7941.   all platforms provide support for the long long data type.
  7942.  
  7943.  SEE ALSO
  7944.   integer, atoi, atol, atof, sscanf
  7945.  
  7946. --------------------------------------------------------------
  7947.  
  7948. char
  7949.  
  7950.  SYNOPSIS
  7951.   Convert an ascii value into a string
  7952.  
  7953.  USAGE
  7954.   String_Type char (Integer_Type c)
  7955.  
  7956.  DESCRIPTION
  7957.   The `char' function converts an integer ascii value `c' to a
  7958.   string of unit character length such that the first character of the
  7959.   string is `c'.  For example, `char('a')' returns the string
  7960.   `"a"'.
  7961.  
  7962.  NOTES
  7963.   If UTF-8 mode is in effect  (`_slang_utf8_ok' is non-zero), the
  7964.   resulting single character may be represented by several bytes.
  7965.  
  7966.  SEE ALSO
  7967.   integer, string, typedef
  7968.  
  7969. --------------------------------------------------------------
  7970.  
  7971. define_case
  7972.  
  7973.  SYNOPSIS
  7974.   Define upper-lower case conversion
  7975.  
  7976.  USAGE
  7977.   define_case (Integer_Type ch_up, Integer_Type ch_low)
  7978.  
  7979.  DESCRIPTION
  7980.   This function defines an upper and lowercase relationship between two
  7981.   characters specified by the arguments.  This relationship is used by
  7982.   routines which perform uppercase and lowercase conversions.
  7983.   The first integer `ch_up' is the ascii value of the uppercase character
  7984.   and the second parameter `ch_low' is the ascii value of its
  7985.   lowercase counterpart.
  7986.  
  7987.  NOTES
  7988.   This function has no effect in UTF-8 mode.
  7989.  
  7990.  SEE ALSO
  7991.   strlow, strup
  7992.  
  7993. --------------------------------------------------------------
  7994.  
  7995. double
  7996.  
  7997.  SYNOPSIS
  7998.   Convert an object to double precision
  7999.  
  8000.  USAGE
  8001.   Double_Type double (x)
  8002.  
  8003.  DESCRIPTION
  8004.   The `double' function typecasts an object `x' to double
  8005.   precision.  For example, if `x' is an array of integers, an
  8006.   array of double types will be returned.  If an object cannot be
  8007.   converted to `Double_Type', a type-mismatch error will result.
  8008.  
  8009.  NOTES
  8010.   The `double' function is equivalent to the typecast operation
  8011.  
  8012.      typecast (x, Double_Type)
  8013.  
  8014.   To convert a string to a double precision number, use the `atof'
  8015.   function.
  8016.  
  8017.  SEE ALSO
  8018.   typecast, atof, int
  8019.  
  8020. --------------------------------------------------------------
  8021.  
  8022. int
  8023.  
  8024.  SYNOPSIS
  8025.   Typecast an object to an integer
  8026.  
  8027.  USAGE
  8028.   Int_Type int (s)
  8029.  
  8030.  DESCRIPTION
  8031.   This function performs a typecast of an object `s' to
  8032.   an object of Integer_Type.  If `s' is a string, it returns
  8033.   returns the ascii value of the first bytes of the string
  8034.   `s'.  If `s' is Double_Type, `int' truncates the
  8035.   number to an integer and returns it.
  8036.  
  8037.  EXAMPLE
  8038.   `int' can be used to convert single byte strings to
  8039.   integers.  As an example, the intrinsic function `isdigit' may
  8040.   be defined as
  8041.  
  8042.     define isdigit (s)
  8043.     {
  8044.       if ((int (s) >= '0') and (int (s) <= '9')) return 1;
  8045.       return 0;
  8046.     }
  8047.  
  8048.  
  8049.  NOTES
  8050.   This function is equivalent to `typecast (s, Integer_Type)';
  8051.  
  8052.  SEE ALSO
  8053.   typecast, double, integer, char, isdigit
  8054.  
  8055. --------------------------------------------------------------
  8056.  
  8057. integer
  8058.  
  8059.  SYNOPSIS
  8060.   Convert a string to an integer
  8061.  
  8062.  USAGE
  8063.   Integer_Type integer (String_Type s)
  8064.  
  8065.  DESCRIPTION
  8066.   The `integer' function converts a string representation of an
  8067.   integer back to an integer.  If the string does not form a valid
  8068.   integer, a SyntaxError will be thrown.
  8069.  
  8070.  EXAMPLE
  8071.   `integer ("1234")' returns the integer value `1234'.
  8072.  
  8073.  NOTES
  8074.   This function operates only on strings and is not the same as the
  8075.   more general `typecast' operator.
  8076.  
  8077.  SEE ALSO
  8078.   typecast, _slang_guess_type, string, sprintf, char
  8079.  
  8080. --------------------------------------------------------------
  8081.  
  8082. isdigit
  8083.  
  8084.  SYNOPSIS
  8085.   Tests for a decimal digit character
  8086.  
  8087.  USAGE
  8088.   Integer_Type isdigit (s)
  8089.  
  8090.  DESCRIPTION
  8091.   This function returns a non-zero value if the character represented
  8092.   by `s' is a digit; otherwise, it returns zero.  If `s' is
  8093.   a string, the first character of `s' will be used for the test.
  8094.  
  8095.  EXAMPLE
  8096.   A simple, user defined implementation of `isdigit' is
  8097.  
  8098.     define isdigit (x)
  8099.     {
  8100.        return ((x <= '9') and (x >= '0'));
  8101.     }
  8102.  
  8103.   However, the intrinsic function `isdigit' executes many times faster
  8104.   than the representation defined above, and works properly when
  8105.   `x' is a Unicode character.
  8106.  
  8107.  SEE ALSO
  8108.   int, integer
  8109.  
  8110. --------------------------------------------------------------
  8111.  
  8112. _slang_guess_type
  8113.  
  8114.  SYNOPSIS
  8115.   Guess the data type that a string represents
  8116.  
  8117.  USAGE
  8118.   DataType_Type _slang_guess_type (String_Type s)
  8119.  
  8120.  DESCRIPTION
  8121.   This function tries to determine whether its argument `s'
  8122.   represents an integer (short, int, long), floating point (float,
  8123.   double), or a complex number.  If it appears to be none of these,
  8124.   then a string is assumed.  It returns one of the following values
  8125.   depending on the format of the string `s':
  8126.  
  8127.     Short_Type     :  short integer           (e.g., "2h")
  8128.     UShort_Type    :  unsigned short integer  (e.g., "2hu")
  8129.     Integer_Type   :  integer                 (e.g., "2")
  8130.     UInteger_Type  :  unsigned integer        (e.g., "2")
  8131.     Long_Type      :  long integer            (e.g., "2l")
  8132.     ULong_Type     :  unsigned long integer   (e.g., "2l")
  8133.     Float_Type     :  float                   (e.g., "2.0f")
  8134.     Double_Type    :  double                  (e.g., "2.0")
  8135.     Complex_Type   :  imaginary               (e.g., "2i")
  8136.     String_Type    :  Anything else.          (e.g., "2foo")
  8137.  
  8138.   For example, `_slang_guess_type("1e2")' returns
  8139.   Double_Type but `_slang_guess_type("e12")' returns
  8140.   String_Type.
  8141.  
  8142.  SEE ALSO
  8143.   integer, string, double, atof, __is_datatype_numeric
  8144.  
  8145. --------------------------------------------------------------
  8146.  
  8147. string
  8148.  
  8149.  SYNOPSIS
  8150.   Convert an object to a string representation.
  8151.  
  8152.  USAGE
  8153.   String_Type string (obj)
  8154.  
  8155.  DESCRIPTION
  8156.    The `string' function may be used to convert an object
  8157.    `obj' of any type to its string representation.
  8158.    For example, `string(12.34)' returns `"12.34"'.
  8159.  
  8160.  EXAMPLE
  8161.  
  8162.      define print_anything (anything)
  8163.      {
  8164.         message (string (anything));
  8165.      }
  8166.  
  8167.  
  8168.  NOTES
  8169.    This function is _not_ the same as typecasting to a String_Type
  8170.    using the `typecast' function.
  8171.  
  8172.  SEE ALSO
  8173.   typecast, sprintf, integer, char
  8174.  
  8175. --------------------------------------------------------------
  8176.  
  8177. tolower
  8178.  
  8179.  SYNOPSIS
  8180.   Convert a character to lowercase.
  8181.  
  8182.  USAGE
  8183.   Integer_Type lower (Integer_Type ch)
  8184.  
  8185.  DESCRIPTION
  8186.   This function takes an integer `ch' and returns its lowercase
  8187.   equivalent.
  8188.  
  8189.  SEE ALSO
  8190.   toupper, strup, strlow, int, char, define_case
  8191.  
  8192. --------------------------------------------------------------
  8193.  
  8194. toupper
  8195.  
  8196.  SYNOPSIS
  8197.   Convert a character to uppercase.
  8198.  
  8199.  USAGE
  8200.   Integer_Type toupper (Integer_Type ch)
  8201.  
  8202.  DESCRIPTION
  8203.   This function takes an integer `ch' and returns its uppercase
  8204.   equivalent.
  8205.  
  8206.  SEE ALSO
  8207.   tolower, strup, strlow, int, char, define_case
  8208.  
  8209. --------------------------------------------------------------
  8210.  
  8211. typecast
  8212.  
  8213.  SYNOPSIS
  8214.   Convert an object from one data type to another.
  8215.  
  8216.  USAGE
  8217.   typecast (x, new_type)
  8218.  
  8219.  DESCRIPTION
  8220.   The `typecast' function performs a generic typecast operation on
  8221.   `x' to convert it to `new_type'.  If `x' represents an
  8222.   array, the function will attempt to convert all elements of `x'
  8223.   to `new_type'.  Not all objects can be converted and a
  8224.   type-mismatch error will result upon failure.
  8225.  
  8226.  EXAMPLE
  8227.  
  8228.     define to_complex (x)
  8229.     {
  8230.        return typecast (x, Complex_Type);
  8231.     }
  8232.  
  8233.   defines a function that converts its argument, `x' to a complex
  8234.   number.
  8235.  
  8236.  SEE ALSO
  8237.   int, double, typeof
  8238.  
  8239. --------------------------------------------------------------
  8240.  
  8241. _typeof
  8242.  
  8243.  SYNOPSIS
  8244.   Get the data type of an object
  8245.  
  8246.  USAGE
  8247.   DataType_Type _typeof (x)
  8248.  
  8249.  DESCRIPTION
  8250.   This function is similar to the `typeof' function except in the
  8251.   case of arrays.  If the object `x' is an array, then the data
  8252.   type of the array will be returned. otherwise `_typeof' returns
  8253.   the data type of `x'.
  8254.  
  8255.  EXAMPLE
  8256.  
  8257.     if (Integer_Type == _typeof (x))
  8258.       message ("x is an integer or an integer array");
  8259.  
  8260.  
  8261.  SEE ALSO
  8262.   typeof, array_info, _slang_guess_type, typecast
  8263.  
  8264. --------------------------------------------------------------
  8265.  
  8266. typeof
  8267.  
  8268.  SYNOPSIS
  8269.   Get the data type of an object
  8270.  
  8271.  USAGE
  8272.   DataType_Type typeof (x)
  8273.  
  8274.  DESCRIPTION
  8275.   This function returns the data type of `x'.
  8276.  
  8277.  EXAMPLE
  8278.  
  8279.   if (Integer_Type == typeof (x)) message ("x is an integer");
  8280.  
  8281.  
  8282.  SEE ALSO
  8283.   _typeof, is_struct_type, array_info, _slang_guess_type, typecast
  8284.  
  8285. --------------------------------------------------------------
  8286.