MODULE T
DECLARE SUB ::md5 ALIAS "md5fun" LIB "t"
DECLARE COMMAND ::ArrayToString ALIAS "serialize" LIB "t"
DECLARE COMMAND ::ArrayToXML ALIAS "xmlserialize" LIB "t"
DECLARE SUB ::StringToArray ALIAS "unserialize" LIB "t"
DECLARE COMMAND ::Array2String ALIAS "serialize" LIB "t"
DECLARE COMMAND ::Array2XML ALIAS "xmlserialize" LIB "t"
DECLARE SUB ::String2Array ALIAS "unserialize" LIB "t"
DECLARE COMMAND ::ArrayToStringMD5 ALIAS "md5serialize" LIB "t"
DECLARE SUB ::StringToArrayMD5 ALIAS "md5unserialize" LIB "t"
DECLARE COMMAND ::Array2StringMD5 ALIAS "md5serialize" LIB "t"
DECLARE SUB ::String2ArrayMD5 ALIAS "md5unserialize" LIB "t"
DECLARE SUB ::SaveString ALIAS "savestring" LIB "t"
DECLARE SUB ::LoadString ALIAS "loadstring" LIB "t"
DECLARE SUB ::Exit ALIAS "toolExit" LIB "t"
SUB merge(left_side, right_side, result)
LOCAL left_size, left_ptr, right_size, right_ptr, result_ptr
left_size = UBOUND(left_side)
left_ptr = 0
right_size = UBOUND(right_side)
right_ptr = 0
result_ptr = 0
WHILE left_ptr <= left_size AND right_ptr <= right_size
IF left_side[left_ptr] <= right_side[right_ptr] THEN
result[result_ptr] = left_side[left_ptr]
left_ptr += 1
result_ptr += 1
ELSE
result[result_ptr] = right_side[right_ptr]
right_ptr += 1
result_ptr += 1
END IF
WEND
WHILE left_ptr <= left_size
result[result_ptr] = left_side[left_ptr]
left_ptr += 1
result_ptr += 1
WEND
WHILE right_ptr <= right_size
result[result_ptr] = right_side[right_ptr]
right_ptr += 1
result_ptr += 1
WEND
END SUB
SUB sort(unsorted)
LOCAL left_side, right_side, the_middle, array_size, result, x, y, z
array_size = UBOUND(unsorted)
IF array_size = 0 THEN
EXIT SUB
END IF
the_middle = FIX((array_size + 1) / 2)
y = 0
FOR x = 0 TO the_middle - 1
left_side[y] = unsorted[x]
y += 1
NEXT
z = 0
FOR x = the_middle TO array_size
right_side[z] = unsorted[x]
z += 1
NEXT
sort(left_side)
sort(right_side)
merge(left_side, right_side, result)
unsorted = result
END SUB
END MODULE