7.4.7 CSS Functions

The following functions are built into CSS, and provide some of the basic functionality found in the standard C library. Note that the String and stream objects encapsulate many commonly-used C library functions, which have not in general been reproduced in CSS (with the exception of some of the file functions).

Int access(String fname, int ac_type)
This POSIX command determines if the given file name is accessible according to the ac_type argument, which should be some bitwise OR of the enums R_OK W_OK X_OK F_OK. Returns success and sets errno flag on failure.
Real acos(Real x)
The arc-cosine.
Real acosh(Real x)
The hyperbolic arc-cosine.
Int alarm(int seconds)
Generate an alarm signal in the given number of seconds. Returns success and sets errno flag on failure.
Real asin(Real x)
The arc-sine.
Real asinh(Real x)
The hyperbolic arc-sine.
Real atan(Real x)
The arc-tangent.
Real atan2(Real y, Real x)
The arc-tangent for given y and x values.
Real atanh(Real x)
The hyperbolic arc-tangent.
Real beta(Real z, Real w)
The Beta function.
Real beta_i(Real a, Real b, Real x)
The incomplete Beta function.
Real bico_ln(Int n, Int j)
The natural logarithm of the binomial coefficient "n choose j". The number of ways of choosing j items out of a set containing n elements:
  / n \        n! 
  |   |  = ------------
  \ j /      k! (n-k)!
Real binom_cum(Int n, Int j, Int p)
The cumulative binomial probability of getting j or more in n trials of probability p.
Real binom_den(Int n, Int j, Real p)
The binomial probability density function for j "successes" in n trials, each with probability p of success.
               / n \   j      (n-j)
  P(n,j,p) =   |   |  p  (1-p) 
               \ j /  
Real binom_dev(Int n, Real p)
The binomial random deviate: produces an integer number of successes for a binomial distribution with p probability over n trials.
Real ceil(Real x)
Rounds up the value to the next-highest integral value.
int chdir(String dir_name)
Change the current directory to given argument. Returns success and sets errno flag on failure.
Real chisq_p(Real X, Real v)
Gives the chi-squared statistic P(X^2 | v).
Real chisq_q(Real X, Real v)
Gives the complement of the chi-squared statistic Q(X^2 | v).
Int chown(String fname, int user, int group)
Changes the ownership of the given file to the given user and group numbers. Returns success and sets errno flag on failure.
Real cos(Real x)
The cosine of angle x (given in radians). Use cos(x / DEG) if x is in degrees.
Real cosh(Real x)
The hyperbolic cosine of angle x.
String ctermid()
Returns the character-id of the current terminal.
String cuserid()
Returns the character-id of the current user.
String_Array& Dir([String& dir_nm])
Fills an array with the names of all the files in the given directory (defaults to "." if no directory name is passed). The user should copy the array if they want to keep it around, since the one returned is just a pointer to an internal array object.
Real drand48()
Returns a uniformly-distributed random number between 0 and 1.
Int EditObj(<object>, [Int wait])
This is the function version of the edit command. If the GUI (graphical user interface) is active (i.e., by using -gui to start up CSS), edit will bring up a graphical edit dialog for the given object, which must be either a script-defined or hard-coded class object. The optional second argument, if TRUE, will cause the system to wait for the user to close the edit dialog before continuing execution of the script.
Real erf(Real x)
The error function, which provides an approximation to the integral of the normal distribution.
Real erf_c(Real x)
The complement of the error function.
Real exp(Real x)
The exponential (e to the power x).
css* Extern(String& name)
Returns the object with the given name on the 'extern' variable list. This provides a mechanism for passing arbitrary (i.e., class objects) data across different name spaces (i.e., across different instances of the css program space), since you can pass the name of the extern class object that contains data relevant to another script, and use this function to get that object from its name.
Real fabs(Real x)
The absolute value of x.
Real fact_ln(Int x)
The natural logarithm of the factorial of x (x!).
void fclose(FILE fh)
Closes the file, which was opened by fopen. The FILE type is not actually a standard C FILE, but actually a fstream type, so stream operations can be performed on it.
Real floor(Real x)
Rounds the value down to the next lowest integral value.
Real fmod(Real x, Real y)
Returns the value of x modulo y (i.e., x % y) for floating-point values.
FILE fopen(String& file_nm, String& mode)
Opens given file name in the given mode, where the modes are "r", "w", and "a" for read, write and append. The FILE type is not actually a standard C FILE, but actually a fstream type, so stream operations can be performed on it.
void fprintf(FILE strm, v1 [,v2...])
Prints the given arguments (which must be comma separated) to the stream. Values to be printed can be of any type, and are actually printed with the << operator of the stream classes. Unlike the standard C function, there is no provision for specifying formatting information. Instead, the formatting must be specified by changing the parameters of the stream object. The FILE type is not actually a standard C FILE, but actually a fstream type, so stream operations can be performed on it.
Real Ftest_q(Real F, Real v1, Real v2)
Gives the F probability distribution for P(F | (v1 < v2)). Useful for performing statistical significance tests. The _q suffix means that this is the complement distribution.
Real gamma_cum(Int i, Real l, Real t)
The cumulative gamma distribution for event i with parameters l=lambda and t=time, which is the same as gamma_p(j, l * t).
Real gamma_den(Int j, Real l, Real t)
The gamma probability density function for j events, l=lambda, and t=time.
                 j  (j-1)
                l  t         -lt 
  P(j,l,t)  =  -----------  e           (t > 0)
                    j!
Real gamma_dev(Int j)
A random gamma deviate: how long it takes to wait until j events occur with a unit lambda (l=1).
Real gamma_ln(Real z)
The natural logarithm of the gamma function, which is a generalization of (n-1)! to real-valued arguments. Note that this is not the gamma probability distribution.
                x
              /   z-1  -t
  Gamma(z) =  |  t    e   dt 
              /
               0             
Real gamma_p(Real a, Real x)
The incomplete gamma function:
                          x            
                1       /   a-1  -t    
  P(a,x) =  --------    |  t    e   dt          (a > 0)
            Gamma(a)    /              
                         0             
Real gamma_q(Real a, Real x)
The incomplete gamma function as the complement of gamma_p
                         inf            
                1       /   a-1  -t    
  P(a,x) =  --------    |  t    e   dt          (a > 0)
            Gamma(a)    /              
                         x             
Real gauss_cum(Real x)
The cumulative of the Gaussian or normal distribution up to given x (sigma = 1, mean = 0).
Real gauss_den(Real x)
The Gaussian or normal probability density function at x with sigma = 1 and mean = 0.
Real gauss_dev()
Returns a Gaussian random deviate with unit variance and 0 mean.
String getcwd()
Returns the current working directory path.
String getenv(String var)
Returns the environment variable definition for varable var.
Int getegid()
Returns the current effective group id number for this process.
Int geteuid()
Returns the current effective user id number for this process.
Int getgid()
Returns the current group id number for this process.
Int getuid()
Returns the current user id number for this process.
String getlogin()
Returns the name the current user logged in as.
Int getpgrp()
Returns the process group id for current process.
Int getpid()
Returns the process id for current process.
Int getppid()
Returns the parent process id for current process.
Real hyperg(Int j, Int s, Int t, Int n)
The hypergeometric probability function for getting j number of the "target" items in an environment of size "n", where there are "t" targets and a sample (without replacement) of this environment of size "s" is taken.
Int isatty()
Returns true if the current input terminal is a tty (as opposed to a file or a pipe or something else).
Int link(String from, String to)
Creates a hard link from given file to other file. (see also symlink). Returns success and sets errno flag on failure.
Real log(Real x)
The natural logarithm of x.
Real log10(Real x)
The logarithm base 10 of x.
Int lrand48()
Returns a uniformly-distributed random number on the range of the integers.
MAX(<v1>, <v2>) or max(<v1>, <v2>)
Works like the commonly-used #define macro that gives the maximum of the two given arguments. The return type is that of the maximum-valued argument.
MIN(<v1>, <v2>) or min(<vi>, <v2>)
Just like MAX, except it returns the minimum of the two given arguments.
Int pause()
Pause (wait) until an alarm or other signal is received. Returns success and sets errno flag on failure.
void perror(String prompt)
Prints out the current error message to stderr (cerr). The prompt argument is printed before the error message. Also, the global variable errno can be checked. Further, there is an include file in css/include called errno.css that defines an enumerated type for the defined values of errno.
Real poisson_cum(Int j, Real l)
The cumulative Poisson distribution for getting 0 to j-1 events with an exected number of events of l (lambda).
Real poisson_den(Int j, Real l)
The Poisson probability density function for j events given an expected number of events of l (lambda).
               j
              l    -l
  P(j, l) =  ---- e
              j!
Real poisson_dev(Real l)
A random Poisson deviate with a mean of l (lambda).
Real pow(Real x, Real y)
Returns x to the y power. This can also be expressed in CSS as x ^ y.
void PrintR(<object>)
This is the function version of the printr command. Prints an object and any of its sub-objects in a indented style output. This can be very long for objects near the top of the object hierarchy (i.e., the root object), so be careful!
void printf(FILE strm, v1 [,v2...])
Prints the given arguments (which must be comma separated) to the standard output stream. Values to be printed can be of any type, and are actually printed with the << operator of the stream classes. Unlike the standard C function, there is no provision for specifying formatting information. Instead, the formatting must be specified by changing the parameters of the standard stream output object, cout. The FILE type is not actually a standard C FILE, but actually a fstream type, so stream operations can be performed on it.
Int random()
Returns a uniformly-distributed random number on the range of the integers. CSS actually uses the lrand48 function to generate the number given the limitations of the standard random generator.
String_Array& ReadLine(istream& strm)
Reads a line of data from the given stream, and returns a reference to an internal array (which is reused upon a subsequent call to ReadLine) of strings with elements containing the whitespace-delimited columns of the line. The size of the array gives the number of columns, etc. This allows one to easily implement much of the functionality of awk. See the file `css_awk.css' in `css/include' for an example.
Int rename(String from, String to)
Renames given file. Returns success and sets errno flag on failure.
Int rmdir(String dir_name)
Removes given directory. Returns success and sets errno flag on failure.
Int setgid(Int id)
Sets group id for given process to that given. Note that only the super-user can in general do this. Returns success and sets errno flag on failure.
Int setpgid(Int id)
Sets process group id for given process to that given. Note that only the super-user can in general do this. Returns success and sets errno flag on failure.
Int setuid(Int id)
Sets user id for given process to that given. Note that only the super-user can in general do this. Returns success and sets errno flag on failure.
Real sin(Real x)
The sine of angle x (given in radians). Use sin(x / DEG) if x is in degrees.
Real sinh(Real x)
The hyperbolic sine of x.
Real sqrt(Real x)
The square-root of x.
Int sleep(Int seconds)
Causes the process to wait for given number of seconds. Returns success and sets errno flag on failure.
Real students(Real t, Real v)
Gives the Student's distribution for v degrees of freedom t test.
Int symlink(String from, String to)
Creates a symbolic link from given file to other file. (see also link). Returns success and sets errno flag on failure.
void system(String& cmd)
Executes the given command in the Unix shell.
Real tan(Real x)
The tangent of angle x (given in radians). Use tan(x / DEG) if x is in degrees.
Real tanh(Real x)
The hyperbolic tangent of x.
Int tcgetpgrp(Int file_no)
Gets the process group associated with the given file descriptor. Returns success and sets errno flag on failure.
Int tcsetpgrp(Int file_no)
Sets the process group associated with the given file descriptor. Returns success and sets errno flag on failure.
String ttyname(Int file_no)
Returns the terminal name associated with the given file descriptor.
Token(<obj_type>, Int tok_no)
Returns the token of the given type of object at index tok_no in the list of tokens. Use the tokens command to obtain a listing of the tokens of a given type of object.
TypeDef Type(String& typ_nm)
Returns a type descriptor object (generated by TypeAccess), for the given type name. Typically, these types are available by simply using the type name directly, but this can be useful for accessing types that were not registered in the list of types used by CSS.
Int unlink(String fname)
Unlinks (removes) the given file name.