X11 Basic Manual
Total Page:16
File Type:pdf, Size:1020Kb
X11-BASIC VERSION 1.26 User Manual (C) 1997-2018 by Markus Hoffmann ([email protected]) (see http://x11-basic.sourceforge.net/) Latest revision: June 24, 2018 X11-Basic is a dialect of the BASIC programming language with graphics capa- bility that integrates features like shell scripting, cgi-programming and full graphical visualization into the easy to learn BASIC language on modern computers. The syntax is most similar to the old GFA-Basic on ATARI-ST implementation. Old GFA- programs should run with only few changes. About this document This document describes the features of X11-Basic. You will find information about the X11-Basic interpreter (the program xbasic under Unix or xbasic.exe under Windows) and the compiler (the program xbc under UNIX or xbc.exe under Win- dows) as well as the language itself. For a more compact description you may want to read the x11basic(1) man-page or the man-page of the X11-Basic compiler xbc(1). The latest information and updates and new versions of X11-Basic can be found at http://x11-basic.sourceforge.net/. 2 X11-Basic CONTENTS 1 About X11-Basic 1 2 Usage 5 2.1 InstallingX11-Basic . 5 2.2 Using the X11-Basic Interpreter . 10 2.2.1 Using the X11-Basic Interpreter under UNIX, Linux . 10 2.2.2 Using the WINDOWS Version of X11-Basic . 11 2.2.3 The Android Version of X11-Basic . 13 2.2.4 Command line parameters . 18 2.3 Editing X11-Basic programs . 19 2.4 The Bytecode Compiler and the Virtual Machine . 20 2.5 Using the X11-Basic to C translator . 23 2.6 The X11-Basic compiler manager xbc ................ 24 2.7 The ANSI-Basic to X11-Basic converter . 26 2.8 Using GFA-BASIC programs . 26 3 Programming in X11-Basic 27 3.1 The dialect of X11-BASIC . 27 3.2 Gettingstarted ............................ 28 3.3 Your first X11-Basic program . 28 3.4 Programstructure . 30 3.5 GeneralSyntax............................ 30 3.6 The very BASIC commands: PRINT, INPUT, IF and GOTO . 32 3.7 Variables ............................... 33 3.7.1 ThescopeofaVariable. 35 3.7.2 Datatypes .......................... 35 3.7.3 Variablenaming. 36 3.7.4 Numbers ........................... 37 3.7.5 Strings ............................ 38 3.7.6 Arrays............................. 39 3.7.7 Arbitrary precision numbers . 39 3.8 ArithmeticsandCalculations . 42 3.8.1 Expressions and Conditions . 42 3.8.2 Operators........................... 42 i CONTENTS CONTENTS 3.8.3 Stringprocessing . 46 3.8.4 Arrays............................. 46 3.9 Procedures and Functions . 49 3.9.1 Procedures .......................... 49 3.9.2 Functions ........................... 50 3.9.3 Parameters and local variables . 51 3.10SimpleInput/Output . 53 3.10.1 Printingdatatotheconsole. 54 3.10.2 Screen control . 55 3.10.3 Formatting output with PRINT USING . 56 3.10.4GatheringUserInput . 61 3.11FlowControl ............................. 62 3.11.1 Conditional and endless loops . 64 3.12Diagnostics.............................. 66 3.13AddressSpaces ........................... 67 3.14 Graphics: Drawing and Painting . 67 3.15ReadingfromandWritingtoFiles . 67 3.16 Internet and bluetooth connections, special files and sockets . 68 3.16.1 Local inter process communication: Pipes . 68 3.16.2 World-Wide communication: Sockets . 69 3.17 Bluetooth connections . 73 3.18 Accessing USB devices . 76 3.19Datawithintheprogram . 77 3.20Dynamic-linklibraries. 78 3.20.1 Using shared libraries and C functions . 78 3.21Memorymanagement . 80 3.21.1Allocatingmemory . 81 3.21.2Sharedmemory. 81 3.22Otherfeatures ............................ 82 4 Graphical User Interface 83 4.1 ALERT and FILESELECT . 83 4.2 Resources .............................. 84 4.2.1 Objects ............................ 86 4.2.2 Theguifileformat. 95 4.3 Menus ................................ 97 ii CONTENTS CONTENTS 5 WEB Programming 99 5.1 WhatisCGI?............................. 99 5.1.1 Configuration ......................... 99 5.2 Howitworks ............................. 101 5.2.1 Environment Variables . 101 5.2.2 CGI Standard Input . 107 5.2.3 Which CGI Input Method to use? . 107 5.2.4 OutputfromCGIScripts . 108 5.2.5 CGIHeaders ......................... 108 5.2.6 Example cgi-Script envtest.cgi .............. 110 6 Quick reference 111 6.1 Reserved variable names . 111 6.2 Conditions .............................. 112 6.3 NumbersandConstants . 112 6.4 Operators............................... 112 6.5 Abbreviations. 113 6.6 InterpreterCommands . 113 6.7 FlowControlCommands. 114 6.8 Console Input/Output Commands . 115 6.9 FileInput/OutputCommands. 115 6.10 Variable Manipulation Commands . 116 6.11 Memory Manipulation Commands . 117 6.12Mathcommands . 117 6.13OtherCommands . 118 6.14Graphiccommands. 119 6.14.1Drawingandpainting . 119 6.14.2 Screen/Window commands . 120 6.14.3 GUI/User input commands . 121 6.15FileInput/Outputfunctions . 121 6.16 Variable/String Manipulation functions . 122 6.17 Data compression and coding functions . 123 6.18MemoryManipulationfunctions . 124 6.19Logicfunctions . 125 6.20Mathfunctions . 125 6.20.1Angles ............................ 127 6.20.2 Trigonometricfunctions . 127 iii CONTENTS CONTENTS 6.20.3 Random numbers . 127 6.21Systemfunctions . 128 6.22Graphicfunctions. 128 6.23Otherfunctions . 129 6.24 Subroutines and Functions . 129 6.25ErrorMessages . 130 7 Command Reference 137 7.1 Syntaxtemplates. 137 7.2 A ...................................138 7.3 B ...................................166 7.4 C ...................................185 7.5 D ...................................228 7.6 E ...................................256 7.7 F ...................................292 7.8 G...................................326 7.9 H ...................................352 7.10I.................................... 361 7.11J ...................................381 7.12K ...................................384 7.13L ...................................387 7.14M................................... 415 7.15N ................................... 442 7.16O ................................... 452 7.17P ...................................470 7.18Q ................................... 509 7.19R ................................... 511 7.20S ...................................548 7.21T ...................................612 7.22U ................................... 630 7.23V ...................................643 7.24W................................... 653 7.25X ...................................664 8 Frequently asked Questions 671 iv CONTENTS CONTENTS 9 Compatibility 674 9.1 Generalremarks . 674 9.2 GFA-Basiccompatibility . 677 9.3 Ideas for future releases of X11-Basic . 685 A GNU License 689 Index 695 v CONTENTS CONTENTS vi X11-Basic 1 ABOUT X11-BASIC X11-Basic is a dialect of the BASIC programming language with graphics and sound which integrates features like traditional BASIC language syntax, structured programming, shell scripting, cgi programming, powerful math, and full graphical visualization into the easy to learn BASIC language on modern computers. The syntax of X11-Basic is most similar to GFA-Basic in its original ancient implementation for the ATARI ST. Old GFA-programs should run with only a few changes. Also DOS/QBASIC programmers will feel comfortable. X11-Basic is appropriate for virtually all programming tasks. For science and engineering X11-Basic has already proven its capability of handling complex sim- ulation and control problems. For system programs, X11-Basic has high level lan- guage 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. X11-Basic supports complex numbers and complex math, as well as arbitrary precision numbers and calculations where needed, as well as very fast 32bit inte- ger and 64bit floating point operations, very powerful string handling functions for character strings of any length and any content. X11-Basic supports the principle ’small is beautiful’. Its aim is to use the fewest system resources and execute with the highest speed. X11-Basic meets in this, by providing very powerful built-in commands and functions, and a very fast compiler producing even faster applications. X11-Basic lets you write an application with very little effort, giving you full control over your application. In case the X11-Basic commands and functions aren’t sufficient, you can easily use the native shell to execute other programs and commands, or you will be able to use any shared library on the system, which can be dynamically linked. Because it is an interpretive language each new step in your program can be tested quickly providing you with instant feedback. And when you finished your program you can use the X11-Basic compiler to create a very fast stand-alone executable. 1 CHAPTER 1. ABOUT X11-BASIC Portability The X11-Basic language was designed to be platform independant as much as possible. You can expect X11-Basic programs run on many operating systems giv- ing nearly the same look and feel everywhere. X11-Basic programs are portable. X11-Basic is designed to run on many platforms with extremely low resources. It has originally been developped for UNIX workstations and Linux-systems with the X-Window system (commonly known as X11, based on its current major version being 11). But soon versions for other operating systems (MS WINDOWS, MAC OSX, ATARI ST/TOS) have been built. In case where no X11 window graphics system implementation is available, X11-Basic can be compiled