Manual Basic X11
Manual Basic X11
VERSION 1.14
(C) 1997-2007 by Markus Hoffmann
([email protected])
(see http://x11-basic.sourceforge.net/)
X11-Basic is a comprehensive non-standard Basic interpreter with full X capability that in-
tegrates fratures like shell scripting, cgi programming and full graphical visualisation into the
easy to learn basic language on moden computers. The syntax is most similar to the old GFA-
Basic on ATARI-ST implementation. Old GFA-programs should run with only few changes.
This document describes the features of X11-Basic. You will find information about the X11-
Basic interpreter (the program xbasi
under Unix or xbasi
.exe under Windows) as well as
the language itself. For a more compact description you may want to read the x11basi
(1)
man-page or the man-page of the X11-Basic pseudo compiler xb
(1).
The latest information and updates and new versions of X11-Basic can be found at
http://x11-basi
.sour
eforge.net/.
2
Contents
1 ABOUT X11-Basic 1
2 Usage 3
2.1 Installing X11-Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 The X11-Basic Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Using Syntax highlighting with nedit . . . . . . . . . . . . . . . . . . . . . 7
2.4 The pseudo compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 The WINDOWS Version of X11-Basic . . . . . . . . . . . . . . . . . . . . . 8
2.6 The ANSI-Basic to X11-Basic converter . . . . . . . . . . . . . . . . . . . . 9
3 Getting Started 10
3.1 Introduction to this Dialect of BASIC . . . . . . . . . . . . . . . . . . . . . 10
3.2 Interpreter vs Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 Your first X11-Basic program . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 General Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.5 The very BASIC commands: PRINT, INPUT, IF and GOTO . . . . . . . . . 13
3.6 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.7 Arithmetics and Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.8 Program structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.9 Simple Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.10 Flow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.11 Adress spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.12 Graphics: Drawing and painting . . . . . . . . . . . . . . . . . . . . . . . . 30
3.13 Reading from and writing to files . . . . . . . . . . . . . . . . . . . . . . . . 30
3.14 Internet connections, special files and sockets . . . . . . . . . . . . . . . . . 30
3.15 Data within the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.16 Dynamic-link libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.17 Memory management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.18 Other features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.19 Using the Graphical User Interface (GUI) . . . . . . . . . . . . . . . . . . . 38
3.20 WEB programming with X11-Basic . . . . . . . . . . . . . . . . . . . . . . 51
i
Contents
4 Quick reference 64
4.1 reserved variable names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.2 Abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.3 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.4 Graphic commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.5 Math commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.6 Math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.7 String functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.8 Graphic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.9 Other functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.10 Subroutines and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.11 Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
ii
Contents
6 Compatibility 419
6.1 General remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
6.2 GFA-Basic compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
6.3 Ideas for future releases of X11-Basic . . . . . . . . . . . . . . . . . . . . . 427
Index 429
iii
Contents
iv
1 ABOUT X11-Basic
X11-Basic is a comprehensive non-standard Basic interpreter with full X capability that inte-
grates features like shell scripting, cgi programming and full graphical visualisation into the
easy to learn basic language on modern computers.
The actual implementation runs on Unix workstations (like HP/UX, DEC alpha and maybe
others) and Linux-PCs with the X-Window system. A MS-Windows version has been started.
Also Hand-held PC Versions or adaptations to VxWorks are actually been thought of.
X11-Basic is as well suited to novices as programming wizards, and is appropriate for
virtually all programming tasks. For science and engineering X11-Basic has already prooved
its capability of handling complex simulation and control problems. For system programs,
X11-Basic has high level language replacements for low level programming features that are
much easier to read, understand, and maintain. For all applications, X11-Basic is designed to
support rapid development of compact, efficient, reliable, readable, portable, well structured
programs.
The X11-Basic environment contains a library of GEM GUI functions. This makes writing
GUI programs in X11-Basic faster and easier than programming with native GUI tools.
Structured programming
1
1 ABOUT X11-Basic
Copyright information
X11-Basic is free software and distributed under the GNU License. Read the file COPYING
for details.
2
2 Usage
The X11-Basic interpreter is called xbasi
(xbasi
.exe under Windows). Under Unix it
is usually installed in the /usr/bin/ (if installed via the .rpm) or in /usr/lo
al/bin (if
installed manually from the source package) path.
3
2 Usage
need to look for them on the internet. Al though they are maintained by third party volunteers,
the file system structure should be similar to what is described in the previous chapter, so you
should expect to find the same files at the same place.
• A C compiler, preferably GNU C (but some ANSI C compilers, like DEC’s will do)
• a ‘csh’-compatible shell
sh ./install.sh
Thats all you will have to do (except for something goes wrong).
A xbasi
binary will be compiled into the ./sr
/ directory
d sr
/
make install
4
2.1 Installing X11-Basic
d ./sr
Libraries
make lib will generate libx11basi
.so
make x11basi
.a will generate x11basi
.a – now you have to be root –
make installroot will generate a dynamic linked binary of the interpreter, copy it to /bin/,
install the libraries in /usr/lo
al/lib/, install the man-page
The compiler
make xb
will make the X11-Basic compiler You can then (beeing root) do a
make xb
install to install the compiler in /usr/lo
al/bin/ and the compiler man-page
After doing all this, you will also find a xbasi
.dyn executabe. This is the interpreter,
dynamically linked and much shorter.
The bytecode compiler and the virtual machine Both programs xbb
and xbb
are
new to this package. The idea is to increase the excecution speed of X11-basic programs a
lot by compiling it to a bytecode before execution. The bytecode then can be run much faster
with the bytecode interpreter, the so-called virtual machine. The conversion to bytecode is a
real compilation (in contrast to what the pseudo compiler xb
does). The step to assembler
or machine code is not far. Also a conversion to C or to JAVA or any other language will be
straigt forward, although the code will practically not be readable to humans anymore. As
with JAVA, the bytecode is still platform independant and can be run on any system, which
has a virtual machine ported to.
One point to mention (whether this is a feature or a disadvantage): X11-basic bytecode can
not be converted back to source code (.bas).
Because this is a new feature which is incomplete and still has a lot of bugs the feature is
not incorporated into the interpreter xbasi
itself.
Please try the bytecode compiler out and maybe you want to report errors etc.
5
2 Usage
Support
If you have trouble with X11-Basic, you may send me a mail or browse the faq.
If you have problems compiling X11-Basic under Unix, you should add the file install.log,
which is created by the install.sh-script and contains all the information needed to pin
down the error.
If you have trouble with some X11-Basic-command or program, you should create a min-
imum sample program to reproduce the error; please keep this sample program as small as
possible. Then take the program and send it to me. Add a short description of you problem,
containing:
• Which Operating system are you using: Windows (95, 98, me, xp, NT, 2000) or Unix
(linux, solaris, FreeBSD, HPUX ...) ?
• How does the program behave on your computer ? What did you expect ?
• Which version of X11-Basic are you using ? Please try the latest one ! You also might
want to fill in the bug report form.
The program does not insist on its name, the person installing can name it xbasi
, x11basi
or any other name. However xbasi
is the preferred name for the executable. When you start
the program without arguments it tells you the different options.
6
2.3 Using Syntax highlighting with nedit
Examples:
xbasi
testme.bas
xbasi
-l dontrunme.bas
xbasi
-e 'alert 1,"Hallo !",1," OK ",b'
xbasi
--eval 1+3-4*3
Example:
To run the X11-Basic interpreter on a tcp-socket on port 1371 create a new user called xbasi
and insert
--- in /et
/inetd.
onf: ---
xbasi
stream t
p nowait xbasi
/usr/sbin/t
pd /bin/xbasi
--daemon
--- in /et
/servi
es: ---
xbasi
1371/t
p
---
Please note that this is not recommended since xbasic would open several security holes on
your system.
7
2 Usage
extensions for programmers). In short, it has everything you want to develop your X11-Basic
programs.
If you like to use nedit as your favorite editor, a nedit.defs file comes with this package.
This enables syntax highlighting for X11-Basic programs in nedit (see fig. 2.1).
8
2.6 The ANSI-Basic to X11-Basic converter
1. Choose "X11-Basic" from the start-menu: xbasi
.exe will come up with a console
window and wait for commands to be typed in right away.
2. Click with the right mousebutton on your desktop. Choose "new" from the context-
menu that appears; this will create a new icon on your desktop. The context-menu of this
icon has three entries "Execute", "Edit" and "View docu" (which shows the embedded
documentation, if any); a double-click executes the program.
3. Create a file containing your X11-Basic-program. This file should have the extension
".bas". Double-click on this file then invokes X11-Basic, to execute your program.
For further options try xbasi
bas2x11basi
.bas --help and read the man-page bas2x11basi
(1).
A compiled version of the ANSI-Basic to X11-Basic converter is included in the RPM-
packages.
9
3 Getting Started
This chapter describes all you need to know to write your own programs in X11-Basic.
• variables and identifiers in general can have up to 250 characters to distinguish them
from each other
• file operations
• commands for using X11-Windows graphics and a port of the AES from the ATARI ST,
allowing for easy use of graphics in your program
• commands for direct memory manipulation, allowing you to access the machine almost
as with machine language
10
3.2 Interpreter vs Compiler
Now save the file as "’hello.bas"’ and run the interpreter with
xbasi hello.bas
X11-Basic should not complain. If it does, check carefully for typing mistakes. The Pro-
gram now should print out your hello message at the console or in the console window the
interpreter was started from. It will not return to the shell, but just prompt for aditional com-
mands. Now type
> quit
Now the program always returns to the shell promt when done.
11
3 Getting Started
PRINT "Hello,"; \
" thats it"
Please note: The '\' character must be placed at a position within the command where a
space would be allowed, too.
Comments
A comment can be inserted into your program code with the REM command or the abbrevia-
tion '. Also the '#' as a first character of the program line reserves the rest of the line for a
comment. Anything behind the REM will be ignored by X11-Basic.
The REM stands for remark and is a generic comment. Comment your programs and you
will be able to understand it later.
If you want to place comments at the end of a line, they have to be prefaced with '!'.
Example:
These end of line comments can not be used after DATA (and REM).
12
3.5 The very BASIC commands: PRINT, INPUT, IF and GOTO
3.6 Variables
Variables in BASIC programming are analogous to variables in mathematics. Variable identi-
fiers consist of alphanumeric strings. These identifiers are used to refer to values in computer
memory. In the X11-Basic program, a variable name is one way to bind a variable to a memory
location; the corresponding value is stored as a data object in that location so that the object
can be accessed and manipulated later via the variable’s name.
X11-Basic uses two scopes for variables: global (which is the default) and local.
Global variables can be modified from anywhere within the program, and any part of the
program may depend on it. A global variable therefore has an unlimited potential for creating
mutual dependencies, and adding mutual dependencies increases complexity. However, in a
few cases, global variables can be suitable for use. They can be used to avoid having to pass
frequently-used variables continuously throughout several functions, for example.
The use of global variables makes software harder to read and understand. Since any code
anywhere in the program can change the value of the variable at any time, understanding the
use of the variable may entail understanding a large portion of the program. They can lead to
problems of naming because a global variable makes a name dangerous to use for any other
local or object scope variable. A local variable of the same name can shield the global variable
from access, again leading to harder to understand code. The setting of a global variable can
create side effects that are hard to understand and predict. The use of globals make it more
difficult to isolate units of code for purposes of unit testing, thus they can directly contribute
to lowering the quality of the code.
Because of all this, X11-Basic also provides local variables, which live only within a certain
function or procedure and their context.
You can refer to a variable by giving its name in the place you want the value of the variable
13
3 Getting Started
to be used. X11-Basic will automatically know where to store the data and how to deal with
it. It is also important to tell X11-Basic what sort of data you want to store. You can have
variables that store only numbers but also variables that deal with a character or a whole string,
a line of text for example. The following valid line of X11-Basic code will create a variable
called x for you and assign it the value of 10.
x=10
You learn here 3 important things. First your variable has a name, x in this case, secondly
you state that you want to do something with this variable, an assignment with the = sign, the
last thing is what you want to do with this variable. You give it the value 10 here. Such an
assignment will overwrite any old data that has been stored before in that variable. As long as
you don’t assign a value to a variable, it will hold a default value, 0 in most cases.
14
3.6 Variables
5s$. Always remember: begin your variable names with a letter from A-Z and you are on the
safe side!
Variable names and commands are case insensitive. Each name is bound to only one kind
of variable; A$ is a whole different variable(value) than A which is different from A(1,1) or
A$(1,1).
Space between commands will be ignored, but note that no space is allowed between the
name of a variable or command and the ’(’ of its parameter list. So, ASC("A") is good,
ASC( "A" ) also, but ASC ("A") isn’t.
Examples:
A wealth of intrinsics and functions are provided to support efficient string processing.
X11-Basic arrays can contain variables of any data type, including strings. All arrays,
even multi-dimensional arrays, can be redimensioned without altering the contents. A
special feature of X11-Basic is the implicit dimensioning of arrays and the existance of
array constants. You may define an array by using the DIM command. You might also
define the array by an assignment like a()=b() if b() already has been DIMed or by
a()=[1,2,3,4;6,7,8,9℄ asigning an array constant (In this example a 2 dimensional
array will be created and the rows are separated by ’;’).
15
3 Getting Started
PRINT (X-1)*10+SIN(x)
Conditions and expression are the same in X11-Basic, FALSE is defined as 0 and TRUE
as -1. Those definitions are defined in defs.h and could be changed, but that is not
recommended. Because BASIC doesn’t have seperate boolean operators for conditions
and expressions, using an boolean operator (AND,OR,XOR,NOT) may give spurious
results. When on each site a value of an 0 or -1 is used, it’s assumed as an condition, if
it’s not, it considered an expression. Problems could occure if you use boolean operators
with negative numbers, but that is also unrecommended because the outcome of such an
expression is highly platform depended.
3.7.2 Operators
X11-Basic provides operators for numerical expressions, character strings and arrays of either
type and any dimension.
Numerical Operators
Numerical operators are roughly categorized in following categories:
• arithmetical operators: ^ * / + -
16
3.7 Arithmetics and Calculations
X11-Basic recognizes the following operators, in order of falling precedence (the prece-
dence of BASIC operators affects the order of expression evaluation):
< <= = => > comparison functions belong to numerical (boolean) functions because the result
is a number.
& the eval operator evaluates command or expression which is given by the String.
17
3 Getting Started
1. Two strings are equal if all the characters inside are identical (also spaces and punctua-
tion marks).
Example:
" 123 v fdh.-," = " 123 v fdh.-,"
2. The comparison of size operates also character by character until one of them is smaller
or a the strings ends first, this is the smaller one.
Examples:
"X11">"X11" result: 0
"X11"<"x11" result: -1
"123"<"ab
" result: -1
"123">"1234" result: 0
The eval-Operator &: The &-operator followed by a string evaluates it for program code.
Example:
To program like this can produce a really unreadable code but this is BASIC.
18
3.8 Program structure
Array operators
+ : Addition element by element - : subtraction element by element * : Array/Matrix multi-
plication
muss noch uebersetzt werden ....
Spanning operators
Some operators operate in between of different classes of operands, like the string comparison
operators produce a number, or also the array comparison operators produce numbers. Her are
...
Procedures are blocks of code that can be called from elsewhere in a program. These
subroutines can take arguments but return no results. They can access all variables
available but also may have local variables (–> LOCAL).
Functions are blocks of code that can be called from elsewhere within an expression (e.g
a=3*myfun
tion(b)). Variables are global unless declared local. For local variables
changes outside a function have no effect within the function except as explicitly spec-
ified within the function. Functions arguments can be variables and arrays of any data
types. Functions can return variables of any data type. By default, arguments are passed
by value.
19
3 Getting Started
3.8.1 Procedures
A procedure starts with the keyword PROCEDURE followed by the procedure name and the
parameters being passed to the procedure. All procedures must end with the keyword RETURN.
Procedures use the following format:
PROCEDURE Pro
Name(parameters)
LOCAL vars
pro
edure logi
RETURN
The parameters of the subroutine are placed between parenthesis behind the subroutine
name and must be in the same order as the procedure call from the main program. All variables
used within the subroutine should be declared local using the LOCAL statement. The rest of the
procedure determines the task the subroutine must perform.
A procedure can be called in two ways: by using the keyword GOSUB or . For instance, the
procedure progress(), which showsa progress bar on the text console given the total amount
a and the fraction b, can be called the following ways:
GOSUB progress(100,i)
progress(100,i)
PROCEDURE progress(a,b)
LOCAL t$
IF verbose
PRINT
hr$(13);"[";string$(b/a*32,"-");">";
PRINT string$((1.03-b/a)*32,"-");"| ";str$(int(b/a*100),3,3);"% ℄";
FLUSH
ENDIF
RETURN
3.8.2 Functions
A function starts with a FUNCTION header followed by a function name, and ends with the
keyword ENDFUNCTION. The function is either a numeric or a string function. A numeric
function defaults to the floating point data type and needs no postfix. A string function returns
a string and the function name ends with a $ postfix. A function must contain at least one
RETURN statement to return the function value. Functions use this format:
FUNCTION Fun
Name[$℄(parameters)
LOCAL vars
fun
tion logi
RETURN value[$℄
ENDFUNCTION
20
3.8 Program structure
The type of the return value must match the function type. A string function must return
a string and a numeric function a numeric value. The numeric value is always converted to
a floating point variable. The function returns to the caller when the RETURN statement is
executed. The ENDFUNCTION statement only indicates the end of the function declaration and
will cause an error if the program tries to execute this statement.
A function is called by preceding the function name with . As an example, the string
function Copy$() is called as follows:
Right$=Copy$("X11-Basi ",4)
FUNCTION Copy$(a$,p)
LOCAL b$
b$=MID$(a$,p)
RETURN b$
ENDFUNC
FUNCTION Copy$(a$,p)
RETURN MID$(a$,p)
ENDFUNC
instead.
An alternative for FUNCTION is the DEFFN statement1, which defines a one line function. The
function Copy$() used in the example above, might be used in a DEFFN statement as well:
DEFFN Copy$(a$,p)=MID$(a$,p)
In contrast with procedures and functions, DEFFN functions may be placed within a proce-
dure or function body, although it doesn’t use the local variables of the subroutine.
21
3 Getting Started
gets a copy of the passed value and a call by reference does not. A VAR variable references
the same variable that is passed to the subroutine. The original variable will change when a
subroutine modifies the corresponding VAR variable. In fact, both variable names reference the
same piece of memory that contains the variable value.
Internally, X11-Basic maintains a list of all variables. Each entry in the list points to a
memory location that contains the variable value. A call by reference variable points to the
same location as the passed variable. Therefore, constants or expressions can not be passed to
a VAR variable.
A copy of an array cannot be passed directly to a subroutine1; arrays should always be
passed as a VAR. X11-Basic swaps the pointers to the array descriptors, when an array is
passed to a parameter array. The following example shows a simple function, which searches
a name in a given string array:
The locally used array N$() references the global array Name$(). The array N$() is only
valid within the procedure, where it points to the descriptor of the Name$() array. Trying to
access N$() outside the procedure and Name$ within the procedure will cause an error.
The LOCAL statement lists the variables only known to a procedure or function. Subroutine
parameters are local variables as well. When a subroutine calls another subroutine the local
variables of the calling routine are known in the called routine as if they where global variables.
Several local variables separated by commas may be listed after the LOCAL statement. Mul-
tiple LOCAL lines are allowed.
22
3.9 Simple Input/Output
PRINT 10+5
PRINT x%
PRINT 10;20;30
PRINT 10,20,30
PRINT "Hello!"
PRINT "y= ";y
PRINT "x=";x;" y=";y;" z=";z
PRINT "Your name is ";nam$
PRINT AT(5,5);"AT() is one of my favorites"
PRINT CHR$(27);"[2J This is a
leared
onsole..."
These are the most simple variations of the PRINT command. Try them out on your own to
see their effects. Try with defining a few sample variables.
Now why do you write PRINT "y =";y instead of PRINT "y =",y? Using ; will add the
following data directly behind your text without altering the cursor position while the , will
advance the cursor to the next vertical tabular position. You can use that to align your data in
tables on screen. In short, if you want to write data directly to some sort of prompt or behind
some text, use the ; notation. Put a ; as the last data on your PRINT statement to let the cursor
stay on the current line. You can use this to prevent a scrolling on the last line of the screen
or if you simply want to split writing of prompt and data into two lines of code. Technically
speaking giving the ; last will suppress a carriage return.
If you want to write direct text onto screen which is not contained in a string variable, just
enclose it in double quotes " like PRINT "Hello!" which will write Hello! on screen.
23
3 Getting Started
PRINT "Hello!"
PRINT
PRINT "This is the first example for s
reen
ontrol!"
As you see it prints the greeting and the other line with an empty line between.
A very important thing is how to clear the screen. For obvious reasons, you’ll sometimes
prepare a screen layout that requires you not to have other text or old data on screen. You’ll
simply clear the screen with the following command.
CLS
A neat thing is to write on screen exactly on a position where you want and not following
the listed flow of ordinary PRINT statements. If you did try the first example in this chapter,
you have noticed the AT() command. This special addition for PRINT allows you to position
the cursor freely on screen so you can write your data where you want. Let’s try the following
example program:
CLS
PRINT AT(1,1);"Top left"
PRINT AT(5,13);"Middle line, text indented 5
hars"
PRINT AT(20,25);"bottom line";
INPUT "",dummy$
Press the RETURN key to terminate the program. You’ll learn soon about the INPUT state-
ment.
Syntax for PRINT AT(); is PRINT AT(
olumn, row);, where row 1 is on top of the screen
and column 1 on the left end. Column and row can be variables, expressions or simply a plain
number. Valid PRINT AT() commands are:
PRINT AT(1,5);"Hello"
PRINT AT(5+x%,10);"x"
PRINT AT(4+8,y%);"y = "
How many character positions do I have at my hand you may ask. This depends on the
current console screen size. You have almost always at least 24 lines of text. 80 columns are
standard. If you want to exactly know the number of rows and collums of the text screen, you
can use the (system) variables ROWS and COLS.
There are more commands you can use with PRINT like SPC() and TAB(). Refer to the
command reference on them.
24
3.9 Simple Input/Output
This will prompt the user to enter a value for x which will be stored into a float variable.
You can then use this variable in your program as normal, doing calculations with it. Your
program will stop until the RETURN key or the ENTER key has been pressed to terminate the
input.
You can read more than one variable with one INPUT statement, just list your variables
where you want your input to go to with separating commata.
The user has then to enter commata at the appropriate places to tell which input goes to
which variable. To the example above the user would respond with 5,6,7. As always you can
then reuse the entered values in expressions and calculations.
CLS
INPUT "Enter a value for x:",x
PRINT "x = ";x
INPUT "What is your name?",your_name$
PRINT "Your name is ";your_name$;"."
PRINT "Bye, ";your_name$;"!"
25
3 Getting Started
While entering strings you may have already noticed that X11-Basic will treat entering a
comma again as a delimiter, effectively cutting your string at that comma. Use the command
LINEINPUT instead of INPUT to read strings.
LINEINPUT txt$
You can now enter strings with a comma in and it will be saved to the string variable as well.
You can read multiple strings with LINEINPUT as well but the user has to press the RETURN
key terminating each string to be entered.
An INPUT statement will erase the former contents of a variable in any case and will place
the entered values in them.
FOR i%=1 TO 5
PRINT i%
NEXT i%
This little example program loops 5 times and counts the variable i% from 1 to 5 and prints
the current value to the screen. This sort of loop is called a FOR-NEXT-loop. You can use
any numerical variable to count. Most often this sort of loop is used to do things a certain
amount of time or to iterate over a list. The loop will repeat the code between the FOR and
its corresponding NEXT. Each time X11-Basic reaches the NEXT, it will increment the count
variable and will stop the loop if the maximum count has been reached.
You can of course have another loop inside the current one. Just make sure not to use the
same variable for counting or X11-Basic will do unpredictable things:
FOR i%=1 TO 5
FOR j%=1 TO 10
PRINT i%;" * ";j%;" = ";i%*j%
NEXT j%
NEXT i%
26
3.10 Flow Control
That sample program has one FOR-NEXT-loop in another and it calculates the product of
the both counter variables creating some sort of multiplication table. Some rules and advice
to keep in mind with FOR-NEXT-loops:
2. Always terminate FOR-loops in the correct order. If you write FOR i%=. . . first and
FOR j%=. . . next, make sure to terminate the inner loop first.
3. You can count downwards with the word DOWNTO instead of TO. Try FOR i%=5 DOWNTO 1.
4. You can count in steps not equal 1 with the keyword STEP: FOR i%=1 TO 10 STEP 2
That will increment i% in steps of 2 until it reaches 10.
5. X11-Basic will check for correct loop termination while entering the code into the editor.
Conditions
A very fundamental idea in programming is to create and use conditionals. These will allow
you to make decisions when certain conditions are met and let your program take an alternative
code segment.
Try to imagine that you count a special variable and want to do something else when the
value of your counter is 5:
FOR i%=1 to 10
IF i%=5
PRINT "i% is now 5"
ELSE
PRINT "i% is not 5"
ENDIF
NEXT i%
This program loops 10 times and counts in the variable i%. For each iteration of the loop it
checks if i% is 5 in the IF line. If that condition is true, i% is 5, then it executes the program
branch until the ELSE and omits the following part. If the condition is not true, X11-Basic
will only execute the part behind the ELSE. Make sure to terminate each IF conditional with
an ENDIF or X11-Basic will get lost and produce an error message.
You may leave out the ELSE fork. X11-Basic will then do nothing if the condition is not
true.
27
3 Getting Started
REPEAT
...
UNTIL <
ondition>
This is a so called REPEAT-UNTIL-loop. It loops at least once and checks for the condition
after the loop contents have been executed by X11-Basic. Use it for things that need to be
done at least once. You can emulate FOR-NEXT-loops with it if you want trickier counting:
i%=1
REPEAT
PRINT "i%=";i%
i%=i%+1
UNTIL i%>5
Surely you can test the condition before entering a loop. This is useful if you want to loop
only when a certain condition is already true:
This is the so called WHILE-WEND loop. It checks the condition first and it will not
execute the loop body if the condition is not fulfilled. Sometimes you want to loop endless.
X11-Basic has a special loop construct for this purpose although you can create never ending
loops easily with the types above if you use a condition that will never get true. The never
ending loop is called DO-loop. The 3 loops in the example are all equal in functionality and
will loop endless.
DO
PRINT "endless"
LOOP
i%=0
REPEAT
PRINT "endless"
UNTIL i%=1
28
3.10 Flow Control
i%=0
WHILE i%=0
PRINT "endless"
WEND
At this point it is important that you know you can terminate at your X11-Basic program at
any point. This is useful if your program gets stuck in an endless loop which was not intended.
Press CONTROL-c together and X11-Basic will stop the program. Another CONTROL-c will
quit the interpreter.
Sometimes you will want to terminate a running loop at another point than the official loop
beginning or loop end. Use the EXIT IF statement in your loop for extra conditions. This
will also terminate FOR-NEXT-loops if you wish to and it is the only way to terminate a
DO-LOOP.
i%=1
DO
PRINT "i%=";i%
EXIT IF i%=5
i%=i%+1
LOOP
Please note that the EXIT IF statement has no ENDIF or the like. It just terminates the loop
and continues your program behind the loop end.
29
3 Getting Started
30
3.14 Internet connections, special files and sockets
Socket Types There are two widely used socket types, stream sockets, and datagram sock-
ets. Stream sockets treat communications as a continuous stream of characters, while datagram
sockets have to read entire messages at once. Each uses its own communciations protocol.
Stream sockets use TCP (Transmission Control Protocol), which is a reliable, stream oriented
protocol, and datagram sockets use UDP (Unix Datagram Protocol), which is unreliable and
message oriented.
TCP/IP Transmission Control Protocol (TCP) provides a reliable byte-stream transfer ser-
vice between two endpoints on an internet. TCP depends on IP to move packets around the
network on its behalf. IP is inherently unreliable, so TCP protects against data loss, data cor-
ruption, packet reordering and data duplication by adding checksums and sequence numbers
to transmitted data and, on the receiving side, sending back packets that acknowledge the
receipt of data.
31
3 Getting Started
Before sending data across the network, TCP establishes a connection with the destination
via an exchange of management packets. The connection is destroyed, again via an exchange
of management packets, when the application that was using TCP indicates that no more data
will be transferred. In OSI terms, TCP is a Connection-Oriented Acknowledged Transport
protocol.
TCP has a multi-stage flow-control mechanism which continuously adjusts the sender’s
data rate in an attempt to achieve maximum data throughput while avoiding congestion and
subsequent packet losses in the network. It also attempts to make the best use of network
resources by packing as much data as possible into a single IP packet, although this behaviour
can be overridden by applications that demand immediate data transfer and don’t care about
the inefficiencies of small network packets.
The system calls for establishing a connection are somewhat different for the client and the
server, but both involve the basic construct of a socket. A socket is one end of an interprocess
communication channel. The two processes each establish their own socket.
The steps involved in establishing a socket on the client side are as follows:
2. Connect the socket to the address of the server using the CONNECT command
onne t #1,"ptbtime1.ptb.de",13
3. Instead of using Steps 1 and 2, you can alternatively use the combined command:
open "UC",#2,"ptbtime1.ptb.de",13
4. Send and receive data. There are a number of ways to do this, but the simplest is to use
the PRINT, SEND, WRITE, READ, RECEIVE INPUT commands.
lose #1
The steps involved in establishing a socket on the server side are as follows:
32
3.14 Internet connections, special files and sockets
1. Create a socket with the OPEN command and bind the socket to a port number on the
host machine.
open "US",#1,"server",5000
open "UA",#2,"",1
This call typically blocks until a client connects with the server.
4. Send and receive data on the accepted connection
print #2,"Wel
ome to X11-Basi
test-server ..."
flush #2
do
if inp?(#2)
lineinput #2,t$
print "got: ";t$
endif
exit if t$="quit"
loop
print #2,"goodbye..."
flush #2
lose #2
lose #1
UDP User Datagram Protocol (UDP) provides an unreliable packetized data transfer service
between endpoints on an internet. UDP depends on IP to move packets around the network on
its behalf.
First a SOcket has to be crated with the OPEN command:
open "UU",#1,"sender",5556
When a UDP socket is created, its local and remote addresses are unspecified. Datagrams
can be sent immedi ately using SEND with a valid destination address and port as argument:
send #1,"This is my message",mkl(
hr$(131)+
hr$(195)+
hr$(15)+
hr$(200)),5000
33
3 Getting Started
UDP uses the IPv4 address format, so a long integer has to be passed.
When CONNECT is called on the socket the default destination address is set and datagrams
can now be sent using SEND without specifying an destination address. It is still possible to
send to other destinations by passing an address to SEND.
onne
t #1,"lo
alhost",5555
send #1,"This is my message"
INP?(#n) Returns the size of the next pending datagram in bytes, or 0 when no datagram is
pending.
The Socket should be closed when the connection is not goint to be used any more:
lose #1
UDP does not guarantee to actually deliver the data to the destination, nor does it guarantee
that data packets will be delivered to the destination in the order in which they were sent by the
source, nor does it guarantee that only one copy of the data will be delivered to the destination.
UDP does guarantee data integrity, and it does this by adding a checksum to the data before
transmission.
The following example shows hot to store arbitrary binary data, which can be used e.g. to
store the bitmapdata for a bitmap ( ).
34
3.16 Dynamic-link libraries
LINK #n,"myfile.so"
35
3 Getting Started
X11-Basic applications can load up to 99 shard object files simultaneously, al though the
channel number space is shared with the open files..
To do this parameter n must specify a value between 1 an 99. X11-Basic maintains an
internal table with 99 entries to store the handle of the loaded shared object modules. These
handles are necessary to unload the .so when the application is finished using them.
The .so’s are unloaded by invoking the UNLINK command:
UNLINK #11
X11-Basic currently allows only a float (double) type for the return value. This is currently a
limitation for the use of the standard libraries. If you have written the library function yourself,
you could bypass this limitation by passing pointers to variables.
The following parameter types are possible:
The SYM_ADR function determines the address of the function from its name. The spelling
of the function name must therefore be identical to the spelling of the function in the .so.
When passing the address of the string, a null byte must be added to the end of the string.
36
3.17 Memory management
Ptr%=MALLOC(2000)
A global memory block allocated with MALLOC must be freed using the FREE() function.
An application should always free all memory blocks before exiting. For instance:
FREE Ptr%
• The current time or date can be retrieved with TIME$ and DATE$.
• It is possible to link shared library objects and use the fuctions provided from within the
X11-basic Program
37
3 Getting Started
ALERT boxes can also be used to manage simple input forms like the one you can see in
fig. 3.2. Here is a little exapmle program:
CLEARW
i=1
name$="TEST01"
posx$="N54◦50'32.3"
posy$="E007◦50'32.3"
t$="Edit waypoint:||Name: "+CHR$(27)+name$+"|"
t$=t$+"Breite: "+
hr$(27)+posx$+"|"
t$=t$+"Länge: "+
hr$(27)+posy$+"|"
t$=t$+"Höhe: "+
hr$(27)+str$(alt,5,5)+"|"
t$=t$+"Typ: "+
hr$(27)+hex$(styp,4,4)+"|"
ALERT 0,t$,1,"OK|UPDATE|LÖSCHEN|CANCEL",a,f$
WHILE LEN(f$)
WORT_SEP f$,CHR$(13),0,a$,f$
PRINT "Feld";i;": ",a$
INC i
WEND
QUIT
Fig. 3.4 shows the fileselector box. The command which produces it is:
38
3.19 Using the Graphical User Interface (GUI)
The complete path and filname of the selected file will be returned in f$.
3.19.2 Recources
X11-Basic resources consist of object trees, strings, and bitmaps used by a basic program.
They encapsulate the user interface and make internationalization easier by placing all pro-
gram strings in a single file. The dataformat of X11Basic recources is downwards compatible
with the Atari-ST GEM implementation.
Resources are generally created using a Resource Construction Set (RCS) and saved to a
.RSC file which is loaded by RSRC_LOAD() at program initialization time.
Resources may also be embedded as data structures in source code (the utility programs
rs
2gui.bas and gui2bas.bas convert .RSC files to source code). Resources contain point-
39
3 Getting Started
ers and coordinates which must be fixed up before being used. RSRC_LOAD() does this auto-
matically, however if you use an embedded resource you must take care of this by yourself
on each object in each object tree to convert the initial character coordinates of to screen co-
ordinates. This allows resources designed on screens with different aspect ratios and system
fonts to appear the same. Once a resource is loaded use rsr
_gaddr() to obtain pointers to
individual object trees which can then be manipulated directly or with the X11-Basic built-in
functions.
3.19.3 Objects
Objects can be boxes, buttons, text, images, and more. An object tree is an array of OBJECT
structures linked to form a structured relationship to each other. The object itself is a section
of data which can be held by a string in X11-Basic.
The OBJECT structure is format is as follows:
obje
t$=MKI$(ob_next)+MKI$(ob_head)+MKI$(ob_tail)+
MKI$(ob_type)+MKI$(ob_flags)+MKI$(ob_state)+
MKL$(ob_spe
)+MKI$(ob_x)+MKI$(ob_y)+MKI$(ob_width)+
MKI$(ob_height)
40
3.19 Using the Graphical User Interface (GUI)
The first object in an OBJECT tree is called the ROOT object (OBJECT 0). It’s coordinates
are relative to the upper-left hand corner of the graphics window. The ROOT object can
have any number of children and each child can have children of their own. In each case,
the OBJECT’s coordinates, ob_x, ob_y, ob_width, and ob_height are relative to that of its
parent. The X11-Basic function obj
_offset() can, however, be used to determine the exact
screen coordinates of a child object. obj
_find() is used to determine the object at a given
screen coordinate.
The ob_next, ob_head, and ob_tail fields determine this relationship between parent
OBJECTs and child OBJECTs.
ob_next the index (counting objects from the first object in the object tree) of the object’s
next sibling at the same level in the object tree array. The ROOT object should set this
value to -1. The last child at any given nesting level should set this to the index of its
parent.
ob_head the index of the first child of the current object. If the object has no children then
this value should be -1.
ob_tail the index of the last child: the tail of the list of the object’s children in the object tree
array If the object has no children then this value should be -1.
ob_type the object type. The low byte of the ob_type field specifies the object type as
follows:
ob_flags The ob_flags field of the object structure is a bitmask of different flags that can be
applied to any object. You may want to apply one ore more flags at once. Just add the
values ob_flags.
41
3 Getting Started
ob_state The ob_state field determines the display state of the object as follows:
42
3.19 Using the Graphical User Interface (GUI)
+------------------------------------------------------------------+
| |The low 16 bits
ontain a WORD
ontaining
olor |
|G_BOX |information for the OBJECT. Bits 23-16
ontain a signed|
| |BYTE representing the border thi
kness of the box. |
+------------------------------------------------------------------+
|G_TEXT |The ob_spe
field
ontains a pointer to a TEDINFO |
| |stru
ture. |
+------------------------------------------------------------------+
|G_BOXTEXT |The ob_spe
field
ontains a pointer to a TEDINFO |
| |stru
ture. |
+------------------------------------------------------------------+
|G_IMAGE |The ob_spe
field points to a BITBLK stru
ture. |
+------------------------------------------------------------------+
|G_PROGDEF |The ob_spe
field points to a APPLBLK stru
ture. |
+------------------------------------------------------------------+
| |The low 16 bits
ontain a WORD
ontaining
olor |
|G_IBOX |information for the OBJECT. Bits 23-16
ontain a signed|
| |BYTE representing the border thi
kness of the box. |
+------------------------------------------------------------------+
|G_BUTTON |The ob_spe
field
ontains a pointer to the text to be |
| |
ontained in the button. |
+------------------------------------------------------------------+
| |The low 16 bits
ontain a WORD
ontaining
olor |
| |information for the OBJECT. Bits 23-16
ontain a signed|
43
3 Getting Started
|G_BOXCHAR |BYTE representing the border thi
kness of the box. Bits|
| |31-24
ontain the ASCII value of the
hara
ter to |
| |display. |
+------------------------------------------------------------------+
|G_STRING |The ob_spe
field
ontains a pointer to the text to be |
| |displayed. |
+------------------------------------------------------------------+
|G_FTEXT |The ob_spe
field
ontains a pointer to a TEDINFO |
| |stru
ture. |
+------------------------------------------------------------------+
|G_FBOXTEXT|The ob_spe
field
ontains a pointer to a TEDINFO |
| |stru
ture. |
+------------------------------------------------------------------+
|G_ICON |The ob_spe
field
ontains a pointer to an ICONBLK |
| |stru
ture. |
+------------------------------------------------------------------+
|G_TITLE |The ob_spe
field
ontains a pointer to the text to be |
| |used for the title. |
+------------------------------------------------------------------+
|G_CICON |The ob_spe
field
ontains a pointer to a CICONBLK |
| |stru
ture. |
+------------------------------------------------------------------+
objc_colorword Almost all objects reference a WORD containing the object color as
defined below.
Available colors for fill patterns, text, and borders are listed below:
44
3.19 Using the Graphical User Interface (GUI)
tedinfo$=MKL$(VARPTR(te_ptext$))+MKL$(VARPTR(te_ptmplt$))+
MKL$(VARPTR(te_pvalid$))+MKI$(te_font)+MKI$(te_fontid)+
MKI$(te_just)+MKI$(te_
olor)+MKI$(te_fontsize)+
MKI$(te_thi
kness)+MKI$(te_txtlen)+MKI$(te_tmplen)
The three character pointer point to text strings required for G_FTEXT and G_FBOXTEXT
objects. te_ptext points to the actual text to be displayed and is the only field used
by all text objects. te_ptmplt points to the text template for editable fields. For
each character that the user can enter, the text string should contain a tilde charac-
ter (ASCII 126). Other characters are displayed but cannot be overwritten by the
user. te_pvalid contains validation characters for each character the user may
enter. The current acceptable validation characters are:
45
3 Getting Started
Caracter Allows
9 Digits 0-9
A Uppercase letters A-Z plus space
a Upper and lowercase letters plus space
N Digits 0-9, uppercase letters A-Z and space
n Digits 0-9, upper and lowercase letters A-Z and space
F Valid DOS filename characters plus question mark and asterisk
P Valid DOS pathname characters, backslash, colon, question mark, asterisk
p Valid DOS pathname characters, backslash and colon
X All characters
te_thickness sets the border thickness (positive and negative values are acceptable)
of the G_BOXTEXT or G_FBOXTEXT object.
te_txtlen and te_tmplen should be set to the length of the starting text and template
length respectively.
BITBLK G_IMAGE objects contain a pointer to a BITBLK structure in their ob_spec
field. The BITBLK structure is defined as follows:
bitblk$=MKL$(VARPTR(bi_pdata$))+MKI$(bi_wb)+MKI$(bi_hl)+
MKI$(bi_x)+MKI$(bi_y)+MKI$(bi_
olor)
bi_pdata should contain a monochrome bit image. bi_wb specifies the width (in
bytes) of the image. All BITBLK images must be a multiple of 16 pixels wide
therefore this value must be even. bi_hl specifies the height of the image in
scan lines (rows). bi_x and bi_y are used as offsets into bi_pdata. Any data
occurring before these coordinates will be ignored. bi_
olor is a standard color
WORD where the fill color specifies the color in which the image will be rendered.
ICONBLK The ob_spe
field of G_ICON objects point to an ICONBLK structure as
defined below:
46
3.19 Using the Graphical User Interface (GUI)
i
onblk$=MKL$(VARPTR(ib_pmask$))+MKL$(VARPTR(ib_pdata$))+MKL$(VARPTR(ib_ptext$))+
MKI$(ib_
har)+MKI$(ib_x
har)+MKI$(ib_y
har)+
MKI$(ib_xi
on)+MKI$(ib_yi
on)+MKI$(ib_wi
on)+MKI$(ib_hi
on)+
MKI$(ib_xtext)+MKI$(ib_ytext)+MKI$(ib_wtext)+MKI$(ib_htext)
ib_pmask and ib_pdata contain the monochrome mask and image data respec-
tively. ib_ptext is a string pointer to the icon text. ib_
har defines the icon
character (used for drive icons) and the icon foreground and background color as
follows:
| ib_
har |
| Bits 15-12 | Bits 11-8 | Bits 7-0 |
|I
on Foreground Color |I
on Ba
kground Color |ASCII Chara
ter (or 0 |
| | | for no
hara
ter). |
ib_x
har and ib_y
har specify the location of the icon character relative to
ib_xi
on and ib_yi
on. ib_xi
on and ib_yi
on specify the location of the
icon relative to the ob_x and ob_y of the object. ib_wi
on and ib_hi
on specify
the width and height of the icon in pixels. As with images, icons must be a mul-
tiple of 16 pixels in width. ib_xtext and ib_ytext specify the location of the
text string relative to the ob_x and ob_y of the object. ib_wtext and ib_htext
specify the width and height of the icon text area.
CICONBLK The G_CICON object defines its ob_spe
field to be a pointer to a CICON-
BLK structure as defined below:
i
onblk$=monoblk$+MKL$(VARPTR(mainlist$))
num_planes indicates the number of bit planes this color icon contains.
ol_data
and
ol_mask contain the icon data and mask for the unselected icon respectively.
Likewise, sel_data and sel_mask contain the icon data and mask for the selected
icon.
i
on2$ contains the next color icon definition. Use MKL$(0) if no more
are available.
The GUI library searches the CICONBLK object for a color icon that has the same
number of planes in the display. If none is found, the GUI library simply uses the
monochrome icon.
47
3 Getting Started
APPLBLK G_PROGDEF objects allow programmers to define custom objects and link
them transparently in the resource. The ob_spe
field of G_PROGDEF objects con-
tains a pointer to an APPLBLK as defined below:
applblk$=MKL$(SYM_ADR(#1,"fun
tion"))+MKL$(ap_parm)
The first is a pointer to a user-defined routine which will draw the object. This
routine must be a c-Function, which has to be linked to X11-basic with the LINK
command. The routine will be passed a pointer to a PARMBLK structure contain-
ing the information it needs to render the object. The routine must be defined with
stack checking off and expect to be passed its parameter on the stack. ap_parm is a
user-defined value which is copied into the PARMBLK structure as defined below:
typedef stru
t parm_blk {
OBJECT *tree;
short pb_obj;
short pb_prevstate;
short pb_
urrstate;
short pb_x;
short pb_y;
short pb_w;
short pb_h;
short pb_x
;
short pb_y
;
short pb_w
;
short pb_h
;
long pb_parm;
} PARMBLK;
tree points to the OBJECT tree of the object being drawn. The object is located
at index pb_obj.
The routine is passed the old ob_state of the object in pb_prevstate and the
new ob_state of the object in pb_
urrstate. If pb_prevstate and pb_
urrstate
is equal then the object should be drawn completely, otherwise only the drawing
necessary to redraw the object from pb_prevstate to pb_
urrstate are neces-
sary.
pb_x, pb_y, pb_w, and pb_h give the screen coordinates of the object. pb_x
,
pb_y
, pb_w
, and pb_h
give the rectangle to clip to. pb_parm contains a copy
of the ap_parm value in the APPLBLK structure. The custom routine should return
a short containing any remaining ob_state bits you wish the GUI Library to draw
over your custom object.
Dialogs
Dialog boxes are modal forms of user input. This means that no other interaction can occur
between the user and applications until the requirements of the dialog have been met and it
48
3.19 Using the Graphical User Interface (GUI)
is exited. A normal dialog box consists of an object tree with a BOX as its root object and
any number of other controls that accept user input. Both alert boxes and the file selector are
examples of dialog boxes.
The form_do() function performs the simplest method of using a dialog box. Simply con-
struct an OBJECT tree with at least one EXIT or TOUCHEXIT object and call form_do()1 .
All interaction with the dialog like editable fields, radio buttons, and selectable objects will be
maintained by the X11-Basic library until the user strikes an EXIT or TOUCHEXIT object.
label: TYPE(variables) {
... blo
k ...
}
The label is optional and gives the object a name. Depending on TYPE of the object, one
or more variables are given as a comma separated list in brackets.
Each object may start a block with ’{’ at the end of the line. Inside this block there might be
one or more objects given which then are considered as sub-objects of the one whichopened
the block. The block will be closed by a ’}’ in a single line.
Example:
' Little sele
tor box (
) Markus Hoffmann 07.2003
'
onvert this with gui2bas !
' as an example for the use of the gui system
' with X11-Basi
49
3 Getting Started
3.19.5 Menus
Most applications use a menu bar to allow the user to navigate through program options. In
addition, future versions of X11-Basic will allow popup menus and drop-down list boxes (a
special form of a popup menu).
Here is a simple example program, which demonstrates the handling of a drop down menu.
' Test-program for Drop-Down-Menus
'
DIM field$(50)
FOR i=0 TO 50
READ field$(i)
EXIT IF field$(i)="***"
NEXT i
oh=0
field$(i)=""
DATA "INFO"," Menutest"
DATA "---------------"
DATA "- A
ess.1","- A
ess.2","- A
ess.3","- A
ess.4","- A
ess.5"
DATA "- A
ess.6",""
DATA "FILE"," new"," open ..."," save"," save as ...","--------------"
DATA " print","--------------"," Quit",""
DATA "EDIT","
ut","
opy"," paste","----------"," help1"," helper"
DATA " assist",""
DATA "HELP"," online help","--------------"," edifa
"," editor"," edilink"
DATA " edouard",""
DATA "***"
grau=get_
olor(32000,32000,32000)
olor grau
pbox 0,0,640,400
MENUDEF field$(),menua
tion
DO
pause 0.05
MENU
LOOP
quit
PROCEDURE menua
tion(k)
lo
al b
IF (field$(k)=" Quit") OR (field$(k)=" exit")
quit
ELSE IF field$(k)=" online help"
oh=not oh
MENUSET k,4*abs(oh)
ELSE IF field$(k)=" Menutest"
~form_alert(1,"[0℄[---- Menutest ----||(
) Markus Hoffmann 2001|X11-Basi
V.1.03℄[ OK ℄")
ELSE
PRINT "MENU sele
ted ";k;"
ontents: ";field$(k)
b=form_alert(1,"[1℄[--- Menutest ---||You sele
ted item (No. "+str$(k)+"),| for whi
h was n
if b=2
MENUSET k,8
endif
ENDIF
RETURN
50
3.20 WEB programming with X11-Basic
3.20.2 Configuration
1. All X11-Basic scripts must begin with the following statement, on the first line:
#!/usr/bin/xbasi
Because Unix does not map file suffixes to programs, there has to be a way to tell Unix
that this file is a X11-Basic program, and that it is to be executed by the X11-Basic
interpreter xbasic. This is seen before in shell scripts, in which the first line tells Unix
to execute it with one of the shell programs. The xbasic executable, which will take this
file, parse it, and execute it, is located in the directory /usr/bin. This may be different on
some systems. If you are not sure where the xbasic executable is, type which xbasic on
the command line, and it will return you the path.
The number 755 is the file access mask. The first digit is your permission; it is 7 for full
access. The user and anyone settings are 5 for read and execute.
51
3 Getting Started
3. The very first print statement in a X11-Basic cgi script that returns HTML should be:
When your X11-Basic script is going to return an HTML file, you must have this as the
very first print statement in order to tell the web server that this is an HTML file. There
must be two end of line characters (CR+LF) (the aditional
hr$(13)) in order for this
to work. The flush statement ensures, that this statement ist sent to the web-server. After
that, you usually print "<HTML><BODY>" etc.
52
3.20 WEB programming with X11-Basic
Environment Variables
Input to CGI scripts is usually in the form of environment variables. The environment variables
passed to gateway scripts are associated with the browser requesting information from the
server, the server processing the request, and the data passed in the request. Environment
variables are case-sensitive and are normally used as described in this section. Although some
environment variables are system-specific, many environment variables are standard. The
standard variables are shown in the following Table:
+--------------------------------------------------------------+
| Variable | Purpose |
|-------------------+------------------------------------------|
| AUTH_TYPE | Spe
ifies the authenti
ation method and |
| | is used to validate a user's a
ess. |
|-------------------+------------------------------------------|
| CONTENT_LENGTH | Used to provide a way of tra
king the |
| | length of the data string as a numeri
|
| | value. |
|-------------------+------------------------------------------|
| CONTENT_TYPE | Indi
ates the MIME type of data. |
|-------------------+------------------------------------------|
| GATEWAY_INTERFACE | Indi
ates whi
h version of the CGI |
| | standard the server is using. |
|-------------------+------------------------------------------|
| HTTP_A
EPT | Indi
ates the MIME
ontent types the |
| | browser will a
ept, as passed to the |
| | gateway s
ript via the server. |
|-------------------+------------------------------------------|
| HTTP_USER_AGENT | Indi
ates the type of browser used to |
| | send the request, as passed to the |
| | gateway s
ript via the server. |
|-------------------+------------------------------------------|
| PATH_INFO | Identifies the extra information |
| | in
luded in the URL after the |
| | identifi
ation of the CGI s
ript. |
|-------------------+------------------------------------------|
| PATH_TRANSLATED | Set by the server based on the PATH_INFO |
| | variable. The server translates the |
53
3 Getting Started
AUTH_TYPE The AUTH_TYPE variable provides access control to protected areas of the Web
server and can be used only on servers that support user authentication. If an area of the
Web site has no access control, the AUTH_TYPE variable has no value associated with it.
If an area of the Web site has access control, the AUTH_TYPE variable is set to a specific
value that identifies the authentication scheme being used.
Using this mechanism, the server can challenge a client’s request and the client can
respond. To do this, the server sets a value for the AUTH_TYPE variable and the client
supplies a matching value. The next step is to authenticate the user. Using the basic
authentication scheme, the user’s browser must supply authentication information that
uniquely identifies the user. This information includes a user ID and password.
Under the current implementation of HTTP, HTTP 1.0, the basic authentication scheme
54
3.20 WEB programming with X11-Basic
is the most commonly used authentication method. To specify this method, set the
AUTH_TYPE variable as follows: AUTH_TYPE = Basi
CONTENT_LENGTH The CONTENT_LENGTH variable provides a way of tracking the length
of the data string. This variable tells the client and server how much data to read on the
standard input stream. The value of the variable corresponds to the number of characters
in the data passed with the request. If no data is being passed, the variable has no value.
CONTENT_TYPE The CONTENT_TYPE variable indicates the data’s MIME type. This vari-
able is set only when attached data is passed using the standard input or output stream.
The value assigned to the variable identifies the MIME type and subtype as follows:
+--------------------------------------------------------------+
| Type | Des
ription |
|-------------+------------------------------------------------|
| appli
ation | Binary data that
an be exe
uted or used with |
| | another appli
ation |
|-------------+------------------------------------------------|
| audio | A sound file that requires an output devi
e to |
| | preview |
|-------------+------------------------------------------------|
| image | A pi
ture that requires an output devi
e to |
| | preview |
|-------------+------------------------------------------------|
| message | An en
apsulated mail message |
|-------------+------------------------------------------------|
| multipart | Data
onsisting of multiple parts and possibly |
| | many data types |
|-------------+------------------------------------------------|
| text | Textual data that
an be represented in any |
| |
hara
ter set or formatting language |
|-------------+------------------------------------------------|
| video | A video file that requires an output devi
e to |
| | preview |
|-------------+------------------------------------------------|
| x-world | Experimental data type for world files |
+--------------------------------------------------------------+
MIME subtypes are defined in three categories: primary, additionally defined, and ex-
tended. The primary subtype is the primary type of data adopted for use as a MIME
content type. Additionally defined data types are additional subtypes that have been of-
ficially adopted as MIME content types. Extended data types are experimental subtypes
that have not been officially adopted as MIME content types. You can easily identify
extended subtypes because they begin with the letter x followed by a hyphen. The fol-
lowing Table lists common MIME types and their descriptions.
55
3 Getting Started
+--------------------------------------------------------------+
| Type/Subtype | Des
ription |
|------------------------------+-------------------------------|
| appli
ation/msword | Mi
rosoft Word do
ument |
|------------------------------+-------------------------------|
| appli
ation/o
tet-stream | Binary data that
an be |
| | exe
uted or used with another |
| | appli
ation |
|------------------------------+-------------------------------|
| appli
ation/pdf | ACROBAT PDF do
ument |
|------------------------------+-------------------------------|
| appli
ation/posts
ript | Posts
ript-formatted data |
|------------------------------+-------------------------------|
| appli
ation/rtf | Ri
h Text Format (RTF) |
| | do
ument |
|------------------------------+-------------------------------|
| appli
ation/x-
ompress | Data that has been
ompressed |
| | using UNIX
ompress |
|------------------------------+-------------------------------|
| appli
ation/x-dvi | Devi
e-independent file |
|------------------------------+-------------------------------|
| appli
ation/x-gzip | Data that has been
ompressed |
| | using UNIX gzip |
|------------------------------+-------------------------------|
| appli
ation/x-latex | LATEX do
ument |
|------------------------------+-------------------------------|
| appli
ation/x-tar | Data that has been ar
hived |
| | using UNIX tar |
|------------------------------+-------------------------------|
| audio/basi
| Audio in a nondes
ript format |
|------------------------------+-------------------------------|
| audio/x-wav | Audio in Mi
rosoft WAV format |
|------------------------------+-------------------------------|
| image/gif | Image in gif format |
|------------------------------+-------------------------------|
| image/jpeg | Image in JPEG format |
|------------------------------+-------------------------------|
| image/tiff | Image in TIFF format |
|------------------------------+-------------------------------|
| image/x-portable-bitmap | Portable bitmap |
|------------------------------+-------------------------------|
| image/x-portable-graymap | Portable graymap |
|------------------------------+-------------------------------|
| image/x-portable-pixmap | Portable pixmap |
|------------------------------+-------------------------------|
| image/x-xbitmap | X-bitmap |
|------------------------------+-------------------------------|
| image/x-xpixmap | X-pixmap |
56
3.20 WEB programming with X11-Basic
|------------------------------+-------------------------------|
| message/external-body | Message with external data |
| | sour
e |
|------------------------------+-------------------------------|
| message/partial | Fragmented or partial message |
|------------------------------+-------------------------------|
| message/rf
822 | RFC 822-
ompliant message |
|------------------------------+-------------------------------|
| multipart/alternative | Data with alternative formats |
|------------------------------+-------------------------------|
| multipart/digest | Multipart message digest |
|------------------------------+-------------------------------|
| multipart/mixed | Multipart message with data |
| | in multiple formats |
|------------------------------+-------------------------------|
| multipart/parallel | Multipart data with parts |
| | that should be viewed |
| | simultaneously |
|------------------------------+-------------------------------|
| text/html | HTML-formatted text |
|------------------------------+-------------------------------|
| text/plain | Plain text with no HTML |
| | formatting in
luded |
|------------------------------+-------------------------------|
| video/mpeg | Video in the MPEG format |
|------------------------------+-------------------------------|
| video/qui
ktime | Video in the Apple Qui
kTime |
| | format |
|------------------------------+-------------------------------|
| video/x-msvideo | Video in the Mi
rosoft AVI |
| | format |
|------------------------------+-------------------------------|
| x-world/x-vrml | VRML world file |
+--------------------------------------------------------------+
The boundary parameter, which is required, is used with multipart data to identify the
boundary string that separates message parts. The boundary value is set to a string of
57
3 Getting Started
1 to 70 characters. Although the string cannot end in a space, it can contain any valid
letter or number and can include spaces and a limited set of special characters. Boundary
parameters are unique strings that are defined as follows:
GATEWAY_INTERFACE = name/version
The current version of the CGI specification is 1.1. A server conforming to this version
would set the GATEWAY_INTERFACE variable as follows:
GATEWAY_INTERFACE = CGI/1.1
HTTP_ACCEPT The HTTP_ACCEPT variable defines the types of data the client will accept.
The acceptable values are expressed as a type/subtype pair. Each type/subtype pair is
separated by commas.
PATH_INFO The PATH_INFO variable specifies extra path information and can be used to
send additional information to a gateway script. The extra path information follows the
URL to the gateway script referenced. Generally, this information is a virtual or relative
path to a resource that the server must interpret.
/ gi-bin/doit. gi?string
58
3.20 WEB programming with X11-Basic
When the query string is URL-encoded, the browser encodes key parts of the string.
The plus sign is a placeholder between words and acts as a substitute for spaces:
/ gi-bin/doit. gi?word1+word2+word3
Equal signs separate keys assigned by the publisher from values entered by the user. In
the following example, response is the key assigned by the publisher, and never is the
value entered by the user:
/ gi-bin/doit. gi?response=never
Ampersand symbols separate sets of keys and values. In the following example, re-
sponse is the first key assigned by the publisher, and sometimes is the value entered by
the user. The second key assigned by the publisher is reason, and the value entered by
the user is I am not really sure:
/ gi-bin/doit. gi?response=sometimes&reason=I+am+not+really+sure
Finally, the percent sign is used to identify escape characters. Following the percent sign
is an escape code for a special character expressed as a hexadecimal value. Here is how
the previous query string could be rewritten using the escape code for an apostrophe:
/ gi-bin/doit. gi?response=sometimes&reason=I%27m+not+really+sure
REMOTE_ADDR The REMOTE_ADDR variable is set to the Internet Protocol (IP) address of
the remote computer making the request.
REMOTE_HOST The REMOTE_HOST variable specifies the name of the host computer mak-
ing a request. This variable is set only if the server can figure out this information using
a reverse lookup procedure.
REMOTE_IDENT The REMOTE_IDENT variable identifies the remote user making a request.
The variable is set only if the server and the remote machine making the request sup-
port the identification protocol. Further, information on the remote user is not always
available, so you should not rely on it even when it is available.
REMOTE_USER The REMOTE_USER variable is the user name as authenticated by the user,
and as such is the only variable you should rely upon to identify a user. As with other
types of user authentication, this variable is set only if the server supports user authen-
tication and if the gateway script is protected.
59
3 Getting Started
60
3.20 WEB programming with X11-Basic
The HTTP POST method uses the standard input streams. When a server receives data by
the standard input stream, the server assigns the value associated with the length of the input
stream to the CONTENT_LENGTH variable.
After the script finishes processing the input, the script should return output to the server. The
server will then return the output to the client. Generally, this output is in the form of an HTTP
response that includes a header followed by a blank line and a body. Although the CGI header
output is strictly formatted, the body of the output is formatted in the manner you specify in
the header. For example, the body can contain an HTML document for the client to display.
CGI Headers
CGI headers contain directives to the server. Currently, these three server directives are valid:
* Content-Type
* Lo
ation
* Status
A single header can contain one or all of the server directives. Your CGI script outputs
these directives to the server. Although the header is followed by a blank line that separates
the header from the body, the output does not have to contain a body.
The Content-Type field in a CGI header identifies the MIME type of the data you are
sending back to the client. Usually the data output from a script is a fully formatted document,
such as an HTML document. You could specify this output in the header as follows:
Content-Type: text/html
But of course, if your program outputs other data like images etc. you should specify the
corresponding content type.
Locations The output of your script doesn’t have to be a document created within the
script. You can reference any document on the Web using the Location field. The Location
field references a file by its URL. Servers process location references either directly or indi-
rectly depending on the location of the file. If the server can find the file locally, it passes the
file to the client. Otherwise, the server redirects the URL to the client and the client has to
retrieve the file. You can specify a location in a script as follows:
61
3 Getting Started
Status The Status field passes a status line to the server for forwarding to the client. Status
codes are expressed as a three-digit code followed by a string that generally explains what has
occurred. The first digit of a status code shows the general status as follows:
Although many status codes are used by servers, the status codes you pass to a client via
your CGI script are usually client error codes. Suppose the script could not find a file and you
have specified that in such cases, instead of returning nothing, the script should output an error
code. Here is a list of the client error codes you may want to use:
404 Not found. The spe ified resour e ould not be found.
405 Method not allowed. The submission method used is not allowed.
#!/usr/bin/xbasi
print "Content-type: text/html"+
hr$(13)
print ""+
hr$(13)
flush
print "<html><head><TITLE>Test CGI</TITLE><head><body>"
print "<h1>Commandline:</h1>"
i=0
while len(param$(i))
print str$(i)+": "+param$(i)+"<br>"
in
i
wend
print "<h1>Environment:</h1><pre>"
flush ! flush the output before another program is exe
uted !
system "env"
print "</pre><h1>Stdin:</h1><pre>"
length=val(env$("CONTENT_LENGTH"))
if length
for i=0 to length-1
t$=t$+
hr$(inp(-2))
next i
print t$
62
3.20 WEB programming with X11-Basic
endif
print "</pre>"
print "<FORM METHOD=POST ACTION=/
gi-bin/envtest.
gi>"
print "Name: <INPUT NAME=name><BR>"
print "Email: <INPUT NAME=email><BR>"
print "<INPUT TYPE=submit VALUE="+
hr$(34)+"Test POST Method"+
hr$(34)+">"
print "</FORM>"
print "<hr><h6>(
) Markus Hoffmann
gi with X11-basi
</h6></body></html>"
flush
quit
63
4 Quick reference
4.2 Abbreviations
In direct mode in the interpreter every command can be abbreviated as long as the command
parser can identify uniquely the command. So you may use q instead of QUIT.
In addition there are abbreviations which are actually alternate commands like:
64
4.3 Commands
' REM
? PRINT
GOSUB
~ VOID
& EVAL
4.3 Commands
65
4 Quick reference
66
4.3 Commands
67
4 Quick reference
68
4.5 Math commands
• trigonometric
• arc-trigonometric
• hyperbolic
69
4 Quick reference
• arc-hyperbolic
4.6.1 Angles
Angles are always radians, for both, arguments and return values.
70
4.7 String functions
b=SIN(a) sine
b=COS(a) cosine
b=TAN(a) tangent
b=COT(a) cotangent
b=SEC(a) secant
b=CSC(a) cosecant
b=ASIN(a) arc-sine
b=ACOS(a) arc-cosine
b=ATAN(a) arc-tangent
b=ATAN2(a,
) extended arc-tangent
b=ACOT(a) arc-cotangent
b=ASEC(a) arc-secant
b=ACSC(a) arc-cosecant
b=SINH(a) hyperbolic sine
b=COSH(a) hyperbolic cosine
b=TANH(a) hyperbolic tangent
b=COTH(a) hyperbolic cotangent
b=SECH(a) hyperbolic secant
b=CSCH(a) hyperbolic cosecant
b=ASINH(a) hyperbolic arc-sine
b=ACOSH(a) hyperbolic arc-cosine
b=ATANH(a) hyperbolic arc-tangent
b=ACOTH(a) hyperbolic arc-cotangent
b=ASECH(a) hyperbolic arc-secant
b=ACSCH(a) hyperbolic arc-cosecant
71
4 Quick reference
72
4.9 Other functions
73
4 Quick reference
PROCEDURE name(argumentlist)
... many
ommands
RETURN
FUNCTION name(argumentlist)
.. many more
al
ulations
RETURN returnvalue
ENDFUNCTION
0 Divide by zero
1 Overflow
2 Value not integer −2147483648 . . . 2147483647
3 Value not byte 0 . . . 255
4 Value not short −32768 . . . 32767
5 Square root: only positive numbers
6 Logarithmen nur für Zahlen größer Null
7 Unknown Error
74
4.11 Error Messages
8 Out of Memory
9 Function or command not yet implemented
10 String too long
12 Program too long, buffer size exeeded –> NEW
14 Array () already dimensioned
15 Array () not dimensioned
16 Field index too large
17 Dim too large
18 Wrong number of indicies
19 Procedure not found
20 Label not found
21 Open only "I"nput "O"utput "A"ppend "U"pdate
22 File already opened
23 Wrong file #
24 File not opened
25 Wrong input, no number
26 EOF - reached end of file
27 Too many points for Polyline/Polyfill
28 Array must be one dimensional
30 Merge - no ASCII file
31 Merge - line too long - CANCEL
32 ==> Syntax error
33 Marke nicht definiert
34 Zu wenig Data
35 Data nicht numerisch
36 Programmstruktur Fehlerhaft
37 Diskette voll
38 Befehl im Direktmodus nicht möglich
39 Programmfehler Kein Gosub möglich
40 Clear nicht möglich in For-Next-Schleifen oder Proceduren
41 Cont nicht möglich
42 Zu wenig Parameter
43 Ausdruck zu komplex
44 Funktion nicht definiert
45 Zu viele Parameter
46 Parameter falsch, keine Zahl
47 Parameter falsch, kein String
48 Open "R" - Satzlänge falsch
49 Zu viele "R"-Files (max. 31)
50 Kein "R"-File
51 Parser: Syntax Error <>
52 Fields größer als Satzlänge
75
4 Quick reference
76
4.11 Error Messages
77
4 Quick reference
78
4.11 Error Messages
79
5 X11-Basic command reference
5.1 Syntax templates
This manual describes the syntax of BASIC commands and BASIC functions in a generalized
form. Here is an example:
Those parts of the command that must appear literally in the source code (like PRINT in
the example above) are all uppercase. Descriptions in angle brackets ("<>") are not meant to
appear literally in the source code but are descriptive references to the element that is supposed
to be used in the source code at this place, like a variable, a numeric expression etc. Optional
elements are listed inside square brackets ("[]"). They may be omitted from the command
line. Mutually exclusive alternatives are separated by the "|" character. Exactly one of these
alternatives must appear in the command line. Finally, repetitive syntax is indicated by three
dots "...". Here are some BASIC command lines that all match the syntax template above:
PRINT x
PRINT #1,2*y
PRINT "result = ";result
80
5.2 A
5.2 A
81
5 X11-Basic command reference
Function: ABS()
Syntax: <num-result>=ABS(<num-expression>)
DESCRIPTION:
Returns the absolute value of an expression. The absolute value is the value without regard
to the sign (negative, zero or positive). The result of ABS will always be a positive number or
zero.
EXAMPLE:
PRINT ABS(-34.5),ABS(34)
Result: 34.5 34
82
5.2 A
Function: ACOS()
Syntax: <num-result>=ACOS(<num-expression>)
DESCRIPTION:
The acos() is the arcus cosine-function, i.e. the inverse of the cos()-function. It returns the
angle (in radian), which, fed to the cosine-function will produce the argument passed to the
acos()-function.
EXAMPLE:
PRINT ACOS(0.5),ACOS(COS(PI))
Result: 1.047197551197 3.14159265359
Function: ACOSH()
Syntax: <num-result>=ACOSH(<num-expression>)
DESCRIPTION:
83
5 X11-Basic command reference
Command: ADD
Syntax: ADD <num-variable>,<num-expression>
DESCRIPTION:
EXAMPLE:
a=0
ADD a,5
Function: ADD()
Syntax: <num-result>=ADD(<num-expression>,<num-expression>)
DESCRIPTION:
(Integer) addition.
EXAMPLE:
b=ADD(a,5)
84
5.2 A
Command: AFTER
Syntax: AFTER <num-variable>, <pro
edure-name>
AFTER STOP
AFTER CONT
DESCRIPTION:
Procedures can be called after the expiry of a set time. Time in seconds. To continue the
process, use CONT, and to stop use STOP.
EXAMPLE:
PRINT "You have 10 se
onds to enter your name: "
AFTER 10,alarm
INPUT name$
END
PROCEDURE alarm
PRINT "Time out !"
QUIT
RETURN
85
5 X11-Basic command reference
Command: ALERT
Syntax: ALERT <type>,<message-string>,<default-button>,
<button-string>,<num-var>[,<string-var>℄
DESCRIPTION:
EXAMPLES:
ALERT 1,"Pi
k a|button",1,"Left|Right",a
ALERT 0,"You pressed|Button"+STR$(a),0,"OK",a
' Example of editable fields
i=1
name$="TEST01"
posx$="N54◦50'32.3"
t$="Edit waypoint:||Name: "+
hr$(27)+name$+"|"
t$=t$+"Position: "+
hr$(27)+posx$+"|"
ALERT 0,t$,1,"OK|UPDATE|DELETE|CANCEL",a,f$
WHILE LEN(f$)
WORT_SEP f$,CHR$(13),0,a$,f$
PRINT "Field";i;": ",a$
INC i
WEND
86
5.2 A
Operator: AND
Syntax: <num-expression1> AND <num-expression2>
DESCRIPTION:
Used to determine if BOTH conditions are true. If both expression1 AND expression2 are
true (non-zero), the result is true. Returns -1 for true, 0 for false.
Also used to compare bits in binary number operations. 1 AND 1 return a 1, all other
combinations of 0’s and 1’s produce 0.
EXAMPLES:
Print 3=3 AND 4>2 Result: -1 (true)
Print 3>3 AND 5>3 Result: 0 (false)
PRINT (30>20 AND 20<30) Result: -1 (true)
PRINT (4 AND 255) Result: 4
Function: AND()
Syntax: <num-result>=AND(<num-expression>,<num-expression2>)
DESCRIPTION:
87
5 X11-Basic command reference
Command: ARRAYCOPY
Syntax: ARRAYCOPY d(),s()
DESCRIPTION:
Copys the contents of array s() to d() (including dimensions). This is the same as the
statement: d()=s().
Command: ARRAYFILL
Syntax: ARRAYFILL x(),n
ARRAYFILL x$(),t$
DESCRIPTION:
EXAMPLE:
DIM a(100)
ARRAYFILL a(),13
PRINT a(22) Result: 13
88
5.2 A
Function: ARRPTR()
Syntax: <int-result>=ARRPTR(<array>())
DESCRIPTION:
89
5 X11-Basic command reference
Function: ASC()
Syntax: <num-result>=ASC(<string-expression>)
DESCRIPTION:
Returns the ASCII code value (a number between 0 and 255) of the first character in a string.
ASCII stands for American Standard Code for Information Interchange. ASC returns 0 if the
length of string is zero or the ASCII code of the string is zero.
EXAMPLE:
PRINT ASC("A"), ASC("T") Result: 65, 84
PRINT ASC("TEST") Result: 84
90
5.2 A
Function: ASIN()
Syntax: <num-result>=ASIN(<num-expression>)
DESCRIPTION:
The asin() is the arcus sine-function, i.e. the inverse of the sin()-function. Or, more elabo-
rate: It Returns the angle (in radian, not degree !), which, fed to the sine-function will produce
the argument passed to the asin()-function.
EXAMPLE:
PRINT 6*ASIN(0.5) Result: 3.14159265359
Function: ASINH()
Syntax: <num-result>=ASINH(<num-expression>)
DESCRIPTION:
The asinh() function calculates the inverse hyperbolic sine of x; that is the value whose
hyperbolic sine is x.
91
5 X11-Basic command reference
Keyword: AT()
Syntax: PRINT AT(y,x);[...℄
DESCRIPTION:
The AT-statement takes two numeric arguments (e.g. AT(2,3)) and can be used in combina-
tion with the PRINT- or GPRINT-command.
The two numeric arguments of the AT-function may range from 0 to the width of your
terminal minus 1, and from 0 to the height of your terminal minus 1; if any argument exceeds
these values, it will be truncated accordingly. However, X11-Basic has no influence on the
size of your terminal (80x25 is a common, but not mandatory), the size of your terminal and
the maximum values acceptable within the AT-statement may vary. To get the size of your
terminal you may use the CRSLN and CRSCOL variables.
92
5.2 A
DESCRIPTION:
EXAMPLE:
PRINT 4*ATAN(1) Result: 3.14159265359
Function: ATAN2()
Syntax: <num-result>=ATAN2(<num-expression>,<num-expression>)
DESCRIPTION:
The atan()-function has a second form which accepts two arguments: atan2(a,b) which is
(mostly) equivilantly to atan(a/b) except for the fact, that the two-argument-form returns an
angle in the range -pi to pi, whereas the one-argument-form returns an angle in the range -pi/2
to pi/2.
EXAMPLE:
PRINT DEG(ATAN2(0,-1)) Result: 180
93
5 X11-Basic command reference
Function: ATANH()
Syntax: <num-result>=ATANH(<num-expression>,<num-expression>)
DESCRIPTION:
The atanh() function calculates the inverse hyperbolic tangent of x; that is the value whose
hyperbolic tangent is x. If the absolute value of x is greater than 1.0, acosh() returns not-a-
number (NaN).
94
5.3 B
5.3 B
95
5 X11-Basic command reference
Function: BCHG()
Syntax: <num-result>=BCHG(<num-expression>,<num-expression>))
DESCRIPTION:
Function: BCLR()
Syntax: <num-result>=BCLR(<num-expression-x>,<num-expression-y>))
DESCRIPTION:
96
5.3 B
DESCRIPTION:
Sounds the speaker of your terminal. This command is not a sound-interface, so you can
neither vary the length or the height of the sound (technically, it just prints chr$(7)). BELL is
exactly the same as BEEP.
97
5 X11-Basic command reference
Command: BGET
Syntax: BGET #<devi
e-nr>,<adr>,<len>
DESCRIPTION:
Reads <len> bytes from a data channel into an area of memory starting at address <adr>
Unlike BLOAD, several different areas of memory can be read from a file.
98
5.3 B
Function: BIN$()
Syntax: <string-result>=BIN$(<num-expression>[,<num-expression>)℄)
DESCRIPTION:
The bin$()-takes a numeric argument an converts it into a string of binary digits (i.e. ’0’
and ’1’). The length of the output, number of digits can be specified by the optional second
argument.
EXAMPLE:
PRINT BIN$(64),BIN$(-2000,16)
Result: 01000000 1111100000110000
99
5 X11-Basic command reference
Command: BLOAD
Syntax: BLOAD <filename>,<address>
DESCRIPTION:
BLOAD reads the specified file into memory. The adress space <address> is pointing to
should be allocated before. You should check if the file exists prior to using this function.
This command is meant to be used for loading binary data. To load a text file, use OPEN and
INPUT # to remain compatible with other BASIC implementations.
100
5.3 B
Command: BMOVE
Syntax: BMOVE <s
r>,<dst>,<len>
DESCRIPTION:
101
5 X11-Basic command reference
Command: BOUNDARY
Syntax: BOUNDARY <num-expression>
DESCRIPTION:
Switch off (or on) borders on filled shapes (PBOX, PCIRCLE ..). If the argument is zero -
no border will be drawn.
102
5.3 B
Command: BOX
Syntax: BOX <x>,<y>,<x2>,<y2>
DESCRIPTION:
103
5 X11-Basic command reference
Command: BPUT
Syntax: BPUT #<devi
e-nr>,<adr>,<len>
DESCRIPTION:
Reads <len> bytes from an area of memory starting at <adr> out to a data channel.
104
5.3 B
Command: BREAK
Syntax: BREAK
DESCRIPTION:
BREAK transfers control immediately outside the enclosing loop or select statement. This
is the preferred way of leaving such a statement (rather than goto).
105
5 X11-Basic command reference
Command: BSAVE
Syntax: <filename>,<adr>,<len>
DESCRIPTION:
Save <len> bytes in memory from adress <adr> to file. This command is meant be be used
for saving binary data obtained via BLOAD. To save text files, use OPEN and PRINT # to
remain compatible with other BASIC implementations.
106
5.3 B
Function: BSET()
Syntax: <num-result>=BSET(<num-expression-x>,<num-expression-y>)
DESCRIPTION:
Allows setting and resetting of bits. BSET sets the y-th bit of x to 1.
107
5 X11-Basic command reference
Function: BTST()
Syntax: <bool-result>=BTST(<num-expression-x>,<num-expression-y>)
DESCRIPTION:
108
5.3 B
Function: BWTD$()
Syntax: b$=BWTD$(a$)
DESCRIPTION:
109
5 X11-Basic command reference
Function: BWTE$()
Syntax: b$=BWTE$(a$)
DESCRIPTION:
110
5.3 B
Function: BYTE()
Syntax: <num>=BYTE(<num-expression>)
DESCRIPTION:
111
5 X11-Basic command reference
5.4 C
112
5.4 C
Command: CALL
Syntax: CALL <adr>[,<parameter-list>℄
DESCRIPTION:
Calls a machine code or C subroutine at address <adr> without return value. Optinal pa-
rameters are passed on the stack. (like in C). The default parameter-type is (4-Byte) integer. If
you want to specify other types, please use prefixes:
D: – double (8-Bytes) F: – float (4-Bytes) L: – long int
EXAMPLE:
DIM result(100)
LINK #1,"simlib.so"
adr=SYM_ADR(#1,"Cal
Beta")
CALL adr,D:1.2,L:0,L:VARPTR(result(0))
UNLINK #1
113
5 X11-Basic command reference
Function: CARD()
Syntax: <num>=CARD(<num-expression>)
DESCRIPTION:
114
5.4 C
Keyword: CASE
Syntax: SELECT ... CASE <num-expression> ... ENDSELECT
DESCRIPTION:
See SELECT.
115
5 X11-Basic command reference
Function: CBRT()
Syntax: a=CBRT(x)
DESCRIPTION:
The CBRT() function returns the cube root of x. This function cannot fail; every repre-
sentable real value has a representable real cube root.
116
5.4 C
Function: CEIL()
Syntax: <num-result>=CEIL(<num-expression>)
DESCRIPTION:
Ceiling function: return smallest integral value not less than argument.
117
5 X11-Basic command reference
Command: CHAIN
Syntax: CHAIN <file-name>
DESCRIPTION:
CHAIN loads and runs another BASIC program. Global variables will be available with
their current value to the new program, all other variables are erased. If you want to append
another program to the current program (as opposed to erasing the current program and loading
a new program), use the MERGE command instead.
118
5.4 C
Function: CHR$()
Syntax: <string-result> = CHR$(<num-expression>)
DESCRIPTION:
Control codes
24 CAN 32 SP -- Spa
e
25 EM 127 DEL -- Delete
26 SUB
119
5 X11-Basic command reference
27 ESC28 FS
29 GS
30 RT
31 US
EXAMPLE:
PRINT CHR$(34);"Hello World !";CHR$(34)
Result: "Hello World !"
120
5.4 C
Function: CINT()
Syntax: <num-result>=CINT(<num-expression>)
DESCRIPTION:
CINT() returns the rounded absolute value of its argument prefixed with the sign of its
argument.
EXAMPLE:
PRINT CINT(1.4), CINT(-1.7)
Result: 2, -2
121
5 X11-Basic command reference
Command: CIRCLE
Syntax: CIRCLE <x>,<y>,<r>[,<w1>,<w2>℄
DESCRIPTION:
Draw a circle with actual color (and fillpattern). The x- and y-coordinates of the center and
the radius of the circle in screen coordinates. Optionally a starting angle <w1> and stop angle
<w2> can be passed to draw a circular arc.
EXAMPLE:
CIRCLE 100,100,50
122
5.4 C
Command: CLEAR
Syntax: CLEAR
DESCRIPTION:
Clear all variables and arrays as if they were never used before.
123
5 X11-Basic command reference
Command: CLEARW
Syntax: CLEARW [<num>℄
DESCRIPTION:
Clear graphic window. If a number is given, clear window with the number given. The
Window is filled with the backgound color given by the X-server.
124
5.4 C
Command: CLIP
Syntax: CLIP x,y,w,h[,ox,oy℄
DESCRIPTION:
This command provide the ’Clipping’ function, ie. the limiting of graphic display within a
specified rectangular screen area. The command CLIP x,y,w,h defines the clipping rectangle
starting at upper left coordinates x,y and extends w wide and h high. The optional additional
command parameters ox,oy make it possible to redefine the origin of the graphic display.
SEE ALSO:
125
5 X11-Basic command reference
Command: CLOSE
Syntax: CLOSE [[#℄<num-expression>[,[#℄<num-expression>,...℄℄
DESCRIPTION:
This statement is used to CLOSE one or more OPEN files or other devices. The parameter
expression indicates a device number or file number. If no file or device numbers are declared
all OPEN devices will be closed.
COMMENT:
All files should be closed before leaving a program to insure that data will not be lost or
destroyed. If a program exit is through END or QUIT, all files will be closed. If a program is
stopped with the STOP command, alle open files remain open.
EXAMPLE:
CLOSE #1,#2
CLOSE
126
5.4 C
Command: CLOSEW
Syntax: CLOSEW [<num>℄
DESCRIPTION:
Close graphic window (make it disappear from the screen). If a number is given, closes
window with the number given. The Window will again be opened, when the next graphic
command is executed.
127
5 X11-Basic command reference
Command: CLR
Syntax: CLR <var>[,<var>,...℄
DESCRIPTION:
128
5.4 C
Command: CLS
Syntax: CLS
DESCRIPTION:
Clear text screen and move cursor home (upper left corner).
129
5 X11-Basic command reference
Command: COLOR
Syntax: COLOR <foreground-
olor>[,<ba
kground-
olor>℄
DESCRIPTION:
COLOR sets the foreground color (and optionally the background color) for graphic output
into the graphic window. The color values are dependant of the color depth of the Screen/X-
Server. Usually the COLOR statement is used together with the GET_COLOR() function, so
arbitrary colors may be used.
EXAMPLE:
yellow=GET_COLOR(65535,65535,0)
blue=GET_COLOR(0,0,65535)
COLOR yellow,blue
130
5.4 C
Function: COMBIN()
Syntax: <num-result>=COMBIN(<n>,<k>)
DESCRIPTION:
Calculates the number of combinations of <n> elements to the <k>th class without repeti-
tions. Defined as z=n!/((n-k)!*k!).
131
5 X11-Basic command reference
Function: COMPRESS$()
Syntax:
$=COMPRESS$(a$)
DESCRIPTION:
Performs a losless compression on the String a$. The algorithm uses run length encoding
in combination with the Burrows-Wheeler transform. The result is a better compression than
p.ex. the algorithm used by gzip. At the moment the COMPRESS$() function is identical to
following combination: b$=ARIE$(RLE$(MTFE$(BWTE$(RLE$(a$)))))
132
5.4 C
Command: CONNECT
Syntax: CONNECT #n,server$,port%
DESCRIPTION:
133
5 X11-Basic command reference
Command: CONT
Syntax: CONT
DESCRIPTION:
134
5.4 C
Command: COPYAREA
Syntax: COPYAREA x,y,w,h,xd,yd
DESCRIPTION:
135
5 X11-Basic command reference
Function: COS()
Syntax: <num-result>=COS(<num-expression>)
DESCRIPTION:
EXAMPLE:
PRINT COS(0) Result: 1
Function: COSH()
Syntax: <num-result>=COSH(<num-expression>)
DESCRIPTION:
The cosh() function returns the hyperbolic cosine of x, which is defined mathematically as
(exp(x)+exp(-x))/2
Function: CRC()
Syntax: <num-result>=CRC(t$[,o
℄)
136
5.4 C
DESCRIPTION:
Calculates a 32 bit checksum on the given String. If oc is passed, the checksum will be
updated with the given String.
137
5 X11-Basic command reference
DESCRIPTION:
138
5.4 C
Variable: CTIMER
Syntax: CTIMER
DESCRIPTION:
Returns CPU-Clock in seconds. This timer returns the amount of time this application was
running. It is most usefull for benchmark applications on multi tasking environments.
139
5 X11-Basic command reference
Function: CVA()
Syntax: <array-result>=CVA(<string-expression>)
DESCRIPTION:
Returns array reconstructed from the string. This function is the compliment of MKA$().
EXAMPLE:
a()=CVA(t$)
140
5.4 C
Function: CVD()
Syntax: <num-result>=CVD(<string-expression>)
DESCRIPTION:
Returns the binary double value of the first 8 characters of string. This function is the
compliment of MKD$().
Function: CVF()
Syntax: <num-result>=CVF(<string-expression>)
DESCRIPTION:
Returns the binary float value of the first 4 characters of string. This function is the compli-
ment of MKF$().
Function: CVI()
Syntax: <num-result>=CVI(<string-expression>)
DESCRIPTION:
141
5 X11-Basic command reference
Returns the binary integer value of the first 2 characters of string. This function is the
compliment of MKI$(). Null string returns 0, One character strings will return the ASCII
value.
Function: CVL()
Syntax: <num-result>=CVL(<string-expression>)
DESCRIPTION:
Returns the binary long integer value of the first 4 characters of string. This function is the
compliment of MKL$(). Null string returns 0.
Function: CVS()
Syntax: <num-result>=CVS(<string-expression>)
DESCRIPTION:
Returns the binary float value of the first 4 characters of string. This function is the compli-
ment of MKS$().
142
5.5 D
5.5 D
143
5 X11-Basic command reference
Command: DATA
Syntax: DATA [<
onst>[,<
onst>, ...℄℄
DESCRIPTION:
The DATA statement is used to hold information that may be read into variables using the
READ statement. DATA items are a list of string or numeric constants separated by commas
and may appear anywhere in a program. No comment statement may follow the DATA state-
ment on the same line. Items are read in the order they appear in a program. RESTORE will
set the pointer back to the beginning of the first DATA statement.
Alphanumeric string information in a DATA statement need not be enclosed in quotes if the
first character is not a number, math sign or decimal point. Leading spaces will be ignored
(unless in quotes). DATA statements can be included anywhere within a program and will be
read in order.
144
5.5 D
Variable: DATE$
Syntax: DATE$
DESCRIPTION:
145
5 X11-Basic command reference
Command: DEC
Syntax: DEC <num-variable>
DESCRIPTION:
146
5.5 D
Keyword: DEFAULT
Syntax: SELECT ... DEFAULT ... ENDSELECT
DESCRIPTION:
See SELECT.
147
5 X11-Basic command reference
Command: DEFFILL
Syntax: DEFFILL <
ol>,<style>,<pattern>
DESCRIPTION:
Sets fill colour and pattern. <col> - not used at the moment <style> - 0=empty, 1=filled,
2=dots, 3=lines, 4=user (not used) <pattern> - 24 dotted patterns and 12 lined can by chosen.
148
5.5 D
Command: DEFFN
Syntax: DEFFN <fun
tion-name>[$℄[(<variable list>)℄=<expression>
DESCRIPTION:
This statement allows the user to define a single line inline function that can thereafter be
called by FN name or @name. This is a handy way of adding functions not provided in the
language. The expression may be a numeric or string expression and must match the type the
function name would assume if it was a variable name. The name must adhere to variable
name syntax.
EXAMPLES:
DEFFN av(x,y)=SQR(x^2+y^2)
a=av(b,
) !
all av
DEFFN add$(a$,b$)=a$+b$
149
5 X11-Basic command reference
Command: DEFLINE
Syntax: DEFLINE <style>,<thi
kness>[,<begin_s>,<end_s>℄
DESCRIPTION:
Sets line style, width and type of line start and end. <style> – determines the style of line:
1 Solid line 2 Long dashed line 3 Dotted 4 Dot-dashed 5 Dashed 6 Dash dot dot .. 7 User
defined (not used) <thickness> – sets line width in pixels. <begin_s>,<end_s> – The start and
end symbols are defined by the last parameter, and can be: 0 Square 1 Arrow 2 Round
150
5.5 D
Command: DEMARK
Syntax: DEMARK <
olor>,<style>,<size>
DESCRIPTION:
Sets colour,type and size of the corner points to be marked using the command POLY-
MARK. The color value will be ignored. The color of the points can be set with the COLOR
command. The following typesare possible : 0=point 1=dot (circle) 2=plus sign 3=asterisk
4=square 5=cross 6=hash 8=filled circle 9=filled square
151
5 X11-Basic command reference
Command: DEMOUSE
Syntax: DEMOUSE <style>
DESCRIPTION:
Chooses a pre-defined mouse form. The following mouse forms are available :
0=arrow 1=expanded (rounded) X 2=busy bee 3=hand, pointing finger 4=open hand 5=thin
crosswire 6=thick crosswire 7=bordered crosswire and about 100 other X-Window specific
symbols.
152
5.5 D
Command: DEFTEXT
Syntax: DEFTEXT <
olour>,<attr>,<angle>,<height>,<width>
DESCRIPTION:
Defines the colour,style,rotation and size of text to be printed using the LTEXT command.
<colour> not used. <attr> text style - 0=normal 1=bold 2=light 4=italic 8=underlined
16=outlined (can be combined). <angle> rotation in degrees <width> and <height> size of
text in % (100% correspondt to 100 Pixel font)
153
5 X11-Basic command reference
Function: DEG()
Syntax: <num-expression>=DEG(<num-expression_x>)
DESCRIPTION:
154
5.5 D
Command: DELAY
Syntax: DELAY <num-of-se
onds>
DESCRIPTION:
155
5 X11-Basic command reference
Function: DET()
Syntax: d=DET(a())
DESCRIPTION:
156
5.5 D
Command: DIM
Syntax: DIM <arrayname>(<indi
es>)[,<arrayname>(<indi
es>),...℄
DESCRIPTION:
EXAMPLES:
DIM a(10)
DIM b(100,100)
DIM
$(20,30,405,6)
Function: DIM?()
Syntax: <num-result>=DIM?(<array-name>())
DESCRIPTION:
Determines the number of elements in an array. Note - arrays have an element ’0’.
EXAMPLE:
DIM a(10,10)
PRINT DIM?(A()) Result: 121
157
5 X11-Basic command reference
Command: DIV
Syntax: DIV <num-var>,<num-expression>
DESCRIPTION:
Function: DIV()
Syntax: <num-result>=DIV(<num-expression>,<num-expression>)
DESCRIPTION:
158
5.5 D
Command: DO
Syntax: DO ... LOOP
DESCRIPTION:
DO implements an unconditional loop. The lines between the DO line and the LOOP line
form the loop body. The unconditional DO...LOOP block simply loops and the only way out
is by EXIT IF or BREAK (or GOTO).
EXAMPLE:
DO
INPUT a$
EXIT IF a$=""
LOOP
159
5 X11-Basic command reference
Keyword: DOWNTO
Syntax: FOR ... DOWNTO ...
DESCRIPTION:
Used within a FOR..NEXT loop as a counter. Instead of using STEP -1, the command
DOWNTO is used, however STEP is not possible with DOWNTO. eg: FOR c=100 DOWNTO
1 is the same as FOR c=100 TO 1 STEP -1
160
5.5 D
Function: DPEEK()
Syntax: <num-result>=DPEEK(<adr>)
DESCRIPTION:
Command: DPOKE
Syntax: DPOKE <adr>,<num-expression>
DESCRIPTION:
161
5 X11-Basic command reference
Command: DRAW
Syntax: DRAW [<x1>,<y1>℄[TO <x2>,<y2>℄[TO <x3>,<y3>℄[TO ...℄
DESCRIPTION:
Draws points and connects two or more points with straight lines. DRAW x,y is the same
as PLOT x,y. DRAW TO x,y connects the point to the last set point (set by PLOT, LINE or
DRAW).
162
5.5 D
Command: DUMP
Syntax: DUMM [t$℄
DESCRIPTION:
163
5 X11-Basic command reference
5.6 E
164
5.6 E
Command: ECHO
Syntax: ECHO ON
ECHO OFF
DESCRIPTION:
Switches the trace function on or off. This causes each command to be listed on the stdout.
165
5 X11-Basic command reference
Command: EDIT
Syntax: EDIT
DESCRIPTION:
EDIT invokes the standart editor (given by the environment variable $(EDITOR) to edit the
BASIC program in memory. The command invokes the following actions:
- SAVE "name. " writes the BASIC-program into a temporary file, - calls the editor ’$ED-
ITOR’, waits until editor is closed - NEW clears internal values - LOAD "name. " reads the
BASIC-program from the temporary file.
You may want to SAVE the file before using the EDIT command if the file has not yet
been saved in order to choose a name at that occasion. The default name is "name. ". This
command requires that the editor installed on your system does not detach itself from the
calling process or EDIT will not recognize any changes (in that case, use LOAD to load the
modified source code).
166
5.6 E
Command: ELLIPSE
Syntax: ELLIPSE <x>,<y>,<a>,<b> [,<w0>,<w1>℄
DESCRIPTION:
Draws an ellipse at <x>,<y>, having <a> as horizontal radius and <b> vertical radius The
optional angles <w0> and <w1> give start and end angles in degrees, to create an elliptical
arc.
167
5 X11-Basic command reference
DESCRIPTION:
ELSE IF <expression> introduces another condition block and the unqualified ELSE in-
troduces the default condition block in a multi-line IF statement. SEE ALSO: IF,
ENDIF
EXAMPLE:
IF (N=0)
PRINT "0"
ELSE IF (N=1)
PRINT "1"
ELSE
PRINT "Out of range"
ENDIF
168
5.6 E
Command: END
Syntax: END
DESCRIPTION:
169
5 X11-Basic command reference
Command: ENDFUNCTION
Syntax: ENDFUNCTION
DESCRIPTION:
Terminates a user defined function. The Program must return with a RETURN command.
170
5.6 E
Command: ENDIF
Syntax: ENDIF
DESCRIPTION:
171
5 X11-Basic command reference
Command: ENDSELECT
Syntax: ENDSELECT
DESCRIPTION:
172
5.6 E
Command: ENV$()
Syntax: <string-result>=ENV$(<env-variable>)
DESCRIPTION:
ENV$() returns the current value of the specified "environment variable". Environment
variables are string variables maintained by the operating system. These variables typically
are used to save configuration information. Use the SETENV command to set the values of
environment variables.
EXAMPLE:
PRINT ENV$("USER")
Result: hoffmann
173
5 X11-Basic command reference
Function: EOF()
Syntax: <boolean-result>=EOF(#<dev-number>)
DESCRIPTION:
EOF() checks the end-of-file status of a file previously opened for reading by the OPEN
command. It returns -1 (TRUE) if the end of file has been reached, otherwise null (FALSE).
EXAMPLE:
OPEN "I",#1,"filename"
WHILE NOT EOF(#1)
LINEINPUT #1,a$
WEND
CLOSE #1
174
5.6 E
Operator: EQV
Syntax: <num-result>=<num-expression> EQV <num-expression>
DESCRIPTION:
The operator EQV (equivalence) produces a TRUE result only if the arguments of both are
either TRUE or both FALSE. (same as NOT(x XOR y)) and ((A IMP B) AND (B IMP A)).
table: A | B | A EQV B —–+—–+———– -1 | -1 | -1 -1 | 0 | 0 0 | -1 | 0 0 | 0 | -1
Function: EQV()
Syntax: <num-result>=EQV(<num-expression>,<num-expression>)
DESCRIPTION:
EXAMPLE:
PRINT BIN$(EQV(15,6),4)
Result: 0110
175
5 X11-Basic command reference
Command: ERASE
Syntax: ERASE <array>()[,<array>(),...℄
DESCRIPTION:
176
5.6 E
Variable: ERR
Syntax: ERR
DESCRIPTION:
177
5 X11-Basic command reference
Function: ERR$()
Syntax: <string-result>=ERR$(<error-nr)
DESCRIPTION:
Returns, as a string containing the X11-Basic error mesage which belongs to the error num-
ber.
EXAMPLE:
PRINT "X11-Basi
Error messages:"
FOR i=0 TO 255
PRINT i,ERR$(i)
NEXT i
178
5.6 E
Command: ERROR
Syntax: ERROR <error-number>
DESCRIPTION:
ERROR simulates an error, i.e., displays the message appropriate for a given error code or
calls the error handler if one was installed via the ON ERROR command. This command is
helpful in writing ON ERROR GOSUB routines that can identify errors for special treatment
and then ERROR ERR (i.e. default handling) for all others.
EXAMPLE:
> ERROR 245
Line -1: * Timeout
179
5 X11-Basic command reference
Command: EVAL
Syntax: EVAL a$
DESCRIPTION:
EXAMPLE:
b$="a=5"
a$="print a"
EVAL a$
EVAL b$
EVAL a$
180
5.6 E
Function: EVAL()
Syntax: a=EVAL(b$)
DESCRIPTION:
EXAMPLE:
b$="sin(0.5*exp(0.001))"
result=EVAL(b$)
181
5 X11-Basic command reference
Function: EVEN()
Syntax: <bool-result>=EVEN(<num-expression>)
DESCRIPTION:
182
5.6 E
Command: EVENT
Syntax: EVENT typ,[x,y,xroot,yroot,s,k,ks,t$℄
DESCRIPTION:
183
5 X11-Basic command reference
Command: EVERY
Syntax: EVERY <se
onds> GOSUB <pro
edure>
EVERY CONT
EVERY STOP
DESCRIPTION:
The command EVERY causes the procedure to be called every <seconds> seconds. Using
EVERY STOP, the calling of a procedure can be prevented. With EVERY CONT this is again
allowed.
184
5.6 E
Command: EXEC
Syntax: EXEC <adr>[,<parameter-list>℄
DESCRIPTION:
Calls a machine code or C subroutine at address <adr> without return value. Optinal pa-
rameters are passed on the stack. (like in C). The default parameter-type is (4-Byte) integer. If
you want to specify other types, please use prefixes:
D: – double (8-Bytes) F: – float (4-Bytes) L: – long int
Function: EXEC()
Syntax: <int-return>=EXEC(<adr>[,<parameter-list>℄)
DESCRIPTION:
Calls a machine code or C subroutine at address <adr> and returns an integer value. Optinal
parameters are passed on the stack. (like in C). The default parameter-type is (4-Byte) integer.
If you want to specify other types, please use prefixes:
D: – double (8-Bytes) F: – float (4-Bytes) L: – long int
185
5 X11-Basic command reference
Function: EXIST()
Syntax: <bool-result>=EXIST(<filename>)
DESCRIPTION:
186
5.6 E
Command: EXIT IF
Syntax: EXIT IF <expression>
DESCRIPTION:
The innermost loop will be exited if the expression is true. WHILE, REPEAT, DO and
FOR loops can be aborted prematurely with the EXIT command. EXIT leaves the current
(innermost) loop immediately. EXIT IF leaves the current loop only if the expression after
EXIT IF is not FALSE (not null).
187
5 X11-Basic command reference
Function: EXP()
Syntax: <num-result> = EXP(<num-expression>)
DESCRIPTION:
EXP() returns the exponential value of its argument (e to the specified power).
EXAMPLE:
PRINT EXP(1)
Result: 2.718281828459
188
5.6 E
Function: EXPM1()
Syntax: <num-result> = EXPM1(<num-expression>)
DESCRIPTION:
Returns a value equivalent to ‘exp(x)-1’. It is computed in a way that is accurate even if the
value of x is near zero–a case where ‘exp(x)-1’ would be inaccurate due to subtraction of two
numbers that are nearly equal.
EXAMPLE:
PRINT EXPM1(1)
Result: 1.718281828459
189
5 X11-Basic command reference
5.7 F
190
5.7 F
Function: FACT()
Syntax: <num-result>=FACT(<num-expression>)
DESCRIPTION:
191
5 X11-Basic command reference
Variable: FALSE
Syntax: FALSE
DESCRIPTION:
Constant 0. This is simply another way of expressing the value of a condition when it is
false and is equal to zero.
192
5.7 F
Command: FFT
Syntax: FFT a(),
DESCRIPTION:
193
5 X11-Basic command reference
Command: FILESELECT
Syntax: FILESELECT <title$>,<path$>,<default$>,<string-variable>
DESCRIPTION:
Opens a fileselect box. <title$> gives a short title to be placed in the fileselect box. Such as
’Select a .DOC file to open...’.
<path$> path - if none specified then the default path is assumed. The pathname should
include a complete path specification including a drive letter (except for UNIX file system),
colon, path, and filemask. The filemask may (and usually does include wildcard characters).
<default$> contains the name of the file to apppear in the selection line. ("" for no default).
FILESELECT returns the selected filename (including path) in <string-variable>. If CAN-
CEL is selected an empty string is returned.
EXAMPLE:
FILESELECT "LOAD File",".\*.dat","input.dat",file$
194
5.7 F
Command: FILL
Syntax: FILL x,y[,b
℄
DESCRIPTION:
Fills a bordered area with a color commencing at the co-ordinates ’x,y’. If a border color
(bc) is specified, the fill stops at boundaries with this color. If no border color is given, the fill
will stop at any oter color than the one of the starting coordinate. The fill color can be chosen
with the command COLOR.
195
5 X11-Basic command reference
196
5.7 F
Function: FIX()
Syntax: <num-result>=FIX(<num-expression-x>)
DESCRIPTION:
Returns the integer of x after it has been rounded. Same as INT(x) for positive numbers
but for negative numbers INT(-1.99)=-2 AND FIX(-1.99)=1. FIX is identical to the function
TRUNC and complements FRAC.
197
5 X11-Basic command reference
Function: FLOOR()
Syntax: <num-result>=FLOOR(<num-expression-x>)
DESCRIPTION:
198
5.7 F
Command: FLUSH
Syntax: FLUSH [#<devi
e-name>℄
DESCRIPTION:
Flushes the output to the file or console. Usually a Line is printed when the newline charac-
ter is encountered. To enforce output of everything which has been printed so far use FLUSH.
199
5 X11-Basic command reference
Command: FOR
Syntax: FOR <variable> = <start-expression> TO <target-expression> [STEP <in
r
FOR <variable> = <start-expression> DOWNTO <target-expression> [STEP <
DESCRIPTION:
FOR initiates a FOR...NEXT loop with the specified <variable> initially set to <start-
expression> and incrementing in <increment> steps (default is 1). The statements between
FOR and NEXT are repeated until the variable value reaches or steps over <target-expression>.
EXAMPLE:
FOR n=2 TO 0 STEP -1
PRINT n,
NEXT n
RESULT: 2 1 0
200
5.7 F
Function: FORK()
Syntax: <int-result>=FORK()
DESCRIPTION:
FORK() creates a child process of the running task (usually the X11-Basic interpreter with
the Basic program) that differs from the parent process only in its PID and PPID, and in the
fact that resource utilizations are set to 0.
On success, the PID of the child process is returned in the parent’s thread of execution,
and a 0 is returned in the child’s thread of execution. On failure, a -1 will be returned in the
parent’s context, no child process will be created.
EXAMPLE:
a=FORK()
IF a=-1
PRINT "error"
QUIT
ELSE IF a=0
PRINT "I am
hild"
ELSE
PRINT "I am parent. My
hild is PID=";a
ENDIF
201
5 X11-Basic command reference
Function: FORM_ALERT()
Syntax: <num-result>=FORM_ALERT(<default-button>,<string$>)
DESCRIPTION:
Creates an alert box. button = number of the default button (0= none). string$ = string defin-
ing the message in the alert. Note that the square brackets are part of the string: $[$i$]$$[$Message$]$$[$
where i = the required alert symbol - see ALERT. FORM_ALERT returns the number of the
selected Button.
EXAMPLE:
~FORM_ALERT(1,"[0℄[This is my message!℄[OK℄")
202
5.7 F
Function: FORM_CENTER()
Syntax: <num-result>=FORM_CENTER(tree,x,y,w,h)
DESCRIPTION:
Centers the tree, and returns its coordinates. INPUT: tree - address of the object tree. OUT-
PUTS: x,y coordinates of top left corner w,h form width and height. returns a reserved value.
203
5 X11-Basic command reference
Function: FORM_DIAL()
Syntax: <num-result>=FORM_DIAL(flag,x1,y1,w1,h1,x2,y2,w2,h2)
DESCRIPTION:
Release (or reserve) a rectangular screen area and draw an expanding/shrinking rectangle.
Returns 0 if an error occured. flag function 0 reserve a display area. 1 draw expanding box. 2
draw shrinking box. 3 release reserved display area. x1,y1 top left corner of rectangle at min
size w1,h1 width & height " " " " " x2,y2 top left corner of rectangle at max size w2,h2 width
& height " " " " "
204
5.7 F
Function: FORM_DO()
Syntax: <num-result>=FORM_DO(tree,obj)
DESCRIPTION:
Manages an Object tree, interacts with the user until an object with EXIT or TOUCH EXIT
status is clicked on. Returns the number of the object whose clicking or double clicking caused
the function to end. If it was a double click, bit 15 will be set. tree = address of the object tree.
obj = Number of the first editable field (if there is one).
205
5 X11-Basic command reference
Function: FRAC()
Syntax: <num-result> = FRAC(<num-expression>)
DESCRIPTION:
EXAMPLE:
PRINT FRAC(-1.234)
Result: -0.234
206
5.7 F
Command: FREE
Syntax: FREE <adr>
DESCRIPTION:
207
5 X11-Basic command reference
208
5.7 F
Command: FULLW
Syntax: FULLW [[#℄n℄
DESCRIPTION:
Enlarges window ’n’ to full screen size. ’n’ is the window number.
209
5 X11-Basic command reference
Command: FUNCTION
Syntax: FUNCTION <name>[$℄[(<expression> [, ...℄)℄
DESCRIPTION:
FUNCTION starts a user-defined multi-line function that calculates and returns a value
from an optional list of parameters. The FUNCTION is called by using the function name
preceeded by a @ in an expression. The function return type can either be a numerical value
or a string. In the latter case, the function name must end with the "$" precision qualifier. A
FUNCTION returns a result with the RETURN command inside the function. In a function,
RETURN can be used several times, with IF or the like. A function cannot be terminated
without a RETURN command being before the ENDFUNC command. In a function name
ending with the $ character the function returns a string result.
All variables declared inside the FUNCTION block are global variables unless you declare
them as local with the LOCAL command. The FUNCTION name may be followed by a
list of parameter variables representing the values and variables in the calling line. Variables
in the calling line reach the FUNCTION "by-value" unless the VAR keyword is used in the
calling line. In that case, the variable is passed "by-reference" to the FUNCTION so that
the FUNCTION "gets" the variable and not only its value. Variables passed "by-reference"
can be changed by the FUNCTION. The FUNCTION block is terminated by an ENDFUNC-
TION statement which resumes execution of the calling expression. Unlike a PROCEDURE-
subroutine, a FUNCTION must return a value.
EXAMPLE:
FUNCTION theta(x,a)
if x>a
RETURN 0
else
RETURN a
endif
ENDFUNCTION
210
5.8 G
5.8 G
211
5 X11-Basic command reference
Function: GASDEV()
Syntax: <num-result>=GASDEV(<num-expression>)
DESCRIPTION:
Returns a random number which is gauss distributed. The numbers range from minus infin-
ity to infinity but values around 0 are much more likely. The argument is taken as a seed for
the random generator.
212
5.8 G
Command: GET
Syntax : GET <x1>,<y1>,<x2>,<y2>,<var$>
DESCRIPTION:
GET puts a section of the graphic window into a string variable (x1,y1 and x2,y2 are coor-
dinates of diagonally opposite corners).
213
5 X11-Basic command reference
Function: GET_COLOR()
Syntax: <num-result>=GET_COLOR(<red-value>,<green-value>,<blue-value)
DESCRIPTION:
GET_COLOR() returns acolor number for the specified color. The rgb-values range from 0
(dark) to 65535 (bright). The returned number depends on the screen depth of the X-Server.
For 8 bit a color cell is allocated or if there is no free cell, a color is chosen which is most
similar to the specified. The color numbers may be passed to the COLOR command.
EXAMPLE:
yellow=GET_COLOR(65535,65535,0)
COLOR yellow
214
5.8 G
Function: GLOB()
Syntax: <bool>=GLOB(name$,pattern$[,flags℄)
DESCRIPTION:
GLOB() checks if name$ matches the wildcard pattern pattern$ and gives -1 (TRUE), else
0 (FALSE). The kind of check can be secified with the flags parameter.
flags 0 – default, no extras 1 – name$ is treated as a filename (Chars ’/’ are not matched) 2
– Backslashes quote special characters 4 – special treatment of ’.’ 8 – just check path of file
name name$ 16 – case insensitive
EXAMPLES:
glob("ab
d","ab
?") Result: -1
glob("ab
d","*") -1
glob("ab
","ab??") 0
glob("*a[0-9℄*","sad33333") 0
215
5 X11-Basic command reference
DESCRIPTION:
GOSUB initiates a jump to the preocedure specified after GOSUB. The code reached that
way must end with a RETURN statement which returns control to the calling line.
A procedure name can begin with a digit and contain letters, numbers, dots and the underline
dash. <parameterlist> contains expressions which are passed by value to local variables to the
procedure. It is possible to call further procedures whilst in a procedure. It is even possible to
call the procedure one is in at the time (recursive call).
EXAMPLES:
GOSUB testpro
al
va
(12,s,4,t$)
216
5.8 G
Command: GOTO
Syntax: GOTO <label-name>
DESCRIPTION:
Allows an unconditional jump to a label. A label must be defined at the beginning of a line
and must end in a colon.
EXAMPLE:
GOTO here
PRINT "never"
here:
PRINT "ever"
217
5 X11-Basic command reference
Command: GPRINT
Syntax: GPRINT [[AT(),TAB(),SPC()℄a$b|const|USING|...;’,]|
DESCRIPTION:
The GPRINT-statement writes all its arguments to the graphic window. It uses the same
sytax as PRINT. Unlike PRINT thoe output goes to the graphic window.
218
5.8 G
Command: GRAPHMODE
Syntax: GRAPHMODE <n>
DESCRIPTION:
219
5 X11-Basic command reference
Function: GRAY()
Syntax: <num-result>=GRAY(<num-expression>)
DESCRIPTION:
This function calculates the Gray-code of a given positive integer number. If the number is
negative, the inverse Graycode is calculated.
EXAMPLE:
PRINT GRAY(34)
Result: 51
220
5.9 H
5.9 H
221
5 X11-Basic command reference
Command: HELP
Syntax: HELP <string-pattern>
DESCRIPTION:
EXAMPLE:
HELP CL*
Result:
CLEAR [,...℄
CLEARW [,i%℄
CLOSE [,...℄
CLOSEW [,i%℄
CLR [,...℄
CLS
222
5.9 H
Function: HEX$()
Syntax: <string-result>=HEX$(<x>[,<n>℄)
DESCRIPTION:
Changes the value of <x> into a string expression which contains the value in hexadecimal
form. The optional parameter <n> specifies the number of characters to be used.
223
5 X11-Basic command reference
Command: HIDEM
Syntax: HIDEM
DESCRIPTION:
224
5.9 H
Command: HOME
Syntax: HOME
DESCRIPTION:
225
5 X11-Basic command reference
Command: HTAB
Syntax: HTAB <num-expression>
DESCRIPTION:
226
5.9 H
Function: HYPOT()
Syntax: <num-result>=HYPOT(<num-expression:x>,<num-expression:y>)
DESCRIPTION:
The hypot() function returns the sqrt(x*x+y*y). This is the length of the hypotenuse of a
right-angle triangle with sides of length x and y, or the distance of the point (x,y) from the
origin.
EXAMPLE:
PRINT HYPOT(3,4) Result: 5
227
5 X11-Basic command reference
5.10 I
228
5.10 I
Command: IF
Syntax: IF <
ondition> [... ELSE [IF <expression> ...℄ ... ENDIF
DESCRIPTION:
Divides a program up into different blocks depending on how it relates to the ’condition’.
229
5 X11-Basic command reference
Operator: IMP
Syntax: <num-result>=<num-expression> IMP <num-expression>
DESCRIPTION:
The operator IMP (implication) corresponds to a logical consequence. The result is FALSE
if a FALSE expression follows a TRUE one. The sequence of the argument is important.
Table: A | B | A IMP B —–+—–+———– -1 | -1 | -1 -1 | 0 | 0 0 | -1 | -1 0 | 0 | -1
Function: IMP()
Syntax: <num-result>=IMP(<num-expression>,<num-expression>)
DESCRIPTION:
EXAMPLE:
PRINT BIN$(IMP(13,14),4)
Result: 1110
230
5.10 I
Command: INC
Syntax: INC <num-variable>
DESCRIPTION:
INC increments a (numeric) variable. This command is considerably faster then the equiv-
alent statement "<variable> = <variable> + 1".
231
5 X11-Basic command reference
Command: INFOW
Syntax: INFOW [<window-nr>℄,<string-expression>
DESCRIPTION:
Links the (new) information string to the window with the number. On UNIX this Informa-
tion will be displayed in ICONIFIED state of the window.
232
5.10 I
Variable: INKEY$
Syntax: <string-result>=INKEY$
DESCRIPTION:
Returns a string containing the ASCII characters of all keys which have been pressed on the
keyboard.
EXAMPLE:
REPEAT ! Wait until a
UNTIL LEN(INKEY$) ! Key was pressed
233
5 X11-Basic command reference
Function: INLINE$()
Syntax: <string-result>=INLINE$(<string-expression>)
DESCRIPTION:
7Bit-ASCII to Binary conversion. This command basically does a RADIX conversion (from
64 to 256) on the contents of the string. This is intended to be used to include binary data into
the source code of a basic program.
The inverse coding (from binary to 7 bit ASCII) is done by the program inline.bas which
comes with X11-Basic.
EXAMPLE:
sym$=INLINE$("$$$$$$$$0$&T
_>$QL&ZD3
K℄UD<*%D$$$$$$$$$") ! Train
PUT_BITMAP sym$,92,92,16,16
234
5.10 I
DESCRIPTION:
Reads one byte from a file previously opened with OPEN (nr>0) or from the standart files
(-1=stderr, -2=stdin, -4=stdout). INP&() reads a word (2 Bytes) and INP%() reads a long word
(4 bytes).
EXAMPLE:
~INP(-2) ! Waits for a key beeing pressed
PRINT INP%(#1) ! reads a long from a previously opened file
235
5 X11-Basic command reference
Function: INP?()
Syntax: <bool-result>=INP?(<
hannel-nr>)
DESCRIPTION:
Determine the input status of the device. TRUE(-1) is device is ready (chars can be read)
ortherwise FALSE(0).
236
5.10 I
Function: INV()
Syntax: b()=INV(a())
DESCRIPTION:
Calculate the inverse of a square matrix a(). The calculation is done using the singular value
decomposition. If the matrix is singular the algorithm tells you how many singular values are
zero or close to zero.
237
5 X11-Basic command reference
Command: INPUT
Syntax: INPUT [#<devi
e-number>℄<prompt-expression>], <variable> [, ...]|
DESCRIPTION:
INPUT gets comma-delimited input from the standart input or from a previously opened file
as specified by <device-number> (use the LINE INPUT function do read complete lines from
a file and BLOAD to load complete files). Any input is assigned to the variable(s) specified. If
input is expected from a console window, then <prompt-expression> is printed to the console
window to request input from the user.
EXAMPLE:
INPUT #1,a$
INPUT "Enter your name:",a$
238
5.10 I
Function: INPUT$()
Syntax: <string-result>=INPUT$(#<nr>,<len>)
<string-result>=INPUT$(<len>)
DESCRIPTION:
Reads <len> characters from the keyboard and assigns them to a string. Optionally, if the
device-number is specified, the characters are read in from a previously OPENed channel
<nr>.
239
5 X11-Basic command reference
Function: INSTR()
Syntax: <num-result>=INSTR(<a$>,<b$>[,<n>℄)
DESCRIPTION:
Searches to see if b$ is present in a$ and returns its position. <n> is a numeric expression
indicating the position in a$ at which the search is to begin (default=1). If <n> is not given
the search begins at the first character of a$. If b$ is found in a$ the start position is returned,
otherwise 0.
240
5.10 I
Function: INT()
Syntax: <num-result> = INT(<num-expression>)
DESCRIPTION:
INT() returns the largest integer number smaller than or equal to its argument.
EXAMPLE:
PRINT INT(1.4), INT(-1.7)
Result: 1, -2
241
5 X11-Basic command reference
Function: IOCTL()
Syntax: <num-result> = IOCTL(#n,d%[,adr%℄)
DESCRIPTION:
IOCTL() manipulates the underlying device parameters of special files. In particular, many
operating characteristics of character special files (e.g. terminals) may be controlled with ioctl
requests. The argument #n must refer to an open file.
The second argument is a device-dependent request code. The third argument is an untyped
pointer to memory.
An ioctl request has encoded in it whether the argument is an in param- eter or out parameter,
and the size of the argument adr% refers to in bytes.
Usually, on success zero is returned. A few ioctls use the return value as an output pa-
rameter and return a nonnegative value on success. On error, -1 is returned, and errno is set
appropriately.
EXAMPLE:
OPEN "U",#1,"/dev/
onsole"
frequen
y=300
tone=1190000/frequen
y
KIOCSOUND=19247
PRINT io
tl(#1,KIOCSOUND,tone) ! Sounds the speaker
CLOSE #1
Result: 0
242
5.11 J
5.11 J
243
5 X11-Basic command reference
Function: JULDATE$()
Syntax: d$=juldate$(a)
DESCRIPTION:
Returns the date as string (see DATE$) given by the julian day number a.
244
5.11 J
Function: JULIAN()
Syntax: a=JULIAN(date$)
DESCRIPTION:
Returns the julian date corresponding to the date given as a string in standart format. The
number which is returned is an integer number and has the unit days.
EXAMPLE:
PRINT "Number of days sin
e Sept. 11 2001: ";julian(date$)-julian("11.09.2001")
245
5 X11-Basic command reference
5.12 K
246
5.12 K
Command: KEYEVENT
Syntax: KEYEVENT k
,ks[,t$,k,x,y,xroot,yroot℄
DESCRIPTION:
Waits until Key is pressed. (graphic window) After the key event has occured, the variables
have following meaning:
kc – Key-code ks – state of Shift/Control/Alt etc. t$ – correspondig character x – x coor-
dinate of mouse pointer relative to window y – y coordinate xroot – x coordinate of mouse
pointer relative to screen yroot – y coordinate k – mouse button state
247
5 X11-Basic command reference
5.13 L
248
5.13 L
Function: LEFT$()
Syntax: <string-result> = LEFT$(<string-expression> [,<
hara
ters>℄)
DESCRIPTION:
LEFT$() returns the specified number of characters from its argument, beginning at its left
side. If the number of <characters> is not specified then LEFT$() returns only the leftmost
character.
EXAMPLE:
PRINT LEFT$("Hello",1)
Result: H
249
5 X11-Basic command reference
Function: LEN()
Syntax: l=LEN(t$)
DESCRIPTION:
EXAMPLE:
PRINT LEN("Hello")
Result: 5
250
5.13 L
Command: LET
Syntax: LET <variable> = <expression>
DESCRIPTION:
LET assigns the value of <expression> to <variable>. The interpreter also supports implicit
assignments, ie. the LET keyword before an assignment may be omitted. This works because
the first equal sign is regarded as assignment operator.
EXAMPLE:
LET N=1
251
5 X11-Basic command reference
Command: LINE
Syntax: LINE <x1>,<y1>,<x2>,<y2>
DESCRIPTION:
252
5.13 L
Command: LINEINPUT
Syntax: LINEINPUT [[#℄<devi
e-number>,℄ <string-variable>
DESCRIPTION:
LINE INPUT reads an entire line from atandart input or from a previously opened file
as specified by <device-number> (to load a complete file, use BLOAD). Unlike the regular
INPUT command, LINEINPUT does not stop at delimiters (commas).
253
5 X11-Basic command reference
Command: LINK
Syntax: LINK #<devi
e-nr>,<string-expression:name>
DESCRIPTION:
LINK linkes a shared object file/library (*.so in /var/lib) dynamically. It will from now on
be addressed via the device-nr.
The adresses of he symbols of that library can be read with the SYM_ADR() function.
If the Library is not used any more it can be unlinked with the UNLINK command.
254
5.13 L
Command: LIST
Syntax: LIST [<line-number>[,<line-number>℄
DESCRIPTION:
LIST displays the source code or a code segment. Note that the line number of the first line
in a file is 1, that the second line is line 2 etc.
EXAMPLE:
LIST
LIST 1-10
LIST 5
255
5 X11-Basic command reference
Command: LOAD
Syntax: LOAD <string-expression:name>
DESCRIPTION:
EXAMPLE:
LOAD "testme.bas"
256
5.13 L
Function: LOC()
Syntax: <int-result>=LOC(#<devi
e-nre>)
DESCRIPTION:
Returns the location of the file pointer for the file with the device number. The location is
given in number of bytes from the start of the file.
257
5 X11-Basic command reference
Command: LOCAL
Syntax: LOCAL <var>[,<var>,...℄
DESCRIPTION:
EXAMPLE:
LOCAL a,b$,s()
258
5.13 L
Command: LOCATE
Syntax: LOCATE <row>,<
olumn>
DESCRIPTION:
259
5 X11-Basic command reference
Function: LOF()
Syntax: <int-result>=LOF(#<devi
e-nre>)
DESCRIPTION:
260
5.13 L
DESCRIPTION:
Returns the natural logarithm (log, ln) or the logarithm base 10 (log10).
261
5 X11-Basic command reference
Function: LOGB()
Syntax: <int-result>=LOGB(<num-expression>)
DESCRIPTION:
262
5.13 L
Function: LOG1P()
Syntax: <num-result>=LOG1P(<num-expression>)
DESCRIPTION:
Returns a value equivalent to log(1+x). It is computed in a way that is accurate even if the
value of x is near zero.
263
5 X11-Basic command reference
Command: LOOP
Syntax: LOOP
DESCRIPTION:
LOOP terminates a DO loop and can be used as unqualified loop terminator (such a loop
can only be aborted with the EXIT command). Execution continues with the DO line.
264
5.13 L
Function: LPEEK()
Syntax: <int-result>=LPEEK(<num-expression>)
DESCRIPTION:
265
5 X11-Basic command reference
Command: LPOKE
Syntax: LPOKE <adr>,<num-expression>
DESCRIPTION:
266
5.13 L
LSET t$=a$
267
5 X11-Basic command reference
Command: LTEXT
Syntax: LTEXT x,y,t$
DESCRIPTION:
Draws a Text at position x,y. The LTEXT command uses a Linegraphic-Text, which allows
the user to draw very large Fonts and be independant of the system fonts. The Font Style can
be influenced with the DEFLINE and the DEFTEXT command.
268
5.14 M
5.14 M
269
5 X11-Basic command reference
Function: MALLOC()
Syntax: <int-result:adr>=MALLOC(<num-expression:size>)
DESCRIPTION:
Allocates size bytes and returns a pointer to the allocated memory. The memory is not
cleared.
270
5.14 M
Function: MAX()
Syntax: m=MAX(a,b[,
,...℄)
m=MAX(f())
DESCRIPTION:
Returns the largest value out of the list of arguments or the largest value of an array.
271
5 X11-Basic command reference
Command: MENU
Syntax: MENU
DESCRIPTION:
Performs menu check and action. This command handles EVENTs. Prior to use, the re-
quired action should be specified with a MENUDEF command. For constant supervision of
events, MENU is usually found in a loop.
EXAMPLE:
MENUDEF field$(),menua
tion
DO
pause 0.05
MENU
LOOP
PROCEDURE menua
tion(k)
...
RETURN
272
5.14 M
Command: MENUDEF
Syntax: MENUDEF array$(),<pro
name>
DESCRIPTION:
This command reads text for menu-header from array\$() the string-array contains the
text for menu-titles and menu-entrys
- end of row: empty string "" - end of menu-text: empty string ""
<pro
name> The procedure to which control will be passed on selection of a menu entry is
determined.
<pro
name> is a procedure with one parameter which is the number of the selected item to
call when item was selected.
EXAMPLE:
field$()=["INFO"," Menutest ","","FILE"," new"," open ..."," save","\
save as ...","--------------"," print","--------------"," Quit","",""℄
MENUDEF field$(),menua
tion
DO
pause 0.05
MENU
LOOP
PROCEDURE menua
tion(k)
PRINT "MENU sele
ted ";k;"
ontents: ";field$(k)
IF field$(k)=" Quit"
QUIT
ENDIF
RETURN
273
5 X11-Basic command reference
Command: MENUSET
Syntax: MENUSET n,x
DESCRIPTION:
274
5.14 M
Command: MENUKILL
Syntax: MENUKILL
DESCRIPTION:
Erases the menu, which prior has been defined with MENUDEF.
275
5 X11-Basic command reference
Command: MERGE
Syntax: MERGE <filename>
DESCRIPTION:
MERGE appends a BASIC program to the program currently in memory. Program execu-
tion is not interrupted. This command typically is used to append often-used subroutines at
run-time.
EXAMPLE:
MERGE "examples/hello.basi
"
276
5.14 M
Function: MID$()
Syntax: m$=MID$(t$,s[,l℄)
DESCRIPTION:
277
5 X11-Basic command reference
Function: MIN()
Syntax: m=MIN(a,b[,
,...℄)
m=MIN(f())
DESCRIPTION:
Returns the smallest value out of the list of arguments or the smallest value of an array.
278
5.14 M
DESCRIPTION:
279
5 X11-Basic command reference
Operator: MOD
Syntax: <num-result>=<num-expression:x> MOD <num-expression:y>
DESCRIPTION:
Function: MOD()
Syntax: <num-result>=MOD(<num-expression:x>,<num-expression:y>)
DESCRIPTION:
280
5.14 M
Command: MOUSE
Syntax: MOUSE x,y,k
DESCRIPTION:
Determines the mouse position (x,y) relative to the origin of the graphics window and the
status of the mouse buttons (k). k=0 no buttons pressed
k=1 left button
k=2 middle button
k=4 right buttons
or any combinations.
281
5 X11-Basic command reference
Command: MOUSEEVENT
Syntax: MOUSEEVENT x,[y,k,xroot,yroot,s℄
DESCRIPTION:
Waits until a mouse button is pressed (graphic window). Returns Mouse coorinate (x,y)
relative to window, mouse coorinate (xroot,yroot) relative to screen, mouse button and state of
the Alt/Shift/Caps keys.
282
5.14 M
DESCRIPTION:
Determines the mouse position (x,y), the status of the mouse buttons (k) and the status of
the Shift and Control keys (s): k=0 no buttons pressed
k=1 left button
k=2 middle button
k=4 right buttons
or any combinations.
s=0 no Keys
s=1 Shift
s=2 CapsLock
s=4 Control
s=8 Alt
s=16 NumLock
s=64 Windows-Key
s=128 ScrollLock
or any combination.
283
5 X11-Basic command reference
Command: MOTIONEVENT
Syntax: MOTIONEVENT x,y,xrrot,yroot,s
DESCRIPTION:
Waits until the mouse has been moved. (graphic window). Returns new mouse coorinate
(x,y) relative to window, mouse coorinate (xroot,yroot) relative to screen and state of the
Alt/Shift/Caps keys.
284
5.14 M
Command: MOVEW
Syntax: MOVEW n,x,y
DESCRIPTION:
285
5 X11-Basic command reference
Function: MTFD$()
Syntax: b$=MTFD$(a$)
DESCRIPTION:
This function performs a Move To Front decoding function on an input string. The MTF
decoder keeps an array of 256 characters in the order that they have appeared. Each time
the encoder sends a number, the decoder uses it to look up a character in the corresponding
position of the array, and outputs it. That character is then moved up to position 0 in the array,
and all the in-between characters are moved down a spot.
286
5.14 M
Function: MTFE$()
Syntax: b$=MTFE$(a$)
DESCRIPTION:
This function performs a Move To Front encoding function on an input string. An MTF
encoder encodes each character using the count of distinct previous characters seen since the
characters last appearance. This is implemented by keeping an array of characters. Each new
input character is encoded with its current position in the array. The character is then moved
to position 0 in the array, and all the higher order characters are moved down by one position
to make roon.
287
5 X11-Basic command reference
Command: MUL
Syntax: MUL <num-var>,<num-expression>
DESCRIPTION:
Function: MUL()
Syntax: <num-result>=MUL(<num-expression>,<num-expression>)
DESCRIPTION:
288
5.15 N
5.15 N
289
5 X11-Basic command reference
Command: NEW
Syntax: NEW
DESCRIPTION:
NEW erases the program and all variables in memory (and stops execution of program.)
290
5.15 N
Command: NEXT
Syntax: NEXT [<variable>℄
DESCRIPTION:
NEXT terminates a FOR loop. FOR loops must be nested correctly: The variable name after
NEXT is for looks only and can not be used to select a FOR statement. Each NEXT jumps to
the matching FOR statement regardless if and what <variable> is specified after NEXT.
EXAMPLE:
FOR n=1 TO 2
FOR m=10 to 11
PRINT "n=";n,"m=";m
NEXT m
NEXT n
291
5 X11-Basic command reference
DESCRIPTION:
No Operation: do nothing.
292
5.16 O
5.16 O
293
5 X11-Basic command reference
Command: OBJC_ADD
Syntax: OBJC_ADD tree,parent,
hild
DESCRIPTION:
Adds an object to a given tree and pointers between the existing objects and the new object
are created. tree address of the object tree parent object number of the parent object child
object number of the child to be added.
294
5.16 O
Command: OBJC_DELETE
Syntax: OBJC_DELETE tree,obje
t
DESCRIPTION:
An object is deleted from an object tree by removing the pointers. The object is still there
and can be restored by repairing the pointers.
tree address of the object tree object Object number of the object to delete.
295
5 X11-Basic command reference
Function: OBJC_DRAW()
Syntax: ret=obj
_draw(tree,startob,depth,
x,
y,
w,
h)
DESCRIPTION:
296
5.16 O
Function: OBJC_FIND()
Syntax: idx=obj
_find(tree,startob,depth,x,y)
DESCRIPTION:
Finds an object under a specific screen coordinate. (These may be the mouse coordinates.)
The application supplies a pointer to the object tree, the index to the start object to search
from, the x- and y-coordinates of the mouse’s position, as well as a parameter that tells
OBJC_FIND how far downthe tree to search (depth).
This Fucntion returns the index of the found Object or -1 in case no object could be found.
297
5 X11-Basic command reference
Function: OBJC_OFFSET()
Syntax: ret=obj
_offset(tree,obj,x,y)
DESCRIPTION:
Calculates the absolute screen coordinates of the specified object in a specified tree. Returns
0 on error. tree address of the object tree obj object number x,y returns the x,y coordinates to
these variables.
298
5.16 O
299
5 X11-Basic command reference
Command: ON BREAK
Syntax: ON BREAK CONT
ON BREAK GOSUB <pro
edure>
ON BREAK GOTO <label>
DESCRIPTION:
ON BREAK installs a subroutine that gets called when the BREAK condition (normally
CTRL-c) occurs. ON BREAK CONT causes the program to continue in any case. ON
BREAK GOTO jumps to a specified label.
300
5.16 O
Command: ON ERROR
Syntax: ON ERROR CONT
ON ERROR GOSUB <pro
edure>
ON ERROR GOTO <label>
DESCRIPTION:
ON ERROR installs an error handling subroutine that gets called when the next error occurs.
ON ERROR CONT will ignore any error.
301
5 X11-Basic command reference
Command: OPEN
Syntax: OPEN <mode>,<devi
e-number>,<filename>[,<port-value>℄
DESCRIPTION:
OPEN opens the specified file for reading or writing or both. The <device-number> is the
number you want to assign to the file (functions that read from files or write to files expect to
be given this number). The device number must be between 0 and 99 in the current imple-
mentation of X11-Basic. When you close a file, the device number is released and can be used
again in subsequent OPEN statements.
<mode> is a character string which indicates the way the File should be opened. The first
character of that String may be "O", "I", "U" or "A". These characters correspont to the
mode for which the file is opened: "I" – INPUT, "O" –OUTPUT, "A" – APPEND and "U" –
UNSPECIFIED. Open a file for INPUT if you want to read data from the file. If you open
a file for OUTPUT, you can write to the file. However, all data that was stored in the file
(if the file already exists) is lost. If you want to write new data to a file while keeping the
existing content, open the file for appending to it, using the APPEND mode. When you open
a file using the RANDOM ("U") keyword, you can both read from the file and write to the
file at arbitrary positions. You can, for example, seek a position in the middle of the file and
start appending new lines of text. All file modes but INPUT create the file if it does not exist.
OPEN "I" fails if the file does not exist (use the EXIST() function before OPEN to be sure that
the file exists).
The second character specifies the type of File which should be opened or created: "" default
opens regular file "U" opens a datagramm socket connection "C" opens a Strem socket as client
with connection "S" opens a stream socket as server "A" Socket accept connection "X" extra
settings for a special device following: (e.g. speed and parity of transmission via serial ports)
"UX:baud,parity,bits,stopbits,flow"
<port-nr> The portnr is used only by the OPEN "UC" and OPEN "UU" statement. It deter-
mines the TCP/IP Port of connection (FTP, WWW, TELNET, MAIL etc.).
SEE ALSO: CLOSE, EXIST(), INPUT, LINEINPUT, PRINT, SEEK, LOF(), EOF(),
LOC(), BLOAD, LINK, FREEFILE(), CONNECT
EXAMPLES:
OPEN "I",#1,"data.dat" ---- opens file "data.dat" for input
OPEN "UC",#1,"lo
alhost",80 ---- opens port 80 of lo
alhost for read and#
302
5.16 O
write
OPEN "UX:9600,N,8,1,XON,CTS,DTR",#1,"/dev/ttyS1"
---- open COM2 for input and output with 9600:8:N:1 with
software flow
ontrol and hardware flow
ontrol and also
drop DTR line and raise it again.
303
5 X11-Basic command reference
Command: OPENW
Syntax: OPENW n
DESCRIPTION:
Opens a graphic window. There can be up to 16 graphic windows opened. All graphic
output goes to the window which was opened latest. OPENW can be used to switch between
multiple windows. Window 1 os opened automatically on default when the first graphic com-
mand is executed and no other window is already opened.
304
5.16 O
Command: OUT
Syntax: OUT #n,a
DESCRIPTION:
305
5 X11-Basic command reference
5.17 P
306
5.17 P
Command: PAUSE
Syntax: PAUSE <se
>
DESCRIPTION:
pauses <sec> seconds. The resolution of this command is microseconds (in theory).
307
5 X11-Basic command reference
Command: PBOX
Syntax: PBOX x1,y1,x2,y2
DESCRIPTION:
308
5.17 P
Command: PCIRCLE
Syntax: PCIRCLE x,y,r[,a1,a2℄
DESCRIPTION:
309
5 X11-Basic command reference
Function: PEEK()
Syntax: <int-result>=PEEK(<address>)
DESCRIPTION:
PEEK() reads a byte from an address in memory. The following example dumps a section
of the internal memory near a string t$.
EXAMPLE:
t$="Hallo, this is a string..."
i=varptr(t$)-2000
DO
PRINT "$";HEX$(i,8,8)'
FOR iu=0 TO 15
PRINT HEX$(PEEK(i+iu) and 255,2,2)'
NEXT iu
PRINT '
FOR iu=0 TO 15
a=PEEK(i+iu)
IF a>31
PRINT CHR$(a);
ELSE
PRINT ".";
ENDIF
NEXT iu
PRINT
ADD i,16
LOOP
310
5.17 P
Command: PELLIPSE
Syntax: PELLIPSE x,y,a,b[,a1,a2℄
DESCRIPTION:
311
5 X11-Basic command reference
Command: PIPE
Syntax: PIPE #n1,#n2
DESCRIPTION:
PIPE links two File channels n1 and n2 together to form a pipe. n1 is for reading, n2 is for
writing. Whatever you write to the pipe can be read from it at a different time. The content is
buffered in the kernel. The mechanism is FIFI (0 first in first out). The biggest advantage is,
that you can read and write to it from different processes (created by FORK()). This allows
inter-process communication.
312
5.17 P
Command: PLIST
Syntax: PLIST
DESCRIPTION:
Outputs a formatted listing of the actual program in memory. Alos the internal tokens are
printed ans some internal Information. This is intended for internal use only.
EXAMPLE:
> PLIST
0: $00001a | 0,0 |CLS
1: $000279 | 0,0 |PRINT
2: $000279 | 0,1 |PRINT " example how to use the ansi
olor spe
."
3: $000279 | 0,0 |PRINT
4: $000279 | 0,1 |PRINT "X 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0"
5: $310240 | 12,1 |FOR U=0 TO 3
6: $310240 | 11,1 | FOR J=0 TO 7
7: $310240 | 10,1 | FOR I=0 TO 7
8: $000279 | 0,1 | PRINT AT(J+6,2*I+2+16*U);CHR$(27)+"["+STR$(U)+";"+STR$(30+I)+";"+STR$(40+J)+
9: $320266 | 7,1 | NEXT I
10: $320266 | 6,1 | NEXT J
11: $320266 | 5,1 |NEXT U
12: $000279 | 0,0 |PRINT
13: $00047f | 0,0 |QUIT
14: $0008ff | 0,0 |=?=> 2303
313
5 X11-Basic command reference
Command: PLOT
Syntax: PLOT x,y
DESCRIPTION:
314
5.17 P
Function: POINT()
Syntax:
=POINT(x,y)
DESCRIPTION:
315
5 X11-Basic command reference
Command: POKE
Syntax: POKE adr%,byte%
DESCRIPTION:
316
5.17 P
Command: POLYLINE
Syntax: POLYLINE n,x(),y()[,x_off,y_off℄
DESCRIPTION:
POLYLINE draws a polygon with n corners. The x,y coordinates for the corner points
are given in arrays x() and y(). The optional parameters x_off,y_off can be added to these
coordinates.
To draw a closed polygon, the first point hast to be equal to the last point.
317
5 X11-Basic command reference
Command: POLYFILL
Syntax: POLYFILL n,x(),y()[,x_off,y_off℄
DESCRIPTION:
POLYFILL draws a filled polygon with n corners. The x,y coordinates for the corner points
are given in arrays x() and y(). The optional parameters x_off,y_off can be added to these
coordinates. POLYFILL fills the polygon with the color and pattern previously defined by
COLOR and DEFFILL.
318
5.17 P
Command: POLYMARK
Syntax: POLYMARK n,x(),y()[,x_off,y_off℄
DESCRIPTION:
POLYMARK marks the corner points of an invisible polygon with n corners. The x,y
coordinates for the corner points are given in arrays x() and y(). The optional parameters
x_off,y_off can be added to these coordinates.
POLYMARK marks the points with the shape defined by DEFMARK.
319
5 X11-Basic command reference
320
5.17 P
DESCRIPTION:
The print-statement writes all its arguments to the screen (standard output); after writing its
last argument, print goes to the next line (as in print "Hello ",a$," !"); to avoid this automatic
newline, place a semicolon (;) after the last argument (as in print "Please enter your Name:";).
To insert a tabulator instead of the automatic newline append a colon (,), e.g. print "Please
enter your Name:", . Note that print can be abbreviated with a single question mark (?).
Advanced printing: PRINT AT(), PRINT colour and PRINT USING
PRINT AT
For interactive programs you might want to print output at specific locations. Try the next
example: PRINT AT(4,7);"Test"
TAB and SPC PRINT "Hallo";TAB(30);"Test" PRINT "Hallo";SPC(30);"Test"
PRINT COLOR PRINT COLOR(32,2);"Hallo"
The COLOR statement takes up to three arguments. Their meaning is:
Text Mode: Text color: Backgroud color:
0 default setting 30 black 40 black 1 intensive 31 red 41 red 2 dark 32 green 42 green 33
yellow 43 yellow 4 underline 34 blue 44 blue 5 blink 35 magenta 45 magenta 36 cyan 46 cyan
7 reverse 37 white 47 white
PRINT USING
To control the way numbers are printed, use the print using statement: print 12.34 using
"###.####" produces 12.3400. The format string ("###.####") consists of hashes (#) with one
optional dot and it pictures the appearance of the number to print.
321
5 X11-Basic command reference
Command: PROCEDURE
Syntax: PROCEDURE pro
name [(p1 [,p2℄ ... )℄ * RETURN
DESCRIPTION:
322
5.17 P
Function: PTST()
Syntax:
=PTST(x,y)
DESCRIPTION:
323
5 X11-Basic command reference
PSAVE a$ – writes the reformatted BASIC-program into file with the name a$ PUT x,y,g$
– displays graphic stored in g$ at postion x,y PUTBACK $[$#n,$]$a – puts character a back
to input channel n PUT_BITMAP t$,i,i,i,i
324
5.18 Q
5.18 Q
325
5 X11-Basic command reference
Command: QUIT
Syntax: QUIT [<return-
ode>℄
DESCRIPTION:
QUIT exits the interpreter. You may set a <return-code> which will be passed to the pro-
gram running the interpreter.
326
5.19 R
5.19 R
327
5 X11-Basic command reference
Function: RANDOM()
Syntax: <num-result> = RND(<maximum>)
DESCRIPTION:
EXAMPLE:
PRINT RANDOM(10)
Result: 8
328
5.19 R
Command: RANDOMIZE
Syntax: RANDOMIZE [<seed-expression>℄
DESCRIPTION:
RANDOMIZE seeds the pseudo-random number generator to get a new sequence of num-
bers from RND(). Recommended argument to RANDOMIZE is a "random" number to ran-
domly select a sequence of pseudo-random numbers. If RANDOMIZE is not used then the
sequence of numbers returned by RND() will be identical each time the interpreter is started.
If no argument is given, the TIMER value will be used as a seed.
329
5 X11-Basic command reference
Command: RBOX
Syntax: RBOX x1,y1,x2,y2
DESCRIPTION:
Draws a rectangle with rounded corners from the two diagonally opposite corner points
’x1,y1’ and ’x2,y2’
330
5.19 R
Command: READ
Syntax: READ var[,var2, ...℄
DESCRIPTION:
Reads constant values from a DATA command and assigns them to a variable ’var’. Reading
is taken from the last point a RESTORE was done (if any).
331
5 X11-Basic command reference
Command: RELSEEK
Syntax: RELSEEK [#℄n,d
DESCRIPTION:
Place file pointer on new relative position d which means it moves the file pointer forward
(d>0) or backwards (d<0) d bytes.
332
5.19 R
DESCRIPTION:
SEE ALSO: !
333
5 X11-Basic command reference
Command: REPEAT
Syntax: REPEAT ... UNTIL <expression>
DESCRIPTION:
REPEAT initiates a REPEAT...UNTIL loop. The loop ends with UNTIL and execution
reiterates until the UNTIL <expression> is not FALSE (not null). The loop body is executed
at least once.
EXAMPLE:
REPEAT
INC n
UNTIL n=10
334
5.19 R
Function: REPLACE$()
Syntax: <string-result> = REPLACE$(<string-expression>, <sear
h string>, <repla
e stri
DESCRIPTION:
REPLACE$() returns string-expression where all <search string> have been replaced by
<replace string>.
EXAMPLE:
PRINT REPLACE$("Hello","l","w")
Result: Hewwo
335
5 X11-Basic command reference
Command: RESTORE
Syntax: RESTORE [<label>℄
DESCRIPTION:
RESTORE sets the position DATA is read from to the first DATA line of the program (or to
the first DATA line after <label> if RESTORE is used with an argument).
EXAMPLE:
READ a, b,
RESTORE
READ a, b,
DATA 1, 2, 3
336
5.19 R
Command: RESUME
Syntax: RESUME
RESUME NEXT
RESUME <label>
DESCRIPTION:
The RESUME command is especially meaningful with error capture (ON ERROR GOSUB)
where it allows a reaction to an error. Anyway, X11-Basic allows the us of RESUME <label>
everywhere in the program (instead of GOTO <label>), and can be used to jump out of a
subroutine. If you jump into another Subroutine, you must not reach its RETURN statement.
RESUME is a bad command and I dislike it very much.
RESUME repeats the erroneous command. RESUME NEXT resumes program execution
after an incorrect command. RESUME <label> branches to the <label>. If a fatal error occurs
only RESUME <label> is possible
**** RESUME is still not working. If you use ON ERROR GOSUB to a subroutine then
RESUME NEXT is the default if the subroutine reaches a RETURN. If you want to resume
somwhere else you can just GOTO out of the subroutine. This is possible, but leaves the
internal stack pointer incremented, so you should not do this too often during runtime. other-
wise there will be a stack overflow after 200 events. **** looks like this also happens with
ON ERROR GOTO. *** In future versions of X11-Basic there might be a RESUME <label>
command which properly resets the stack. If you want this to be fixed, please send me an
email with your test program.
337
5 X11-Basic command reference
Command: RETURN
Syntax: RETURN
RETURN <expression>
DESCRIPTION:
RETURN terminates a PROCEDURE reached via GOSUB and resumes execution after the
calling line. Note that code reached via ON ERROR GOSUB should be terminated with a
RESUME NEXT, not with RETURN.
RETURN <expression> states the result of the expression as a result of a user defined
function. This can not be used in PROCEDURES but in FUNCTIONS. The expression must
be of the type the function was.
EXAMPLE:
PROCEDURE testroutine
PRINT "Hello World !"
RETURN
FUNCTION givemefive
RETURN 5
ENDFUNCTION
338
5.19 R
Function: REVERSE$()
Syntax: a$=REVERSE$(t$)
DESCRIPTION:
Reverses a String.
339
5 X11-Basic command reference
Function: RINSTR()
Syntax: <int-result>=RINSTR(s1$,s2$[,n℄)
DESCRIPTION:
Operates in same way as INSTR except that search begins at the right end of s1$. tests if
s2$ is contained in s1$, then returns start-position of s2$, else 0. start comparison at pos. n
(default=1) start comparison at right
340
5.19 R
Function: RLD$()
Syntax: a$=RLD$(a$)
DESCRIPTION:
Does a run length decoding of string a$. This function reverses the Run Length Encoding
function on a string.
In the input string, any two consecutive characters with the same value flag a run. A byte
following those two characters gives the count of additional(!) repeat characters, which can
be anything from 0 to 255.
341
5 X11-Basic command reference
Function: RLE$()
Syntax: a$=RLE$(a$)
DESCRIPTION:
Does a run length encoding of string a$. This function performs a Run Length Encoding
function on a string. In the output string, any two consecutive characters with the same value
flag a run. A byte following those two characters gives the count of additional(!) repeat
characters, which can be anything from 0 to 255. The resulting String might be shorter than
the input string if there are many equal characters following each other. In the worst case the
resulting string will be 50% longer.
342
5.19 R
Function: RND()
Syntax: <num-result> = RND(<dummy>)
DESCRIPTION:
RND() returns a pseudo-random number between 0 (inclusive) and 1 (exclusive). The se-
quence of pseudo-random numbers is identical each time you start the interpreter unless the
RANDOMIZE statement is used prior to using RND(): RANDOMIZE seeds the pseudo-
random number generator to get a new sequence of numbers from RND().
EXAMPLE:
PRINT RND(1)
Result: 0.3352227557149
343
5 X11-Basic command reference
Function: ROUND()
Syntax: <num-result>=ROUND(<num-expression:b>[,n℄)
DESCRIPTION:
Rounds off a value to n fractional digits. n<0: round to digits in front of the decimal point.
344
5.19 R
345
5 X11-Basic command reference
Command: RUN
Syntax: RUN
DESCRIPTION:
346
5.20 S
5.20 S
347
5 X11-Basic command reference
Command: SAVE
Syntax: SAVE [a$℄
DESCRIPTION:
348
5.20 S
Command: SAVESCREEN
Syntax: SAVESCREEN t$
DESCRIPTION:
Saves the whole Graphic-Screen (Desktop) into a file with name t$. The Graphics format is
XWD (X-Window dump). Maybe later this will be changed to png (portable network graphic).
349
5 X11-Basic command reference
Command: SAVEWINDOW
Syntax: SAVEWINDOW t$
DESCRIPTION:
Saves the actual X11-Basic Graphic-Window into a file with name t$. The Graphics format
is XWD (X-Window dump).
350
5.20 S
Command: SCOPE
Syntax: SCOPE a(),typ,ys
ale,yoffset -- S
hnelles Plotten des Feldes a()
SCOPE y(),x(),typ,ys
ale,yoffset,xs
ale,xoffset -- 2D Plot
DESCRIPTION:
351
5 X11-Basic command reference
Command: SCREEN
Syntax: SCREEN n
DESCRIPTION:
352
5.20 S
Command: SEEK
Syntax: SEEK #n[,d℄
DESCRIPTION:
Place file pointer of channel n on new absolute position d (Default on Position 0 which is
the beginning of File.)
353
5 X11-Basic command reference
Command: SEND
Syntax: SEND #n,msg$[,adr%,port%℄
DESCRIPTION:
SEND is used to transmit a message via fast UDP datagramms to another socket which may
be on another host. Send with only two parameters may be used only when the socket is in
a connected state (see CONNECT), otherwise the destination adress and the port has to be
specified.
The address of the target is given by adr%, which usually contains a IP4 adress (e.g.
cvl(chr$(127)+chr$(0)+chr$(0)+chr$(1)) which corresponds to 127.0.0.1). msg$ can be an
arbitrary message with any data in it. The length of the message must not exceed 1500 Bytes.
If the message is too long to pass atomically through the underlying protocol, an error occurs,
and the message is not transmitted.
No indication of failure to deliver is implicit in a send.
When the message does not fit into the send buffer of the socket, send blocks. The OUT?()
function may be used to determine when it is possible to send more data.
354
5.20 S
355
5 X11-Basic command reference
Command: SETFONT
Syntax: SETFONT t$
DESCRIPTION:
Loads and sets a X11 Font. t$ may be the fontname or any valid Font pattern.
356
5.20 S
Command: SETMOUSE
Syntax: SETMOUSE x,y[,k℄
DESCRIPTION:
The SETMOUSE command permits the positioning of the mouse cursor under program
control. Tje optional parameter k can simulate the mouse button being pressed or released.
357
5 X11-Basic command reference
Command: SGET
Syntax: SGET s
reen$
DESCRIPTION:
358
5.20 S
Function: SGN()
Syntax: a=SGN(b)
DESCRIPTION:
359
5 X11-Basic command reference
Function: SHM_ATTACH()
Syntax: adr=SHM_ATTACH(id)
DESCRIPTION:
360
5.20 S
Command: SHM_DETACH
Syntax: SHM_DETACH id
DESCRIPTION:
361
5 X11-Basic command reference
Command: SHM_FREE
Syntax: SHM_FREE adr
DESCRIPTION:
362
5.20 S
Function: SHM_MALLOC()
Syntax: adr=SHM_MALLOC(a,b)
DESCRIPTION:
363
5 X11-Basic command reference
Command: SHOWPAGE
Syntax: SHOWPAGE
DESCRIPTION:
364
5.20 S
Function: SIN()
Syntax: <num-result>=SIN(<num-expression>)
DESCRIPTION:
EXAMPLE:
PRINT SIN(PI/2) Result: 1
365
5 X11-Basic command reference
Function: SINH()
Syntax: <num-result>=SINH(<num-expression>)
DESCRIPTION:
366
5.20 S
Command: SIZEW
Syntax: SIZEW nr,w,h
DESCRIPTION:
367
5 X11-Basic command reference
Command: SORT
Syntax: SORT <array-name>()[,<n>[,<2nd array>()℄℄
DESCRIPTION:
SORT sorts the one-dimensional array specified as argument. Numeric arrays and string
arrays can be sorted. If <n> is given, only the first <n> values are sorted. If <2nd array> is
given, this (numerical) array will also be sorted corresponding to the first. This is useful for
creating an index table.
368
5.20 S
Command: SOUND
Syntax: SOUND <frequen
y>
DESCRIPTION:
SOUND sounds the internal speaker with frequency $[$Hz$]$. If frequency=0 shut up
speaker.
COMMENT: The internal speaker is accessed via a console device. The sound does not
work unter xterm.
EXAMPLE:
SOUND 500
PAUSE 0.1
SOUND 0
369
5 X11-Basic command reference
Variable: SP
Syntax <int-value>=SP
DESCRIPTION:
SEE ALSO: PC
370
5.20 S
Function: SPACE$()
Syntax: t$=SPACE$(n)
DESCRIPTION:
371
5 X11-Basic command reference
Function: SOLVE()
Syntax: x()=SOLVE(m(),d())
DESCRIPTION:
Soves a set of linear equations d()=M()*x(). M() has to be a 2 dim Array not necessarily
a square matrix. d() must be a 1 dim Array with exactly as many elements as lines of M().
x() will be a 1 dim Array with exactly as many elements as rows of M(). Internally a singular
value decomposition is used to solve the equation. If singular values found to be smaller than
1e-10 of the largest value they are set to zero.
372
5.20 S
Command: SPLIT
Syntax: SPLIT t$,t$,i%,var$[,var$℄
DESCRIPTION:
Same as WORT_SEP.
373
5 X11-Basic command reference
Command: SPUT
Syntax: SPUT s
reen$
DESCRIPTION:
374
5.20 S
DESCRIPTION:
EXAMPLES:
PRINT SQR(25)
Result: 5
PRINT "Cal
ulate square root of a number."
INPUT "Number=",z
r124=1
105:
r123=r124
r124=(r123^2+z)/(2*r123)
IF ABS(r124-r123)-0.00001>0
PRINT r124
GOTO 105
ENDIF
PRINT "Result of this algorithm:"'r124
PRINT "Compare with: sqrt(";z;")=";SQRT(z)
PRINT "Deviation:"'ABS(SQRT(z)-r124)
375
5 X11-Basic command reference
Function: SRAND()
Syntax: VOID SRAND(b)
DESCRIPTION:
The SRAND() function sets its argument as the seed for a new sequence of pseudo-random
integers to be returned by RAND(), RANDOM() or RND(). These sequences are repeatable
by calling SRAND() with the same seed value.
376
5.20 S
Variable: STIMER
Syntax: <int-result>=STIMER
DESCRIPTION:
377
5 X11-Basic command reference
Command: STOP
Syntax: STOP
DESCRIPTION:
STOP halts program execution and sets the interpreter to interactive mode. The execution
can be continued with the CONT command.
378
5.20 S
379
5 X11-Basic command reference
Function: SWAP()
Syntax: <num-result>=SWAP(<num-expression:b>)
DESCRIPTION:
380
5.20 S
Function: SYM_ADR()
Syntax: adr=SYM_ADR(#n,sym_name$)
DESCRIPTION:
SYM_ADR() resolves the adress of a symbol name of a given shared object library which
has been linked before.
EXAMPLE:
t$="/usr/lib/libreadline.so" ! If the readline shared obje
t file
IF EXIST(t$) ! exist,
LINK #1,t$ ! link it, resolve the symbol "readline"
DUMP "#" ! and exe
ute that subroutine with
promt$=">>>" ! one string parameter.
adr=EXEC(SYM_ADR(#1,"readline"),L:VARPTR(promt$))
r=adr
WHILE PEEK(r)>0 ! Print the result
PRINT CHR$(PEEK(r));
INC r
wend
PRINT
UNLINK #1 ! Unlink the dynami
lib
FREE adr
ENDIF
381
5 X11-Basic command reference
Command: SYSTEM
Syntax: SYSTEM <string-expression>
DESCRIPTION:
Passes a command to the shell. Executes shell command. This command provides a way to
use alle commands like rm, rmdir, mkdir etc. which are not implemented in X11-Basic.
EXAMPLE:
SYSTEM "mkdir folder"
382
5.20 S
Function: SYSTEM$()
Syntax: <string-result>=SYSTEM$(<string-expression>)
DESCRIPTION:
Passes a command to the shell. Executes shell command. The function returns a string
containing the stdout of the command executed.
EXAMPLE:
d$=SYSTEM$("ls")
PRINT d$
383
5 X11-Basic command reference
5.21 T
384
5.21 T
Function: TERMINALNAME$()
Syntax: t$=TERMINALNAME$(#n)
DESCRIPTION:
385
5 X11-Basic command reference
Command: TEXT
Syntax: TEXT x,y,t$
DESCRIPTION:
EXAMPLE:
' Show the
omplete ASCII Font
SETFONT "*writer*18*"
COLOR GET_COLOR(65535,10000,10000)
FOR x=0 to 15
FOR y=0 to 15
TEXT 320+16*y,20+24*x,CHR$(y+16*x)
NEXT y
NEXT x
SHOWPAGE
386
5.21 T
Variable: TIMER
Syntax: TIMER
DESCRIPTION:
387
5 X11-Basic command reference
Command: TITLEW
Syntax: TITLEW n,title$
DESCRIPTION:
388
5.21 T
Command: TOPW
Syntax: TOPW [n℄
DESCRIPTION:
Activates the windows number n and moves it to the top of the window stack.
389
5 X11-Basic command reference
Command: TROFF
Syntax: TROFF
DESCRIPTION:
TROFF disables tracing output. This command is meant to be used during program devel-
opment.
390
5.21 T
Command: TRON
Syntax: TRON
DESCRIPTION:
TRON enables tracing output: each program line is displayed on the console before it is
executed. This command is meant to be used during program development.
391
5 X11-Basic command reference
5.22 U
392
5.22 U
Function: UCASE$()
Syntax: <string-result>=UCASE$(<string-expression>)
DESCRIPTION:
Transforms all lower case letters of a string to upper case. Any non letter characters are left
unchanged.
393
5 X11-Basic command reference
Variable: UNCOMPRESS$()
Syntax: t$=UNCOMPRESS$(
$)
DESCRIPTION:
Uncompresses the content of a string which has been compressed with the COMPRESS$()
function before.
394
5.22 U
Variable: UNIX?
Syntax: <bool-result>=UNIX?
DESCRIPTION:
395
5 X11-Basic command reference
DESCRIPTION:
These functions return the date and time as a string which has the same format as DATE$
and TIME$ given by a TIMER value.
EXAMPLE:
PRINT UNIXDATE$(1045390004.431), UNIXTIME$(1045390004.431)
Result: 16.02.2003 11:06:44
396
5.22 U
Command: UNLINK
Syntax: UNLINK #n
DESCRIPTION:
unlinks shared object file which has been linked before and occupies channel nr #n.
397
5 X11-Basic command reference
Command: UNTIL
Syntax: UNTIL <expression>
DESCRIPTION:
EXAMPLE:
REPEAT
N=N+1
UNTIL (N=10)
398
5.22 U
Function: UPPER$()
Syntax: <string-result>=UPPER$(<string-expression>)
DESCRIPTION:
Transforms all lower case letters of a string to upper case. Any non letter characters are left
unchanged.
399
5 X11-Basic command reference
5.23 V
400
5.23 V
Function: VAL()
Syntax: <num-result> = VAL(<string-expression>)
DESCRIPTION:
EXAMPLE:
a=VAL("3.1415926")
401
5 X11-Basic command reference
Function: VAL?()
Syntax: a=val?(t$)
DESCRIPTION:
EXAMPLE:
print val?("12345.67e12Hallo") Result: 11
402
5.23 V
Function: VARPTR()
Syntax: <adr>=VARPTR(<variable>)
DESCRIPTION:
Determines the address of a variable and returns a pointer. VARPTR() can also be used to
determin the adress of an array index.
EXAMPLE:
PRINT VARPTR(t$), VARPTR(a(2,4))
403
5 X11-Basic command reference
Command: VERSION
Syntax: VERSION
DESCRIPTION:
EXAMPLE:
VERSION
Result: X11-BASIC Version: 1.08 vom Sat Feb 15 12:00:38 CET 2003
404
5.23 V
DESCRIPTION:
This command performs a calculation and forgets the result. Sounds silly but there are
occasions when this command is required, eg. when you want to execute a function but you
are not really interested in the return value. e.g. waiting for a keystroke (inp(-2)).
EXAMPLE:
~INP(-2)
VOID FORM_ALERT(1,"[1℄[Hello℄[OK℄")
405
5 X11-Basic command reference
Command: VSYNC
Syntax: VSYNC
DESCRIPTION:
Enables synchronization with the screen. Actually this is a synonyme for SHOWPAGE.
Graphic output will not be shown in the window until SHOWPAGE (or VSYNC).
406
5.24 W
5.24 W
407
5 X11-Basic command reference
Command: WHILE
Syntax: WHILE <num-expression>
DESCRIPTION:
WHILE initiates a WHILE...WEND loop. The loop ends with WEND and execution reiter-
ates while the WHILE <num-expression> is not FALSE (not null). Unlike a REPEAT...UNTIL
loop, the loop body is not necessarily executed at least once.
EXAMPLE:
WHILE NOT EOF(#1)
LINEINPUT #1,a$
WEND
408
5.24 W
Command: WEND
Syntax: WEND
DESCRIPTION:
EXAMPLE:
WHILE NOT EOF(#1)
LINEINPUT #1,a$
WEND
409
5 X11-Basic command reference
Function: WORD()
Syntax: a=WORD(b)
DESCRIPTION:
410
5.24 W
Command: WORT_SEP
Syntax: WORT_SEP t$,d$,mode,a$,b$
DESCRIPTION:
Splits up string t$ into two parts a$ and b$ concerning a delimiter string d$. So that
t$=a$+d$+b$. mode can be: 0 – default 1 – do not serch parts of t$ which are in brackets.
Quoted parts of the string are not spit up.
EXAMPLE:
WORT_SEP "Hallo, this is a string."," ",0,a$,b$
411
5 X11-Basic command reference
Function: WORT_SEP()
Syntax: <num-result>=WORT_SEP(t$,d$,mode,a$,b$)
DESCRIPTION:
Splits up string t$ into two parts a$ and b$ concerning a delimiter string d$. So that
t$=a$+d$+b$. mode can be: 0 – default 1 – do not serch parts of t$ which are in brackets.
Quoted parts of the string are not spit up.
The return value can be: 2 – The string has been split up. 1 – The string did not contain d$,
a$=t$, b$="" 0 – The string was empty. a$="",b$=""
412
5.25 X
5.25 X
413
5 X11-Basic command reference
Command: XLOAD
Syntax: XLOAD
DESCRIPTION:
Opens a fileselector where the user can select a basic source file which then will be load
into memory.
414
5.25 X
Operator: XOR
Syntax: <num-expression1> XOR <num-expression2>
DESCRIPTION:
Logical exclusive OR operator. XOR returns fale (0) if both arguments have the same
logical value.
A & B & A XOR B
-1 & -1 & 0
Table: -1 & 0 & -1
0 & -1 & -1
0&0&0
EXAMPLE:
Print 3=3 XOR 4>2 Result: 0 (flase)
Print 3>3 XOR 5>3 Result: -1 (true)
PRINT (4 XOR 255) Result: 251
415
5 X11-Basic command reference
Function: XOR()
Syntax: <num-result>=XOR(<num-expression>,<num-expression2>)
DESCRIPTION:
416
5.25 X
Command: XRUN
Syntax: XRUN
DESCRIPTION:
Opens a fileselector where the user can select a basic source file which then will be load
into memory and executed.
417
5 X11-Basic command reference
418
6 Compatibility
6.1 General remarks
X11-Basic deviates in numerous aspects from ANSI BASIC. It in event is also different from
Gfa-Basic (Atari ST) all though it really looks similar:
Local variables
Local variables must be declared local in the procedure/function. Any other variables are
treated as global.
Assignment operator
X11-BASIC does not have an assignment operator but overloads the equal sign to act as the
assignment operator or as comparison operator depending on context: In a regular expression,
all equal signs are considered to be the comparison operator, as in IF (a=2). However, in
419
6 Compatibility
an "assignment-style" expression (as in LET a=1), the first equal sign is considered to be the
assignment operator. Here is an example which assigns the result of a comparison (TRUE or
FALSE) to the variable <a> and thus shows both forms of usage of the equal sign:
a=(b= )
TOS/GEM implementation
Because Gfa-Basic on ATARI-ST makes much use of the built in GUI functions of the ATARI
ST, the X11-Basic interpreter can only have limited compatibility. GEM style (and compat-
ible) ALERT boxes, menus and object trees are included in the interpreter and can be used
in a similar way. Even ATARI ST *.rsc files can be loaded. But Other functions like LINEA
functions, the VDISYS, GEMSYS, BIOS, XBIOS and GEMDOS calls are (of course) not
possible. Also many other commands are not implemented because the author thinks that they
have no useful effect on UNIX platforms. Some might be included in a later Version of X11-
Basic (see the list below). Since many Gfa-basic programs make use of more or less of these
functions, they will have to be modified before they can be run with X11-Basic.
420
6.2 GFA-Basic compatibility
For some GFA-Basic commands you can construckt replacement functions in X11-Basic
like:
' Get the free memory available (in Bytes)
' n=0 physi
al memory
' n=1 Swap spa
e
FUNCTION fre(n)
LOCAL i,a,t$,a$
a=FREEFILE()
OPEN "I",#a,"/pro
/meminfo"
LINEINPUT #a,t$
IF n=1
LINEINPUT #a,t$
ENDIF
LINEINPUT #a,t$
t$=TRIM$(t$)
FOR i=0 to 3
WORT_SEP t$," ",0,a$,t$
NEXT i
CLOSE #a
RETURN val(a$)
ENDFUNCTION
421
6 Compatibility
422
6.2 GFA-Basic compatibility
423
6 Compatibility
424
6.2 GFA-Basic compatibility
425
6 Compatibility
426
6.3 Ideas for future releases of X11-Basic
ENCLOSE$(str[, pair℄)
En
loses a string.
The default pair is ""
Example:
? en
lose$("ab
","()")
Result:
(ab
)
========================
LEFTOF$(s1,s2),
427
6 Compatibility
RIGHTOF$(s1,s2)
========================
CRSCOL n.n.
CRSLIN n.n.
========================
implemention of mmap in x11basi
:
open "I",#1,"myfile"
adr%=map("I|O|U",#1,len,offset)
msyn adr%,len
unmap adr%,len
lose #1
428
Acknowlegements
Thanks to all people, who helped me to realize this package.
Many thanks to the developers of GFA-Basic. This basic made me start programming in
the 1980s. Many ideas and most of the command syntax has been taken from the ATARI ST
implementation.
Thanks to sourceforge.net for hosting this project on the web.
Unfortuantely derivates of the routines of the famous book "numerical recepies in C" are
not allowed to be distributed as part of the X11-Basic program. So I have not included all of
the mathematics features of X11-Basic in this distribution. (see mathemat_dummy.
). If you
own the book and have a licence you may ask me for the sources of the routines.
429
6 Compatibility
430