mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-07 16:30:18 +00:00
Simplebuffers refactoring
Implements the latest refactoring changes done in my Simplebuffers library.
This commit is contained in:
parent
74b0c80fe3
commit
7d66a171bc
2 changed files with 27 additions and 23 deletions
|
@ -1,8 +1,9 @@
|
||||||
This is a massively reduced version of "The Simplebuffer System" library
|
This is a massively reduced version of "The Simplebuffer System" library
|
||||||
by RhoSigma. The full package with many more functions for bookmarking,
|
by RhoSigma. The full package with many more functions for bookmarking,
|
||||||
searching, copy'n'paste and EOL conversion, inclusive documentation and
|
searching, copy'n'paste and EOL conversion, inclusive documentation and
|
||||||
examples can be downloaded from the respective forum post here:
|
examples is part of the author's "Libraries Collection" and can be found
|
||||||
https://qb64phoenix.com/forum/showthread.php?tid=486
|
for download at the respective forum thread here:
|
||||||
|
https://qb64phoenix.com/forum/forumdisplay.php?fid=23
|
||||||
|
|
||||||
Note: The sb_qb64_extension.bi/.bm files are not part of the buffer system.
|
Note: The sb_qb64_extension.bi/.bm files are not part of the buffer system.
|
||||||
These files provide glue code for use of the system inside qb64pe.
|
These files provide glue code for use of the buffers inside qb64pe.
|
||||||
|
|
|
@ -18,13 +18,13 @@ buf& = 0: CreateBuf% = SBE_NoMoreBuffers
|
||||||
WHILE buf& < aub&
|
WHILE buf& < aub&
|
||||||
IF simplebuffer_array$(buf& + 1) = "" THEN EXIT WHILE
|
IF simplebuffer_array$(buf& + 1) = "" THEN EXIT WHILE
|
||||||
buf& = buf& + 106
|
buf& = buf& + 106
|
||||||
IF buf& >= 3473408 THEN EXIT FUNCTION '=> allow max. 32768 buffers
|
IF buf& >= 3473090 THEN EXIT FUNCTION '=> allow max. 32765 buffers
|
||||||
WEND
|
WEND
|
||||||
'--- expand array, if necessary ---
|
'--- expand array, if necessary ---
|
||||||
IF aub& < buf& + 105 THEN REDIM _PRESERVE simplebuffer_array$(0 TO buf& + 10599) 'extend by 100 buffers
|
IF aub& < buf& + 105 THEN REDIM _PRESERVE simplebuffer_array$(0 TO buf& + 10599) 'extend by 100 buffers
|
||||||
'--- init buffer ---
|
'--- init buffer ---
|
||||||
simplebuffer_array$(buf& + 0) = SPACE$(10000) ' => the actual buffer
|
simplebuffer_array$(buf& + 0) = SPACE$(16384) ' => the actual buffer (will grow as needed)
|
||||||
simplebuffer_array$(buf& + 1) = MKL$(1) + MKL$(0) + "EolU" + MKL$(-1) '=> cursor position + buffer length + EOL mode + changed state
|
simplebuffer_array$(buf& + 1) = MKL$(1) + MKL$(0) + "EolU" + MKL$(-1) '=> cursor position + buffer length + EOL mode + change state
|
||||||
'--- return new handle ---
|
'--- return new handle ---
|
||||||
CreateBuf% = buf& \ 106
|
CreateBuf% = buf& \ 106
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
@ -42,31 +42,33 @@ END SUB
|
||||||
'---------------------------------------------------------------------
|
'---------------------------------------------------------------------
|
||||||
SUB BufToFile (handle%, fileSpec$)
|
SUB BufToFile (handle%, fileSpec$)
|
||||||
'--- option _explicit requirements ---
|
'--- option _explicit requirements ---
|
||||||
DIM buf&, ff%, op$
|
DIM buf&, ff%, dat$
|
||||||
'--- write file (overwrite existing !!!) ---
|
'--- write file (overwrite existing !!!) ---
|
||||||
buf& = handle% * 106
|
buf& = handle% * 106
|
||||||
ff% = FREEFILE: op$ = LEFT$(simplebuffer_array$(buf& + 0), GetBufLen&(handle%))
|
ff% = FREEFILE: dat$ = LEFT$(simplebuffer_array$(buf& + 0), GetBufLen&(handle%))
|
||||||
OPEN fileSpec$ FOR OUTPUT LOCK WRITE AS ff%: CLOSE ff%
|
OPEN fileSpec$ FOR OUTPUT LOCK WRITE AS ff%: CLOSE ff%
|
||||||
OPEN fileSpec$ FOR BINARY LOCK WRITE AS ff%
|
OPEN fileSpec$ FOR BINARY LOCK WRITE AS ff%
|
||||||
PUT ff%, , op$
|
PUT ff%, , dat$
|
||||||
CLOSE ff%
|
CLOSE ff%
|
||||||
'--- set state ---
|
'--- reset change state ---
|
||||||
MID$(simplebuffer_array$(buf& + 1), 13, 4) = MKL$(0)
|
MID$(simplebuffer_array$(buf& + 1), 13, 4) = MKL$(0)
|
||||||
END SUB
|
END SUB
|
||||||
|
|
||||||
'---------------------------------------------------------------------
|
'---------------------------------------------------------------------
|
||||||
SUB WriteBufLine (handle%, text$)
|
SUB WriteBufLine (handle%, text$)
|
||||||
'--- option _explicit requirements ---
|
'--- option _explicit requirements ---
|
||||||
DIM buf&, cur&, txl&, brc$, brl%, cbl&&, chg&
|
DIM buf&, cur&, txl&, brc$, brl%, cbl&&, chg&, bsz&, ext&
|
||||||
'--- prepare values ---
|
'--- prepare values ---
|
||||||
buf& = handle% * 106
|
buf& = handle% * 106
|
||||||
cur& = GetBufPos&(handle%): txl& = LEN(text$)
|
cur& = GetBufPos&(handle%): txl& = LEN(text$)
|
||||||
brc$ = BufEolSeq$(handle%): brl% = LEN(brc$)
|
brc$ = BufEolSeq$(handle%): brl% = LEN(brc$)
|
||||||
cbl&& = GetBufLen&(handle%): chg& = txl& + brl%
|
cbl&& = GetBufLen&(handle%): chg& = txl& + brl%
|
||||||
'--- check buffer length ---
|
'--- adjust buffer length ---
|
||||||
WHILE cbl&& + chg& > LEN(simplebuffer_array$(buf& + 0))
|
bsz& = LEN(simplebuffer_array$(buf& + 0)): ext& = 0
|
||||||
simplebuffer_array$(buf& + 0) = simplebuffer_array$(buf& + 0) + SPACE$(10000)
|
WHILE cbl&& + chg& > bsz& + ext&: ext& = ext& + 16384: WEND
|
||||||
WEND
|
IF ext& > 0 THEN
|
||||||
|
simplebuffer_array$(buf& + 0) = simplebuffer_array$(buf& + 0) + SPACE$(ext&)
|
||||||
|
END IF
|
||||||
'--- write into buffer ---
|
'--- write into buffer ---
|
||||||
MID$(simplebuffer_array$(buf& + 0), cur&) = text$ + brc$ + MID$(simplebuffer_array$(buf& + 0), cur&, cbl&& - cur& + 1)
|
MID$(simplebuffer_array$(buf& + 0), cur&) = text$ + brc$ + MID$(simplebuffer_array$(buf& + 0), cur&, cbl&& - cur& + 1)
|
||||||
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(cur& + chg&)
|
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(cur& + chg&)
|
||||||
|
@ -90,21 +92,22 @@ END FUNCTION
|
||||||
'---------------------------------------------------------------------
|
'---------------------------------------------------------------------
|
||||||
SUB WriteBufRawData (handle%, rawData$)
|
SUB WriteBufRawData (handle%, rawData$)
|
||||||
'--- option _explicit requirements ---
|
'--- option _explicit requirements ---
|
||||||
DIM buf&, cur&, rdl&, cbl&&
|
DIM buf&, cur&, rdl&, cbl&&, bsz&, ext&
|
||||||
'--- prepare values ---
|
'--- prepare values ---
|
||||||
buf& = handle% * 106
|
buf& = handle% * 106
|
||||||
cur& = GetBufPos&(handle%): rdl& = LEN(rawData$)
|
cur& = GetBufPos&(handle%): rdl& = LEN(rawData$)
|
||||||
cbl&& = GetBufLen&(handle%)
|
cbl&& = GetBufLen&(handle%)
|
||||||
'--- check buffer length ---
|
'--- adjust buffer length ---
|
||||||
WHILE cbl&& + rdl& > LEN(simplebuffer_array$(buf& + 0))
|
bsz& = LEN(simplebuffer_array$(buf& + 0)): ext& = 0
|
||||||
simplebuffer_array$(buf& + 0) = simplebuffer_array$(buf& + 0) + SPACE$(10000)
|
WHILE cbl&& + rdl& > bsz& + ext&: ext& = ext& + 16384: WEND
|
||||||
WEND
|
IF ext& > 0 THEN
|
||||||
|
simplebuffer_array$(buf& + 0) = simplebuffer_array$(buf& + 0) + SPACE$(ext&)
|
||||||
|
END IF
|
||||||
'--- write into buffer ---
|
'--- write into buffer ---
|
||||||
MID$(simplebuffer_array$(buf& + 0), cur&) = rawData$ + MID$(simplebuffer_array$(buf& + 0), cur&, cbl&& - cur& + 1)
|
MID$(simplebuffer_array$(buf& + 0), cur&) = rawData$ + MID$(simplebuffer_array$(buf& + 0), cur&, cbl&& - cur& + 1)
|
||||||
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(cur& + rdl&)
|
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(cur& + rdl&)
|
||||||
MID$(simplebuffer_array$(buf& + 1), 5, 4) = MKL$(cbl&& + rdl&)
|
MID$(simplebuffer_array$(buf& + 1), 5, 4) = MKL$(cbl&& + rdl&)
|
||||||
IF rdl& > 0 THEN
|
IF rdl& > 0 THEN
|
||||||
MID$(simplebuffer_array$(buf& + 1), 9, 4) = "EolU"
|
|
||||||
MID$(simplebuffer_array$(buf& + 1), 13, 4) = MKL$(-1)
|
MID$(simplebuffer_array$(buf& + 1), 13, 4) = MKL$(-1)
|
||||||
END IF
|
END IF
|
||||||
END SUB
|
END SUB
|
||||||
|
@ -132,7 +135,7 @@ IF newPos& < 1 OR newPos& > eob& THEN
|
||||||
SeekBuf& = SBE_OutOfBounds
|
SeekBuf& = SBE_OutOfBounds
|
||||||
ELSE
|
ELSE
|
||||||
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(newPos&)
|
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(newPos&)
|
||||||
SeekBuf& = cur&
|
SeekBuf& = cur& 'return old position
|
||||||
END IF
|
END IF
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
|
@ -170,7 +173,7 @@ DIM buf&
|
||||||
'--- return buffer specific EndOfLine sequence ---
|
'--- return buffer specific EndOfLine sequence ---
|
||||||
buf& = handle% * 106
|
buf& = handle% * 106
|
||||||
SELECT CASE MID$(simplebuffer_array$(buf& + 1), 9, 4)
|
SELECT CASE MID$(simplebuffer_array$(buf& + 1), 9, 4)
|
||||||
CASE "EolU", "EolN" 'OS native mode
|
CASE "EolU", "EolN" 'unknown (maybe mixed) or OS-native EOL mode
|
||||||
BufEolSeq$ = CHR$(13) + CHR$(10) 'default is Windows
|
BufEolSeq$ = CHR$(13) + CHR$(10) 'default is Windows
|
||||||
IF INSTR(_OS$, "[LINUX]") > 0 THEN BufEolSeq$ = CHR$(10) 'true for MacOSX too
|
IF INSTR(_OS$, "[LINUX]") > 0 THEN BufEolSeq$ = CHR$(10) 'true for MacOSX too
|
||||||
CASE "EolL" 'forced Linux/MacOSX
|
CASE "EolL" 'forced Linux/MacOSX
|
||||||
|
|
Loading…
Reference in a new issue