ScriptEase Standard Library

The Standard ScriptEase Library is based on the standard C libraries, as defined by ANSI and ISO. All of these routines are available to any ScriptEase program executed by ScriptEase.

Minimal modifications have been made to the standard C library to support the differences between the ScriptEase and the C languages. In most cases, these modifications involve the redefinition of a variable pointer to become a variable-passed-by-reference. Usually, the ScriptEase call to one of these functions looks identical to the C call. The experienced C programmer must only give thought to the changes when an ampersand (&) operator or a sizeof() statement would otherwise be in order.

A few functions are missing, mostly those dealing with locales (locales will be added if there is demand for them). A few functions have been added beyond those in the ANSI and ISO standards. The functions that seem to be common across most existing implementations of C libraries were implemented.

Note: Any functions beginning with "str" automatically tags character-arrays as "strings", which means that further use of those variables will always ensure that they are null-terminated.

The following defines are include as part of the standard ScriptEase library

CLOCKS_PER_SEC

(e.g. 18.2, 100) Number of system clock ticks
per second

FALSE

0 (Indicates FALSE)

TRUE

1 (Indicates TRUE)

NULL

0 Used to initialize arrays to being empty

EXIT_FAILURE

(e.g. 1, 255) Program return code to indicate failure

EXIT_SUCCESS

(e.g. 0) Program return code to indicate success

RAND_MAX

Maximum value returned by the rand function

EOF

Status returned when end of file is reached

stderr

FILE for standard error device; can be changed with freopen()

stdin

FILE for standard input device; can be changed with freopen()

stdout

FILE for standard output device; can be changed with freopen()

errno

errno is a variable used to store diagnostic messages in the case of an error in executing a fuction. Many library functions will set errno to non-zero in case of error to provide more specific information about the error. ScriptEase implements errno as a macro to the internal function_errno(). This variable can be accessed with perror() or strerror().

 


abort

DESCRIPTION

Terminate program; most likely due to an error.

SYNTAX

void abort()

void abort(bool AbortAll)

COMMENTS

Causes abnormal program termination, and should only be called on fatal error. It does not return to the caller, but instead exits returning EXIT_FAILURE to the operating system.

The second form of this call, which adds an additional parameters to the standard-C abort() function, will abort through all levels of ScriptEase interpretation. This means that if you are within multiple levels of interpret(), and AbortAll is TRUE (i.e., not FALSE), then this will abort through all interpret() levels.

RETURN

Does not return.

SEE ALSO

assert(), exit()


asctime

DESCRIPTION

Convert date and time to an ASCII string.

SYNTAX

string asctime(struct tm)

COMMENTS

Converts time stored in tm structure into an ascii string of this form:

Mon Jul 19 09:14:22 1993\n

See localtime() for a description of the tm structure.

RETURN

Returns ascii string, ending in newline and null-terminated, representing a date and time.

SEE ALSO

ctime(), gmtime(), localtime(), mktime(), time(), strftime()


abs

DESCRIPTION

Calculate the absolute value

SYNTAX

int abs(int x)

COMMENTS

Since int and long int are the same in ScriptEase, this function is the same as labs().

RETURN

Returns the absolute (positive) value of x.

SEE ALSO

labs(), fabs(),


acos

DESCRIPTION

Calculate the arc cosine.

SYNTAX

float acos(float x)

RETURN

Return arc cosine of x in the range [0,pi] radians.


asin
 

DESCRIPTION

Calculate the arc sine.

SYNTAX

float asin(float x)

RETURN

Return arc sine of x in the range [-pi/2,pi/2] radians.


assert
 

DESCRIPTION

Test a condition and abort if it is FALSE.

SYNTAX

void assert(bool test)

COMMENTS

If the assertion test evaluates to FALSE then will print file name and line number to stderr, and then abort. If the assertion evaluates to TRUE then the program continues. assert() is typically used as a debugging technique to test that assumptions are true before executing code that is based on those assumptions. Unlike C, the ScriptEase implementation of assert does not depend upon NDEBUG being defined or undefined. It is always active.

RETURN

None. Will abort if the assertion fails.

SEE ALSO

abort(), exit()

EXAMPLE

The Inverse() function returns the inverse of the input number (i.e., 1/x):

Inverse(x) // return 1/x

{

assert(0 != x);

return 1 / x;

}

 


atan
 

DESCRIPTION

Calculate the arc tangent.

SYNTAX

float atan(float x)

RETURN

Return arc tangent of x in the range [-pi/2,pi/2] radians.


atan2
 

DESCRIPTION

Calculate the arc tangent of a fraction.

SYNTAX

float atan2(float y, float x)

RETURN

Return the arc tangent of y/x, in the range [-pi, +pi] radians.


atexit
 

DESCRIPTION

Register function to be called at program exit.

SYNTAX

void atexit(string FunctionName)

COMMENTS

Function name is string for function to call.

SEE ALSO

abort(), assert(), exit()


atof
 

DESCRIPTION

Convert ascii string to a floating-point number.

SYNTAX

float atof(string str)

COMMENTS

Converts the ascii string str, as long as str can be converted, to a floating-point value.

RETURN

Return str converted to floating-point. Returns 0 if the string evaluates to 0 ("0.000", e.g.), or str cannot be converted to a floating point number.


atoi
 

DESCRIPTION

Convert ascii string to an integer.

SYNTAX

int atoi(string str)

COMMENTS

Converts the ascii string str, as long as str can be converted, to an integer.

RETURN

Return str converted to an integer. Returns 0 if the string evaluates to 0, or str cannot be converted to an integer.


atol
 

DESCRIPTION

Convert ascii string to an integer.

SYNTAX

int atol(string str)

COMMENTS

Converts the ascii string str, as long as str can be converted, to an integer. This is the same as the atoi() function because longs and integers are the same in ScriptEase.

RETURN

Return str converted to an integer. Returns 0 if sting is equivalent to zero (0.00, e.g.), or str cannot be converted to an integer.


bsearch
 

DESCRIPTION

Binary search for member of a sorted array.

SYNTAX

var[] bsearch(var key, var [] SortedArray, [int ElementCount,]
string CompareFunction)

COMMENTS

The CompareFunction will receive the key variable as its first argument and a variable from the array as its second argument. If ElementCount is not supplied then will search the entire array.

RETURN

Will return the array variable at the offset in the array of the found element, else NULL if the key is not matched in the array. This function assumes all array indices are greater than or equal to 0.

NOTE

ElementCount is limited to 64K for 16-bit version of ScriptEase.

SEE ALSO

qsort()

EXAMPLE

The following example demonstrates the use of qsort() and bsearch() to locate a name and related item in a list:

// create array of names and favorite food

list = {

{ "Brent", "salad" },

{ "Laura", "cheese" },

{ "Alby", "sugar" },

{ "Josh", "anything" },

{ "Aiko", "cats" },

{ "Quinn", "anything from the garbage" }

};

// sort the list

qsort(list,"ListCompareFunction");

// Create key to search for item

// key must work in compare function

Key[0] = "brent";

// search for the name Brent in the list

Found = bsearch(Key,list,"ListCompareFunction");

// display name, or not found

if ( Found )

printf("%s's favorite food is %s\n",

Found[0][0],Found[0][1]);

else

puts("Could not find name in favorite-food list.");

 

ListCompareFunction(Item1,Item2) // used in qsort and { // bsearch

return strcmpi(Item1[0],Item2[0]);

}


ceil
 

DESCRIPTION

Ceiling; round up.

SYNTAX

float ceil(float x)

RETURN

Return the smallest integral value not less than x.

SEE ALSO

floor()


clearerr
 

DESCRIPTION

Clear end-of-file and error status for a file.

SYNTAX

void clearerr(FILE stream)

COMMENTS

Clear error status end reset end-of-file flags for this file stream.

RETURN

None.

SEE ALSO

ferror()


clock
 

DESCRIPTION

Get processor time.

SYNTAX

int clock()

COMMENTS

Gets a processor and operating-system dependent value for the clock. This value is incremented CLOCKS_PER_SEC times per second. Clock value starts at 0 when ScriptEase program begins.

RETURN

Return current processor tick count.

SEE ALSO

time()


cos
 

DESCRIPTION

Calculate the cosine.

SYNTAX

float cos(float x)

RETURN

Return the cosine of x in radians.


cosh
 

DESCRIPTION

Calculate the hyperbolic cosine.

SYNTAX

float cosh(float x)

RETURN

Return the hyperbolic cosine of x.


ctime
 

DESCRIPTION

Convert date-time to an ascii string.

SYNTAX

string ctime(int time)

COMMENTS

time is a date-time value as returned by the time() function.

ctime() is equivalent to: asctime(localtime(time))

RETURN

Returns ascii string as returned by the asctime() function.

SEE ALSO

asctime(), gmtime(), localtime(), mktime(), time(), strftime()


difftime
 

DESCRIPTION

Compute difference between two times.

SYNTAX

float difftime(int time1,int time0)

COMMENTS

Compute time in seconds corresponding to time1 - time0, where time1 and time0 are the value types as might be returned by the time() function.

RETURN

time1 - time0 in seconds.

SEE ALSO

time()


div
 

DESCRIPTION

Integer division, returning quotient and remainder.

SYNTAX

struct div(int numerator, int denominator)

COMMENTS

Same as ldiv(). The value returned is a structure with the following elements:

.quot quotient

.rem remainder

RETURN

Returns result in a structure with quotient (.quot) and remainder (.rem) members.

SEE ALSO

ldiv(), fmod(), modf()


exit
 

DESCRIPTION

Normal program termination.

SYNTAX

void exit(int status)

COMMENTS

Calls all functions registered with atexit(), flushes and closes all open file streams, updates environment variables if applicable to this version of ScriptEase, and returns control to the OS environment with the return code of status.

RETURN

Does not return.

SEE ALSO

abort(), assert(), atexit()

 


exp
 

DESCRIPTION

Compute the exponential function.

SYNTAX

float exp(float x)

RETURN

Return the exponential value of x.

SEE ALSO

frexp(), ldexp(), pow()


fabs
 

DESCRIPTION

Absolute value.

SYNTAX

float fabs(float x)

RETURN

Return the absolute (i.e., non-negative) value of x.

SEE ALSO

abs()


fclose
 

DESCRIPTION

Close an open file.

SYNTAX

int fclose(FILE stream)

COMMENTS

Cause the stream file buffers to be flushed and then closes the file, making stream no longer valid.

RETURN

Returns zero for success, else returns EOF.

SEE ALSO

fopen(), fflush(), freopen()


feof
 

DESCRIPTION

Test if at end of file stream.

SYNTAX

bool feof(FILE stream)

COMMENTS

Test end-of-file indicator for stream.

RETURN

Returns an integer which is non-zero if at end of file, and 0 if NOT at end of file.

SEE ALSO

clearerr(), ferror()


ferror
 

DESCRIPTION

Test for error on a file stream.

SYNTAX

int ferror(FILE stream)

COMMENTS

Tests and returns the error indicator for stream file.

RETURN

Returns 0 if no error, else returns the error value.

SEE ALSO

clearerr(), strerror()


fflush
 

DESCRIPTION

Flush stream for open file(s).

SYNTAX

int fflush(FILE stream)

COMMENTS

Causes any unwritten buffered data to be written to the file. If stream is NULL then flushes buffers in all open files.

RETURN

Returns zero for success, otherwise EOF.

SEE ALSO

fclose(), fopen(), freopen()


fgetc
 

DESCRIPTION

Get a character from file stream.

SYNTAX

int fgetc(FILE stream)

COMMENTS

Read the next character, if there is one, from stream.

RETURN

Return the next character as a byte converted to an integer (remember that all bytes in ScriptEase are unsigned. Return EOF if there is a read error or if at end-of-file; if read error then ferror() will indicate the error condition.

SEE ALSO

getc(), getch(), getchar(), getche(), ungetc()


fgetpos
 

DESCRIPTION

Get current position of a file stream.

SYNTAX

int fgetpos(FILE stream, Var pos)

COMMENTS

Stores the current position of the file stream pointer for future restoration using fsetpos().

MODIFIES

Sets pos to be a variable of undefined type for file-position restoration on a later call to fsetpos.

RETURN

Returns zero for success, else non-zero and an error value is stored in errno.

SEE ALSO

fseek(), fsetpos(), ftell(), rewind()


fgets
 

DESCRIPTION

Get a string from an input stream.

SYNTAX

string fgets([string buf[, int buflen], ] FILE stream)

COMMENTS

Reads a string into buf until buflen-1 characters are read or until a newline is read, whichever comes first. If a newline was read then it is retained at the end of buf. A null byte (`\0') as always appended at the end of the string. If buf is not supplied then a buffer variable is automatically created. If buflen is not supplied then a very large value for buflen is assumed.

MODIFIES

If buf is supplied, then it will be altered to be a string, if necessary, and the data read will be stored in buf.

RETURN

If error or end-of-file then return NULL, else return the value of buf if buf is supplied or the variable created if buf is not supplied.

SEE ALSO

fputs(), fscanf(), gets()


floor
 

DESCRIPTION

Round down.

SYNTAX

float floor(float x)

RETURN

Return the largest integral value not greater than x.

SEE ALSO

ceil()


fmod
 

DESCRIPTION

Modulus; calculate remainder.

SYNTAX

float fmod(float x, float y)

RETURN

Return the remainder of x / y.

SEE ALSO

div(), ldiv(), modf()


fopen
 

DESCRIPTION

Open a file.

SYNTAX

FILE fopen(string filename, string mode)

COMMENTS

This function opens the file specified by filename for file operations specified by mode.

Filename can be any valid file name, excluding wildcard characters.

Mode is a string composed of `r', `w', or `a' followed by other characters as follows:

r open file for reading; file must already exist

w open file for writing; create if doesn't exist; if file exists then truncate to zero length

a open file for append; create if doesn't exist; set for writing at end-of-file

b binary mode; if b is not specified then open file in text mode (end-of-line translation)

t text mode

+ open for update (reading and writing)

When a file is successfully opened, its error status is cleared and buffer is initialized for automatic buffering of reads and writes to the file.

RETURN

Returns NULL for failure, else returns FILE handle (which is a blob) for subsequent file actions.

SEE ALSO

fclose(), freopen(), fflush()

EXAMPLE

The following code opens the text file "ReadMe" for text-mode reading, and prints out each line in that file:

fp = fopen("ReadMe","r");

if ( fp == NULL )

printf("\aError opening file for reading.\n")

else {

while ( NULL != (line=fgets(fp)) ){

fputs(line,stdout);

}

fclose(fp);

}

This function copies binary files one byte at a time (buffers would be faster):

BinaryCopy(SrcFile,DstFile)

// binary copy SrcFile to DstFile;

// return TRUE for success {

success = FALSE; // assume failure

SrcFP = fopen(SrcFile,"rb");

if ( SrcFP == NULL )


printf("Unable to open \"%s\" for reading.\n",SrcFile);
else {
DstFP = fopen(DstFile,"wb");
if ( DstFP == NULL )
printf("Unable to open \"%s\" for writing.\n",DstFile);
else {
// copy one byte at a time from source to destination
while( EOF != (c = fgetc(SrcFP)) )
fputc(c,DstFP);
// success if there were no errors on either file
if ( ferror(SrcFP) )
printf("Error reading from source file.\n")
else if ( ferror(DstFP) )
printf("Error writing to destination file.\n")
else
success = TRUE;
if ( fclose(DstFP) ) {
success = FALSE;
printf("Error closing dest. file \"%s\"\n", DstFP);
}
}
fclose(SrcFP);
}
// if not success then make a long beeping noise
if ( !success )
printf("\a\a\a\a");
return(success);

}


fprintf
 

DESCRIPTION

Formatted output to a file stream.

SYNTAX

int fprintf(FILE stream,string format,...)

COMMENTS

This flexible function writes output to the file specification specified by stream according to the format string. The format string can contain character combinations indicating how following parameters may be written.

stream must have been previously opened with write access (most likely with fopen()).

See printf() for a description of this format string.

RETURN

Returns the number of characters written, or a negative number if there was an output error.

SEE ALSO

fputs(), printf(), puts(), sprintf(), vfprintf()


fputc
 

DESCRIPTION

Write a character to a file stream.

SYNTAX

int fputc(int c,FILE stream)

COMMENTS

Write the character c, converted to a byte, to output file stream.

RETURN

Returns c for success, and EOF for a write error.

SEE ALSO

putc(), putchar()


fputs
 

DESCRIPTION

Write a string to a file stream.

SYNTAX

int fputs(string s,FILE stream)

COMMENTS

Write the string s to stream. Do not write the terminating null character.

RETURN

Returns EOF if write error, else returns a non-negative value.

SEE ALSO

fgets(), fprintf(), puts()


fread
 

DESCRIPTION

Read data from a file.

SYNTAX

int fread(byte[] DestBuffer,bufferLen,stream)

int fread(Var DestVar,int DataTypeInFile,stream)

int fread(struct DestStruct,struct DataStructureDefinition,stream)

COMMENTS

Reads data from a file opened for reading into a destination variable. The destination is created, if necessary, to contain the data read. In the first syntax form for this routine, up to bufferLen bytes are read into the DestBuffer byte array. In the second syntax form for this routine, a single data item is read into DestVar, and the DataTypeInFile parameter specifies how that data is to be read from the file. DataTypeInFile may be one of the following:

UWORD8 Stored as a byte in DestVar

SWORD8 Stored as an integer in DestVar

UWORD16 Stored as an integer in DestVar

SWORD16 Stored as an integer in DestVar

UWORD24 Stored as an integer in DestVar

SWORD24 Stored as an integer in DestVar

UWORD32 Stored as an integer in DestVar

SWORD32 Stored as an integer in DestVar

FLOAT32 Stored as an float in DestVar

FLOAT64 Stored as an float in DestVar

FLOAT80 Stored as an float in DestVar

In the third form, which reads data into a ScriptEase structure, the DataStructureDefinition sets each possible element of DestStruct from the same elements of DataStructureDefinition, with the exception that member names beginning with an underscore (_) are not copied. This allows you to read only those portions of the structure in the file that you are interested in. For example, the definition of a structure might be:

ClientDef.Sex = UWORD8;

ClientDef.MaritalStatus = UWORD8;

ClientDef._Unused1 = UWORD16;

ClientDef.FirstName = 30;

ClientDef.LastName = 40;

ClientDef.Initial = UWORD8;

The ScriptEase version of fread() differs from the standard C version in that the standard C library is set up for reading arrays of numeric values or structures into consecutive bytes in memory.

For the second and third forms, data types will be read from the file in a byte-order described by the current value of the _BigEndianMode variable (see _BigEndianMode in chapter 8).

MODIFIES

Modifies the first input parameter. If DestBuffer is the first parameter then set buffer to be an array of characters. If buffer is a DataType then create or modify DestVar to hold the numeric DataType.

RETURN

Returns the number of elements read. For DestBuffer this would be the number of bytes read, up to bufferLen. For DataTypeInFile this returns 1 if the data is read or 0 if read error or end-of-file is encountered.

SEE ALSO

_BigEndianMode, fopen(), fwrite()

EXAMPLE

To read the 16-bit integer `i', the 32-bit float `f', and then 10-byte buffer `buf' from open file `fp':

if ( !fread(i,SWORD16,fp) || !fread(f,FLOAT32,fp)

|| 10 != fread(buf,10,fp) ) {

printf("Error reading from file.\n");

abort();

}


freopen
 

DESCRIPTION

Assign a new file specification to a file handle.

SYNTAX

FILE freopen(string filename,string mode,FILE OldFP)

COMMENTS

This function closes the file associated with OldFP (ignoring any close errors), and then opens filename according to mode, just as in the fopen() call, and reassociated OldFP to this new file specification. This function is most commonly used to redirect one of the pre-defined file handles (stdout, stderr, stdin) to or from a file.

MODIFIES

Modifies OldFP to be associated with the new file specification.

RETURN

Returns NULL for failure, else returns a copy of the modified OldFP.

SEE ALSO

fclose(), fopen(), fflush()

EXAMPLE

This sample code will call the ScriptEase for DOS program with no parameters (which causes a help screen to be printed), but redirecting stdout to a file CENVI.OUT so that CENVI.OUT will contain the text of the ScriptEase help screens.

if ( NULL == freopen("CENVI.OUT","w",stdout) )

printf("Error redirecting stdout\a\n");

else

system("SEDOS")


frexp
 

DESCRIPTION

Break into a mantissa and an exponential power of 2.

SYNTAX

float frexp(float x,int exponent)

COMMENTS

Breaks x into a normalized mantissa between 0.5 and 1.0, or zero, and calculates and calculates an integer exponent of 2 such that x=mantissa*2 ^ exponent.

MODIFIES

Modifies exponent, to the exponent.

RETURN

Returns normalized mantissa between 0.5 and 1.0, or 0.

SEE ALSO

exp(), frexp(), ldexp(), pow()


fscanf
 

DESCRIPTION

Formatted input from a file stream.

SYNTAX

int fscanf(FILE stream,string format,...)

COMMENTS

This flexible function reads input from a file specification and stores in parameters following the format string according the character combinations in the format string, which indicate how the file data is to be read and stored. Stream must have been previously opened with read access.

See scanf() for a description of this format string.

MODIFIES

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

RETURN

Returns EOF if input failure before any conversion occurs, else returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure.

SEE ALSO

atof(), atoi(), atol(), scanf(), sscanf(), vfscanf(), vsscanf()

EXAMPLE

With the following text file, WEIGHT.DAT:

Crow, Barney 180

Claus, Santa 306

Mouse, Mickey 2

then this code:

fp = fopen("WEIGHT.DAT","r");

FormatString = "%[
,] %*c %s %d\n";

while (3==fscanf(fp,FormatString,LastName,

Firstame,weight) )

printf("%s %s weighs %d pounds.\n",

FirstName,LastName,weight);

fclose(fp);

would result in this output:

Barney Crow weighs 180 pounds.

Santa Claus weighs 306 pounds.

Mickey Mouse weighs 2 pounds.


fseek
 

DESCRIPTION

Set the file position for an opened file stream

SYNTAX

int fseek(FILE stream,int offset[,int mode])

COMMENTS

Set the position offset of the file pointer of an open file stream. mode can be any of the following predefined values:

SEEK_CUR seek is relative to the current position of the file

SEEK_END position is relative from the end of the file

SEEK_SET position is relative to the beginning of the file

If mode is not supplied then absolute offset from the beginning of file (SEEK_SET) is assumed. For text files (i.e., not opened in binary mode) the file position may not correspond exactly to the byte offset in the file.

RETURN

Returns zero for success, or non-zero if cannot set the file pointer to the indicated position.

SEE ALSO

fgetpos(), fsetpos(), ftell(), rewind()


fsetpos
 

DESCRIPTION

Set position of a file stream.

SYNTAX

int fsetpos(stream,Var pos)

COMMENTS

Set the current file stream pointer to the value defined in pos, which should be a value obtained from a previous call to fsetpos(stream,pos) on the same open file stream.

RETURN

Returns zero for success, else non-zero and an error value is stored in errno.

SEE ALSO

fgetpos(), fseek(), ftell(), rewind()


ftell
 

DESCRIPTION

Get the current value of the file position.

SYNTAX

int ftell(FILE stream)

COMMENTS

Gets the position offset of the file pointer of an open file stream from the beginning of the file. For text files (i.e., not opened in binary mode) the file position may not correspond exactly to the byte offset in the file.

RETURN

Returns the current value of the file position indicator, or -1 for an error and an error value is stored in errno.

SEE ALSO

fgetpos(), fseek(), fsetpos(), rewind()


fwrite
 

DESCRIPTION

Write data to a file.

SYNTAX

int fwrite(byte[] SourceBuffer,bufferLen,FILE stream)

int fwrite(Var SourceVar,int DataTypeInFile,FILE stream)

COMMENTS

Writes data from a variable into the current location of a file opened for writing.

In the first syntax form of this routine, up to bufferLen bytes are written from the SourceBuffer byte array.

In the second syntax form of this routine, a single data item is written from SourceVar, and the DataTypeInFile parameter specifies how that data is to be read from the file. See fread() (above) for valid DataTypeInFile parameters.

The ScriptEase version of fwrite() differs from the standard C version in that the standard C library is set up for writing arrays of numeric values or structures from consecutive bytes in memory.

RETURN

Returns the number of elements written. For DestBuffer this would be the number of bytes written, up to bufferLen. For DataTypeInFile this returns 1 if the data is written or 0 if a write error or end-of-file is encountered.

SEE ALSO

_BigEndianMode, fopen(), fread()

EXAMPLE

To write the 16-bit integer `i', the 32-bit float `f', and then 10-byte buffer `buf' into open file `fp':

if ( !fwrite(i,SWORD16,fp) || !fwrite(f,FLOAT32,fp)

|| 10 != fwrite(buf,10,fp) )

{

printf("Error writing to file.\n");

abort();

}

 


getc
 

DESCRIPTION

Get a character from file stream.

SYNTAX

int getc(FILE stream)

COMMENTS

This function is identical to fgetc().

RETURN

Returns the next character as a byte (unsigned) converted to an integer. Returns EOF if there is a read error or if at end-of-file; if read error then ferror() will indicate the error condition.

SEE ALSO

fgetc(), getch(), getchar(), getche(), ungetc()


getch
 

DESCRIPTION

Get a character from the keyboard; without echo.

SYNTAX

int getch()

COMMENTS

Read keyboard key pressed without echoing to the screen. If no key is available then will wait until a key is pressed. Some key presses, such as extended keys and function keys, may generate multiple getch() return values.

RETURN

Character read from the keyboard.

SEE ALSO

fgetc(), getc(), getchar(), getche(), ungetc()


getchar
 

DESCRIPTION

Get a character from standard input (keyboard).

SYNTAX

int getchar()

COMMENTS

Get the next character from the stdin stream. This call is the same as fgetc(stdin).

RETURN

Return the next character as a byte (unsigned) converted to an integer. Return EOF if there is a read error or if at end-of-file; if read error then ferror() will indicate the error condition.

SEE ALSO

fgetc(), getc(), getch(), getche(), ungetc()


getche
 

DESCRIPTION

Get a character from the keyboard; with echo.

SYNTAX

int getch()

COMMENTS

Read keyboard key pressed with echo to the screen. If no key is available then will wait until a key is pressed. Some key presses, such as extended keys and function keys, may generate multiple getche() return values.

RETURN

Character read from the keyboard.

SEE ALSO

fgetc(), getc(), getch(), getchar(), ungetc()


getenv
 

DESCRIPTION

Get an environment string.

SYNTAX

string getenv(string VariableName)

string[] getenv()

COMMENTS

In the first form (the standard form), returns the value of VariableName, where VariableName is an environment variable, as a string. In the second form, with no parameter supplied, this returns an array of all the environment variable names. The last element of this array will always be NULL.

RETURN

If VariableName is supplied, then this returns environment value as a string if the variable exists in the environment, or returns NULL if VariableName does not exist. If no name is supplied then returns an array of all environment variable names, ending with a NULL element.

SEE ALSO

putenv()

EXAMPLE

The following code would print the existing environment variables, in "EVAR=Value" format, sorted alphabetically.

// get array of all environment variable names

EnvList = getenv();

// sort array alphabetically

qsort(EnvList,GetArraySpan(EnvList),"stricmp");

// display each element in ENV=VALUE format

for ( lIdx = 0; EnvList[lIdx]; lIdx++ )

printf("%s=%s\n",EnvList[lIdx],getenv(EnvList[lIdx]));


gets
 

DESCRIPTION

Read a string from standard input (keyboard).

SYNTAX

string gets([string buf])

COMMENTS

Reads a string into buf until a newline or EOF is read. If a newline was read then it is discarded. A null byte (`\0') as always appended at the end of the string. If buf is not supplied, a buffer variable is automatically created.

This function is identical to fgets(buf,stdin) except that new-lines are discarded.

MODIFIES

If buf is supplied, then it will be altered to be a string, if necessary, and the data read will be stored in buf.

RETURN

If error or end-of-file then return NULL, else return the value of buf if buf is supplied or the variable created if buf is not supplied.

SEE ALSO

fgets(), puts(), scanf()


gmtime
 

DESCRIPTION

Convert date and time to Greenwich mean time (GMT).

SYNTAX

struct gmtime(int t)

COMMENTS

Takes the integer t, which is the data type returned by the time() function, and converts to a structure representing date and time fields converted to Greenwich mean time.

RETURN

Returns structure for GMT. See localtime() for a description of the returned structure.

SEE ALSO

asctime(), ctime(), localtime(), time(), strftime()


isalnum
 

DESCRIPTION

Test for alphanumeric character.

SYNTAX

bool isalnum(int c)

RETURN

Return TRUE if c is a letter (A to Z or a to z) or a digit (0 to 9), else return FALSE.


isalpha
 

DESCRIPTION

Test for alphabetic character.

SYNTAX

bool isalpha(int c)

RETURN

Return TRUE if c is a letter (A to Z or a to z), else return FALSE.


isascii
 

DESCRIPTION

Test for ASCII coded character.

SYNTAX

bool isascii(int c)

RETURN

Return TRUE if c is in the range 0 to 127, inclusive, else return FALSE.


iscntrl
 

DESCRIPTION

Test for any control character.

SYNTAX

bool iscntrl(int c)

RETURN

Return TRUE if c is a control character or delete character, else return FALSE.


isdigit
 

DESCRIPTION

Test for any decimal-digit character.

SYNTAX

bool isdigit(int c)

RETURN

Return TRUE if c is a digit (0 to 9), else return FALSE.


isgraph
 

DESCRIPTION

Test for any printing character except for space.

SYNTAX

bool isgraph(int c)

RETURN

Return TRUE if c is a printable character that is not a space, else return FALSE.


islower
 

DESCRIPTION

Test for lower-case alphabetic letter.

SYNTAX

bool islower(int c)

RETURN

Return TRUE if c is a lowercase letter (a to z), else return FALSE.


isprint
 

DESCRIPTION

Test for any printing character including space.

SYNTAX

bool isprint(int c)

RETURN

Return TRUE if c occupies one space when printed, else return FALSE.


ispunct
 

DESCRIPTION

Test for punctuation character.

SYNTAX

bool ispunct(int c)

RETURN

Return TRUE if c is a punctuation character, else return FALSE.


isspace
 

DESCRIPTION

Test for white-space character.

SYNTAX

bool isspace(int c)

RETURN

Return TRUE if c is a whitespace character (alters position on display device without displaying a graphic), else return FALSE. Space, tab, and carriage-return are examples of whitespace characters.


isupper
 

DESCRIPTION

Test for upper-case alphabetic character.

SYNTAX

bool isupper(int c)

RETURN

Return TRUE if c is an uppercase letter (A to Z), else return FALSE.


isxdigit
 

DESCRIPTION

Test for hexadecimal-digit character.

SYNTAX

bool isxdigit(int c)

RETURN

Return TRUE if c is a hexadecimal digit (0 to 9, A to F, or a to f), else return FALSE.


kbhit
 

DESCRIPTION

Check if a keyboard keystroke is available.

SYNTAX

bool kbhit()

COMMENTS

Test whether a key-press is available to be returned by either getch() or getche().

RETURN

Return TRUE if a key has been pressed, else FALSE.

SEE ALSO

getch(), getche()

EXAMPLE

The following routine can be called to check if the user has pressed the `Q' key:

IsItQYet()

// Throw out all keys until Q is pressed.

{

// Return TRUE if Q has been pressed.

while( kbhit() )

{

if ( `Q' == toupper(getch()) ) return TRUE;

}

return FALSE;

}


labs
 

DESCRIPTION

Return the absolute value of an integer (non-negative).

SYNTAX

int labs(int x)

COMMENTS

Since int and long int are the same in ScriptEase, this function is the same as abs().

RETURN

Returns the absolute (positive) value of x.

SEE ALSO

abs()


ldexp
 

DESCRIPTION

Calculate mantissa * 2 ^ exp; inverse of frexp().

SYNTAX

float ldexp(float mantissa, int exponent)

COMMENTS

This is the inverse function of frexp(). It calculates mantissa * 2
exponent.

RETURN

Returns the result of the calculation: mantissa * 2
exponent.

SEE ALSO

exp(), frexp(), pow()


ldiv
 

DESCRIPTION

Integer division, returning quotient and remainder.

SYNTAX

struct ldiv(int numerator, int denominator)

COMMENTS

Same as div(). The value returned is a structure with the following element members:

.quot quotient

.rem remainder

RETURN

Returns result in a structure with quotient (.quot) and remainder(.rem) members.

SEE ALSO

div(), fmod(), modf()


localtime
 

DESCRIPTION

Convert date and time to broken-down structure.

SYNTAX

struct localtime(int t)

COMMENTS

Convert the calendar time t, as might be returned by the time() function, into a broken-down date-time structure.

RETURN

Returns t converted to a structure with the following integer elements:

.tm_sec second after the minute (from 0)

.tm_min minutes after the hour (from 0)

.tm_hour hour of the day (from 0)

.tm_mday day of the month (from 1)

.tm_mon month of the year (from 0)

.tm_year years since 1900 (from 0)

.tm_wday days since Sunday (from 0)

.tm_yday day of the year (from 0)

.tm_isdst daylight-savings-time flag

SEE ALSO

asctime(), ctime(), gmtime(), time(), strftime()

EXAMPLE

The following function prints the current date and time on the screen, and then returns to its caller the day of the year, where Jan 1. is the 1st day of the year:

ShowToday()

// show today's date; return day of the year in USA format

{

// get current time structure

tm = localtime(time());

// display the date in USA format

printf("Date: %02d/%02d/%02d ", tm.tm_mon+1,

tm.tm_mday,

tm.tm_year % 100);

// convert hour to run from 12 to 11, not 0 to 23

hour = tm.tm_hour % 12;

if ( hour == 0 )

hour = 12;

// print current time

printf("Time: % 2d:%02d:%02d\n", hour, tm.tm_min,

tm.tm_sec);

// return day of year, where Jan. 1 would be day 1

return( tm.tm_yday + 1 );

}


log
 

DESCRIPTION

Calculate the natural logarithm.

SYNTAX

float log(float x)

RETURN

Return the natural logarithm of x.

SEE ALSO

exp(), log10(), pow()


log10
 

DESCRIPTION

Calculate the base-ten logarithm.

SYNTAX

float log10(float x)

RETURN

Return the base-ten logarithm of x.

SEE ALSO

exp(), log, pow()


max
 

DESCRIPTION

Return the largest of one or more values.

SYNTAX

var max(var v1[,var v2[,var v3[,...]]])

COMMENTS

Similar to the standard C macro max() with the addition that only one variable must be supplied and any number of other variables may be supplied for the comparison.

RETURN

Return the maximum value of all the variables passed to this function.

SEE ALSO

min()


memchr
 

DESCRIPTION

Search a byte array, or blob, for a character.

SYNTAX

byte[] memchr(byte[] array, byte c[, int size])

COMMENTS

Searches all the bytes in a byte array (which could be a blob) and returns a variable for this array that starts at the first occurrence of byte c. If size is not specified then searches the entire array from element zero.

RETURN

Returns NULL if c is not found in array; else returns var for this array offset to the first occurrence of c.

SEE ALSO

strchr()


memcmp
 

DESCRIPTION

Compare two byte arrays.

SYNTAX

int memcmp(byte[] array1, byte[] array2[, int len])

COMMENTS

Compare the first len bytes of array and array2. If len is not specified then len is the smaller of the array index spans of array1 and array2. If one of the arrays is shorter than the length specified, ScriptEase will treat it as being len.

RETURN

Returns result of comparison, which will be:

< 0 if array1 is less than array2

= 0 if array1 is the same as array2 for len bytes

> 0 if array 1 is greater than array2

SEE ALSO

memicmp(), strncmpi(), strnicmp()

EXAMPLE

This function will check to see if the shorter string is the same as the beginning of the longer string. This function differs from strcmp() in that this function will return TRUE if given the strings "foo" and "foobar", because it only compares characters up to the end of the shorter string.

MyStrCmp(string1,string2)

{

len = min(strlen(string1),strlen(string2));

return(memcmp(string1,string2,len));

}


memcpy
 

DESCRIPTION

Copy bytes from one array to another.

SYNTAX

byte[] memcpy(byte[] dest, byte[] src[, int len])

COMMENTS

Copies len bytes from src array to dest array. If dest is not already defined then this defines it as a byte array. If len is not supplied then copies all of the bytes from src to dest.

ScriptEase insures protection from data overwrite, so in ScriptEase the memcpy() function is the same as memmove().

RETURN

Returns the value of dest; that is, a variable into the dest array based at dest[0].

SEE ALSO

memmove(), strncpy()


memicmp
 

DESCRIPTION

Case-insensitive compare two byte arrays.

SYNTAX

int memicmp(byte[] array1,byte[] array2[,int len])

COMMENTS

Compare the first len bytes of array1 and array2. If len is not specified then len is the smaller of the array index spans of array1 and array2. Each byte comparison is case-insensitive, so `A' is equal to `a'. If one of the arrays is shorter than the length specified, ScriptEase will treat it as being len.

RETURN

Returns result of comparison, which will be:

< 0 if array1 is less than array2

= 0 if array1 is the same as array2 for len bytes

> 0 if array 1 is greater than array2

SEE ALSO

memcmp(), strncmp()

EXAMPLE

This function performs the same as the internal stricmp() library function.

MyStrICmp(string1,string2)

{

len = min(strlen(string1),strlen(string2));

return(memicmp(string1,string2,len));

}


memmove
 

DESCRIPTION

Copy bytes from one array to another.

SYNTAX

byte[] memmove(byte[] dest, byte[] src[, int len])

COMMENTS

Copies len bytes from src array to dest array. If dest is not already defined then this defines it as a byte array. If len is not supplied then copies all of the bytes from src to dest. ScriptEase insures protection from data overwrite, so in ScriptEase the memcpy() function is the same as memmove().

RETURN

Returns the value of dest; that is, a variable into the dest array based at dest[0].

SEE ALSO

memcpy(), strncpy()


memset
 

DESCRIPTION

Set values in a byte array to specific character.

SYNTAX

byte[] memset(byte[] buf, int c[, int len])

COMMENTS

Sets the first len bytes of buf to character c. If buf is not already defined then this defines it as a byte array of size len. If buf is less than len bytes big then buf is grown to be big enough for len. If len is not supplied then len is the total size of buf (starting at index 0).

RETURN

Returns the value of buf; that is, a variable into the buf array based at buf[0].


min
 

DESCRIPTION

Return the minimum of one or more values.

SYNTAX

var min(var v1[,var v2[,var v3[,...]]])

COMMENTS

Similar to the standard C macro min() with the addition that only one variable must be supplied; any number of other variables may be supplied for the comparison.

RETURN

Return the minimum value of all the variables passed to this function.

SEE ALSO

max()


mktime
 

DESCRIPTION

Convert time structure into calendar time.

SYNTAX

int mktime(struct TimeStruct)

COMMENTS

This creates a calendar time, which is the time format returned by time(), from the elements of the TimeStruct structure. TimeStruct is a structure of the format used by localtime(). All elements of TimeStruct not defined will be set to 0.

RETURN

Returns time structure converted to calendar time. Return -1 if time cannot be converted or represented.

SEE ALSO

asctime(), ctime(), gmtime(), localtime(), time(), strftime()


modf
 

DESCRIPTION

Split a value into integer and fractional parts.

SYNTAX

float modf(float x, float i)

COMMENTS

Splits x into integer and fraction parts, where integer and fraction both have the same sign as x.

MODIFIES

Sets i to the integer part of x.

RETURN

Returns the fraction part of x.

SEE ALSO

ldiv(), fmod()


perror
 

DESCRIPTION

Prints an message describing error in errno

SYNTAX

void perror(string s)

void perror()

COMMENTS

Prints an error message describing the error defined by errno. This function is identical to calling strerror(errno). If s is supplied then the error string is copied to s and s is returned. If s is not supplied then only returns the error string.

RETURN

None.

SEE ALSO

errno, strerror()


pow

 

DESCRIPTION

Calculates x to the power of y.

SYNTAX

float pow(float x, float y)

RETURN

Return the x to the power of y.

SEE ALSO

exp(), frexp(), log(), sqrt()


printf

 

DESCRIPTION

Formatted output to the standard output stream (screen).

SYNTAX

int printf(string format,...)

COMMENTS

This flexible function writes output to the standard output device according to the format string ( this is identical to calling fprintf with `stdout' as the first parameter). The format string can contain character combinations indicating how following parameters are to be treated. Characters are printed as read to standard output until a per cent character (`%') is reached. % indicates that a value is to be printed from the parameters following the format string. Each subsequent parameter specification takes from the next parameter in the list following format. A parameter specification takes this form (square brackets indicate optional fields, angled brackets indicate required fields):

%[flags][width][.precision]<type>

Where flags may be:

- Left justification in the field with blank padding; else right justifies with zero or blank padding

+ Force numbers to begin with a plus (+) or minus (-)

blank Negative values begin with a minus (-); positive values begin with a blank

# Convert using the following alternate form, depending on output data type:

c, s, d, i, u No effect

o 0 (zero) is prepended to non-zero output

x, X 0x, or 0X, are prepended to output

f, e, E Output includes decimal even if no digits follow decimal

g, G same as e or E but trailing zeros are not removed

width may be:

n (n is a number e.g., 14) At least n characters are output, padded with blanks

0n At least n characters are output, padded on the left with zeros

* The next value in the argument list is an integer specifying the output width

.precision If precision is specified, then it must begin with a period (.), and may be as follows:

.0 For floating point type, no decimal point is output

.n n characters or n decimal places (floating point) are output

.* The next value in the argument list is an integer specifying the precision width

 

 

type may be:

d, i signed integer

u unsigned integer

o octal integer x

x hexadecimal integer with 0-9 and a, b, c, d, e, f

X hexadecimal integer with 0-9 and A, B, C, D, E, F

f floating point of the form [-]dddd.dddd

e floating point of the form [-]d.ddde+dd or [-]d.ddde-dd

E floating point of the form [-]d.dddE+dd or [-]d.dddE-dd

g floating point of f or e type, depending on precision

G floating point of For E type, depending on precision

c character (`a', `b', `8', e.g.)

s string

To include the `%' character as a character in the format string, you must use two % together (`%%') to prevent the computer from trying to interpret it as on of the above forms.

RETURN

Returns the number of characters written, or a negative number if there was an output error.

SEE ALSO

fprintf(), fputs(), puts(), sprintf(), vfprintf(), vprintf()

EXAMPLES

Each of the following lines shows a printf example followed by what would show on the output in boldface:

printf("Hello world!")

Hello world!

printf("I count: %d %d %d.",1,2,3)

I count: 1 2 3

a = 1;

b = 2;

c = a+b;

printf("%d %d %d",a,b,c)

1 2 3


putc
 

DESCRIPTION

Write a character to a file stream.

SYNTAX

int putc(int c, FILE stream)

COMMENTS

Write the character c, converted to a byte, to output file stream. This function is identical to fputc(c,stream).

RETURN

Returns c for success, and EOF for a write error.

SEE ALSO

fputc(), putchar()


putchar
 

DESCRIPTION

Write a character to the standard output stream (console).

SYNTAX

int putchar(int c)

COMMENTS

Write the character c, converted to a byte, to the stream defined by stdout (usually the console). This function is identical to fputc(c,stdout).

RETURN

Returns c for success, and EOF for a write error.

SEE ALSO

fputc(), putc()


putenv
 

DESCRIPTION

Set an environment string.

SYNTAX

int putenv(string VariableName, string Value)

COMMENTS

Sets the VariableName environment variable to the Value string. If Value is NULL then VariableName is removed from the environment. For those operating systems for which ScriptEase can alter the parent environment (DOS, or OS/2 when invoked with SESet.cmd or using ESet()) the variable setting will still be valid when ScriptEase exits; otherwise the variable change applies only to the ScriptEase code and to child processes of the ScriptEase program.

RETURN

Returns -1 if there is an error, else 0.

SEE ALSO

getenv()


puts
 

DESCRIPTION

Write a string to the standard output stream (console).

SYNTAX

int puts(string s)

COMMENTS

Write the string s followed by a new-line character to stream. Do not write the terminating null-character. This function is identical to fputs(s, stdout) except that a new-line character is written after the string.

RETURN

Returns EOF if write error, else returns a non-negative value.

SEE ALSO

fputs(), gets(), printf()


qsort
 

DESCRIPTION

Sort an array using specified comparison function.

SYNTAX

void qsort(var [] array, [int ElementCount,] string CompareFunction)

COMMENTS

Sort elements in this array, starting from index 0 to ElementCount-1. If ElementCount is not supplied then will sort the entire array.

RETURN

No return value.

NOTE

ElementCount is limited to 64K

SEE ALSO

bsearch()

EXAMPLE

The following code would print a list of colors sorted reverse-alphabetically and case-insensitive:

// initialize an array of colors

colors = { "yellow", "Blue", "GREEN", "purple", "RED", "BLACK", "white", "orange" };

// sort the list of colors in place using qsort

// and our own defined ColorSorter routine

qsort(colors,"ReverseColorSorter");

// display the sorted colors

for ( i = 0; i <= GetArraySpan(colors); i++ )

puts(colors[i]);

 

ReverseColorSorter(color1,color2)

// function called from qsort to compare two colors. In
// this case do a simple case insensitive string

// comparison, and reverse the results too

{

CompareResult = stricmp(color1,color2)

return( -CompareResult );

}

The output of the above code would be:

yellow

white

RED

purple

orange

GREEN

Blue

BLACK


rand
 

DESCRIPTION

Generate a random number.

SYNTAX

int rand()

COMMENTS

Generates a result between 0 and RAND_MAX, inclusive. The sequence of pseudo-random numbers is affected by the initial generator seed (see srand()) and by earlier calls to rand().

RETURN

Returns pseudo-random number between 0 and RAND_MAX, inclusive.

SEE ALSO

srand(), RAND_MAX


remove
 

DESCRIPTION

Delete a file.

SYNTAX

int remove(string filename)

COMMENTS

Deletes the filename specified by filename.

RETURN

Returns zero for success, and non-zero for failure.


rename
 

DESCRIPTION

Rename a file.

SYNTAX

int rename(string OldFilename, string NewFilename)

RETURN

Returns zero for success, and non-zero for failure.


rewind
 

DESCRIPTION

Reset file position to beginning of file.

SYNTAX

void rewind(FILE stream)

COMMENTS

Set stream file-position pointer to the beginning of file. This call is identical to fseek(stream,0,SEEK_SET) except that it also clears the error indicator for this stream.

RETURN

No return value.

SEE ALSO

fgetpos(), fseek(), fsetpos(), ftell()


scanf
 

DESCRIPTION

Formatted input from the standard input stream (keyboard)

SYNTAX

int scanf(string format,...)

 

This flexible function reads input from the standard input stream (the keyboard unless some other file has been redirected as input) and stores the data read in variables provided as parameters following the format string. The data will be stored according to the character combinations in format strings indicating how the input data is to be read and stored. This function is identical to calling fscanf() with stdin as the first parameter.

The format string specifies the admissible input sequences, and how the input is to be converted to be assigned to the variable number of arguments passed to this function.

In Windows, the input will not be read until it has been entered by hitting return.

Characters from input are matched against the characters of the format string until a per cent character (`%') is reached. % indicates that a value is to be read and stored to subsequent parameters following the format string. Each subsequent parameter after the format string gets the next parsed value taken from the next parameter in the list following format.

COMMENTS

A parameter specification takes this form (square brackets indicate optional fields, angled brackets indicate required fields):

%[*][width]<type>

Where:

* Suppress assigning this value to any parameter

width maximum number of characters to read; fewer will be read if whitespace or nonconvertible character

type

d,D,i,I signed integer

u,U unsigned integer

o,O octal integer

x,X hexadecimal integer

f,e,E,g,G floating point number

c character; if width was specified then this is an array of characters

s string

[abc] string consisting of all characters within brackets; where A-Z represents range `A' to `Z'

[^abc] string consisting of all character NOT within brackets

MODIFIES

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

RETURN

Returns EOF if input failure before any conversion occurs, else returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure.

SEE ALSO

fscanf(), fgets(), gets(), sscanf(), vfscanf(), vscanf()

EXAMPLES

See fscanf for examples on using this function.


sin
 

DESCRIPTION

Calculate the sine.

SYNTAX

float sin(float x)

RETURN

Return the sine of x in radians.


sinh
 

DESCRIPTION

Calculate the hyperbolic sine.

SYNTAX

float sinh(float x)

RETURN

Return the hyperbolic sine of x


sprintf
 

DESCRIPTION

Formatted output to a string.

SYNTAX

int sprintf(string buffer, string format,...)

COMMENTS

This flexible function writes output to the string variable specified by buffer according to the format string. The format string can contain character combinations indicating how following parameters may be written. buffer need not be previously defined; it will be created large enough to hold the string result. See printf() for a description of this format string.

RETURN

Returns the number of characters written into buffer not including the terminating null byte, or EOF if there was an error.

SEE ALSO

printf(), vsprintf()


sqrt
 

DESCRIPTION

Calculate the square root.

SYNTAX

float sqrt(float x)

RETURN

Return the square root of x.


srand
 

DESCRIPTION

Initialize random number generator.

SYNTAX

void srand([int seed])

COMMENTS

If seed is not supplied then a random seed is generated in an operating-system-specific manner.

SEE ALSO

rand(), RAND_MAX


sscanf
 

DESCRIPTION

Formatted input from a string.

SYNTAX

int sscanf(string buffer, string FormatString,...)

COMMENTS

This flexible function reads input from a string and stores in parameters following the format string according to the character combinations in FormatString indicating how the buffer data is to be read and stored. See scanf() for a description of this format string.

MODIFIES

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

RETURN

Returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure.

SEE ALSO

fscanf(), scanf(), vsscanf()

EXAMPLES

See fscanf for examples on using this function.


strcat
 

DESCRIPTION

Append (concatenate) one string onto the end of another

SYNTAX

string strcat(string dest, string src)

COMMENTS

Appends src string onto the end of dest string. The dest array is made big enough to hold src and a terminating null byte. In ScriptEase, the string copy is safe, so that you can copy from one part of a string to another part of itself.

RETURN

Returns the value of dest; that is, a variable into the dest array based at dest[0].

SEE ALSO

sprintf(), strcpy(), memcpy(), memmove()

EXAMPLE

The following code would create the string Giant to be "FeeFieFoeFum".

Giant = "Fee";

// giant initially says only "Fee"

strcat(Giant,"Fie");
// now giant says "FeeFie"

// remember that strcat returns Giant strcat(strcat(Giant,"Foe"),"Fum")


strchr
 

DESCRIPTION

Search a string for a character.

SYNTAX

string strchr(string s, byte c)

COMMENTS

Searches for the byte c in string s.

RETURN

Returns NULL if c is not found in s; else returns variable for this string based at the first c character.

SEE ALSO

memchr(), strcspn(), strpbrk(), strrchr(), strspn(), strstr(), strtok()

EXAMPLE

This code:

str = "I can't stand soggy cereal."

substr = strchr(str,'s');

printf("str = %s\n", str);

printf("substr = %s\n", substr);

Results in this output:

str = I can't stand soggy cereal.

substr = stand soggy cereal.


strcmp
 

DESCRIPTION

Compare two strings.

SYNTAX

int strcmp(string s1,string s2)

COMMENTS

Compare the bytes of s1 against s2 until there is a mismatch or reach the terminating null byte.

RETURN

Returns result of comparison, which will be: < 0 if s1 is less than s2 = 0 if s1 is the same as s2 > 0 if s1 is greater than s2

SEE ALSO

memcmp(), stricmp(), strncmp()


strcmpi
 

DESCRIPTION

Case-insensitive compare two strings.

SYNTAX

int strcmpi(string s1,string s2)

COMMENTS

Compare the bytes of s1 against s2, case-insensitive such that `A' is equal to `a', until there is a mismatch or reach the terminating null byte.

RETURN

Returns result of comparison, which will be:

< 0 if s1 is less than s2

= 0 if s1 is the same as s2

> 0 if s1 is greater than s2

SEE ALSO

memicmp(), stricmp(), strncmpi()


strcpy
 

DESCRIPTION

Copy from one string into another.

SYNTAX

string strcpy(string dest, string src)

COMMENTS

Copies bytes from src to dest, up to and including the terminating null byte. If dest is not already defined then this defines it as a string. strcpy() is identical in behavior to memmove(dest,src,strlen(src)) with string enforcement. It is safe to copy from one part of a string to another part of the same string.

RETURN

Returns the value of dest; that is, a variable into the dest array based at dest[0].

SEE ALSO

memcpy(), memmove(), strcat(), strncpy(), sprintf()


strcspn
 

DESCRIPTION

Search string for first instance of any character from a set of characters.

SYNTAX

int strcspn(string Str, string CharSet)

COMMENTS

Searches string Str for any of the characters in CharSet, and returns the offset of that character. This function is similar to strpbrk, except that strpbrk returns the string beginning at the first character found, while strcspn returns the offset number for that character.

RETURN

Return the index in Str of the first character that is also in CharSet; if no CharSet character is found then the length of Str will be returned.

SEE ALSO

strrchr(), strspn(), strstr(), strtok()

EXAMPLE

The following script demonstrates the difference between strcspn and strpbrk:

string="There's more than one way to skin a cat."

rStrpbrk = strpbrk(string, "dxb8w9k!");

rStrcspn = strcspn(string, "dxb8w9k!");

printf("The string is: %s\n", string);

printf("\nstrpbrk returns a string: %s\n", rStrpbrk);

printf("\nstrcspn returns an integer: %d\n", rStrcspn);

printf("string +strcspn = %s\n", string + rStrcspn); getch();

And results in the following output:

The string is: There's more than one way to skin a cat.

strpbrk returns a string: way to skin a cat.

strcspn returns an integer: 22

string +strcspn = way to skin a cat


strerror
 

DESCRIPTION

Get a string describing an error number.

SYNTAX

string strerror (int err)

COMMENTS

An error number may be generated by certain library calls, such as fopen(). This error number can be converted to readable ascii text for error reporting.

RETURN

Returns descriptive error message string.

SEE ALSO

errno, perror()

EXAMPLE

This function opens a file for reading, and if it cannot open the file then it prints a descriptive message and exits the program:

MustOpen(filename)

{

fh = fopen(filename,"r");

if ( fh == NULL ) {

printf("Unable to open %s for reading.\n",filename);

printf("Error:%s\n",strerror(errno));

exit(EXIT_FAILURE);

}

return(fh);

}


strftime
 

DESCRIPTION

Formatted write of date and/or time into a string.

SYNTAX

int strftime(string buf, [int MaxBufSize,] string Format, struct tm)

COMMENTS

This function follows the pattern of the printf() functions: Format specifies the form of output and tm is the input describing a date/time in the structure defined in localtime(). If maxsize not supplied then will use a very big value.

Format is a string copied directly to buf ; when the conversion character (%) is encountered then the following character is replaced by a string representing the data and/or time. These are the conversion characters and their meaning (and an example in parentheses):

%a abbreviated weekday name (Sun)

%A full weekday name (Sunday)

%b abbreviated month name (Dec)

%B full month name (December)

%c date and time (Dec 2 06:55:15 1979)

%d two-digit day of the month (02)

%H two-digit hour of the 24-hour day (06)

%I two-digit hour of the 12-hour day (06)

%j three-digit day of the year from 001 (335)

%m two-digit month of the year from 01 (12)

%M two-digit minute of the hour (55)

%p AM or PM (AM)

%S two-digit seconds of the minute (15)

%U two-digit week of the year where Sunday is first day of the week (48)

%w day of the week where Sunday is 0 (0)

%W two-digit week of the year where Monday is the first day of the week (47)

%x the date (Dec 2 1979)

%X the time (06:55:15)

%y two-digit year of the century (79)

%Y the year (1979)

%Z name of the time zone, if known (EST)

%% the per cent character (%)

MODIFIES

buf is created as a string (if it isn't one already) containing a string which is the formatted result of strftime().

RETURN

Returns the number of characters put into buf.

SEE ALSO

asctime(), ctime(), gmtime(), localtime(), mktime(), time()

EXAMPLE

The following code prints the full day name and month name of the current day:

strftime(TimeBuf,"Today is: %A, and the month is: %B",

localtime(time()));

puts(TimeBuf);


stricmp
 

DESCRIPTION

Case-insensitive compare two strings.

SYNTAX

int stricmp(string s1,string s2)

COMMENTS

Compare the bytes of s1 against s2 until there is a mismatch or reach the terminating null byte. Comparison is done case-insensitive, so
`a' == `A'.

RETURN

Returns result of comparison, which will be: < 0 if s1 is less than s2 = 0 if s1 is the same as s2 > 0 if s1 is greater than s2

SEE ALSO

memicmp(), strcmpi(), strncmpi()


strlen
 

DESCRIPTION

Determine the length of a string.

SYNTAX

int strlen(string s)

RETURN

Returns the number of character in s, starting from the character at s[0], before (and not including) the terminating null-byte.


strlwr
 

DESCRIPTION

Converts string to lower-case characters.

SYNTAX

string strlwr(string s);

COMMENTS

Converts all uppercase letters in s to lowercase, starting at s[0] and up to the terminating null byte.

RETURN

Returns the value of s; that is, a variable into the s array based at s[0].

SEE ALSO

strupr(), tolower(), isupper()


strncat
 

DESCRIPTION

Append (concatenate) up to len bytes of one string onto the end of another.

SYNTAX

string strncat(string dest, string src, int MaxLen)

COMMENTS

Appends up to MaxLen bytes of src string onto the end of dest string. Characters following a null-byte in src are not copied. The dest array is made big enough to hold min(strlen(src),MaxLen) and a terminating null byte.

SEE ALSO

memcpy(), memmove(), strcat(), strcpy(), sprintf()

RETURN

Returns the value of dest; that is, a variable into the dest array based at dest[0].


strncmp
 

DESCRIPTION

Compare part of two strings.

SYNTAX

int strncmp(string s1, string s2, int MaxLen)

COMMENTS

Compare up to MaxLen bytes of s1 against s2 until there is a mismatch or reach the terminating null byte. The comparison ends when MaxLen bytes have been compared or when a terminating null-byte has been compared, whichever comes first.

RETURN

Returns result of comparison, which will be: < 0 if s1 is less than s2 = 0 if s1 is the same as s2 > 0 if s1 is greater than s2

SEE ALSO

memcmp(), stricmp(), strcmp()


strncmpi
 

DESCRIPTION

Case-insensitive compare part of two strings.

SYNTAX

int strncmpi(string s1, string s2, int MaxLen)

COMMENTS

This function is the same as strnicmp().

RETURN

Same as strnicmp().

SEE ALSO

memicmp(), strcmp(), stricmp(), strncmp(), strnicmp()


strncpy
 

DESCRIPTION

Copy given number of bytes from one string into another.

SYNTAX

string strncpy(string dest, string src, int MaxLen)

COMMENTS

Copies min(strlen(src)+1,MaxLen) bytes from src to dest. If dest is not already defined then this defines it as a string. dest is null-padded if MaxLen is greater than the length of src, and a null-byte is appended to dest if MaxLen bytes are copied. It is safe to copy from one part of a string to another part of the same string.

RETURN

Returns the value of dest; that is, a variable into the dest array based at dest[0].

SEE ALSO

memcpy(), memmove(), strcat(), strcpy(), sprintf()


strnicmp
 

DESCRIPTION

Case-insensitive compare part of two strings.

SYNTAX

int strnicmp(string s1, string s2, int MaxLen)

COMMENTS

This is the same as strncmp() except that the comparison is case-insensitive, such that `a' == `A'. It is the same as strncmpi().

RETURN

Returns result of comparison, which will be:

less than 0 if s1 is less than s2, equal to 0 if s1 is the same as s2, or greater than 0 if s1 is greater than s2

SEE ALSO

memicmp(), strcmp(), stricmp(), strncmp(), strncmpi()


strpbrk
 

DESCRIPTION

Search string for first character from a set of characters.

SYNTAX

string strpbrk(string Str,string CharSet)

COMMENTS

Searches string Str for any of the characters in CharSet, and returns the string based at the found character.

RETURN

Returns NULL if no character from CharSet is found in s; else returns variable for the Str array based at the first CharSet character.

SEE ALSO

strchr(), strcspn(), strrchr(), strspn(), strstr(), strtok()

EXAMPLE

See strcspn() for an example using this function.


strrchr
 

DESCRIPTION

Search a string for the last occurrence of a character.

SYNTAX

string strrchr(string s, byte c)

COMMENTS

Searches in the reverse direction for the byte c in string s.

RETURN

Returns NULL if c is not found in s; otherwise it returns variable for this string based at the last c character.

SEE ALSO

strchr(), strcspn(), strpbrk(), strspn(), strstr(), strtok()

EXAMPLE

This code:

str = "I can't stand soggy cereal."

substr = strrchr(str,'s');

printf("str = %s\n",str);

printf("substr = %s\n", substr);

Results in this output:

str = I can't stand soggy cereal.

substr = soggy cereal.


strspn
 

DESCRIPTION

Search string for first character not in a set of characters.

SYNTAX

int strspn(string Str,string CharSet)

COMMENTS

Searches string Str for any characters that are not in CharSet, and returns the offset of the first instance of such a character.

RETURN

Returns the index in Str of the first character that is not also in CharSet; if all characters in Str are also in CharSet will return the length of Str.

SEE ALSO

strchr(), strcspn(), strpbrk(), strrchr(), strstr(), strtok()


strstr
 

DESCRIPTION

Search string for a substring.

SYNTAX

string strstr(string Str,string SubStr)

COMMENTS

Searches Str, starting at Str[0], for the first occurrence of SubStr. Comparison is case-sensitive.

RETURN

Returns NULL if SubStr is not found anywhere in Str; otherwise it returns a variable for the Str array based at the first offset matching SubStr.

SEE ALSO

strchr(), strcspn(), strpbrk(), strrchr(), strspn(), strtok(), strstri()

EXAMPLE

This code:

Phrase = "To be or not to be? Beep beep!";

do {

puts(Phrase);

Phrase = strstr(Phrase+1,"be");

} while ( Phrase != NULL );

would result in this output.

To be or not to be? Beep beep!

be or not to be? Beep beep!

be? Beep beep!

beep!


strstri
 

DESCRIPTION

Case insensitive search string for a substring.

SYNTAX

string strstri(string Str,string SubStr)

COMMENTS

Searches Str, starting at Str[0], for the first occurrence of SubStr. Comparison is case-sensitive.

RETURN

Returns NULL if SubStr is not found anywhere in Str; otherwise returns variable for the Str array based at the first offset matching SubStr.

SEE ALSO

strchr(), strcspn(), strpbrk(), strrchr(), strspn(), strtok(), strstr()


strtod
 

DESCRIPTION

Convert a string to a floating-point value.

SYNTAX

float strtod(string Str[, string End])

COMMENTS

This function converts the string Str into a number and optionally returns string starting beyond the characters parsed in this function. Whitespace characters are skipped at the start of Str, then the string characters are converted to a float as long as they match this format:

[sign][digits][.][digits][format[sign]digits]

The following values, for example, can be converted:

1

1.8

-400.456e-20

.67e50

2.5E+50

End is not compared against NULL, as it is in standard C implementations. Instead if you don't want End then don't supply the parameter.

MODIFIES

If End is supplied, then End will be set to the Str array based on the first character that was not used in converting.

RETURN

Returns the first part of Str converted to a floating-point number.

SEE ALSO

atof(), sscanf(), strtol()

EXAMPLE

This code:

numbers = " 3.14159 +2.4e-13 0.0000001" " me and little joe 4.6473";

while( True ) {
f = strtod(numbers,next);
if( next == numbers ) // no chars used means no float found
break;
printf("%G\n",f);
numbers = next; }

produces this printed output:

3.14159

2.4E-13

1E-007


strtok
 

DESCRIPTION

Search a string for delimited tokens.

SYNTAX

string strtok(string Source, string Delimiters)

COMMENTS

This is a weird function.

Source is a string that consists of text tokens (substrings) separated by delimiters found in the Delimiters string. Bytes of Source may be altered during the first and subsequent calls to strtok().

On the first call to strtok(), Source points to the string to tokenize and Delimiters is a list of characters which are used to separate tokens in source. This first call returns a variable pointing to the Source array and based at the first character of the first token in Source. On subsequent calls, the first argument is NULL and strtok will continue through Source returning subsequent tokens.

The ScriptEase implementation of this function is as weird as any: the initial var must remain valid throughout following calls with NULL as the initial var. If you change the string in any way, a following call to strtok() must be of the first syntax form (i.e., the new string must be passed as a first parameter).

RETURN

Returns NULL if there are no more tokens; else returns Source array variable based at the next token in Source.

SEE ALSO

strchr(), strcspn(), strpbrk(), strrchr(), strspn(), strstr()

EXAMPLE

This code:

source = " Little John,,,Eats ?? crackers;;;! ";

token = strtok(source,", ");

while( NULL != token ) {
puts(token);
token = strtok(NULL,";?, "); }

produces this list of tokens:

Little

John

Eats

crackers

!


strtol
 

DESCRIPTION

Convert a string to an integer value.

SYNTAX

int strtol(string Str)

int strtol(string Str,string End)

int strtol(string Str,string End, string Radix)

COMMENTS

This function converts the string Str into a number and optionally returns a string starting beyond the characters parsed in this function. Whitespace characters are skipped at the start of Str, then the string characters are converted to an integer as long as they match this format:

[sign][0][x][digits]

these values can be converted, for example:

1

12

-400

0xFACE

End is not compared against NULL, as it is in standard C implementations. Instead if you don't want End then don't supply the parameter. Radix specifies the base for conversion; for instance base 10 would be decimal numbers zero through nine and base 16 would be used for Hexadecimal numbers `0' (zero) through `F'. If Radix is zero, or if the Radix argument is not supplied, then the radix is determined based on the first characters of Str.

.MODIFIES

If End is supplied, then End will be set to the Str array based on the first character that was not used in converting.

RETURN

Returns the first part of Str converted to a floating-point number.

SEE ALSO

atoi(), atol(), sscanf(), strtof()

EXAMPLE

This code:

numbers = " 3 14159 +2 0xFACE 7.4e-13 0.0000001 ";

while( True ) {
i = strtol(numbers,next,0);
if ( next == numbers ) // no chars used means no int found

break;
printf("%d\n",i);
numbers = next; }

results in this output:

3 14159 2 64206 7


strupr
 

DESCRIPTION

Converts string to upper-case characters.

SYNTAX

string strupr(string s)

COMMENTS

Converts all lowercase letters in s to uppercase, starting at s[0] and up to the terminating null byte.

RETURN

Returns the value of s; that is, a variable into the s array based at s[0].

SEE ALSO

strlwr(), toupper()


system
 

DESCRIPTION

Pass a command to the command processor.

SYNTAX

int system(string Command)

int system(string CommandFormat, var arg1,...)

 

DOS versions only:

int system(P_SWAP,string Command)

int system(P_SWAP,string CommandFormat, var arg1,...)

COMMENTS

Passes Command to the command processor. If the CommandFormat form is used then system() formats the CommandFormat according to the rules defined in printf().

 

DOS In the DOS version of ScriptEase, if the special argument P_SWAP is used then SEDOS.exe is swapped to EMS/XMS/INT15 memory or disk while the system command is executed. This leaves almost all available memory for executing the command. See spawn() for a discussion of P_SWAP.

 

DOS32 The 32-bit protected mode version of DOS ignores the first parameter if it is an not a string; in other words, P_SWAP is ignored.

RETURN

Returns value returned by the command processor.

SEE ALSO

spawn()


tan
 

DESCRIPTION

Calculate the tangent.

SYNTAX

float tan(float x)

RETURN

Return the tangent of x in radians.


tanh
 

DESCRIPTION

Calculate the hyperbolic tangent.

SYNTAX

float tanh(float x)

RETURN

Return the hyperbolic tangent of x.


time
 

DESCRIPTION

Get current time.

SYNTAX

int time([t])

COMMENTS

This gets the current system time. The format of the time is not specifically defined except that it represents the current time, to the system's best approximation, and can be used in many other time-related functions. If t is supplied then it is also set to the current time.

RETURN

Returns an integer representation of the current time.

SEE ALSO

difftime(), mktime(), ctime(), gmtime(), localtime(), Directory()


tmpfile
 

DESCRIPTION

Create a temporary binary file.

SYNTAX

FILE tmpfile()

COMMENTS

This creates a binary temporary file that will automatically be removed when it is closed or when the program exits. If FILE variable is an environment variable then it is invalid after the program ends.

RETURN

Returns a file pointer, which will be NULL if the function fails.

SEE ALSO

tmpnam()


tmpnam
 

DESCRIPTION

Get a temporary file name.

SYNTAX

string tmpname([string filename])

COMMENTS

This creates a string that is a valid file name that is not the same as the name of any existing file and not the same as any filename returned by this function during execution of this program.

MODIFIES

If filename is supplied then sets filename to the string that will be returned by this function.

RETURN

Returns a valid filename.

SEE ALSO

tmpfile()


toascii
 

DESCRIPTION

Translate character to ASCII (7-bit) format

SYNTAX

int toascii(int c)

COMMENTS

Converts c to ASCII by clearing all but the lower 7 bits.

RETURN

Return lower 7 bits of c.


tolower
 

DESCRIPTION

Translate character to lower-case if it is upper-case.

SYNTAX

int tolower(int c)

RETURN

If c is upper-case alphabetic then returns c converted to lower-case alphabetic; otherwise it returns c unaltered.

SEE ALSO

strlwr(), toupper()


toupper
 

DESCRIPTION

Translate character to upper-case if it is lower-case.

SYNTAX

int toupper(int c)

RETURN

If c is lower-case alphabetic then returns c converted to upper-case alphabetic; otherwise it returns c unaltered.

SEE ALSO

strupr(), tolower()


ungetc
 

DESCRIPTION

Push character back to input stream.

SYNTAX

int ungetc(int c, FILE stream)

COMMENTS

Pushes c (converted to be a byte) back onto the input stream for subsequent re-retrieval. Only one character of pushback is guaranteed.

RETURN

Return the character c, or EOF for failure.

SEE ALSO

fgetc(), getc(), getch(), getchar(), getche()


va_arg
 

DESCRIPTION

Retrieve variable from variable argument list.

SYNTAX

var va_arg(blob valist[, int offset])

var va_arg(int offset)

int va_arg()

COMMENTS

va_arg() is called to retrieve a parameter passed to a function even when the number of parameters that can be passed to the function is not constant.

If valist is used then the variable returned is the one at offset from the first of the valist variables. If offset is not passed in then the next variable from valist is retrieved and valist is updated so that a further call to va_arg(valist) will return the subsequent variable.

If the va_arg(int offset) form is used then this returns the input variable at index: offset.

The va_arg() form of this function returns only the number of parameters passed to the current function.

It is a fatal error to retrieve an argument offset beyond the number of parameters in the function or the valist.

RETURN

Returns a variable for the forms that take a parameter; the va_arg() form returns the number of parameters passed to the current function.

SEE ALSO

va_end(), va_start(), vfprintf(), vfscanf(), vprintf(), vscanf(), vsprintf(), vsscanf()

EXAMPLE

For the following examples, assume that the trait function is called like this:

trait("Doug",34,"Blue","pizza");

All of the following examples of the trait() function will set FavoriteColor to Doug's favorite color:

trait(name,age,color,food){
FavoriteColor = color;

}

 

trait(){

assert( 3 <= va_arg() );

FavoriteColor = va_arg(2);

}

 

trait(name){

va_start(valist,name);

va_arg(valist);

FavoriteColor = va_arg(valist);
va_end(valist);

}

 

trait(name){

va_start(valist,name);

FavoriteColor = va_arg(valist,1);
va_end(valist); }

 

trait(){

va_start(valist);
va_arg(valist);
va_arg(valist);
FavoriteColor = va_arg(valist);
va_end(valist);

}


va_end
 

DESCRIPTION

Terminate variable argument list.

SYNTAX

void va_end(blob valist)

COMMENTS

This function makes valist invalid. Many implementations of C require that you call this function. ScriptEase does not, but since people may expect it to be there, we provided it.

SEE ALSO

va_arg(), va_start(), vfprintf(), vfscanf(), vprintf(), vscanf(), vsprintf(), vsscanf()


va_start
 

DESCRIPTION

Initialize variable argument list.

SYNTAX

int va_start(blob va_list[, var InputVar])

COMMENTS

Initialize va_list for a function that takes a variable number of arguments. va_list will then be used in further calls to va_arg() to get the next argument(s) passed to the function.

InputVar must be one of the parameters defined in the function line, and then the first argument returned by the first call to va_arg() will be the variable passed after InputVar.

If InputVar is not provided, then the first parameter passed to the function will be the first one returned by va_arg(va_list).

RETURN

Returns the number of valid calls to va_arg(va_list), i.e., how many variables are available in this va_list.

MODIFIES

va_list will be set to a blob, which can then be passed to other functions and/or used by subsequent calls to va_arg().

SEE ALSO

va_arg(), va_end(), vfprintf(), vfscanf(), vprintf(), vscanf(), vsprintf(), vsscanf()

EXAMPLE

The following example uses and accepts a variable number of strings and concatenates them all together:

MultiStrcat(Result,InitialString)
// Append any number of strings to InitialString.
// e.g., MultiStrcat(Result,"C:\\","FOO",".","CMD")

{
strcpy(Result,""); // initialize the result
Count = va_start( ArgList, InitialString )

for ( i = 0; i < Count; i++ )

strcat( Result, va_arg(ArgList) )

}


vfprintf
 

DESCRIPTION

Formatted output to a file stream using arg_list.

SYNTAX

int vfprintf(FILE stream, string format, blob valist)

COMMENTS

This is similar to fprintf() except that it takes a variable argument list (see va_start()). See fprintf() for more details.

RETURN

Returns the number of characters written, or a negative number if there was an output error.

SEE ALSO

fprintf(), va_arg(), va_end(), va_start()


vfscanf
 

DESCRIPTION

Formatted input from a file stream using arg_list.

SYNTAX

int vfscanf(FILE stream, string format, blob valist)

COMMENTS

This is similar to fscanf() except that it takes a variable argument list (see va_start()). See fscanf() for more details.

MODIFIES

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

RETURN

Returns EOF if input failure before any conversion occurs, otherwise returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure.

SEE ALSO

fscanf(), va_arg(), va_end(), va_start()


vprintf
 

DESCRIPTION

Formatted output to the standard output stream (screen) using arg_list.

SYNTAX

int vfprintf(FILE stream, blob valist)

COMMENTS

This is similar to printf() except that it takes a variable argument list (see va_start()). See printf() for more details.

RETURN

Returns the number of characters written, or a negative number if there was an output error.

SEE ALSO

printf(), va_arg(), va_end(), va_start()

EXAMPLES

The following function would act just like a printf statement except that it beeps, then prints the message, then beeps again and waits a second before returning. This might be uses as a wrapper for the printf function when urgent messages are output:

UrgentPrintf(FormatString /*,arg1,arg2,arg3,etc...*/ ) {

//create variable arg list

va_start(va_list,FormatString);

printf("\a"); // audible beep

// printf original statement

ret = vprintf(FormatString,va_list);

printf("\a"); // beep again

suspend(1000); // wait one second before returning

va_end(va_list); // end using va_list (not required)

return(ret); // return as printf would }

}


vscanf
 

DESCRIPTION

Formatted input from the standard input stream (keyboard) using arg_list.

SYNTAX

int vscanf(string format, blob valist)

COMMENTS

This is similar to scanf() except that it takes a variable argument list (see va_start()). See scanf() for more details.

MODIFIES

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

RETURN

Returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure.

SEE ALSO

scanf(), va_arg(), va_end(), va_start()

EXAMPLES

The following function would act exactly like scanf, including taking a variable number of input arguments, except that it beeps and tries again if there are zero matches:

Must_scanf(FormatString /*,arg1,arg2,arg3,etc...*/ ) {

vastart(va_list,FormatString);

// create variable arg list

do { // mimic original scanf() call

count = vscanf(FormatString,va_list);

if ( 0 == count ) // if no match, then beep

printf("\a");

} while( 0 == count );

// if not match, then try again

va_end(va_list);

// end using va_list (optional)

return(count);

// return as scanf would

}


vsprintf
 

DESCRIPTION

Formatted output to a string using arg_list.

SYNTAX

int vsprintf(string buffer,string format, blob valist)

COMMENTS

This is similar to sprintf() except that it takes a variable argument list (see va_start()). See sprintf() for more details.

RETURN

Returns the number of characters written into buffer not including the terminating null byte, or EOF if there was an error.

SEE ALSO

sprintf(), va_arg(), va_end(), va_start()


vsscanf
 

DESCRIPTION

Formatted input from a string.

SYNTAX

int vsscanf(string buffer, string format, blob valist)

COMMENTS

This is similar to sscanf() except that it takes a variable argument list (see va_start()). See sscanf() for more details.

MODIFIES

Modifies any number of parameters following the format string, setting the parameters to data according to the specifications of the format string.

RETURN

Returns the number of input items assigned; this number may be fewer than the number of parameters requested if there was a matching failure.

SEE ALSO

sscanf(), va_arg(), va_end(), va_start()