I've already try to get this running but get stuck on the example (after call interface line).
It doesn't create any file on c:\bigtest.txt
What am I doing wrong?
;============================================================
; Script Name: TrailMyx's Advanced File System Handling Subs
; Author: TrailMyx
; Version: 1.3
; Shard OSI / FS: Any
; Revision Date: 10/20/2007
; Purpose:
; Simplify the saving of variables to a file. Also to speed up the process
; by minimizing the number times calls to the shell are issued. A maximum of
; 2000 bytes are assigned to each shell call, with an unlimited amount of calls
; possible. It's easy to store 1000's of variables in a relatively short period
; of time.
;
; This set of functions will also handle any namespace (local, global, immediate)!
; Also, this file is ready to be 'called'.
;
; Limitations:
; You cannot store spaces to a file due to the way DOS handles the command line.
; So if a space is found, it will be converted to an underscore '_'
;
; Functions:
; TM_FileSystem_CreateFileHandle
; -- ex. gosub TM_FileSystem_CreateFileHandle handle1
; TM_FileSystem_SaveVariable
; -- ex. gosub TM_FileSystem_SaveVariable local std handle1 testval ; note not to include the '%' or '!' for variable
; TM_FileSystem_SaveFile
; -- ex. gosub TM_FileSystem_SaveFile handle1 c:\bigtest.txt
; TM_FileSystem_LoadFile
; -- ex. gosub TM_FileSystem_LoadFile c:\bigtest.txt
; TM_FileSystem_SaveArray
; -- ex. gosub TM_FileSystem_SaveArray local ns1 handle ns1_test 10 20
;
; Support functions:
; TM_ReadVariables
; AddUnderscore
; AddSpace
;
;============================================================
; Revision History:
; v1.0 - Initial release.
; v1.1 - 5/16/2007 - Added support for array saving TM_SaveArray.
; v1.2 - Much faster load times.
; v1.3 - Much faster save preparation, fixed a bug in load pointer, added call handler
;=================================================================
;------------------------ Call interface -----------------------
;=================================================================
set #LPC 10000
for %i 0 1000
set %test . %i %i * 100
gosub TM_FileSystem_CreateFileHandle NULL handle1 ; clear handle named 'handle1'
for %i 0 1000
{
gosub TM_FileSystem_SaveVariable NULL local std handle1 test , %i ; store %test0, %test1, %test2, etc.
}
gosub TM_FileSystem_SaveFile NULL handle1 c:\bigtest.txt ; save the file
halt
set !TM_FunctionCalled #FALSE
if %0 = 1
gosub %1
if %0 = 2
gosub %1 %2
if %0 = 3
gosub %1 %2 %3
if %0 = 4
gosub %1 %2 %3 %4
if %0 = 5
gosub %1 %2 %3 %4 %5
if %0 = 6
gosub %1 %2 %3 %4 %5 %6
if %0 = 7
gosub %1 %2 %3 %4 %5 %6 %7
if %0 = 8
gosub %1 %2 %3 %4 %5 %6 %7 %8
if %0 = 9
gosub %1 %2 %3 %4 %5 %6 %7 %8 %9
if %0 = 10
gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10
if %0 = 11
gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11
if %0 > 11
{
display ok Too many arguments for "call", edit file.
stop
}
if !TM_FunctionCalled = #TRUE
exit
if %0 = N/A
display ok You may not run this script directly.
else
display ok Function " , %1 , " not found.
stop
;================================ File System ==================================
;-------------------------------------------------------------------------------
; %1 - Name of file handle name to create
sub TM_FileSystem_CreateFileHandle
namespace push
namespace local TM_FileSystem
set !ptr %1 , _ptr ; {userhandle}_ptr
set ! . !ptr 0 ; !{userhandle}_ptr (actual pointer)
set !handle ! . !ptr
set !handle %1 , !handle
set ! . !handle ; assume new variable
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 = namespace location (local, global)
; %2 = namespace name
; %3 = file handle name
; %4 = variable name
sub TM_FileSystem_SaveVariable
namespace push
namespace local TM_FileSystem
set !ns_loc %1
set !ns_name %2
set !handle %3
set !var %4
set !sep
set !temp_LPC #LPC
set #LPC 1000
if !handle = handle
set !handle __ , handle
set !ptr !handle , _ptr ; {userhandle}_ptr
set !handle_copy !handle
if ! . !ptr = N/A
{
set ! . !ptr 0 ; !{userhandle}_ptr (actual pointer)
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy ; assume new variable
}
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
if !ns_loc = local && !ns_name = std
set !value % . !var
else
{
namespace copy !var from !ns_loc !ns_name
set !value ! . !var
}
gosub AddUnderscore !value ; must not have spaces in stored variables!!!
set ! . !handle_copy ! . !handle_copy , !ns_loc , !sep , !ns_name , !sep , !var , !sep , #RESULT , !sep
str len ! . !handle_copy
if #STRRES > 2000
{
set !len #STRRES
str left ! . !handle_copy 2000
set !temp #STRRES
str del ! . !handle_copy 1 2000
set ! . !handle_copy !temp
set ! . !ptr ! . !ptr + 1
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy #STRRES
}
set !value
set !temp
set #LPC !temp_LPC
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 = namespace location (local, global)
; %2 = namespace name
; %3 = file handle name
; %4 = array name
; %5 = starting index
; %6 = ending index
sub TM_FileSystem_SaveArray
namespace push
namespace local TM_FileSystem
set !temp_LPC #LPC
set #LPC 10000
set !ns_loc %1
set !ns_name %2
set !handle %3
set !var %4
set !start_index %5
set !end_index %6
set !sep
if !handle = handle
set !handle __ , handle
set !ptr !handle , _ptr ; {userhandle}_ptr
set !handle_copy !handle
if ! . !ptr = N/A
{
set ! . !ptr 0 ; !{userhandle}_ptr (actual pointer)
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy ; assume new variable
}
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
for !i !start_index !end_index
{
if !ns_loc = local && !ns_name = std
{
set !newvar !var , !i
set !value % . !newvar
}
else
{
set !newvar !var , !i
namespace copy !newvar from !ns_loc !ns_name
set !value ! . !newvar
}
gosub AddUnderscore !value ; must not have spaces in stored variables!!!
set ! . !handle_copy ! . !handle_copy , !ns_loc , !sep , !ns_name , !sep , !newvar , !sep , #RESULT , !sep
str len ! . !handle_copy
if #STRRES > 2000
{
set !len #STRRES
str left ! . !handle_copy 2000
set !temp #STRRES
str del ! . !handle_copy 1 2000
set ! . !handle_copy !temp
set ! . !ptr ! . !ptr + 1
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy #STRRES
}
}
set !value
set !temp
set #LPC !temp_LPC
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 = file handle name
; %2 = file name
sub TM_FileSystem_SaveFile
namespace push
namespace local TM_FileSystem
set !temp_LPC #LPC
set #LPC 10000
set !LINE_LENGTH 2000 ; near DOS maximum
set !handle %1
set !filename %2
if !handle = handle
set !handle __ , handle
set !ptr !handle , _ptr ; {userhandle}_ptr
for !i 0 ! . !ptr
{
set !handle_copy !handle , !i
set !str ! . !handle_copy
if !i = 0
execute cmd.exe /c echo set , #spc , ! , fileout , !i , #spc , !str > !filename
else
execute cmd.exe /c echo set , #spc , ! , fileout , !i , #spc , !str >> !filename
}
set #LPC !temp_LPC
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 - file line variable
sub TM_ReadVariables
set !temp %1
set !fileoutindex 0
set !fileout !fileout0
TM_ReadVariables_loop1:
gosub ReadItem ns_loc
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
gosub ReadItem ns_name
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
gosub ReadItem var
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
gosub ReadItem value
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
if !ns_loc in local_LOCAL && !ns_name in std_STD
set % . !var !value
else
{
set ! . !var !value
namespace copy !var to !ns_loc !ns_name
}
goto TM_ReadVariables_loop1
TM_ReadVariables_skip1:
return
;-------------------------------------------------------------------------------
; Passes %fileout(n) as local, #RESULT
sub ReadItem
str pos !fileout
if #STRRES = 0
{
set !fileoutindex !fileoutindex + 1
if !fileout . !fileoutindex <> N/A
{
set !fileout !fileout , !fileout . !fileoutindex
str pos !fileout
}
else
{
return #TRUE
}
}
set !len #STRRES - 1
str left !fileout !len
set ! . %1 #STRRES
set !len !len + 1
str del !fileout 1 !len
set !fileout #STRRES
return #FALSE
;-------------------------------------------------------------------------------
; %2 - file name
sub TM_FileSystem_LoadFile
namespace push
namespace local TM_FileSystem
set !lpc #LPC
set #LPC 10000
set !filename %1
for !i 0 1000
set !fileout . !i N/A
call !filename
if !fileout0 = N/A
{
set #LPC !lpc
namespace pop
set !TM_Function_found #TRUE
return #TRUE ; error
}
set !index 0
gosub TM_ReadVariables ; assumes namespace TM_FileSystem
set #LPC !lpc
namespace pop
set !TM_Function_found #TRUE
return #FALSE
;-------------------------------------------------------------------------------
; %1 - string to mung
sub AddUnderscore
namespace push
namespace local AU
set !tempstring %1
AddUnderscore_loop1:
str pos !tempstring #SPC
if #STRRES <> 0
{
set !val #STRRES - 1
str left !tempstring !val
set !left #STRRES
set !val !val + 1
str del !tempstring 1 !val
set !tempstring !left , _ , #STRRES
goto AddUnderscore_loop1
}
set #RESULT !tempstring
namespace pop
return #RESULT
;-------------------------------------------------------------------------------
; %1 - string to mung
sub AddSpace
namespace push
namespace local AS
set !tempstring %1
AddSpace_loop1:
str pos !tempstring _
if #STRRES <> 0
{
set !val #STRRES - 1
str left !tempstring !val
set !left #STRRES
set !val !val + 1
str del !tempstring 1 !val
set !tempstring !left , #SPC , #STRRES
goto AddSpace_loop1
}
set #RESULT !tempstring
namespace pop
return #RESULT