Yeah, I agree Close without params shouldn't be changing, so don't worry about that. It'd just get rerouted internally to a different function call.
Here's a tentative patch, for anyone interested (you'll probably have to Quote my post to get a working diff):
Code: Select all
Index: compiler/inc/rtl.bi
===================================================================
--- compiler/inc/rtl.bi (revision 5577)
+++ compiler/inc/rtl.bi (working copy)
@@ -258,6 +258,7 @@
#define FB_RTL_FILEOPEN_COM "fb_FileOpenCom"
#define FB_RTL_FILEOPEN_QB "fb_FileOpenQB"
#define FB_RTL_FILECLOSE "fb_FileClose"
+#define FB_RTL_FILECLOSEALL "fb_FileCloseAll"
#define FB_RTL_FILEPUT "fb_FilePut"
#define FB_RTL_FILEPUTLARGE "fb_FilePutLarge"
@@ -648,6 +649,7 @@
FB_RTL_IDX_FILEOPEN_COM
FB_RTL_IDX_FILEOPEN_QB
FB_RTL_IDX_FILECLOSE
+ FB_RTL_IDX_FILECLOSEALL
FB_RTL_IDX_FILEPUT
FB_RTL_IDX_FILEPUTLARGE
Index: compiler/parser-quirk-file.bas
===================================================================
--- compiler/parser-quirk-file.bas (revision 5577)
+++ compiler/parser-quirk-file.bas (working copy)
@@ -539,7 +539,7 @@
filenum = cExpression( )
if( filenum = NULL ) then
if( cnt = 0 ) then
- filenum = astNewCONSTi( 0, FB_DATATYPE_INTEGER )
+ '' pass NULL to rtlFileClose to get close-all function
else
if( errReport( FB_ERRMSG_EXPECTEDEXPRESSION ) = FALSE ) then
exit function
Index: compiler/rtl-file.bas
===================================================================
--- compiler/rtl-file.bas (revision 5577)
+++ compiler/rtl-file.bas (working copy)
@@ -27,7 +27,7 @@
#include once "inc\lex.bi"
#include once "inc\rtl.bi"
- dim shared as FB_RTL_PROCDEF funcdata( 0 to 65 ) = _
+ dim shared as FB_RTL_PROCDEF funcdata( 0 to ... ) = _
{ _
/' fb_FileOpen( byref s as string, byval mode as integer, byval access as integer,
byval lock as integer, byval filenum as integer, _
@@ -354,6 +354,18 @@
) _
} _
), _
+ /' fb_FileCloseAll( ) as integer '/ _
+ ( _
+ @FB_RTL_FILECLOSEALL, NULL, _
+ FB_DATATYPE_INTEGER, FB_USE_FUNCMODE_FBCALL, _
+ NULL, FB_RTL_OPT_NONE, _
+ 0/', _
+ { _
+ ( _
+ FB_DATATYPE_INTEGER, FB_PARAMMODE_BYVAL, FALSE _
+ ) _
+ }'/ _
+ ), _
/' fb_FilePut ( byval filenum as integer, byval offset as uinteger,
value as any, byval valuelen as integer ) as integer '/ _
( _
@@ -1509,12 +1521,16 @@
function = NULL
''
- proc = astNewCALL( PROCLOOKUP( FILECLOSE ) )
+ if( filenum <> NULL ) then
+ proc = astNewCALL( PROCLOOKUP( FILECLOSE ) )
- '' byval filenum as integer
- if( astNewARG( proc, filenum ) = NULL ) then
- exit function
- end if
+ '' byval filenum as integer
+ if( astNewARG( proc, filenum ) = NULL ) then
+ exit function
+ end if
+ else
+ proc = astNewCALL( PROCLOOKUP( FILECLOSEALL) )
+ end if
''
if( isfunc = FALSE ) then
Index: rtlib/libfb_file_close.c
===================================================================
--- rtlib/libfb_file_close.c (revision 5577)
+++ rtlib/libfb_file_close.c (working copy)
@@ -70,11 +70,19 @@
/*:::::*/
FBCALL int fb_FileClose( int fnum )
{
- /* QB quirk: CLOSE w/o arguments closes all files */
+ /* QB quirk: CLOSE #0 has no effect */
if( fnum == 0 ) {
- fb_FileReset( );
+ /*fb_FileReset( );*/
return fb_ErrorSetNum( FB_RTERROR_OK );
}
- return fb_FileCloseEx( FB_FILE_TO_HANDLE(fnum) );
+ return fb_FileCloseEx( FB_FILE_TO_HANDLE(fnum) );
}
+/*:::::*/
+FBCALL int fb_FileCloseAll( )
+{
+ /* QB quirk: CLOSE w/o arguments closes all files */
+ fb_FileReset( );
+ return fb_ErrorSetNum( FB_RTERROR_OK );
+}
+
Now 'close' has its own function, and 'close #0' does nothing.
Although to be honest I'm thinking of changing the latter to an Illegal Function Call, so people don't just call 'close #0', thinking it's closed all files.
Regarding #lang "qb" compatibility, I'm thinking it's better to return an error than what QB does, and it's easy to circumvent by calling Close(0) as a function, e.g. 'if close(0) then end if', or even just 'if fn <> 0 then close #fn'.
I also think it's more trouble than it's worth to enable a dialect-specific quirk for something like this.
(PS. It's "jumps over the lazy dog":P)