![]() |
<< Index >> |
FutureBasic |
Appendix J - Command Line Tools | appendix | |
|
_buildAsCommandLineTool = _true // _true or _false
#if _buildAsCommandLineTool
include "CommandLineTool"
#else
include "ConsoleWindow"
#endif
A command-line tool always has at least one argument: the path to the command. More arguments may follow if the tool was run via a terminal or pipe.
$ ./test.command 123 nine "a quoted string"
Number of arguments = 4
/Users/username/Desktop/test.command
123
nine
a quoted string
The constant
Environment variables
The command line tool can read any named environment variable from the host environment list as illustrated below:
Standard input and output
In a tool, the input
statement reads from stdin and the print
statement writes to stdout.
Note that only the first 255 characters will be read, or up to the newline character, whichever comes first.
File I/O:
A tool can perform any file-system operation except display a navigation dialog. Several functions in Util_FileDirectory.incl allow access to files in predictable locations. FD_PathGetFSRef() and FD_PathCreateCFURL() can be used to convert a path, passed as a tool argument, to a FSRef or CFURLRef.
64-bit executables
Command line tools (but not console apps) can be compiled in 64-bit mode. This is done by putting "-m64" into FBtoC's 'More compiler options'. That setting tells the compiler to produce a 64-bit executable instead of the older 32-bit kind.
How to make an Xcode project from a FutureBasic command-line tool
[1] Put an Info.plist file in the same folder as the FutureBasic source. The xml content can be vacuous.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
[2] Set Optimization to None in build settings.
[3] Build and Run the FutureBasic source. You can either leave toolname.command running in Terminal.app or kill it.
[4] Choose Command > Make Xcode Project.
[5] In Xcode, Build and Run the translated C source. To see the output, ensure that Xcode's Debugger Console is shown, perhaps by choosing the command Run > Console.
[6] By appropriate manipulations in the Finder you can drag the executable from "build_temp/XcodeProject/build/Debug/toolname.app/Contents/MacOS/toolname" to a more sensible location.
[7] A later release of FutureBasic (version 5 onwards) may provide a special Xcode project template to make step #1 unnecessary and step #6 simpler.