Hello Everyone,

Please read the following introduction before downloading and replacing your current FB; it is important to know the impact. Download link at the bottom.

Introduction
Unlike some FB5 releases, this one contains several changes which impact your current FB source code. Depending on your code, it may not compile with this FB version.
Internally, all of FB runtime disk-based file I/O system ( with some specific exceptions which will be noted later ) was updated and is now 64-bit compatible. In some cases the updates impact the operation and syntax of specific FB file I/O keywords. Most FB file I/O keyword's operation and syntax are exactly the same while a few have slightly different syntax/requirements and behavior. It it important for FBers to understand these impacts, assess the work involved, and decide how/when to implement this new FB release. Like usual, old releases and the prior release ( 5.7.97 ) are available. Hopefully, this moves us closer to a "Future" BASIC. The design goal was to keep the language in familiar territory with the same keywords while upgrading the supporting runtime. 


Overview of Changes to FB File I/O
As usual, the Release History Notes detail the changes but here is an overview.

[A] File-based versions of the OPEN statement( open modes "I", "O", "A", "R" and "N" ) must specifically use the CFURLRef version. OPEN no longer supports FSSpec or FSRef.

[B] OPEN "N" now provides an automatic read-only open when a file is already open in "N" mode.
It notifies the code of the automatic selection of "I" mode, when "N" was requested, via FB's standard ERROR functions. See code below at note:1

[C] READ/WRITE FIELD are removed due to use of deprecated Handles and potential links/associations with old code.
Replacement options were discussed in Jan/Feb 2017 FB list discussions. See this link for a possible replacement strategy: http://freegroups.net/groups/futurebasic/0::67289read.html

[D] FB's FILES$ now uses/returns only a CFURLRef for each of the three major options( i.e. selecting a file, a folder, or save location/name )

[E] Util_Files.incl uses outdated ( parameter block ) file functions. N.B. IF YOUR CODE USES FUNCTIONS FROM THIS INCLUDE, IT WON"T BUILD.
In all cases this include's functions can either be replaced with similar URL functionality or the functionality is obsolete ( Resource fork stuff ). If you can't find modern replacements, please ask on the list. One replacement example: fn FSSendFileToTrash( sourceObj as ^FSSpec ) can be replaced with one of the new Util_FileManager.incl code. ( see FB Examples==>Files==>Util_FileManager Demos==>TrashItemAtURL

[F] Coding errors can cause crashes because the error isn't found until it runs. 
For example:
(1) A "Bad file descriptor" crash message indicates a file i/o attempt which isn't allowed by the OPEN mode (i.e. opening in mode "I" and trying to WRITE the file )
(2) Using the wrong filedID. i.e. opening file #1 for read and then trying to read file #2 when fileID #2 doesn't exist.


The Release History Notes detail many other additions and changes and FBers are strongly encouraged to read and understand their impact.


What didn't change in FB File I/O
[F] Even though their underlying code changed a lot, most FB file I/O verbs/keywords use the same syntax. For example, Error, Close, Write#, Input#, Print#, Record, LOF, EOF, Rec, Loc, Read File, Write File, Append, Open "C" and Open "UNIX" all have the same syntax. Such is the benefit of an abstracted high-level language.

[G] The relative performance and usage recommendations remain the same. For example, using read# with multiple variables generates more code( potentially a lot more ) than doing a read file# into a FB record ( C structure ) or pointer. Read# generates one physical read per variable versus one read for the entire FB Record in Read File#. Here is an example with an FB record reading four variables with Read File vs. Read:
  
begin Record myRec
dim as short   a
dim as long    b
dim as Str255  c
dim as double  d
end Record
dim as myRec        aRec

This FB:          read file #2, @aRec, fileSize
Generates this C: FBReadFile( 2, (void*)(void*)&aRec, false, fileSize );  

This FB:          read #2, aRec.a,aRec.b,aRec.c;13,aRec.d
Generates this C: aRec.a = FBReadSwapShort( 2 ); 
  aRec.b = FBReadSwapLong( 2 ); 
  FBReadString( 2, (char*)&aRec.c, 13 );  
  aRec.d = FBReadSwapDouble( 2 ); 

[H] This FB release brings lots of new headers, updates and bug fixes. Most timely is the new addition of Util_FileManger to assist with the new OPEN and FILES$. Thank you Bernie.

------------------------------------------------------------------------------------------------------------------------------------------------------

Notes:

1. Code below shows interception of an OPEN "N" notification and how to determine if "I" mode was assigned because file is in use.

//--------------------------------
include "NSlog.incl"

dim as CFURLRef     url
dim as short        ioError : ioError = 0
dim as CFIndex      fileSize 
dim as CFStringRef  s 
dim as dim as       p

s = @"/Users/brians/Desktop/mytextfile2.txt"
url = fn CFURLCreateWithFileSystemPath( NULL, s, _kCFURLPOSIXPathStyle, _false )

on error end
error = _noErr
open "N",1, @url
ioError  = error
error = _noErr
// _opWrErr ( -49 ) file already open with with write permission*/
// in this case another process has the same file open in mode "N"( since this process does not ),
// so the runtime opens the file for you in read-only mode ( like mode "I" ) and notifies
// the FBer of this action by sending back the _opWrErr code. Brian 20170303

select switch ( ioError )

case _noErr
   // No problem, your code has the file open in "N"

case _opWrErr
   // other code ( or code in another process ) already has the file open in "N"
   // so your code now has this file open in "I" mode
   NSLog(@"ioError = %d", ioError )
   fileSize = lof(1,1)
   p = fn malloc( fileSize )
   read file #1, p, fileSize
   s = fn CFStringCreateWithBytes( NULL, #p, fileSize, _kCFStringEncodingMacRoman, _false )
   free( p )
   NSLog (@"%@",s ) 
   CFRelease( s )
   Close #1
end select

CFRelease( url )

RunApplicationEventLoop
//--------------------------------

General note: Several FBers contribute to the update effort and the release notes now identity the persons mostly ( approximately 95%+ of the effort ) responsible for the coding effort in each area, even though others not mentioned might have contributed.

20170320 FB 5.7.99

http://www.4toc.com/fb/index.htm  [you will need to reload the page if your browser cached the page mentioning FB 5.7.97]

FB 5.7.99 requires OS X 10.6 or higher





=

--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@... = To access the list archives, go to: http://freegroups.net/groups/futurebasic/


=

--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@... To access the list archives, go to: http://freegroups.net/groups/futurebasic/