From 8f294a82bae1d4c4930a5736d3dd6433f39e14d7 Mon Sep 17 00:00:00 2001 From: SMcNeill Date: Sun, 20 Jul 2014 17:34:28 -0400 Subject: [PATCH] Adding _BLINEINPUT for an alternative to LINE INPUT, which seems much faster. --- .../c/User Mods/Steve Stuff/file_access.cpp | 41 +++++++++++++++++++ internal/c/User Mods/Steves_Main-List.cpp | 1 + internal/c/User Mods/steve_mods.h | 3 +- .../extensions/Steve Stuff-ID_Includes.bas | 10 +++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 internal/c/User Mods/Steve Stuff/file_access.cpp diff --git a/internal/c/User Mods/Steve Stuff/file_access.cpp b/internal/c/User Mods/Steve Stuff/file_access.cpp new file mode 100644 index 000000000..ba8abaa38 --- /dev/null +++ b/internal/c/User Mods/Steve Stuff/file_access.cpp @@ -0,0 +1,41 @@ +void sub__getinput(int32 filehandle, qbs *deststr) { + if (new_error) return; + int32 filebuf_size = 512; + qbs *eol; + gfs_file_struct *gfs; + int32 fileno; + + if (gfs_fileno_valid(filehandle)!=1){error(52); return;}//Bad file name or number + fileno=gfs_fileno[filehandle];//convert fileno to gfs index + gfs=&gfs_file[fileno]; + if (gfs->type!=2){error(54); return;}//Bad file mode + if (!gfs->read){error(75); return;}//Path/file access error + + eol = qbs_new_txt_len("\n", 1); + + int64 start_byte = func_seek(filehandle); + if (start_byte + filebuf_size > func_lof(filehandle)) filebuf_size = func_lof(filehandle) - start_byte; + if (start_byte > func_lof(filehandle)) { + error(62);//input past end of file + return; + } + qbs *buffer = qbs_new(filebuf_size, 0); + qbs_set(deststr, qbs_new_txt_len("", 0)); + do { + + sub_get2(filehandle, start_byte, buffer, 1); + int32 eol_pos = func_instr(0, buffer, eol, 0); + if (eol_pos == 0) { + start_byte += filebuf_size; + qbs_set(deststr, qbs_add(deststr, buffer)); + } + else { + start_byte += eol_pos - 1; + qbs_set(deststr, qbs_add(deststr, qbs_left(buffer, eol_pos - 1))); + break; + } + } while (!func_eof(filehandle)); + if (deststr->chr[deststr->len - 1] == '\r') qbs_set(deststr, qbs_left(deststr, deststr->len-1)); + sub_seek(filehandle, start_byte + eol->len); + qbs_free(buffer); +} \ No newline at end of file diff --git a/internal/c/User Mods/Steves_Main-List.cpp b/internal/c/User Mods/Steves_Main-List.cpp index 44e38fb09..0be84cc07 100644 --- a/internal/c/User Mods/Steves_Main-List.cpp +++ b/internal/c/User Mods/Steves_Main-List.cpp @@ -1,3 +1,4 @@ #include "Steve Stuff/convert_angle.cpp" #include "Steve Stuff/pi.cpp" #include "Steve Stuff/screeninfo.cpp" +#include "Steve Stuff/file_access.cpp" diff --git a/internal/c/User Mods/steve_mods.h b/internal/c/User Mods/steve_mods.h index 182bd2f17..e97f48899 100644 --- a/internal/c/User Mods/steve_mods.h +++ b/internal/c/User Mods/steve_mods.h @@ -15,4 +15,5 @@ extern double func_grad2deg(double degree); extern double func_grad2rad(double degree); extern double func_pi(); extern int32 func_screenwidth(); -extern int32 func_screenheight(); \ No newline at end of file +extern int32 func_screenheight(); +void sub__getinput(int32 filehandle, qbs *deststr); \ No newline at end of file diff --git a/source/subs_functions/extensions/Steve Stuff-ID_Includes.bas b/source/subs_functions/extensions/Steve Stuff-ID_Includes.bas index e691633e6..45dfb7191 100644 --- a/source/subs_functions/extensions/Steve Stuff-ID_Includes.bas +++ b/source/subs_functions/extensions/Steve Stuff-ID_Includes.bas @@ -194,3 +194,13 @@ id.n = "_SCREENICON" 'name change to from _ICONIFYWINDOW to _SCREENICON to m id.subfunc = 2 id.callname = "glutIconifyWindow" regid + +clearid +id.n = "_BLINEINPUT" +id.subfunc = 2 +id.callname = "sub__getinput" +id.args = 2 +id.specialformat = "[#]?,?" +id.arg = MKL$(LONGTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) +regid +