Statement & functions manual

The iOS dependent functions are here.
The X68 compatible/Convenient/Card functions are here.
The music functions are here.
All statement/function/constant/variable list is here.

In beginning

For about X-BASIC' is here.

X-BASIC looks like the C language on the appearance, but behavior itself is several different.
If you are familiar with C language, it may be easy to mistake. Please be careful. 

Easily mistaken items:
  X-BASIC' C language
Equal sign = ==
{} only for if/dim assign generate local block
return () is required () is optional
Hexadecimal notation &h 0x
Truth-value -1 1

In the following explanation, "expression" means the operation result by the constant number, variables and its combination.
You can include a function.

The constant number (expression) means one constant numerical value and character string or its operating result.
If you use enum statement, you can also give names to any int constant.
If you use fenum statement, you can also give names to any float constant.
You can include operator in a constant number expression, but the function is not usable.
Of course, it must not include variable.

Type

Variable and function (with some arguments and a return value) have four kinds of following types.
NameContentsRangeSupplement
charUnsigned 8bit integer 0 to 255
int Signed 32bit integer -2147483648 to +2147483647 Sometimes char and int are referred to collectively as an integer.
Integer values can be specified in decimal, binary, hexadecimal,octal or a character by adding a prefix.
Note)Even on the 64bit devices, the int of X-BASIC is 32bit.
&hHexadecimal
&oOctal
&bBinary
'?' Character code for any single character enclosed in ' (All characters can be specified).
Standard character encoding is UTF8, but when forced SHIFT-JIS mode, encode with SHIFT-JIS.
float64bit float number+-2.225074*10-308 to 1.797693*10+308

The number of significant figures is about 15.
It is a floating-point, so it may be rounding errors.
When there is a point/e/E in a string of digits or there is a # behind a string of digits, it is considered as float number.
Example:
 0.1
 1.0#
 3e10
 4.012E-10

X-BASIC's float is corresponds to double in C.
strstringAny group of characters enclosed in ".

Maximum number of bytes that can be stored is variable depending on the setting.
Default is 255 bytes(except the end code).
Behind the string ,it stores EOS(end of string) code &h00.
Therefore, the inclusion of chr$(0) in the string is not allowed.
(If you need to store 0 in byte sequence, you use dim char.)
Empty string It is string with length 0 written by "".
You can also substitute it in system variable NULL$.
Please note that This is not same as NULL of C.
1 byte specified in the string If you get/update an any byte in the string, you can specify its location in [ ].
You can be specified from 0 to maximum string length -1.
But if you have specified the location exceeds the current string length, reading code is undefined and writing is invalid.

Example:Change 1 byte in the string.
s[0]='A'
Note)In X-BASIC/68, you can set string length for each string variable by the format "str name[length]". But X-BASIC' can not do so. You can describe it But is ignored. The maximum string length is follow in the setting.
Array
    Each type array is available, and it can be set max 10 dimension.
    For more information see statement below.


In the program, variable declaration can do anywhere.
(It does not need to place in the top of program or function.)

The variable content can be changed at any time.
On the other hand, immediate value is called the constant.
In the constant, it is not difference  distinction between char and int.


About the name

A variable / array or function name can use the following characters.

    Alphanumeric character
    _ (under bar)
    $ (dollar mark)

The case of the letters are case sensitive.
The name can not begin with the numbers.
The name must not begin with $ because this is reserved for system.

The length of the name is max 255 bytes regardless maximum string length setting.
(Because name has only ASCII characters, the number of characters is equal to number of bytes).

The same name as the functions and statements can not use.
In addition, the following names are reserved for the system, you will not be able to use.
    gosub,exit


Function and local variable

In X-BASIC, all subroutines is written by function.
The functions that are provided by the system calls "external function" or "system function".
The functions that are written by user calls "internal function" or "user function".

X-BASIC program is roughly is consists of two groups.
Global part from the beginning of program is executed by RUN 
and the local part is group of internal functions.
The local part is optional, but global section can not be omitted.

Function of the local part will be registered automatically at run time.
Therefore, as same as C language, it is not need to declare or implement functions earlier that
use them.

The function describe after the next line of the statement 'end' always.

RUN -> global part (the program top)
    All variables that you declared here become global variable.

    ... process ... 
    
    end
    // Here and later the local part, ie that part of the function description.
    
    func name1(param1;int,param2;str)
    ...
    endfunc
    //
    func name2()
    ...
    endfunc
* * *

(The internal) function describe as follows.
[ ] is an omissible item.
... indicates that the following be continued as well.

    func [type of function] function name ([argument[;type of argument],...])
    ... process ...
        return[(return value)]
    endfunc

You must not be a space between a function name and '('.
The type of the function is the type of return value.
If it is omitted, it is assumed to int.
But, it is recommended that you do not omit.

If the return value of functions do not need, you omit the return value or return statement itself.
Conversely, when there is a return type specification, it requires return(value) statement.
Return statement with a return value is required ().
(This can not omit like C language.)


Example:
    // Function with no return value (void as C language)
    func name1(...)
        ... process ...
        if ... then return
        ... process ...
        // return statement is not need because this function has no return value
    endfunc

    // Function with the return value
    func float name2(...)
        ... process ...
        if ... then return(1.0)
        ... process ...
        // return statement must need because this function has return value
        return(2.0)
    endfunc

//------------------------------

You listed the argument name and its type followed by ';'.
If it is omitted ,it is assumed to int (but it is recommended that you do not omit).
Argument can have up to 10 (external function's argument can have up to 12).

If you do not need even one argument, you describe only ().

Example:
    func name1(param1;int,param2;str)
        ...
    endfunc
    
    func int name2() :/* This funcsion has no argument. So describe only ()
        ...
    endfunc

You can use array for the function's argument.
(For the array are described below.)

Example:
    dim str ss(4,1)={
        "s01","s02","s03","s04","s05", 
        "s11","s12","s13","s14","s15"
    }
    testFunc(4,ss)
    end
    //
    func testFunc(n;int,s(4,1);str)
    print "n="; n
    int i,j
    for i=0 to 1
        for j=0 to 4
            print "s("; j;","; i; ")="; s(j,i)
        next
    next
    endfunc

When you describe array argument in func, you will describe "name();type".
From the system of constraints, you can not use the enum constant in the number of elements specified in this argument array.

When you set the number of elements in array at function side,
the number of array elements must match at function side and the caller side.
It is also possible to omit the number of elements in the function side.
In this case,  the number of array elements in the function side will be set same as the caller side automatically(extend array).
The dimension can not change.

Example:
    dim int a(10,5),b(20,15)
    f2(a)
    f2(b)
    ...
    end

    func f2(n(,);int)
        // When it is called in f2(a), it is set to n(10, 5).
        // When it is called in f2(b), it is set to n(20,15).
        // Use following statements, you will understand easily.
        int size1,all
        all=sizeofArray(n,size1)
        print "1element size=";size1;"/the number of elements(total)=";all
    endfunc

To know dimension, it can not omit ','.
If you change the array in passed function, the caller side will also be changed.

//------------------------------

You can use the local variable in the function.
Local variable names can be duplicated by a global variable.
Global variable will be hiding in that case.
Arguments of the function will be treated as local variables.

Example:
    int i=1     :/* global variable
    print "i=";i:/* i=1
    f0()
    print "i=";i:/* i=1
    end
    //
    func f0()
        print "i=";i:/* i=1;It is a global variable that is referenced here
        int i=2     :/* Declaration of local variable
        print "i=";i:/* i=2
    endfunc

X-BASIC can not use pointer in internal function.
Therefore, if you want to return value greater than 1, you will need to use global variable.


The array only in local area, you can specify the number of elements by a variable.
This is called a variable-length arrays(extend array).

Example:
    func f1(n;int)
      dim int a(n)
      ...
    endfunc

In addition, to declare array in the global must use constant.

Note:
The function is able to recursive call, but if you do very deep call, system may issue error.

Operator

The following operators are prepared in X-BASIC'.
Each operator has decided what is available depending on the type of variable or constant.
Operator is in all lowercase letters.
Dyadic operator
Arithmetic operator int/char float str  () is required in enum
+ Yes Yes Yes Strings can combine by + operator.
- Yes Yes No  
/ Yes Yes No  
* Yes Yes No  
mod Yes Yes No Residue (remainder)Yes
\ Yes Yes* No Integer divisionYes

Logic/Bit operator int/char float str  () is required in enum
and Yes Yes* No Logical product
Yes
or Yes Yes* No Logical sum
Yes
xor Yes Yes* No Exclusive OR
Yes
shl Yes Yes* No shift left (same as << in C)
If the second parameter is negative, it shift reverse.
Yes
shr Yes Yes* No shift right (same as >> in C)
if the second parameter is negative, it shift reverse.
Yes

Relational operator int/char float str  () is required in enum
< Yes Yes Yes  Yes
> Yes Yes Yes  Yes
<= Yes Yes Yes  Yes
>= Yes Yes Yes  Yes
= Yes Yes Yes Comparison matchYes
<>Yes Yes Yes Comparison unmatchYes
String can also be compared by relational operators same as numbers.
Each string is compared byte-by-byte from the beginning. If both are exactly the same it is equal.
If it is different even in one byte, the larger of the different bytes will be determined to a large string.
If the comparison has finished in the middle because byte length of either string is small , it will be judged as shorter string is small.
In UTF8, number of bytes can not be determined from the number of characters. Therefore, often, the comparison result is different from your expectations.
In addition, note that in the string comparison blank also has a meaning.

Unary operator
  int/char float str  () is required in enum
not Yes Yes* × Negative(Logic/Bit operator;All bit reverse)
Yes
- Yes Yes × Minus signYes
Yes* = Truncate after the decimal point in the float numbers and execute as type of int.


operator priority
  1. enclosed in brackets
  2. functions
  3. signal(+/-)
  4. * /
  5. \
  6. mod
  7. + -
  8. shr shl
  9. relational operator
  10. not
  11. and
  12. or
  13. xor

Truth-value
The relational operator returns a truth-value.
The value of the truth-value is prepared for the constant number.
YES
true
truth-1
(It is different from C)
NO
false
false0

In addition, boolean in X-BASIC is determined as follows:
=0False
<>0True
This is same as C language.


Statement
[ ] is an omissible item.
... indicates that the following be continued as well.

All the statements are small letters.

// Variable declaration statement

Name char
Format char variable name[=initialization expression][,name[=initialization expression],・・・・]
Function Declare char type variable.
Can also set the initial value at the same time.
Example
char c      :// declaration only
char c='A'  :// declaration with initial value 'A'
char d=c+1  :// In the initialization expression, it can refer to another variable
            :// previously declared.

Name int
Format int variable name[=initialization expression][,name[=initialization expression],・・・・]
Function Declare int type variable.
Can also set the initial value at the same time.
Example
int i
int j=0
int k=i+j

Name float
Format float variable name[=initialization expression][,name[=initialization expression],・・・・]
Function Declare a float type variable.
Can also set the initial value at the same time.
Example
float f1=3.14
float f2=pi(1)  :// initialization can assign by the function.
float f3=f1+f2

Name str
Format str variable name [=initialization expression][,name[=initialization expression],・・・・]
Function Declare a str type variable.
Can also set the initial value at the same time.
Example
str s1
str s2="String"
str s3="3rd "+s2

Name dim
Format dim type name(the maximum value of the subscript,[the maximum value of the subscript...]) = {initial value of element1,element2,...}
Function Declaration of the array.
Type is specified in the char/int/float/str.
Element is usable from (0) to (the maximum value of the subscript). (Note : maximum number is different from C.)
The number of elemens is max 65535(any type). The number of all elements is up to 65536 in through all dimensions. This is not each dimension. If it is over 65535, error does not occur (just overflow).
Dimension can be used up to a maximum of 10.
Example
dim int a(10)       :// Declare 11 elements int array(one dimension). 
                    :// The initial value of each element is 0.
dim b(10)={0,1,2}   :// Give an initial value in the range does not exceed the number of elements.
                    :// Part that is not specified initial value is 0.
dim str c(3)        :// str type array has the initial value an empty string
c={"A","B","C","D"} :// After the declaration, you can assign at any location.
c={"A",         
    "B","C",    // It can also be written on multiple lines.
    "D"     
}

dim float x(3,2)    :// Two dimension array ; 1st dimension has 3+1 elements, 2nd dimension
                    :// has 2+1 elements.
// Even if it is multidimensional array, you write all initial value in one set of {}.
// As in language C, you don't need to separate by {} to each dimension.
x={10,20,30,40,     // store x(0,0) to x(3.0)
   11,21,31,41,     // x(0,1) to x(3,1)
   12,22,32,42      // x(0,2) to x(3,2)
}           :// Storage order is from the first dimension to the last dimension.
            :// (Note : it is reverse with C language.)
Note If you write a comment in dim element store expression, don't use ':' (means multi statement).
(Because there is not the place where is able to write multi statement.)
Mistake
dim str pai(3)={    :// comment
     "123456789"    :// comment
}

Correct
dim str pai(3)={    // comment
     "123456789"    // comment
}

Name enum/endenum
Format enum
ConstantName1[=int constant value]
ConstantName2[=int constant value]
...
endenum
Function It defines integer constant with continuous values.
If you specify a value, it set the value, and if you omitted, it set the previous value+1.
Default value is 0.
The variable can not use for case value, however, enum values is possible to use because of constant.
You can use the integer constant , previously defined enum value and result of the calculation them to specify the value.
However, if you use the following operators , it must be enclosed by () in one expression at a time.   
Operator that needs to be enclosed in ()
\ mod shr shl = <> < > <= >= and or xor
It is not possible to use functions and variables.
It does one definition in one line.
Unlike C language, even when the successive definition, it is not necessary to describe the ','.
Of course, you can not change later because it is constant.
Example
enum
  CONST1  // Default initial value is 0
  CONST2
endenum
// CONST1=0,CONST2=CONST1+1=1

enum
  CONST1=10
  CONST2
endenum
// CONST1=10,CONST2=CONST1+1=11

enum
  CONST1=1
  CONST2=CONST1*10    // reference of defined constants and using operator are available
endenum
// CONST1=1,CONST2=CONST1*10=10

int a=5
enum
  CONST1=bit(0)   // Error ; Can not use functions
  CONST2=a*10       // Error ; Variable can not reference
endenum

case CONST1 // OK
case a      // Error ; Variable can not use for case value
Note The enum values are registered before compiling the BASIC source.
Therefore, they always defined to be described in the if statement.
if val(basicVersion$)<=3.0 then {
  // These are always defined even under than v3.0
  enum
    CONST1
    CONST2
  endenum
}
Attention From the system of constraints, you can not use the enum constant in the number of elements specified in this argument array.
Example:
enum
  WW=3
endenum
...
func f(masu(WW,WW);int):// error

Name fenum/endenum
Format fenum
fConstantName1[=float constant value]
fConstantName2[=float constant value]
...
endenum:// fenum is also closed by endenum statement.
Function It defines float constant with continuous values.
If you specify a value, it set the value, and if you omitted, it set the previous value+1.0.
Default value is 0.0.
You can use the float constant , previously defined fenum value and result of the calculation them to specify the value.
However, it is not possible to use functions and variables.
It does one definition in one line.
This is constant. So this can not be changed later.
Example
fenum
    FCONST1=3.141592
    FCONST2
endenum
// FCONST1=3.141592,FCONST2=FCONST1+1.0=4.141592

fenum
    FCONST1=10.10
    FCONST2=FCONST1*10    // reference of defined constants and using operator are available
endenum
// FCONST1=10.10,FCONST2=FCONST1*10=1010.0
Note The fenum values are registered before compiling the BASIC source.
Therefore, they always defined to be described in the if statement.


// Structure control statement

Name for - next
Format
for variable = start-value to end-value
    ...process...
next
Function
Loop while increasing by +1 from starting value to ending value into int variable.
(There is no statement for changing the increment).
Note it is not possible to use a type other than int variable (not even char).
The end value is less than the start value, the loop is not executed.
Example
int i
for i=0 to 5
  print "i=";i;","; :// display i=0,1,2,3,4,5, 
next
print
Supplement At terminate of the loop, the int variable become end value + 1.
Note
For and next statement is corresponding 1:1 always.
As the old MS-BASIC , by enumerating several variable name after the "next",
you can not receive more than one "for" to single "next".
(You can not write the variable names after the "next".)

Name repeat - until
Format
repeat
    ...process...
until end conditional expression
Function
Until the end condition is true, it repeats the process.
The conditional expression is placed at the end of loop, so the process is executed at least once.
Example
i=0
repeat
  print "i=";i;","; :// display i=0,1,2,3,4,5, 
  i=i+1
until i=5+1     :// exit the loop at i = 5 +1
print

Name while - endwhile
Format
while conditional expression
    ...process...
endwhile
Function
Between the condition is true, it repeats a process.
The conditional expression is at first.
Therfore sometimes the process is not executed even once.
Example
Example1:
i=0
while i<5+1      :// loop while i<5+1
  print "i=";i;","; :// display i=0,1,2,3,4,5, 
  i=i+1
endwhile
print

Example2:
i=10
while i<5+1      :// do not execute this loop
  print "i=";i;",";
  i=i+1
endwhile
// jump to here immediately

Above 3 loop statements are shown in the flow chart as follows.
 


Name switch - endswitch/case/default
Format
switch expression
    case 1st-constant
        process 1
        [break]
    case 2nd-constant
        process 2
        [break]
    ...
    [default[:process n]]
endswitch
Function
By the result of the expression, it branch some process by the constant value.
It can use integer or string・for constant value.e
It is called "numeric switch" or "string switch".

The "numeric switch" use int constant (include enum value) at case value, 
and "string switch" use str constant at case value.
Expression containing variables and expression can not use.

If the expression include char / float value, it is automatically converted to int.
Therefore, if it is numeric switch, the case value must be int regardless of 
the result type of the expression.

The string can not contain a character less than space code.

When you write break statement in the processing, it jumps to endswitch.
When the result of expression which does not match any case value, jump to default statement.
Default statement must write after the last case statements(if you need).
(In the C language, default statement location is free, but X-BASIC has the constraints.)

Unlike the C language , default and case statement is not required ':'.
(When you write ':', it is regarded as a multi-statement.)

In the one set of switch and endswitch statements, you can write the case statement up to 256.
And In the one seto of switch and endswitch statements, default statement can write only one.
Example
Example1: numeric switch
int i
for i=0 to 5
  switch i
    case 0      :// Jump to here only at i=0.
      print "0"
      break
    case 1
    case 2      :// Execute here at i=1 or i=2.
      print "1/2"
      break

    default     :// Jump to here when i is other than the above.
      print "その他"
      break
  endswitch
next


Example2: string switch
str s
input "string=";s
//  dim str menues(3)={"A","BC",DEF","GHI"}
//  s=menues(selectMenu("strings",menues))
switch s
  case "A"      :// Jump to here only at s="A"
    print "s = A"
    break
  case "BC"
  case "DEF"    :// Execute here at s="BC" or s="DEF"
    print s;"<"
    break
  default       :// Jump to here when s is other than the above.
    print s
    break
endswitch

Name continue
Format continue
Function Jump to the loop conditional expression of the hierarchy(called "nest") that is currently running.
Example
for i=0 to 10
    if i>=5 then continue
    print "i=";i    :// when i>=5, does not execute here
next
Note The continue statement can not be described in switch statement.
(It is different with C language.)

Name break
Format break
Function Exit from the loop or switch hierarchy(nest) that is currently running.
Example
for i=0 to 10
    if i=5 then break   :// when i = 5, exit from for loop
    print "i=";i
next

Name if/then/else
Format if condition-expression then process-at-true [else process-at-false]
Function When the conditional expression is true, it execute process at true,
When the conditional expression is false,it execute process at false.
There are four type of notation (see example).
Example
Example1 : Describe in 1 line. else statement is none.
if a=1 then print "a=1"

Example2 : Describe in 1 line. else statement is there.
if a=1 then print "a=1" else print "a<>1"

Note: you must not write else statement to another line.
Disable     if a=1 then print "a=1"
        else print "a<>1"

Example3 : Describe process at true in multiple lines.
if a=1 then {
    print "a=1"
    ...process...
}

Example4 : Describe process at true and false in multiple lines.
if a=1 then {
    print "a=1"
    ...process...
} else {
    print "a<>1"
    ...process...
}

Name label
Format label "label-name"
Function Declare a label to destination of goto statement.
The label name can be used by any character.
Note
Label is not set for the describing position.
It is set for the beginning of the line.
Therefore, 
    label "A":print "label A"
    print "label A":label "A"
These two description means the same.

Name goto
Format goto "label"
Function Jump to label.
It is not able to jump between grobal and functions, or between function and another function.
Example
Example1:
for i=0 to 10
  for j=0 to 10
    if i=5 and j=5 then goto *loopout:// exit two for loops at once
  next
next
*loopout

Example2:
switch n
    case 1
      print "1"
      goto "L1"
    case 2
      print "2"
      goto "L1"
    default
      print "another"
    label "L1"
      ...common process...
      break
endswitch
NoteThe goto statement should not be unnecessarily use.

Name func - endfunc / return()
Format
func [type of function] function name ([argument[;type of argument],...])
... process ...
    return[(return value)]
endfunc
Function
Internal function define.
For more information, as described above.

Name stop
Format stop
Function Terminate program running.
It outputs a stop line number in the debug screen.

Name end
Format end
Function Terminate program running.
And 'end' declares the end of the global section.
Description of the func must be a later end statement.
(Conversely, it required end before it begins to describe the func.)
Note The 'stop' will use for program stop during test running,
the 'end' uses for program termination in production.
You can separately set the output timing in both.


// Input and output

Name print
Function Display string and numerical value to the text screen.
Format
print variable[;]
    Display the contents of the variable. 

print "string"[;]
    Display string.

print expression1;expression 2; ... ;expression n[;]
    Display some result of expression side-by-side.

print expression1,expression 2, ... ,expression n[,]
    Display some result of expression with 8 character spacing(equivalent to TAB).
    If you put a ',' at the back, it dos not begins newline after displaying.
    In graphic coordinate mode,expression are displayed with 1 character spacing(insted of TAB).

The expression can also be a mix of numbers and strings.
Each syntax, If you put a ';' at the back, it does not begin newline after displaying.

print
    Begins newline only.
Note
  • If the control code is included in the string, it is processed as follows:
    • In text coordinate mode, all control code is ignored.
    • In graphic coordinate mode, whole of strings is not display
    There are for speed up.
    If you write as follows, the control code is not executed.
    Because "string"+chr$(control code) means string addition, so it is one string including control code.
    print "string"+chr$(control code)
  • Display control code is executed only when you print just the one control code character.
    If you write as follows, the control code is executed. Because print process is separated by ';'(or ',').
    print "string";chr$(control code)
  • If you print from the same cursor position in a short interval(less than 1 second) , the display might wink.

Name print using
Format print using "format";numeric expression[;numeric expression...]
Function
Display the formatted numeric value.
The format string is composed of a combination of the following groups of characters.
This string must be a constant.
# Specify the number of digits to be displayed.
The part that is not enough digits is filled with blank.
% Specify the number of digits to be displayed.
The part that is not enough digits is filled with '0'.
. Specify the location of the decimal point
+
-
Display with a sign. If you want to set '-' ,it set the back of #.
** Fill in the blank with '*'. The number of digits add "**" itself (+2).
$$ Put a $ in top of numbers.
**$ Fill in the blank with '*' and put a $ in top of numbers.
^^^^^ Display numeric value by the index representation.
, Every three digits, put a ','. It is described as "#,".
When there is "^^^^^" it will be ignored and will be treated as digit one '#'.
_(underbar)Display a character as an ordinary character just behind this.
(Primarily for the display of formatting characters.)
It can mix format characters and ordinary characters in the using statement.
Ordinary character will be displayed as normal.

The required number of expressions specified number format must be the same.
Example
Specification   Display result
"+####";0       "   +0"     :// 0 also has sign symbol '+'
"+####";10      "  +10"
"+####";-10     "  -10"
"####-";0       "   0 "     :// 0 does not have sign symbol.
"####-";10      "  10 "
"####-";-10     "  10-"
"+%%%%";0       "+0000"     :// 0 also has sign symbol '+'
"+%%%%";10      "+0010"
"+%%%%";-10     "-0010"
"%%%%-";0       "0000 "     :// 0 does not have sign symbol.
"%%%%-";10      "0010 "
"%%%%-";-10     "0010-"

"+###.####"
        The number of integer places is 3 digits and the number of decimal places is 4.
        Sign is preceded.
"**#,####-"
        The number of integer places is 2+1+4=7 digits.
        If the number of digits is less than it, it is filled by the '*'.
        Separate every three digits by ','.
        Sign is attached behind.

    print using "Width:## x ##  Time:#####";wx,wy,dt    Right ; 3 format specifiers and 3 variables
    print using "Width:## x ##  Time:";wx,wy,dt         Wrong ; 2 format specifiers and 3 variables
Note You can't describe ',' after the using statement for tab display same as print statement. If you need, please describe as follows:
print using "#";v;:print ,
When you describe ';' after the using statement, it is not a new line.

Name print using
Format print using "format";string expression[;string expression...]
Function
Display the formatted string.
The format string is composed of a combination of the following groups of characters.
This string must be a constant.
! Display only one character(not in byte) at the beginning of the string.
@ Display full string.
& & Display number of characters between the two '&'.
_(underbar)Display a character as an ordinary character just behind this.
(Primarily for the display of formatting characters.)
It can mix format characters and ordinary characters in the using statement.
Ordinary character will be displayed as normal.

The required number of expressions specified number format must be the same.

Name input
Format input ["message";]variable[,variable...]
Function
Input data from keyboard to variable.
All type variables can be specified.

If you specify a message, it will be displayed before the input.
The message must be string constant (must not string variable).
If you need variable string, you will use with print statement.
    Example :
        print message$;:input a

The input column is to the termination of a line except for the message.
Therefore, when the message does not fit on one line, input can not do.

The input statement is not able to select keybord type (KeyboardTypeNumbersAndPunctuation fix).
If you want, use inputWithPlaceholder() function.

You can specify more than one variable. The input is to be listed separated by ','.
Input is repeated until it is entered the number necessary at the same time.
If it is not entered, It will be repeated.
Variable type is able to mix different type.

Each input should have correct type.
If it is not correct, you are asked to re-enter.
Example
Example1:
int a
input "a=";a    :// input to int variable "a"

Example2:
int a
str s
input "a,s=";a,s:// input int variable "a" and string variable "s" at same time
        :// The following cases, the input will be repeated.
        :// (1)There are not two input at the same time.
        :// (2)Input type incorrect(unmatch).
Note When you run the input when the cursor is at the bottom of the screen, input frame is hidden by the keyboard.
Please note at the cursor position.

Name linput
Format linput ["message";]str variable
Function
Input data from keyboard to str variable.
However variable is limited to the type str and it must be single.
Unlike the input statement, you can enter all the characters,
including commas, quotation marks, the single quotes.
If you specify a message, it will be displayed before the input.
Example
str s
linput "s=";s
Note When you run the linput when the cursor is at the bottom of the screen, input frame is hidden by the keyboard.
Please note at the cursor position.
The input column is to the termination of a line except for the message.
Therefore, when the message does not fit on one line, input can not do.


// Others

Name error
Format error off / error on / error on2
Function Set an action when an error occurs in the external function.
off Even if an error occurs in the external function,
error message does not display and program does not stop.
on When an error occurs in the external function, program stops with an error message
(without fopen()'s file open error).
on2 At file open error in fopen(), program stops with an error message.
At Immediately after the program execution, it sets error on automatically.
NoteFor abnormalities while to turn off the error, you must determine status with return value.


External functions

External function is a set of functions that provided by the system.
Except that the user does not need to write, the usage is almost the same as an internal function.

If you set a different numeric type to a function that requires the int/char/float as an argument, 
if possible the conversion, it converts the type argument automatically
(If an error occurs, not be converted.)

Note:
[ ] is an omissible item.
... indicates that the following be continued as well.


// File system functions


In the file system functions, the "end of file" means the status as follows:
  1. Read the file to end of 1 byte.
  2. Try to read one or more bytes
The "end of file" does not means the last 1 byte of file.

Name fopen
Format int fopen(name;str,md;str)
Function open a file.
You can open 15 files at the same time.
Argument
name File name
It must specify in UTF8 or ASCII.
md open mode
"c" Create a file with read and write.
If the same name file is already exist then remove old file.
"r" Open a exist file with read only.
"w" Open a file with write only.
If the same name file is already exist then append file.
"rw" Open a exist file with read and write.
"ra" Open a exist file with read and write (append).
Return value
>=0file number
The return value will use in other file function.
You must save it in a variable, and not destroyed.
-1file can not open(error)
Any other errors will stop with displaying an error message.
Note Unlike X-BASIC/68, it does not stop with an error in the file open error in the default(only returns error code).
It is able to stop at error with error on2.
Caution In v3.10, the Return value has been changed to match the X-BASIC/68.
If you want to use old error value, you can set the old error value by "Error value of fopen" in settings or using errorCodeFopen(NO).
In the future, please judgment error in as much as possible new value.
Reference: Return value to V3.00
>=1file number
0file can not open(error)

Name fopenError
Format int fopenError(fp;int)
Function It determines the return value of fopen() is whether error or not.
Argument
fp file number(Return value of fopen)
Return value
NO normally terminated
YES error has occurred
Note As long as you use this function, you can correctly judgment if you set how the error value of fopen().

Name errorCodeFopen
Format int errorCodeFopen([mode;int])
Function Set then error value of fopen(). Or read current error value of fopen().
Argument
Default Return current error valu of fopen().
NO Set old error value(previous V3.00)
YES Set new error value(V3.10 or later)
Return value Return current or change before error value of fopen(). (new is -1,old is 0.)

Name fclose
Format int fclose(fp;int)
Function close a opened file.
Argument
fp File number returned by fopen().
Return value
0 Successful completion
-1 Error

Name fcloseall
Format int fcloseall()
Function Close all opened files.
Argument None
Return value
0 Successful completion
-1 Error

Name fputc
Format int fputc(ch;char,fp;int)
Function Write 1 byte to a file.
Argument
ch Data to write.
fp File number returned by fopen().
Return value
>=0 ch itself
-1 Error

Name fgetc
Format int fgetc(fp;int)
Function Read 1 byte from a file.
Argument
fp File number returned by fopen().
Return value
>=0 1 byte data read from a file
-1 error or at end of file

Name fwrite
Format int fwrite(ary;one-dimensional array,n;int,fp;int)
Function Write any numerical array to a file.
Argument
ary char/int/float type one-dimensional array with data for writing.
The case of any type, write packed with all the bytes in it.
(Not an element in one byte).
n Number of elements for writing.
Write ary(0) to ary(n).
The number of elements in the array declaration when less than n,
the number of elements to write the declaration.
fp File number returned by fopen().
Return valueActual written number of elements(not number of byte except dim char)

Name fread
Format int fread(ary();numeric type,n;int,fp;int)
Function Read from file to any numerical array.
Argument
ary char/int/float type one-dimensional array for reading data.
In the case of any type, read packed with all the bytes in it.
(Not an element in one byte).
n Number of elements for reading.
Read ary(0) to ary(n).
The number of elements in the array declaration when less than n,
the number of elements to read the declaration.
fp File number returned by fopen().
Return valueActual read number of elements(not number of byte except dim char)

Name fwrites
Format int fwrites(st;str,fp;int)
Function Write a string to a file.
Argument
st string for write.
End of string code(&h00) is not written.
fp File number returned by fopen().
Return value
>=0Actual written number of bytes
-1 Error
Note if you will use freads() for reading,so you must add new line character to end of string.
You can use the new line character either chr$(13) or chr$(10) only or chr$(13)+chr$(10).

Name freads
Format int freads(st;str,fp;int)
Function Read a string(which is terminate by new line character) from a file.
The new line character itself is not read.
You can use the new line character either chr$(13) or chr$(10) only or chr$(13)+chr$(10).
Argument
st string variable for reading
fp File number returned by fopen().
Return value
>=0 Actual read number of bytes(text line is terminated with linefeeed character)
-1 error or at end of file
Note If the file is terminated without new line character, st becomes the content of line and return value becomes -1.
Example : if you read the file consists with TEST&h1a then st="TEST",return value =-1.

Name fseek
Format int fseek(fp;int,ofst;int,md;int)
Function Set the reading and writing position in a file.
Argument
fp File number returned by fopen().
ofst Offset from base position (bytes)
base base position
0 From the top of the file
1 From a current data point
2 From the end of the file
Return value
>=0the position after this function execute
-1Error

Name frewind
Format frewind(fp;int)
Function Set the reading and writing position to top of a file.
Argument
fp File number returned by fopen().
Return valueNone

Name feof
Format int feof(fp;int)
Function Check whether the file end came
Argument
fp File number returned by fopen().
Return value
YES file end
NO not file end

Name ferror
Format int ferror(fp;int)
Function Check whether file error was occured
Argument
fp File number returned by fopen().
Return value
YES error was occured
NO no error

Name ftell
Format int ftell(fp;int)
Function Get current reading or writing position
Argument
fp File number returned by fopen().
Return value
>=0current position(from top of a file)
-1 Error

Name frename
Format int frename(oldname;str,newname;str)
Function Rename file
Argument
oldname old file name
newname new file name
Return value
0 Successful completion
-1 Error
Note In file name , you must not put the name of the directory.

Name fdelete
Format int fdelete(name;str)
Function Delete file.
Argument
name Target file name
Return value
0 Successful completion
-1 Error

Name filelength
Format filelength(fname;str)
Function Get file size.
Argument
fname Target file name
Return value
>=0file byte size
If the file is in the open, return immediate file size after open.
(It does not change even then file is appended).
0If the file is none, return 0.

Name mkdir
Format int mkdir(dir;str)
Function Make directory
Argument
dir directory name
You do not care even with a '/' at the end.
Return value
0 Successful completion
-1 Error
Note When you make very deep directories , it may become inaccessible. One hierarchy is safe.
"X-BASIC'" dose not have concept of current directory. So there is not chdir().

Name rmdir
Format int rmdir(dir;str)
Function Remove directory.
The directory must be empty.
Argument
dir directory name
You do not care even with a '/' at the end.
Return value
0 Successful completion
-1 Error

Name filecopy
Format int filecopy(srcfile;str,desfile;str)
Function Copy file.
Argument
srcfile source file name
desfile destination file name
When you want to copy to another directory with the same name as the srcfile, desfile describes as "directory/" and you may omit the file name.
Return value
0 Successful completion
-1 Error

Name files
Format int files(pathes();str[,basedir;str][,ext;str][,fhave;int][,mode;int][,freg;int][,farea;int])
Function Search for a file or directory, including sub-directory.
The name that match the requirements will be stored in string array.
Argument
pathes One dimension string array to store the result.
basedir Sarch start directory. Default is root of user file area.
In system area, basedir is ignored(always from root because system area does not have directory).
ext Search extension. Default is all extensions.
fhave Specify the match condition of the extension.
YES(Default) Get match name
NO Get unmatch name
mode Specify search target.
FILES_FILE file only
FILES_DIR directory only
FILES_ALL(Default) both
freg Whether you use a regular expression to ext.
YES ext is regular expression
NO(Default) ext is normal string
farea Selection of searching area
FILES_FAREA_USER(Default) Only user area
FILES_FAREA_SYSTEM Only system area
FILES_FAREA_ALL both
Return value The number of matching files and directories.
The name are stored from pathes(0) to (return value-1).
The path name which exceeds the maximum length of the string is ignored.
Supplemental or extend regular expressions, please see here.
https://www.gnu.org/software/grep/manual/html_node/Regular-Expressions.html
Samplefiler.bas,soundloader.bas,picloader.bas,emailTest.bas

Name lastPathComponent
Format str lastPathComponent(path;str)
Function Get filename.extension string from directory/filename.extension string.
Argument
path Directory/filename.extension string
Return value filename+Extension

Name pathExtension
Format str pathExtension(path;str)
Function Get extension string from directory/filename.extension string.
Argument
path Directory/filename.extension string
Return value Extension



// Data conversion functions

Name chr$
Format str chr$(c;int)
Function Convert ASCII or UTF8 character code to string.
Argument
c Character code
In the standard UTF8 or ASCII, if it is started in forced SHIFT-JIS mode, it must be specified in the SHIFT-JIS.
Return value string (by one character)
Note If you want to convert the character code of the SHIFT-JIS/UTF8 explicitly use the sjisChr$() / utf8Chr$().

Name utf8Chr$
Format utf8Chr$(c;int)
Function Convert UTF8 or ASCII character code to string.
Argument
c Character code (UTF8 or ASCII)
Return value string (by one character)
Note If you want to convert the character code of the SHIFT-JIS to explicitly use the sjisChr$().

Name sjisChr$
Format str sjisChr$(c;int)
Function Convert SHIFT-JIS or ASCII character code to string.
Argument
c Character code (SHIFT-JIS or ASCII)
Return value string (by one character)
Note If you want to convert the character code of the UTF8 to explicitly use the utf8Chr$().

Name asc
Format int asc(s;str)
Function Return the character code of a first byte of the string.
Argument
s string
Return valuecharacter code
Note If you want to get the first character code reliably, you must use sjis() or utf8() on the understanding type of character code.

Name bin$
Format str bin$(n;int)
Function Int number convert into a binary string.
Top 0 is excluded.
Argument
n int number
Return value Binary string
Discussion bin$(&b001011)="1011"

Name oct$
Format str oct$(n;int)
Function Int number convert into a octal string.
Argument
n int number
Return value Octal string
Discussion oct$(&o123)="123"

Name hex$
Format str hex$(n;int)
Function Int number convert into a hexadecimal string.
Argument
n int number
Return value Hexadecimal string
Discussion hex$(&h1234)="1234"

Name itoa/itoa$
Format str itoa(n;int)
itoa$(n;int)
Function Int number convert into a decimal string.
Argument
n int number
Return value Decimal string
Discussion itoa(1234)="1234"

Name atoi
Format int atoi(s;str)
Function Convert decimal string into int type numerical value
Argument
s Decimal string
Return value int number
Discussion atoi("1234")=1234

Name atof/val
Format float atof(s;str)
float val(s;str)
Function Convert floating point notation string to float number.
It can also convert decimal string represented by &h, &b, &o.
Argument
s float notation string
Return value float value
Discussion atof("12.34E2")=1234#

Name str$
Format str str$(n;float)
Function Convert floating value to point notation string.
Argument
n float number
Return value float notation string

Name int
Format int int(n;float)
Function Truncate after the decimal point in the float numbers and return as data of type int.
This is not a variable declaration int, this is function int().
Argument
n float number
Return value int number

Name fix
Format float fix(n;float)
Function Truncate after the decimal point in the float number
Argument
n float number
Return value Result
Discussion fix(3.14)=3#

Name modf
Format float modf(n;float)
Function Get after the decimal point in the float number.
Argument
n float number
Return value Result
Discussion modf(3.14)=0.14

Name tolower
Format int tolower(c;int)
Function If c is uppercase , it returns c itself.
Otherwise it returns the code of lowercase letters corresponding to it.
Argument
c Character code
Return value Result
Discussion tolower('A')='a'
Note An alphabetic may come to the second byte of a 2-byte code in the SHIFT-JIS.
No problem in UTF8.

Name toupper
Format int toupper(c;int)
Function If c is lowercase , it returns c itself.
Otherwise it returns the code of uppercase letters corresponding to it.
Argument
c Character code
Return value Result
Discussion tolower('a')='A'
Note An alphabetic may come to the second byte of a 2-byte code in the SHIFT-JIS.
No problem in UTF8.

in
Name toascii
Format int toascii(c;int)
Function The code &h80 to &hff are converted to &h00 to &h7f.
Argument
c Character code
Return value Result
Discussion toascii(&hff)=&h7f

Name gcvt
Format str gcvt(f;float,n;int)
Function float number convert to a string of the specified number of digits.
Argument
f float number
n Number of significant digits.
(Number of digits to be displayed without the decimal point, minus sign is included.)
If there is no integer numeric value(=0),so it is processed by only the number of digits following the decimal point.
Return value conversion result string
Discussion
gcvt(12.3456,3)="12.3"
gcvt(12.3456,4)="12.35" Round off at ordered digit
gcvt(0.012345,4)="0.0123" There is no integer numeric value, so it is processed by only the number of digits following the decimal point.

Name ecvt
Format str ecvt(f;float,n;int,p;int,Sign;int)
Function float number convert to a string without sign and decimal point.
Argument
f float number
p Specify the number of digits in the string
Return valueConversion result string
p Decimal point position.
If you put a decimal point in the p-th bytes from the left edge of the result string, it will be the same as the original number.
Sign if f>=0 then Sign=0, if f<0 then Sign=1
For returning a value, p and Sign must be variable.
Discussion
ecvt( 12.3456,3,p,Sign)="123" p=2,Sign=0
ecvt(-12.3456,4,p,Sign)="1234" p=3,Sign=1
Note Difference between the ecvt() and fcvt() is p meaning.

Name fcvt
Format str fcvt(f;float,n;int,p;int,Sign;int)
Function float number convert to a string without sign and decimal point.
Argument
f float number
n Specify the number of decimal places in the string
Return valueConversion result string
p Decimal point position.
If you put a decimal point in the p-th bytes from the left edge of the result string, it will be the same as the original number.)
Sign if f>=0 then Sign=0, if f<0 then Sign=1
For returning a value, p and Sign must be variable.
Discussion
fcvt( 12.3456,2,p,Sign)="1234" p=2,Sign=0
fcvt(-12.3456,3,p,Sign)="12346" p=3,Sign=1
fcvt( 0.12345,2,p,Sign)="12" p=0,Sign=0
fcvt(-0.12345,2,p,Sign)="12" p=0,Sign=1
Note Difference between the fcvt() and ecvt() is p meaning.

Name strToArray
Format int strToArray(s;str,ary();char or int)
Function A string is decomposed to a byte and store it into one-dimensional array.
Also end of string code(EOS) is stored.
Argument
s The string that wants decomposition
ary Char or int array to store the decomposition results.
Also in the int array , byte code is entered in one element.
Return valueNumber of used element
If it can not fit in the number of elements, it returns the number of the array declaration.
Discussion dim int a(3)
strToArray("1A@",a) -> a(0)='1',a(1)='A',a(2)='@',a(3)=0
The return value is 4.

Name arrayToStr
Format int arrayToStr(ary();char or int,s;str)
Function To rebuild the string from bytes character code array which has been decomposed.
Argument
ary Char or int array with the byte character code that has been decomposed by the strToArray().
s (String variable to store ASCII string merging with byte data array from element(0) to element with EOS.
Return valuestrlen()
If it can not fit in the string, it returns maximum string length.

Name utf8ToArray
Format int utf8ToArray(s;str,ary();int)
Function A UTF8 string is decomposed to a character and store it into one-dimensional int array.
Also end of string code is stored.
Argument
s The UTF8 string that wants to decomposition.
ary Int array to store the decomposition results.
In the int array , one character code is entered in one element.
Return valueNumber of used element
If it can not fit in the number of elements, it returns the number of the array declaration.

Name arrayToUtf8
Format int arrayToUtf8(ary();int,s;str)
Function To rebuild the string from character code array which has been decomposed.
Argument
ary Int array with the character code that has been decomposed by the utf8ToArray().
s String variable to store UTF8 string merging with byte data array from element(0) to element with EOS.
Return valueutf8Len()
If it can not fit in the string ,it returns maximum string length.

Name sjisToArray
Format int sjisToArray(s;str,ary();int)
Function A SHIFT-JIS string is decomposed to a character and store it into one-dimensional int array.
Also end of string code is stored.
Argument
s The SHIFT-JIS string that wants to decomposition.
ary Int array to store the decomposition results.
In the int array , one character code is entered in one element.
Return value Number of used element.
If it can not fit in the number of elements, it returns the number of the array declaration.

Name arrayToSjis
Format int arrayToSjis(ary();int,s;str)
Function To rebuild the string from character code array which has been decomposed.
Argument
ary Int array with the character code that has been decomposed by the sjisToArray().
s String variable to store SHIFT-JIS string merging with byte data array from element(0) to element with EOS.
Return value sjisLen()
If it can not fit in the string ,it returns maximum string length.

Name hexstrToArray
Format int hexstrToArray(s;str,ary();char or int)
Function The hexadecimal string is converted into one byte code by each two-digit, and they are stored in one dimensional array.
Argument
s Two digits hexadecimal string
The ',' , '/' , '_' and space are ignored as separators.
When there was a character that can not be converted, it is up to that just before.
ary Char or int array to store the covert results.
Also in the int array , byte code is entered in one element.
Return value Number of used element.
If it can not fit in the number of elements, it returns the number of the array declaration.
Discussion dim int a(3)
hexstrToArray("0088FC",a) -> a(0)=&h00,a(1)=&h88,a(2)=&hFC
The return value is 3.



// Letter judgment functions

As the character code, to give one character of UTF8/SJIS/ASCII.
(It may not one byte.)
Otherwise it does not guarantee correct results.

Name iscntrl
Format int iscntrl(c;int)
Function Check whether the character code is <&h20 or &h7f.
Argument
c Character code
Return value
YES match
NO unmatch

Name isspace
Format int isspace(c;int)
Function Check whether the character code is blank character (&h09 to &h0d,&h20).
Argument
c Character code
Return value
YES match
NO unmatch

Name isascii
Format int isascii(c;int)
Function Check whether the character code is ASCII character (&h00 to &h7f).
Argument
c Character code
Return value
YES match
NO unmatch

Name ispunct
Format int ispunct(c;int)
Function Check whether the character code is printable Symbolic characters (&h20 to &h2f , &h3a to &h40 , &h5b to &h60 , &h70 to &h7e).
Argument
c Character code
Return value
YES match
NO unmatch

Name isalnum
Format int isalnum(c;int)
Function Check whether the character code is alphanumeric character (A to Z , a to z , 0 to 9).
Argument
c Character code
Return value
YES match
NO unmatch

Name isalpha
Format int isalpha(c;int)
Function Check whether the character code is alphabetic (A to Z , a to z).
Argument
c Character code
Return value
YES match
NO unmatch

Name isdigit
Format int isdigit(c;int)
Function Check whether the character code is number (0 to 9).
Argument
c Character code
Return value
YES match
NO unmatch

Name isgraph
Format int isgraph(c;int)
Function Check whether the character code is printable characters except the space (&h21 to &h7e).
Argument
c Character code
Return value
YES match
NO unmatch

Name islower
Format int islower(c;int)
Function Check whether the character code is lowercase (a to z).
Argument
c Character code
Return value
YES match
NO unmatch

Name isupper
Format int isupper(c;int)
Function Check whether the character code is uppercase (A to Z).
Argument
c Character code
Return value
YES match
NO unmatch

Name isprint
Format int isprint(c;int)
Function Check whether the character code is printable characters (&h20 to &h7e).
Argument
c Character code
Return value
YES match
NO unmatch

Name isxdigit
Format int isxdigit(c;int)
Function Check whether the character code is hexadecimal characters (0 to 9 , A to F , a to f).
Argument
c Character code
Return value
YES match
NO unmatch

Name iskanji1Sjis
Format iskanji1Sjis(c;int)
Function Check whether the first byte of the character of SHIFT-JIS 2byte code.
Argument
c 1byte code
Return value
YES match
NO unmatch

Name iskanji2Sjis
Format iskanji2Sjis(c;int)
Function Check whether the legitimate character as the second byte of byte SHIFT-JIS 2byte code.
Argument
c 1byte code
Return value
YES match
NO unmatch


// ASCII character string functions

Note
As how to specify a certain position in the string,
there are 2-ways : left edge is 0 (offset position) or left edge is 1 (counted by number of characters).
That according to the specifications X-BASIC/68.
The function in here is for ASCII code (except some one).

Name instr
Format int instr(pos;int,s;str,ss;str)
Function Find a ss of from string in the string s.
This is bytes sequence search, so it does not depend on the character code.
Argument
pos The position at which to begin searching(left edge is 1)
s Target string
ss Search string
Return value
>=1Found position(left edge is 1)
0Not found or pos<0

Name strchr
Format int strchr(s;str,c;char)
Function Looking for a byte from the string, it returns the position found for the first time.
Argument
s Target string
c Search character(1byte)
Return value
>=0Found position (left edge is 0)
-1Not found

Name strrchr
Format int strrchr(s;str,c;char)
Function Looking for a byte from the string, it returns the position found for the last time.
Argument
s Target string
c Search character(1byte)
Return value
>=0Found position (left edge is 0)
-1Not found

Name strcspn
Format int strcspn(s1;str,s2;str)
Function Returns the position found for the first time in any one byte of string s2 from string s1.
Argument
s1 Target string
s2 Search characters
Return valueFound position (left edge is 0)
If not found then return strlen(s1)

Name strspn
Format int strspn(s1;str,s2;str)
Function Returns the position not found for the first time in any one byte of string s2 from string s1.
Argument
s1 Target string
s2 Compare characters
Return valueFound position (left edge is 0)
If not found then return strlen(s1).
Return 0 if either string is empty string.

Name strtok
Format str strtok(s1;str,s2;str)
Function Retrieve sequentially sub-string from s1 by any one character in the s2 as a separator.
This means "retrieve a token from the from string".
When the first call, it ignore the characters in s2 consecutive from the beginning of s1.
Then, when you call to set to ""(or NULL$) s1, returns the next token.
When no character is found that is included in the s2, returns an empty string.
Argument
s1 Target string
s2 Separator strings
Return valueRetrieved string
When str2 = "" as it returns str1.
Discussion
tok=strtok(",,..123,456.ABC",",.") tok="123"
tok=strtok("",",.") tok="456"
tok=strtok("",",.") tok="ABC"
tok=strtok("",",.") tok="" Not found

Name space$
Format str space$(cnt;int)
Function Create a string with the repeated space
Argument
cnt repeat count
Exceeds the maximum string length is cut.
If you specify less than or equal to 0, returns an empty string.
Return valuegenerated string

Name string$
Format str string$(cnt;int,s;str)
Function Create a string with the repeated character which is the first byte of the string.
Argument
cnt repeat count
Exceeds the maximum string length is cut.
If you specify less than or equal to 0, returns an empty string.
s Target string
Return valuegenerated string

Name mirror$
Format str mirror$(s;str)
Function Make the string a sequence of bytes left and right were reversed.
Argument
s1 Target string
Return valuegenerated string

Name mid$
Format str mid$(s;str,pos;int,len;int)
Function Returns a string of len bytes from the position from the left of the string.
Argument
s1 Target string
pos Position to begin retrieving.
1 to strlen(s)
You get an empty string at the time of pos>strlen(s) or len<=0
len The number of the bytes to retrieve
-1 means all the rest
Return valueRetrieved string

Name left$
Format str left$(s;str,len;int)
Function Returns a string of len bytes from the left side of a string.
Argument
s Target string
len The number of the bytes to retrieve.
-1 means all the rest
Return valueRetrieved string

Name right$
Format str right$(s;str,len;int)
Function Returns a string of len bytes from the right side of a string.
Argument
s Target string
len The number of the bytes to retrieve.
-1 means all the rest
Return valueRetrieved string

Name strlen/len
Format int strlen(s;str)
int len(s;str)
Function Get the string length (bytes).
It is not include end of string code.
Argument
s Target string
Return valuebytes of string
if s="" then return 0

Name strnset
Format str strnset(s;str,c;char,len;int)
Function Replace len bytes from the beginning of the string by specified character.
Argument
ss Target string
String variable only (because rewriting the content directly.
c Replace character (ASCII code)
len The number of bytes to be replaced
Return valueResult s itself

Name strrev
Format str strrev(s;str)
Function Invert byte order of the string left to right.
Argument
s Target string
String variable only (because rewriting the content directly).
Return valueResult s itself
Note Difference between the mirror$() is that the contents of the argument s is reversed left and right directly.

Name strset
Format str strset(s;str,c;char)
Function Replace the entire string with the specified character.
Argument
s Target string String variable only (because rewriting the content directly).
c Replace character (ASCII code)
Return valueResult s itself

Name strupr
Format str strupr(s;str)
Function Convert letters lowercase to uppercase in the string.
Argument
s Target string String variable only (because rewriting the content directly).
Return valueResult s itself

Name strlwr
Format str strlwr(s;str)
Function Convert letters uppercase to lowercase in the string.
Argument
s Target string String variable only (because rewriting the content directly).
Return valueResult s itself

Name chrhex$
Format str chrhex$(s;str)
Function From the beginning of the string, convert ASCII character code to two-digit hexadecimal numeric string.
Argument
s Target string
Return valueresult string
Discussion chrhex$("Aa0") = "416130"

Name hexchr$
Format str hexchr$(s;str)
Function The hexadecimal string is converted into one byte ASCII code by each two-digit, and they will be a string.
Argument
s Two digits hexadecimal string
"00" is not able to convert (ignore).
The ',' , '/' , '_' and space are ignored as separators.
When there was a character that can not be converted, it is up to that just before.
Return valueresult string
Discussion hexchr$("416130") = "Aa0"
hexchr$("41006130") = "Aa0" :// because 00 is skipped

Name regcomp
Format int regcomp(src;str,reg;str[,mode;int][,sret;int][,eret;int])
Function Compare strings with regular expressions
Argument
src Compare target string
reg regular expressions(Extended expression support)
mode 1=ignore case
0=case sensitive(when omit)
Return value
NO unmatch
YES match
Below, the value is stored only when the match.
sret Return match position(left edge=0)
Match from the sret-th byte.
Need to specify the variable to return a value.
When this is omitted, no value is returned.
eret Return next of match area = Starting position the next compare.
Need to specify the variable to return a value.
When this is omitted, no value is returned.
Supplemental About extend regular expressions, please see here.
https://www.gnu.org/software/grep/manual/html_node/Regular-Expressions.html


// Character code conversion functions

This is a group of functions for string or character code also corresponding to the SHIFT-JIS or UTF8.

Name utf8ToSjis
Format int utf8ToSjis(utf8;int)
Function Convert a character code of UTF8 into a character code of SHIFT-JIS.
Argument
utf8 UTF8 character code
Return valueSHIFT-JIS character code
If you give a character code does not exist '※' is returned.

Name sjisToUtf8
Format int sjisToUtf8(sjis;int)
Function Convert a character code of SHIFT-JIS into a character code of UTF8.
Argument
sjis SHIFT-JIS character code
Return valueUTF8 character code
If you give a character code does not exist '※' is returned.

Name utf16ToSjis
Format int utf16ToSjis(c;int)
Function Converts a character code of UTF16 into a cord of SHIFT-JIS.
Argument
c UTF16 character code
Return valueSHIFT-JIS character cord

Name sjisToUtf16
Format int sjisToUtf16(c;int)
Function Converts a character code of SHIFT-JIS into a cord of UTF16.
Argument
c SHIFT-JIS character code
Return valueUTF16 character code

Name utf16ToUtf8
Format int utf16ToUtf8(c;int)
Function Convert a character code of UTF16 into a cord of UTF8.
Argument
c UTF16 character code
Return valueUTF8 character code

Name utf8ToUtf16
Format int utf8ToUtf16(c;int)
Function Converts a character code of UTF8 into a cord of UTF16.
Argument
c UTF8 character code
Return valueUTF16 character code

Name utf8ToSjis$
Format str utf8ToSjis$(utf8s;str,sjiss;str)
Function Convert UTF8 string into SHIFT-JIS string.
Argument
utf8s UTF8 string
sjiss SHIFT-JIS string (to store conversion result. must use variable)
Return valuesjiss itself

Name sjisToUtf8$
Format str sjisToUtf8$(sjiss;str,utf8s;str)
Function Convert SHIFT-JIS string into UTF8 string.
Argument
sjiss SHIFT-JIS string
utf8s UTF8 string (to store conversion result. must use variable)
Return valueutf8s itself

Name utf8Len
Format int utf8Len(utf8s;str)
Function Get the number of the letters in UTF8 string.
Argument
utf8s UTF8 string
Return valueletters
It is not the number of bytes.

Name sjisLen
Format int sjisLen(sjiss;str)
Function Get the number of the letters in SHIFT-JIS string.
Argument
sjiss SHIFT-JIS string
Return valueletters
It is not the number of bytes.

Name utf8StrWidth
Format int utf8StrWidth(mes;str)
Function Get the string width as width of double-byte characters is 2 and width of half-width characters is 1.
In UTF8, some half-width characters are multiple byte.
So this is primarily the function for obtaining the width of the display.
Argument
mes UTF8 string
Return value String width

Name sjisStrWidth
Format int sjisStrWidth(mes;str)
Function Get the string width as width of double-byte characters is 2 and width of half-width characters is 1.
X68000 has 1/2-width or 1/4-width characters in SHIFT-JIS code.
So this is primarily the function for obtaining the width of the display.
Argument
mes SHIFT-JIS string
Return value String width

Name utf8
Format int utf8(utf8s;str)
Function Return the character code of a character beginning UTF8 string.
Argument
utf8s UTF8 string
Return valuecharacter code (UTF8))

Name sjis
Format int sjis(sjiss;str)
Function Return the character code of a character beginning SHIFT-JIS string.
Argument
sjiss SHIFT-JIS string
Return valuecharacter code (SHIFT-JIS)

Name utf8String$
Format str utf8String$(cnt;int,utf8s;str)
Function Create a string with the repeated character which is the first letter of the UTF8 string.
Argument
cnt repeat count
Exceeds the maximum string length is cut.
If you specify less than or equal to 0, returns an empty string.
utf8s Target UTF8 string
Return valuegenerated string
Discussion utf8String$(5,"あいうえお") = "あああああ"

Name sjisString$
Format str sjisString$(cnt;int,sjiss;str)
Function Create a string with the repeated character which is the first letter of the SHIFT-JIS string.
Argument
cnt repeat count
Exceeds the maximum string length is cut.
If you specify less than or equal to 0, returns an empty string.
sjiss Target SHIFT-JIS string
Return valuegenerated string
Discussion sjisString$(5,"あいうえお") = "あああああ"

Name utf8Mirror$
Format str utf8Mirror$(utf8s;str)
Function Make the UTF8 string a sequence of characters left and right were reversed.
Argument
utf8s UTF8 string
Return valuegenerated string
Note mirror$() is inverted in bytes.
Thus, in UTF8 string can not get the correct results.

Name sjisMirror$
Format str sjisMirror$(sjiss;str)
Function Make the SHIFT-JIS string a sequence of characters left and right were reversed.
Argument
sjiss SHIFT-JIS string
Return valuegenerated string
Note mirror$() is inverted in bytes.
Thus, in SHIFT-JIS string can not get the correct results.

Name utf8Mid$
Format str utf8Mid$(utf8s;str,pos;int,len;int)
Function Returns a string of len characters from the pos character from the left of the string UTF8.
Argument
utf8s UTF8 string
pos Position to begin retrieving
1 to utf8Len(utf8s)
You get an empty string at the time of pos>utf8Len(utf8s) or len<=0
len The number of the letters to retrieve.
-1 means all the rest
Return valueRetrieved string

Name utf8Left$
Format str utf8Left$(utf8s;str,len;int)
Function Returns a string of len characters from the left side of a string UTF8.
Argument
utf8s UTF8 string
len The number of the letters to retrieve.
-1 means all the rest
Return valueRetrieved string

Name utf8Right$
Format str utf8Right$(utf8s;str,len;int)
Function Returns a string of len characters from the right side of a string UTF8.
Argument
utf8s UTF8 string
len The number of the letters to retrieve.
-1 means all the rest
Return valueRetrieved string

Name sjisMid$
Format str sjisMid$(sjiss;str,pos;int,len;int)
Function Returns a string of len characters from the pos character from the left of the string SHIFT-JIS.
Argument
sjiss SHIFT-JIS string
pos Position to begin retrieving.
1 to sjisLen(sjiss)
You get an empty string at the time of pos>sjisLen(sjiss) or len<=0
len The number of the letters to retrieve.
-1 means all the rest
Return valueRetrieved string

Name sjisLeft$
Format str sjisLeft$(sjiss;str,len;int)
Function Returns a string of len characters from the left side of a string SHIFT-JIS.
Argument
sjiss SHIFT-JIS string
len The number of the letters to retrieve.
-1 means all the rest
Return valueRetrieved string

Name sjisRight$
Format str sjisRight$(sjiss;str,len;int)
Function Returns a string of len characters from the right side of a string SHIFT-JIS.
Argument
sjiss SHIFT-JIS string
len The number of the letters to retrieve.
-1 means all the rest
Return valueRetrieved string

Name utf8Chr
Format int utf8Chr(utf8s;str)
Function Get one character code of top of UTF8 string.
Argument
utf8s UTF8 string
Return valueone character code of top of UTF8 string.

Name sjisChr
Format int sjisChr(sjiss;str)
Function Get one character code of top of SHIFT-JIS string.
Argument
sjiss SHIFT-JIS string
Return valueone character code of top of SHIFT-JIS string.

Name chars2Sjis
Format int chars2Sjis(c;int)
Function Continue to give in 1byte code, and it returns a established SHIFT-JIS character code.
Argument
c 1byte code
If you give 0 then it resets the byte sequence.
Return value
&hffffffffIt have not finished yet as a character.
anothercomplete SHIFT-JIS or ASCII code
Note If it contains malicious code as a sequence of SHIFT-JIS code, Its operation is not guaranteed.

Name chars2Utf8
Format int chars2Utf8(c;int)
Function Continue to give in 1byte code, and it returns a established UTF8 character code.
Argument
c 1byte code
If you give 0 then it resets the byte sequence.
Return value
&hffffffffIt have not finished yet as a character.
anothercomplete UTF8 code
Note If it contains malicious code as a sequence of UTF8 code, its operation is not guaranteed.

Name sjisHantozen
Format int sjisHantozen(asccode;int,mode;int)
Function Convert ASC character into SHIFT-JIS double-width character.
Argument
asccode ASC half-width character for converting
mode How to convert of kana character(&ha1 to &hdf)
0 convert to Katakana
1 convert to Hiragana
Return value converted SHIFT-JIS character

Name utf8Hantozen
Format int utf8Hantozen(asccode;int)
Function Convert ASC character into UTF8 double-width character.
This is not supported halh-width kana(because UTF8 does not have half-kana).
Argument
asccode ASC half-width character for converting
Return value converted UTF8 character

Name sjisZentohan
Format int sjisZentohan(code;int)
Function Convert SHIFT-JIS double-width character into ASC half-width character.
Argument
code SHIFT-JIS character for converting
Return value converted ASC character

Name utf8Zentohan
Format int utf8Zentohan(code;int)
Function Convert UTF8 double-width character into ASC half-width character.
This is not supported kana(because UTF8 does not have half-kana).
Argument
code UTF8 character for converting
Return value converted ASC character

Name sjisHantozens
Format str sjisHantozens(s;str,mode;int)
Function Convert ASC half-width character's string into SHIFT-JIS double-width character's string.
Argument
s ASC half-width character's string for converting
mode How to convert of kana character(&ha1 to &hdf)
0 convert to Katakana
1 convert to Hiragana
Return value converted SHIFT-JIS double-width character's string

Name utf8Hantozens
Format str utf8Hantozens(s;str)
Function Convert ASC half-width character's string into UTF8 double-width character's string.
This is not supported halh-width kana(because UTF8 does not have half-kana).
Argument
s ASC half-width character's string for converting
Return value converted UTF8 double-width character's string

Name sjisZentohans
Format str sjisZentohans(sjiss;str)
Function Convert SHIFT-JIS double-width character's string into ASC half-width character's string.
The double-width kana is converted to half-width kana.
Argument
sjiss SHIFT-JIS double-width character's string for converting
Return value converted ASC character's string

Name utf8Zentohans
Format str utf8Zentohans(utf8s;str)
Function Convert UTF8 double-width character's string into ASC half-width character's string.
The double-width kana is not converted to half-width kana(because UTF8 does not have half-width kana).
Argument
utf8s UTF8 double-width character's string for converting
Return value converted ASC character's string

Name isSjisHandaku
Format int isSjisHandaku(code;int)
Function Check whether specified double-width SHIFT-JIS character has dakuten or half-dakuten.
Argument
code SHIFT-JIS character for checking
Return value
0 normal character
1 dakuten character
2 half-dakuten character

Name isUtf8Handaku
Format int isUtf8Handaku(code;int)
Function Check whether specified double-width UTF8 character has dakuten or half-dakuten.
Argument
code UTF8 character for checking
Return value
0 normal character
1 dakuten character
2 half-dakuten character


// Mathematical operation functions

Name sin
Format float sin(n;float)
Function calculate trigonometric function sin.
Argument
n angle(The unit is radian)
Return valuecalculation result

Name cos
Format float cos(n;float)
Function calculate trigonometric function cos.
Argument
n angle(The unit is radian)
Return valuecalculation result

Name tan
Format float tan(n;float)
Function calculate trigonometric function tan.
Argument
n angle(The unit is radian)
Return valuecalculation result
Similarly, there are the inverse functions, hyperbolic functions, reverse hyperbolic functions.

    atan()      asin()      acos()
    sinh()      cosh()      tanh()
    asinh()     acosh()     atanh()
Name exp
Format float exp(n;float)
Function calculate the n-th power of e base of natural logarithms.
Argument
n float value
Return valuecalculation result

Name log
Format float log(n;float)
Function calculate a natural logarithm
Argument
n float value
limited n>0
Return valuefloat

Name log10
Format float log10(n;float)
Function calculate common logarithm
Argument
n float value
limited n>0
Return valuecalculation result

Name pi
Format float pi([n;float])
Function calculate a multiple of pi
Argument
n A multiple. Default is 1.
Return valuecalculation result

Name pow
Format float pow(x;float,y;float)
Function calculate the power
Argument
x,y y is limited to an integer in x<0.
In addition, in the case of x=0, y is limited >=0.
Return valuecalculation result

Name sqr
Format float sqr(n;float)
Function calculate the square root.
Argument
n float value>0
In the case of n<0, it becomes error.
Return valuecalculation result

Name abs
Format float abs(n;float)
Function Get absolute value of float number.
Argument
n float value
Return valueabsolute float value

Name iabs
Format int iabs(n;int)
Function Get absolute value of int number
Argument
n int value
Return valueabsolute int value

Name sgn
Format float sgn(n;float)
Function Get sign of float number.
Argument
n float value
Return value
1.0 n is plus(positive)
-1.0 n is minus(negative)
0.0 n equal 0.0

Name isgn
Format int isgn(n;int)
Function Get sign of int number.
Argument
n int value
Return value
1 n is plus(positive)
-1 n is minus(negative)
0 n equal 0

Name inc
Format int inc(n;int)
Function Get n+1 number.
Argument
n int variable.
n must be given by the variable for updating itself.
Return value n+1
Note You must not give array's element (because it is not regarded to int variable).

Name dec
Format int dec(n;int)
Function Get n-1 number.
Argument
n int variable.
n must be given by the variable for updating itself.
Return value n-1
Note You must not give array's element (because it is not regarded to int variable).

Name srand/randomize
Format srand(seed;int)
randomize(seed;int)
Function Initialize function rand() and rnd().
All functions are exactly same.
Argument
seed Initial value (called random seed)
-2147483648 to 2147483647
Return valueNone
Notes rand() and rnd() always returns same random number lines with values in the same seed.

Name rand
Format int rand([type;int])
Function Get integer random number from 0 to 2147483647.
Argument
type Generation method of the random number.
NO or Default Same as less than V3.00.
YES Use the sequence with more long period
Return valuerandom interger number
Note In X-BASIC/68, rand() returns 0 to 32767. If you want the same value range, you must write "(rand() mod 32728)".

Name rnd
Format float rnd([type;int])
Function Get float random number from 0.0 to less than 1.0.
Argument
type Generation method of the random number.
NO or Default Same as less than V3.00.
YES Use the sequence with more long period
Return valuerandom float number

Name isnan
Format int isnan(f;float)
Function Check float f is the Not a Number(NaN).
Argument
f float value
Return value
YES NaN
NO not NaN



// Other functions

Name sizeofArray
Format int sizeofArray(ary();any type,size1;int)
Function Get total count of elements and each element size of array.
Argument
ary int/char/float/str Array
size1 Return 1 element byte size.
For return value, it must be variable.
Return valueTotal count of elements

Name int6880
Format int int6880(num;int)
Function Alternate convert an int value the little endian format to big endian format.
Argument
num int number
Return value return an int converted number

Name float6880
Format float float6880(num;float)
Function Alternate convert an float value the little endian format to big endian format.
Argument
num float number
Return value return an float converted number

Name time
Format int time()
Function Returns the number of seconds elapsed since 1970/01/01 00:00:00.
Argument None
Return valueElapsed seconds

Name clock
Format int clock()
Function Get CPU time
Argument None
Return value CPU time.
It is back to 0 at overflow.
Note It become the approximate number of seconds divided this by constant CLOCKS_PER_SEC.
However, it does not become the constant intervals for some reason on iOS.
Therefore, do not match the time measured in other ways.
Thus, it should not be used for accurate time measurement.

Name bit
Format int bit(bt;int)
Function Returns the value of the specified bit is set to 1
Argument
bt bit number
0 to 31
Return value Substantially (1 shl bt)
Note Constant BIT0 to BIT31 is defined in startup.bas



// System variable / System functions

The system variable is constant or variable value that has system.

Constant NameYES/true
Type int
Value Truth value
Note This is enum constant value. So this is able to use for case value.

Constant NameNO/false
Type int
Value False value
Note This is enum constant value. So this is able to use for case value.

Variable Namedate$
Type str
Value Current date string ("YYYY/MM/DD").

Variable Nameday$
Type str
Value Current weekday string.

Variable Nametime$
Type str
Value Current time string ("hh:mm:ss").

Variable NameNULL$
Type str
Value Empty string ("")

Variable Nameerrno
Type int
Function Return the error number in external function that occurred just before.
It does not have many meanings in the current version.
(As same as X-BASIC/68.)

Name basicVersion$
Type str
Value The version string of X-BASIC' system.

Name basicCoreVersion$
Type str
Value The version string of X-BASIC' language core.

Name iOSInterfaceVersion$
Type str
Value The version string of X-BASIC' interface.

The following are system functions. So these need () after its name.
Name versionXBfilefunc$
Format str versionXBfilefunc$()
Function Return the version string of the file system function.
Argument None
Return value The version string of the file system function

Name versionXBfunc$
Format str versionXBfunc$()
Function Return the version of the standard function.
Argument None
Return value The version string of the standard function

Name versionXBfunc2$
Format str versionXBfunc2$()
Function Return the version of the expansion function.
Argument None
Return value The version string of the expansion function


Supplement
Summary of the functions involved in the character code
ASC only UTF8 only SHIFT-JIS only Function
mid$ utf8Mid$ sjisMid$ get substring
left$ utf8Left$ sjisLeft$ get substring from left edge
right$ utf8Right$ sjisRight$ get substring from right edge
mirror$ utf8Mirror$ sjisMirror$ reverse string
string$ utf8String$ sjisString$ fill string with first byte
len utf8Len sjisLen get string length
To be precise, len() returns bytes.
Therefore, it can be used for UTF8/SHIFT-JIS string.
utf8StrWidth sjisStrWidth get string width
asc utf8 sjis get first byte of the string
       
strchr utf8Chr sjisChr search character in string
arrayToStr arrayToUtf8 arrayToSjis convert array to string
strToArray utf8ToArray sjisToArray convert string to array
chr$ utf8Chr$ sjisChr$ get specified code character
chr$() can use for UTF8.
In addition, in the forced SHIFT-JIS mode, chr$() can be used even SHIFT-JIS.
       
× sjisHantozen utf8Hantozen Convert ASC character to double-width character.
× sjisZentohan utf8Zentohan Convert double-width character to ASC character.
× sjisHantozens utf8Hantozens Convert ASC character's string to double-width character's string.
× sjisZentohans utf8Zentohans Convert double-width character's string to ASC character's string.
× isSjisHandaku isUtf8Handaku Check whether specified double-width character has dakuten or half-dakuten.
       
strcspn As long as the string2 which is consisting by ASCII code only, it also supports UTF8. × Returns the position found for the first time in any one byte of string s2 from string s1.
strspn As long as the string2 which is consisting by ASCII code only, it also supports UTF8. × Returns the position not found for the first time in any one byte of string s2 from string s1.
strtok As long as the string2 which is consisting by ASCII code only, it also supports UTF8. × get token
strlwr <- × covert uppercase to lowercase
strupr <- × convert lowercase to uppercase
       
strrchr × × Looking for a byte from the string, it returns the position found for the last time.
strset × × Replace the entire string with the specified character.
strnset × × Replace len bytes from the beginning of the string by specified character.
strrev × × reverse byte order

Alternating conversion of each character code
UTF16 -> UTF8 -> SHIFT-JIS -> UTF16  
  utf16ToUtf8   utf8ToSjis   sjisToUtf16   character code
  None   utf8ToSjis$   None   string
  <-   <-   <-    
  utf8ToUtf16   sjisToUtf8   utf16ToSjis   character code
  None   sjisToUtf8$   None   string


All statement/function/constant/variable list (alphabetical order)

Type list
External functions


Copyright (C) 2012-16 by AIG-Soft