Scriptbasic Users Guide
Total Page:16
File Type:pdf, Size:1020Kb
ScriptBasic Users Guide Peter Verhas Copyright °c 1999-2001 Peter Verhas Published by peter.verhas.com i Short Contents 1 Introduction................................... 1 2 Using ScriptBasic ............................... 3 3 Installation Instructions .......................... 11 4 Code caching ................................. 21 5 Compiling BASIC programs ....................... 23 6 Compiling BASIC program to EXE .................. 27 7 Compiling BASIC programs to C.................... 29 8 Compiling ScriptBasic with modules ................. 31 9 General Language Format ........................ 33 10 Interacting with the user ......................... 67 11 Name spaces .................................. 69 12 File Handling ................................. 73 13 Networking................................... 89 14 String handling commands ........................ 91 15 Conditional Execution ........................... 95 16 The statement GOTO ........................... 97 17 Loop constructs ............................... 99 18 Functions and Subroutines ....................... 101 19 Reference Variables ............................ 111 20 Pattern matching.............................. 113 21 Handling run-time errors ........................ 117 22 Setting options ............................... 123 23 Other miscellaneous commands .................... 125 24 Using External modules ......................... 127 25 Command reference ............................ 129 ii ScriptBasic Users Guide iii Table of Contents 1 Introduction............................... 1 2 Using ScriptBasic .......................... 3 2.1 Running from command line ............................. 3 2.2 Running CGI programs .................................. 9 2.3 Writing CGI programs................................... 9 3 Installation Instructions ................... 11 3.1 Installation under Windows ............................. 11 3.1.1 Installation under Windows from source ......... 11 3.2 Installation under Linux ................................ 12 3.3 Installation under other Unices .......................... 12 3.4 Configuration .......................................... 12 3.5 Configuration file location under Windows NT............ 17 3.6 Configuration file location under UNIX .................. 18 3.7 Overriding the default configuration file .................. 18 3.8 Trouble shooting installation ............................ 18 4 Code caching ............................. 21 4.1 How cache file name is calculated........................ 21 4.2 Cache handling shortages ............................... 21 4.3 Cache security ......................................... 22 5 Compiling BASIC programs ............... 23 5.1 Binary format of the BASIC code ....................... 23 6 Compiling BASIC program to EXE ........ 27 6.1 BASIC to EXE compilation technical details ............. 27 7 Compiling BASIC programs to C .......... 29 7.1 Compilation under Windows NT ........................ 29 7.2 Compilation under UNIX ............................... 30 8 Compiling ScriptBasic with modules ....... 31 iv ScriptBasic Users Guide 9 General Language Format ................. 33 9.1 Hello World............................................ 33 9.2 Strings ................................................ 33 9.3 Numbers .............................................. 35 9.4 Variables .............................................. 36 9.5 Constants ............................................. 38 9.6 Forcing Variable Declaration ............................ 42 9.7 Arrays ................................................ 43 9.7.1 Creating arrays................................ 44 9.7.2 Array index limits ............................. 45 9.7.3 Deleting an array .............................. 46 9.8 Associative Arrays ..................................... 47 9.8.1 Notes for using associative arrays ............... 50 9.9 Using Array Mixed Mode ............................... 50 9.10 Expressions ........................................... 51 9.10.1 Operators .................................... 52 9.10.1.1 Power operator (^) ................... 52 9.10.1.2 Multiplication operator (*) ........... 53 9.10.1.3 Division operator (/) ................. 53 9.10.1.4 Integer division operator (\) .......... 53 9.10.1.5 Modulus operator (%) ................ 53 9.10.1.6 Addition and subtraction operators (+, -) ......................................... 54 9.10.1.7 Bit-wise and logical NOT (NOT)...... 54 9.10.1.8 Equality operator (=) ................ 54 9.10.1.9 Not equal operator (<>) .............. 55 9.10.1.10 Compare operators (<, <=, >, >=) .... 55 9.10.1.11 Logical operators (and, or, xor) ...... 55 9.10.1.12 Concatenation operator (&) ......... 56 9.10.1.13 ByVal operator ..................... 56 9.10.1.14 LIKE operator...................... 56 9.10.1.15 Extension operators ................. 56 9.10.1.16 Planned, Future Operators .......... 57 9.11 Assignments (LET) ................................... 57 9.12 Operator Assignments ................................. 58 9.13 Comments ............................................ 58 9.14 Including Files ........................................ 59 9.15 Internal preprocessors ................................. 61 9.16 Using external preprocessor ............................ 62 9.17 #! /usr/bin/scriba .................................... 64 9.18 @goto start ........................................... 64 9.19 #!/@goto............................................. 64 10 Interacting with the user ................. 67 10.1 Print ................................................. 67 10.2 Input ................................................ 67 10.3 Handling command line arguments ..................... 68 v 11 Name spaces ............................ 69 12 File Handling............................ 73 12.1 Opening and creating files ............................. 73 12.2 Text and binary files .................................. 73 12.3 Switching between binary and text mode................ 75 12.4 Getting a free file number.............................. 76 12.5 Positioning in a file.................................... 77 12.6 Reading and writing files .............................. 78 12.7 Getting and setting the current working directory........ 79 12.8 Locking a file ......................................... 79 12.9 Locking file range ..................................... 81 12.10 Truncating a file ..................................... 82 12.11 Deleting a file or directory ............................ 82 12.12 Creating a directory .................................. 83 12.13 Setting file parameters................................ 83 12.14 Listing files .......................................... 84 12.14.1 Open directory .............................. 84 12.14.2 Function NextFile ........................... 86 12.14.3 Function EOD .............................. 86 12.14.4 Reset directory .............................. 86 12.14.5 Close directory .............................. 87 13 Networking ............................. 89 13.1 Opening a Socket ..................................... 89 13.2 Getting the host name................................. 89 14 String handling commands ............... 91 14.1 Split and splita ....................................... 91 14.2 Unpack............................................... 93 15 Conditional Execution ................... 95 16 The statement GOTO.................... 97 17 Loop constructs ......................... 99 vi ScriptBasic Users Guide 18 Functions and Subroutines .............. 101 18.1 Declaration of subroutines and function ................ 101 18.2 Calling functions and subroutines ..................... 101 18.3 Returning a value .................................... 103 18.4 Local and global variables ............................ 103 18.5 More on local and global variables ..................... 104 18.6 Parameters passed by value and by reference ........... 105 18.7 ByVal command ..................................... 105 18.8 Calling functions indirectly ........................... 106 18.9 GOSUB and RETURN ............................... 108 19 Reference Variables ..................... 111 20 Pattern matching ....................... 113 20.1 The operator LIKE................................... 113 20.2 The function JOKER................................. 113 20.3 Escaping wild cards .................................. 114 20.4 Ambiguous matching ................................. 115 20.5 Advanced matching .................................. 115 21 Handling run-time errors................ 117 21.1 On error goto ........................................ 117 21.2 Resume ............................................. 118 21.3 RESUME ........................................... 118 21.4 Levels of error handling............................... 119 21.5 Error codes .......................................... 122 22 Setting options ......................... 123 23 Other miscellaneous commands .......... 125 23.1 Sleep ................................................ 125 24 Using External modules................. 127 vii 25 Command reference .................... 129 25.1 ABS ................................................ 129 25.2 ACOS............................................... 129 25.3 ACOSECANT ....................................... 129 25.4 ACTAN ............................................. 129 25.5 ADDDAY ........................................... 129 25.6 ADDHOUR ........................................