Guy LONNE
unread,Nov 21, 2024, 5:59:20 PM11/21/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to xbl...@googlegroups.com
Hi D.!
Please find attached my version of xsx.x.
The attached xsx.x is your own version of
C:\xblite\compiler_sources\xblite_242_src\Xsx\xsx.x, in which I merged
all my modifications.
If you use a file comparator (I use WinMerge), you will easily exhibit
all my changes.
MODIFICATIONS
=============
1.Corrected a bug that returned a locked existing file as "does not exist".
Fix: Return a locked file as existing.
Old Version
=============================================================
FUNCTION XstFileExists (file$)
IFZ file$ THEN RETURN ($$TRUE)
ofile = XxxOpen (file$, $$RD)
IF ofile = -1 THEN RETURN ($$TRUE)
XxxClose (ofile)
END FUNCTION
=============================================================
New Version
=============================================================
FUNCTION XstFileExists (file$)
XLONG fileNumber ' file number
XLONG errno ' last-error code
XLONG lastError, newError ' to set current run-time ERROR
XLONG bFileExists ' $$TRUE if file exists
'
' v0.023-old---
' IFZ file$ THEN RETURN ($$TRUE)
' v0.023-old===
' v0.023-new+++
IFZ file$ THEN
' Invalid Argument
newError = ($$ErrorObjectArgument << 8) OR
$$ErrorNatureInvalidArgument
lastError = ERROR (newError) ' set current run-time error
RETURN (-1) ' failure
ENDIF
' v0.023-new===
'
bFileExists = $$FALSE
SetLastError (0) ' reset the last-error code
fileNumber = XxxOpen (file$, $$RD)
'
' v0.023-old---
' IF fileNumber = -1 THEN RETURN ($$TRUE)
' v0.023-old===
' v0.023-new+++
IF fileNumber > 0 THEN
bFileExists = $$TRUE ' file exists
XxxClose (fileNumber) ' close opened file
fileNumber = 0 ' GL-optional
ELSE
' Error: Can't open the file
errno = GetLastError ()
XstSystemErrorToError (errno, @newError)
lastError = ERROR(newError) ' set current run-time ERROR
'
SELECT CASE errno
CASE $$ERROR_FILE_NOT_FOUND, $$ERROR_PATH_NOT_FOUND
' file not found
CASE ELSE
bFileExists = $$TRUE ' file exists
END SELECT
ENDIF
' v0.023-new===
'
RETURN (bFileExists)
END FUNCTION
=============================================================
2.' In XstLog added XstGetLocalDateAndTime to get also the local
time-stamp, fixed bug in second calculation (Guy Lonne)
' style = 2 (GL-new: add LOCAL time/date stamp)
I remembered what you replied me when I reported the bug and its fix:
"Log records are traditionally time-stamped with Greenwich mean time".
You were right, so I submit to your judgement of keeping GMT time stamp
as before and adding this new style = 2 as an added bonus for Xbliters
like myself (who know already how to handle this issue).
Old Version
=============================================================
' #######################
' ##### XstLog () #####
' #######################
'
' style = 0 (default, add time/date stamp)
' style = 1 (no time/date stamp)
FUNCTION XstLog (message$, style, fileName$)
STATIC enter
'
IFZ fileName$ THEN fileName$ = "x.log"
IFZ style THEN
' GL-18sep07-XstGetDateAndTime (@year, @month, @day, 0, @hour,
@min, @sec, @nanos)
XstGetLocalDateAndTime (@year, @month, @day, 0, @hour, @min,
@sec, @nanos)
'
' stamp$ = RIGHT$("000" + STRING$(year),4) + RIGHT$("0" +
STRING$(month),2) + RIGHT$("0" + STRING$(day),2) + ":" + RIGHT$("0" +
STRING$(hour),2) + RIGHT$("0" + STRING$(min),2) + RJUST$("0" +
STRING$(sec),2) + "." + RIGHT$("000" + STRING$(nanos\1000000),3) + ": "
stamp$ = RIGHT$("000" + STRING$(year),4) + "-" + RIGHT$("0" +
STRING$(month),2) + "-" + RIGHT$("0" + STRING$(day),2) + " " +
RIGHT$("0" + STRING$(hour),2) + ":" + RIGHT$("0" + STRING$(min),2) + ":"
+ RIGHT$("0" + STRING$(sec),2) + " "
message$ = stamp$ + message$
END IF
'
IFZ enter THEN
enter = $$TRUE
ofile = OPEN (fileName$, $$WRNEW)
ELSE
ofile = OPEN (fileName$, $$WR)
END IF
'
IF (ofile >= 3) THEN
length = LOF (ofile)
SEEK (ofile, length)
PRINT [ofile], message$
CLOSE (ofile)
END IF
END FUNCTION
=============================================================
New Version
=============================================================
' #######################
' ##### XstLog () #####
' #######################
'
' style = 0 (default, add time/date stamp)
' style = 1 (no time/date stamp)
' style = 2 (GL-new: add LOCAL time/date stamp)
FUNCTION XstLog (message$, style, fileName$)
STATIC enter
'
IFZ fileName$ THEN fileName$ = "x.log"
SELECT CASE style
CASE 0
' Get the current date and time in GMT (Greenwich mean time)
' for logging time-stamp.
XstGetDateAndTime (@year, @month, @day, 0, @hour, @min,
@sec, @nanos)
'
' GL-new+++
CASE 2
' GL-Get the local date and time.
XstGetLocalDateAndTime (@year, @month, @day, 0, @hour,
@min, @sec, @nanos)
' GL-new===
'
CASE ELSE
year = 0
'
END SELECT
IF year THEN
' stamp$ = RIGHT$("000" + STRING$(year),4) + RIGHT$("0" +
STRING$(month),2) + RIGHT$("0" + STRING$(day),2) + ":" + RIGHT$("0" +
STRING$(hour),2) + RIGHT$("0" + STRING$(min),2) + RJUST$("0" +
STRING$(sec),2) + "." + RIGHT$("000" + STRING$(nanos\1000000),3) + ": "
stamp$ = RIGHT$("000" + STRING$(year),4) + "-" + RIGHT$("0" +
STRING$(month),2) + "-" + RIGHT$("0" + STRING$(day),2) + " " +
RIGHT$("0" + STRING$(hour),2) + ":" + RIGHT$("0" + STRING$(min),2) + ":"
+ RIGHT$("0" + STRING$(sec),2) + " "
message$ = stamp$ + message$
END IF
'
IFZ enter THEN
' GL-first time thru
enter = $$TRUE
mode = $$WRNEW
ELSE
mode = $$WR
END IF
SetLastError(0) ' clear the last Windows lastErr code
ofile = OPEN (fileName$, mode)
IF (ofile < 1) THEN
' Error: Can't open the file
errno = GetLastError ()
XstSystemErrorToError (errno, @newError)
lastError = ERROR(newError) ' set current run-time error
RETURN (-1) ' failure
ENDIF
' Append the log message.
fileSize = LOF (ofile)
SEEK (ofile, fileSize)
PRINT [ofile], message$
CLOSE (ofile)
' v0.023-new===
'
END FUNCTION
=============================================================
3.Added:
' - XstGetFileBOM (file$, @fileBOM$, @code_char) - decode
the Byte Order Mark of a text file
' - XstGetStringTypeBOM (code_char, @strBOM$) - return the Byte Order
Mark of a given STRING type
' - XstResetFileBOM (file$, code_char) - reset the Byte Order
Mark of a file
' (See GetFileBOM.x: demo program for these new functions)
'
' - XstTrimPath$ (file$) - trim a directory path or a
file path
Attached is a demo program for these new functions: GetFileBOM.x along
with some test files.
That's all, folks!
Bye!
Guy