pcosmos.ca

le domaine de Philippe Choquette

Accueil Profil Contact Arrière plan
Half-Life
Diseases
PCASTL
Operators
Data Types
Internal Functions
Tree Structure
Batch Execution
Examples
Interpreter Informatique
OpenGL
Grow
Elements
Lecture
Liens

PCASTL Internal Functions

Page en français

Categorical Listing

Input and Output Functions

Control Flow Functions

Tree Manipulation Functions

Object Manipulation Functions

Array, Chained List, Statements List and String Manipulation Functions

Dynamic-Link Libraries and Shared Object Libraries Access Functions

ANSI C stdio.h Interface

Type Conversion Functions

Utility Functions

Alphabetical Listing

abort
alloc_copy
array
as_array
as_list
as_statements
aton
atovar
clear
clearerr
closelib
cls
concat
copytree
execute
exit
fclose
feof
ferror
fflush
fgetc
fgetpos
fillobject
fopen
fprintf
fputc
fread
free
freetree
freopen
fscanf
fseek
fsetpos
ftell
fwrite
getfuncpt
gettype
getwd
info
insert
length
list
mknode
names
ntoa
openlib
print
printf
prompt
read
remove
replace
return
rewind
rmnode
scan
scanf
setlength
setwd
source
sprintf
sscanf
strclone
strcpy
strlen
subseq
tmpfile
tonode
undefine
ungetc
value
vartoa
write


abort()

This function stops the execution of the submitted statement list and resets the interpreter to an user input waiting state.


alloc_copy(arg)

This function takes any type of argument, allocates a copy of it and returns a pointer to the copy.


array([arg1[, arg2[, ...]]])

This function takes as many arguments as you want, evaluates them and return an array of the according length.

> a = array(1, 2, "c_letter")
[0]     1
[1]     2
[2]     "c_letter"
> a[1]
        2
> a[2] = 3
        3
> a
[0]     1
[1]     2
[2]     3
> array(1,2,array(3,4))
[0]     1
[1]     2
[2][0]  3
[2][1]  4

as_array(sequence)

This function takes one argument, which can be a chained list or a reference to a statement list. The returned value is an array of the same length of the given sequence. If the sequence is a chained list, then the content of each item will be the same. If the sequence is a statement list, then the items of the output will only be defined for corresponding string or number nodes.

> a = scan()
string scanning in progress!
        0x330bf8
> as_array(a)
[0]     "string"
[1]     "scanning"
[2]     "in"
[3]     "progress"
[4]     "!"
> a = `{0 1 {}}'.childset[0]
        0x332cd0
> as_array(a)
[0]     0
[1]     1
[2]     undefined

as_list(sequence)

This function takes one argument, which can be an array or a reference to a statement list. The returned value is an chained list of the same length of the given sequence. If the sequence is an array, then the content of each item will be the same. If the sequence is a statement list, then the items of the output will only be defined for corresponding string or number nodes.


as_statements(sequence)

This function takes one argument, which can be an array or a chained list. The returned value is an statement list of the same length of the given sequence. The items of the output will only be defined for corresponding string of number input items. The undefined nodes are given the numerical value zero.

> a = list("ab", "cd")
[0]     "ab"
[1]     "cd"
> b = as_statements(a)
        0x330ba0
> value(b.childset[0])
        "ab"

aton(string)

This function converts the string it receives as parameter to a numeric value. If the function can't convert, the returned value is zero.


atovar(string)

This function creates a node of "variable" type whose name is the string received as parameter. The string must begin by "_" or by a letter. The returned value is a reference to the new node.

> a = atovar("newname")
        0x3c3a78
> info(a)
        Node type: variable
        Name: "newname"

clear([symbol1[, symbol2[, ...]]])

This function can take no argument, or as many as you want. A call with no argument erases all the symbols in memory, variables and functions. Giving symbol names as arguments will cause their erasement. The value returned is the undefined value. It's like void in C.

> a = 1
        1
> a
        1
> clear(a)
> a
Error: Symbol "a" not found.

clearerr(stream)

Resets the error indicator for a stream. The parameter is a pointer to a FILE structure. The clearerr function resets the error indicator and end-of-file indicator for stream. Error indicators are not automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr, fseek, fsetpos, or rewind is called.

Text in most part from Microsoft Visual C++ 6.0 Docs.


closelib(handle)

Ends the access to a .dll file on Windows or to a .so file son Linux. The parameter is a handle obtained with the openlib function. On Windows, the returned value is one (1) in case of success, while on Linux, the returned value is zero in case of success.


cls()

Clears the console screen. This function does not have parameters. The returned value is the undefined value.


concat(arg1, arg2[, arg3[, ...]])

This function takes two or more arguments, which can be arrays, chained lists, strings or statement lists. All argument have to be of the same type. The returned value is a concatenation of all the evaluated arguments.


copytree(node_reference)

This function evaluates its argument to a node reference. The node referenced is the root a tree. This tree is copied entirely and a reference to the new root is returned. The new root has a NULL parent value.


execute(node_reference)

This function takes a node reference as parameter. The tree under the node is executed and the returned value is the value returned by the executed code.

> execute(`print("hello")'.childset[0])
        "hello"

exit()

This function takes no argument and closes the interpreter.


fclose(stream)

Closes the file which pointer is received as argument. The return value is 0 if the file was successfully closed. Otherwise, the return value is -1.


feof(stream)

Tests for end-of-file on a stream. The parameter is a pointer to a FILE structure. The feof function returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file. There is no error return.

The feof routine determines whether the end of stream has been reached. When end of file is reached, read operations return an end-of-file indicator until the stream is closed or until rewind, fsetpos, fseek, or clearerr is called against it.

Text in most part from Microsoft Visual C++ 6.0 Docs.


ferror(stream)

Tests for an error on a stream. The parameter is a pointer to a FILE structure. If no error has occurred on stream, ferror returns 0. Otherwise, it returns a nonzero value.

The ferror routine tests for a reading or writing error on the file associated with stream. If an error has occurred, the error indicator for the stream remains set until the stream is closed or rewound, or until clearerr is called against it.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fflush(stream)

Flushes a stream. The parameter is a pointer to a FILE structure. fflush returns 0 if the buffer was successfully flushed. The value 0 is also returned in cases in which the specified stream has no buffer or is open for reading only. A return value of -1 (EOF) indicates an error.

The fflush function flushes a stream. If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream. If the stream is open for input, fflush clears the contents of the buffer. fflush negates the effect of any prior call to ungetc against stream. The stream remains open after the call. fflush has no effect on an unbuffered stream.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fgetc(stream)

Read a character from a stream. The parameter is a pointer to a FILE structure. fgetc return the character read in a string of length 2 (the second character is null) or return "\xff" (end-of-file) to indicate an error or end of file. Use feof or ferror to distinguish between an error and an end-of-file condition. If a read error occurs, the error indicator for the stream is set.

fgetc reads a single character from the current position of the file associated with stream. The function then increments the associated file pointer (if defined) to point to the next character. If the stream is at end of file, the end-of-file indicator for the stream is set.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fgetpos(stream, variable)

Gets a stream's file-position indicator. The first parameter is a pointer to a FILE structure. The second parameter is an already defined variable who will receive a pointer to a fpos_t structure. If the variable is not already a pointer to a fpos_t structure, it is converted to this type. If successful, fgetpos returns 0. On failure, it returns a nonzero value.

The fgetpos function gets the current value of the stream argument's file-position indicator and stores it in the object pointed to by variable. The fsetpos function can later use information stored in variable to reset the stream argument's pointer to its position at the time fgetpos was called. The fpos_t pointer type is intended for use only by fgetpos and fsetpos.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = fopen("alphabet.txt", "r")
        0x462b50
> b = "    "
        "    "
> fread(b, 1, 4, a)
        4
> c = 0
        0
> fgetpos(a, c)
        0
> fread(b, 1, 4, a)
        4
> b
        "efgh"
> fread(b, 1, 4, a)
        4
> fsetpos(a, c)
        0
> fread(b, 1, 4, a)
        4
> b
        "efgh"
> fclose(a)
        0

fillobject(object, sequence)

This function takes two arguments. The first parameter is a symbol containing an object. The second parameter can be an array, a chained list or an object. If the sequence has less items than the object has member, then only the first members will receive a value. If the sequence has more items than the object has members, then the last items will be ignored. The returned value is the undefined value.

> a = names("b", "c", "d")
[b]     undefined
[c]     undefined
[d]     undefined
> fillobject(a, array(1,2))
> a
[b]     1
[c]     2
[d]     undefined

fopen(filename, mode)

The first parameter is a string holding the name of the file to be opened. The second parameter is a string holding the type access permitted. The return value is a pointer to the open file. A null pointer value indicates an error.

mode meaning
"r" Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
"w" Opens an empty file for writing. If the given file exists, its contents are destroyed.
"a" Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn't exist.
"r+" Opens for both reading and writing. (The file must exist.)
"w+" Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
"a+" Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn't exist.

When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten.

The "a+" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker.

When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.

In addition to the above values, the b character can be included in mode. It opens in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = fopen("test.txt", "w")
        0x462b50

fprintf(stream, string[, argument]...)

Prints formatted data to a stream. The first parameter is a pointer to a FILE structure. You can also write stdout or stderr. The second argument is the string to be written, which can include format specifications for the other arguments, if any. Each other argument is converted and output according to the corresponding format specification in format. The returned value is the undefined value.

> a = fopen("test.txt", "w")
        0x462b50
> fprintf(a, "text")
> fclose(a)
        0
> fprintf(stdout, "%s\n", "hello")
hello

fputc(string, stream)

Writes a character to a stream. The first parameter is a string containing the character to write at position 0 and null terminated at position 1. The second parameter is a pointer to a FILE structure. The return value is a string containing the character written. A return value of "\xff" (EOF) indicates an error.

fputc writes the single character string[0] to a file at the position indicated by the associated file position indicator (if defined) and advances the indicator as appropriate. The file is associated with stream. If the file cannot support positioning requests or was opened in append mode, the character is appended to the end of the stream.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fread(variable, size, count, stream)

Reads data from a stream. The first parameter is a variable of the string type where to store the read data. The second parameter is the size in bytes of the items read. The third parameter is the maximum number of items read. The last parameter is a pointer to a FILE structure.

fread returns the number of full items actually read, which may be less than count if an error occurs or if the end of the file is encountered before reaching count. Use the feof or ferror function to distinguish a read error from an end-of-file condition. If size or count is 0, fread returns 0 and the variable contents are unchanged.

The fread function reads up to count items of size bytes from the input stream and stores them in variable. The file pointer associated with stream (if there is one) is increased by the number of bytes actually read. If the given stream is opened in text mode and if the operating system is Windows, carriage return-linefeed pairs are replaced with single linefeed characters. The replacement has no effect on the file pointer or the return value. The file-pointer position is indeterminate if an error occurs. The value of a partially read item cannot be determined.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> b = ""
        ""
> setlength(b, 10)
> a = fopen("alphabet.txt", "r")
        0x462b50
> fread(b, 2, 3, a)
        3
> b[6] = "\0"
        ""
> fclose(a)
        0
> b
        "abcdef"

free(pointer)

Deallocate memory allocated by the alloc_copy function. The argument is the return value of that function. The returned value is the undefined value.


freetree(node_reference)

Deallocate a syntax tree of which the root is received as parameter. The returned value is the undefined value.


freopen(path, mode, stream)

Reassign a file pointer. The first parameter is a string containing the path of the file to associate with stream. The second parameter is a string specifying the access mode as with fopen. The last parameter is a pointer to a FILE structure. freopen returns a pointer to the newly opened file. If an error occurs, the original file is closed and the function returns a null pointer value. The freopen function closes the file currently associated with stream and reassigns stream to the file specified by path.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = freopen("err.txt", "w", stderr)
        0x462b30
> if (a) print(1)
        1
> fprintf(stderr, "test\n")
> a == stderr
        1
> fclose(a)
        0

fscanf(stream, format[, argument]...)

The fscanf function reads data from the current position of stream into the locations given by argument (if any). Each argument must be a variable already defined of a type that corresponds to a type specifier in format. format controls the interpretation of the input fields and has the same form and function as the format argument for scanf. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields. The returned value is the indefined value.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fseek(stream, offset, origin)

Moves the file pointer to a specified location. The first parameter is a pointer to a FILE structure. The second parameter is the number of bytes from origin. The last parameter is the initial position. If successful, fseek returns 0. Otherwise, it returns a nonzero value. On devices incapable of seeking, the return value is undefined.

The fseek function moves the file pointer (if any) associated with stream to a new location that is offset bytes from origin. The next operation on the stream takes place at the new location. On a stream open for update, the next operation can be either a read or a write. The argument origin must be one of the following values:

origin value Meaning
0 Beginning of file
1 Current position of file pointer
2 End of file

You can use fseek to reposition the pointer anywhere in a file. The pointer can also be positioned beyond the end of the file. fseek clears the end-of-file indicator and negates the effect of any prior ungetc calls against stream.

When a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. If no I/O operation has yet occurred on a file opened for appending, the file position is the start of the file.

For streams opened in text mode, fseek has limited use, because carriage return-linefeed translations can cause fseek to produce unexpected results. The only fseek operations guaranteed to work on streams opened in text mode are:

  • Seeking with an offset of 0 relative to any of the origin values.
  • Seeking from the beginning of the file with an offset value returned from a call to ftell.

Also in text mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing, fopen and all related routines check for a CTRL+Z at the end of the file and remove it if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z may cause fseek to behave improperly near the end of the file.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fsetpos(stream, variable)

Sets the stream-position indicator. The first parameter is a pointer to a FILE structure. The second parameter is a variable of type pointer to fpos_t structure. If successful, fsetpos returns 0. On failure, the function returns a nonzero value.

The fsetpos function sets the file-position indicator for stream to the value of variable, which is obtained in a prior call to fgetpos against stream. The function clears the end-of-file indicator and undoes any effects of ungetc on stream. After calling fsetpos, the next operation on stream may be either input or output.

Text in most part from Microsoft Visual C++ 6.0 Docs.


ftell(stream)

Gets the current position of a file pointer. The parameter is a pointer to a FILE structure. The value returned by ftell may not reflect the physical byte offset for streams opened in text mode, because text mode causes carriage return-linefeed translation. Use ftell with fseek to return to file locations correctly. On error, ftell returns -1. On devices incapable of seeking (such as terminals and printers), or when stream does not refer to an open file, the return value is undefined.

The ftell function gets the current position of the file pointer (if any) associated with stream. The position is expressed as an offset relative to the beginning of the stream.

Note that when a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. For example, if a file is opened for an append and the last operation was a read, the file position is the point where the next read operation would start, not where the next write would start. (When a file is opened for appending, the file position is moved to end of file before any write operation.) If no I/O operation has yet occurred on a file opened for appending, the file position is the beginning of the file.

Also in text mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing, fopen and all related routines check for a CTRL+Z at the end of the file and remove it if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z may cause fseek to behave improperly near the end of the file.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fwrite(string, size, count, stream)

Writes data to a stream. The first parameter is a string containing the data to be written. The second parameter is the item size in bytes. The third parameter is the maximum number of items to be written. The last parameter is a pointer to a FILE structure. fwrite returns the number of full items actually written, which may be less than count if an error occurs. Also, if an error occurs, the file-position indicator cannot be determined.

The fwrite function writes up to count items, of size length each, from string to the output stream. The file pointer associated with stream (if there is one) is incremented by the number of bytes actually written. If stream is opened in text mode and if the operating system is Windows, each carriage return is replaced with a carriage-return - linefeed pair. The replacement has no effect on the return value.

Text in most part from Microsoft Visual C++ 6.0 Docs.


getfuncpt(handle, string)

Gets a pointer to a function in a .dll file on Windows or in a .so file on Linux. The first parameter is the handle obtained with the openlib function. The second parameter in a string holding the name of the function. The returned value is a pointer to a function. The variable holding this pointer is used the same way as a variable holding a reference to a PCASTL function definition node.

In a file named main.c:

#include <windows.h>

BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
    return TRUE;
}

__declspec(dllexport) void add_int(int n1, int n2, int* sum)
{
   *sum = n1 + n2;
}

On the command line:

cl main.c /LD /O2 /Feadd_int.dll

In the interpreter:

> h = openlib("add_int.dll")
        0x72d50000
> add = getfuncpt(h, "add_int")
        0x72d51010
> sum = (int)0
        0
> add((int)10, (int)30, &sum)
> sum
        40
> closelib(h)
        1

In a file named main.c:

void add_int(int n1, int n2, int* sum)
{
   *sum = n1 + n2;
}

On the command line:

gcc -fPIC -c main.c
ld -shared -soname add_int.so -o add_int.so -lc main.o

In the interpreter:

> h = openlib("./add_int.so")
        0x9c72ab0
> add = getfuncpt(h, "add_int")
        0xb78a0164
> sum = (int)0
        0
> add((int)10, (int)30, &sum)
> sum
        40
> closelib(h)
        0

gettype(expr)

This function takes one argument, evaluates it and returns a string containing its type.


getwd()

This function returns a string containing the path of the current working directory.


info(node_reference)

This function prints information about the node reference it receives as parameter. The value returned is the undefined value.


insert(symbol, content, position)

This function inserts the "content" in "symbol" at position "position". Symbol and content have to be of the same type. The type can be array, chained list, string or reference pointing to a statement list. The returned value is the undefined value.

> a = "ad"
        "ad"
> insert(a, "bc", 1)
> a
        "abcd"

length(sequence)

This function returns the number of elements of the sequence it receives as parameter. The sequence can be an array, a chained list, a string or a reference to a statements list. If the sequence is a string, the length is the amount of allocated memory, not the number of characters before the NULL ending.


list([arg1[, arg2[, ...]]])

This function takes as many arguments as you want, evaluates them and return a chained list of the according length.


mknode(list, source, index)

This function adds a node to list node that it receives the reference as first parameter. The second parameter, "source", is the code to insert in the list. This parameter can be a code segment or a node reference. The subtree inserted is copied entirely. The last parameter is the position index where to insert the code in the list. First place is 0 and last place is the list size. The value returned is the undefined value.

> a = function(x) {}
        0x3308b8
> a(2)
> mknode(a.childset[1], `x*2', 0)
> a(2)
        4
>
> a = function()
+ {
+    mknode(parent.parent.parent, `print(3)', 3)
+    print(1)
+    print(2)
+ }
        0x3334b0
> a()
        1
        2
        3
> a()
        1
        2
        3
        3

names(string1[, string2[, ...]])

This function takes at least one string argument. The returned value is an object with members named according to the strings given. If a member of an object is a function, the context of this function when called will already contain the member variables of the object.

> a = names("b", "c")
[b]     undefined
[c]     undefined
> a.b = 0
        0
> a.c = function() { b = 1 }
        0x333028
> a.c()
        1
> a
[b]     1
[c]     0x333028

ntoa(expr)

This function evaluates its argument, converts it to a string if it is numerical and returns it.


openlib(string)

Opens a .dll file on Windows or a .so file on Linux. The name of this file is in the string received as argument. On Linux, if the file is in the working directory, you must begin its name by "./". The returned value is a handle to the library which will have to be used with the function getfuncpt.


print(expr)

This function evaluates and prints its argument. The value returned is the undefined value.


printf(string[, argument]...)

Displays a formatted output in the standard output stream, stdout. The string argument consists of ordinary characters, escape sequences, and (if arguments follow the string) format specifications. The ordinary characters and escape sequences are copied to stdout in order of their appearance.

Format specifications always begin with a percent sign (%) and are read left to right. When printf encounters the first format specification (if any), it converts the value of the first argument after the string and outputs it accordingly. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all the format specifications. The value returned is the undefined value.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> printf("%s %f %c\n", "abc", 2.3, (char)61)
abc 2.300000 =

prompt(string)

This function lets you change the prompt to any string you want. The value returned is the undefined value.

> prompt("input: ")
input: print("hello")
        "hello"
input: prompt("")
a = 1
        1
a + 2
        3
prompt("> ")
> 

read(filename)

This function reads a text file with name given in a string as parameter. The return value is a reference to a list node that has a string node for each word or punctuation mark read. The recognized punctuation marks are ,.!?


remove(symbol, start[, end])

Removes items from a sequence. The first parameter is a variable holding a string, an array, a list or a reference to a statements list. The second parameter is a number telling at which index begin to delete. If there is no third argument, only one item is removed. If there is a third argument, items are deleted from indexes start to end inclusively. The returned value is the undefined value.


replace(symbol, sequence, position)

This function replace the items in "symbol" from "position" by "sequence". The symbol can contain an array, a chained list, a string or a reference pointing to statement list. The sequence has to be of the same type. The returned value is the undefined value.


return([value])

This function stops the execution of the called function one level up. If you give a parameter, it will be the returned value. If you don't give a parameter, the returned value is the undefined value.


rewind(stream)

Repositions the file pointer to the beginning of a file. The parameter is a pointer to a FILE structure. The returned value is the indefined value. The rewind function repositions the file pointer associated with stream to the beginning of the file. A call to rewind is similar to:

fseek(stream, 0, 0)

However, unlike fseek, rewind clears the error indicators for the stream as well as the end-of-file indicator. Also, unlike fseek, rewind does not indicate whether the pointer was successfully moved in its return value.

To clear the keyboard buffer, use rewind with the stream stdin, which is associated with the keyboard by default.

Text in most part from Microsoft Visual C++ 6.0 Docs.


rmnode(list, index)

This function removes a node from list node that it receives the reference as first parameter. The second parameter is the position index where to delete the node from the list. First place is 0 and last place is list size - 1. The value returned is the undefined value.


scan()

This function scans input from the keyboard until a character not in the set {A-Za-z0-9,.!? } is encountered. The return value is a reference to a list node that has a string node for each word or punctuation mark scanned.

> a = scan()
Hello World!!
        0x330908
> length(a)
        4
> value(a.childset[0])
        "Hello"
> value(a.childset[3])
        "!"

scanf(format[, argument]...)

The scanf function reads data from the standard input stream stdin and writes the data into the location given by argument. Each argument must be a variable already defined of a type that corresponds to a type specifier in format. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields. The value returned is the undefined value.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = (int)0
        0
> b = 0
        0
> c = "      "
        "      "
> scanf("%i %lf %s", &a, &b, c)
100 2.4 hello
> a
        100
> b
        2.4
> c
        "hello"

setlength(symbol, length)

This function has two parameter. The first is a symbol which can contain an array, a chained list, a string or a reference pointing to a statement list. The second parameter is the new length of the symbol content. When the symbol contains a string, the new length include the space for the NULL terminating character.


setwd(path)

This function sets the current working directory to the path it receives in a string as parameter. The value returned is the undefined value.

> setwd("d:\\temp")
> getwd()
        "d:\temp"
> setwd("d:/temp/install")
> getwd()
        "d:\temp\install"
> setwd("..")
> getwd()
        "d:\temp"

source(filename)

This function receives one string argument and execute the statements in the file specified by "filename". The value returned is the undefined value.


sprintf(variable, format[, argument]...)

Write formatted data to a string. The first parameter is an already defined variable of the string type that will receive the ouput. The second parameter is the string to be written, which can include format specifications for the other arguments, if any. Each argument (if any) is converted and output according to the corresponding format specification in format. A null character is appended after the last character written. If copying occurs between strings that overlap, the behavior is undefined. The returned value is the undefined value.

Text in some part from Microsoft Visual C++ 6.0 Docs.

> a = "                 "
        "                 "
> sprintf(a, "%s %f %i", "word", 2.01, (int)40)
> a
        "word 2.010000 40"

sscanf(string, format[, argument]...)

Read formatted data from a string. The sscanf function reads data from string into the location given by each argument. Each argument must be a variable already defined of a type that corresponds to a type specifier in format. format controls the interpretation of the input fields and has the same form and function as the format argument for scanf. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields. The returned value is the indefined value.

Text in some part from Microsoft Visual C++ 6.0 Docs.


strclone(string)

Duplicates the string received as argument. The returned value is the new string.


strcpy(string1, string2)

Calls strcpy from string.h. Does copy characters from string2 to string1 including the terminating null character. The allocated string1 length must be greater or equal to string2 length + 1. The behavior is undefined is string1 and string2 overlap. The returned value is string1.


strlen(string)

This function receives one string argument and returns the number of characters before the NULL ending.


subseq(entity, start, end)

This function returns a sub sequence of the entity it receives as first parameter. The entity can be an array, a chained list, a string or a statements list. The second parameter is the index where the sub items of "entity" are beginning to be copied. The last parameter is the index of the last copied sub item of "entity".

> a = `{
+    print(1)
+    print(2)
+    print(3)
+    print(4)
+ }'.childset[0]
        0x330960
>
> b = subseq(a, 0, 1)
        0x332fa0
> c = function() {}
        0x3332d0
> c.childset[1] = b
        0x3332a8
> c()
        1
        2

tmpfile()

Creates a temporary file. Takes no parameter. The tmpfile function creates a temporary file and returns a pointer to that stream. If the file cannot be opened, tmpfile returns a null pointer. This temporary file is automatically deleted when the file is closed, when the program terminates normally. The temporary file is opened in w+b (binary read/write) mode.

Text in most part from Microsoft Visual C++ 6.0 Docs.


tonode(expr)

This function evaluates its argument and if the result is a numeric value or a string, then the return value is a reference to a new node containing the number or the string.


undefine(symbol)

This function sets the type of the symbol it receives as argument to "undefined". The returned value is the undefined value.


ungetc(string, stream)

Pushes a character back onto the stream. The first parameter is a string containing the character to push and a null terminating character. The second parameter is a pointer to a FILE structure.

The ungetc function pushes the first character of string back onto stream and clears the end-of-file indicator. The stream must be open for reading. A subsequent read operation on stream starts with string[0]. An attempt to push "\xff" (EOF) onto the stream using ungetc is ignored.

Characters placed on the stream by ungetc may be erased if fflush, fseek, fsetpos, or rewind is called before the character is read from the stream. The file-position indicator will have the value it had before the characters were pushed back. The external storage corresponding to the stream is unchanged. On a successful ungetc call against a text stream, the file-position indicator is unspecified until all the pushed-back characters are read or discarded. On each successful ungetc call against a binary stream, the file-position indicator is decremented; if its value was 0 before a call, the value is undefined after the call.

Results are unpredictable if ungetc is called twice without a read or file-positioning operation between the two calls. After a call to fscanf, a call to ungetc may fail unless another read operation (such as fgetc) has been performed. This is because fscanf itself calls ungetc.

Text in most part from Microsoft Visual C++ 6.0 Docs.


value(node_reference)

This function returns the numeric value or the string value of a node reference it receives as argument. The node must contain a number or a string.


vartoa(node_reference)

This function receive as parameter a reference to a node of "variable" type. The returned value is a string containing the name of the variable.

> a = `i + 1'.childset[0]
        0x3c7b30
> vartoa(a.childset[0])
        "i"

write(filename, list, separator)

The first parameter is a string containing the file name where to write the text. The second parameter is a reference to a list node where each subnode contains a string. The last parameter is a string containing the text to insert between each strings of the list in the output file. The value returned is the undefined value.

write("write.txt", `{"Hello" "World" "!" "!"}'.childset[0], " ")

back to PCASTL