Input loop: Difference between revisions
Content added Content deleted
Line 1,449: | Line 1,449: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
Note: This code goes beyond simply specifying the file to open. It includes a dialog window that allows the user to select a text file to read. The entire contents of the file are read in at once, rather than line by line. |
Note: This code goes beyond simply specifying the file to open. It includes a dialog window that allows the user to select a text file to read. The entire contents of the file are read in at once, rather than line by line. |
||
<lang futurebasic> |
<lang futurebasic>include "NSLog.incl" |
||
include "ConsoleWindow" |
|||
local fn ReadTextFile |
local fn ReadTextFile |
||
CFURLRef url |
|||
CFStringRef string |
|||
dim as Handle h |
|||
dim as CFStringRef cfStr : cfStr = NULL |
|||
url = openpanel 1, @"Select text file..." |
|||
dim as long fileLen |
|||
⚫ | |||
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL ) |
|||
if ( files$( _CFURLRefOpen, "TEXT", "Select text file...", @fileRef ) ) |
|||
if ( string ) |
|||
NSLog(@"%@",string) |
|||
⚫ | |||
h = fn NewHandleClear( fileLen ) |
|||
⚫ | |||
⚫ | |||
// user cancelled |
|||
read file 2, [h], fileLen |
|||
⚫ | |||
close #2 |
|||
cfStr = fn CFStringCreateWithBytes( _kCFAllocatorDefault, #[h], fn GetHandleSize(h), _kCFStringEncodingMacRoman, _false ) |
|||
fn DisposeH( h ) |
|||
⚫ | |||
⚫ | |||
// User canceled |
|||
⚫ | |||
fn HIViewSetText( sConsoleHITextView, cfStr ) |
|||
CFRelease( cfStr ) |
|||
end fn |
end fn |
||
fn ReadTextFile |
fn ReadTextFile |
||
</lang> |
|||
HandleEvents</lang> |
|||
=={{header|gnuplot}}== |
=={{header|gnuplot}}== |