![]() |
<< Index >> |
FutureBasic 5 |
Appendix J - Command Line Tools | appendix | |
|
_buildAsCommandLineTool = _true // _true or _false
#if _buildAsCommandLineTool
include "CommandLineTool"
#else
include "ConsoleWindow"
#endif
tool_argc
- the number of argumentsfn tool_arg( j )
- Str255 containing up to 255 characters of the jth argumenttool_argv
- a pointer giving access to the C strings in "argv[]". This can be used to parse arguments longer than 255 characters.#if def _FBUnixTool // tool_argc etc available only for tool, not console
dim as long j
print "Number of arguments =" tool_argc
for j = 0 to tool_argc - 1
print fn tool_arg( j ) // fn tool_arg() returns a Str255
next
print
#endif
$ ./test.command 123 nine "a quoted string"
Number of arguments = 4
/Users/username/Desktop/test.command
123
nine
a quoted string
_FBUnixTool
is defined by FBtoC when building a tool, and is undefined otherwise. It is used in the code snippet above to 'conditionalise out' the argument inspection code when building a console app. Only tools receive useful arguments.#if def _FBUnixTool // tool only, not console
print fn tool_getenv( "HOME" ) // fn tool_getenv() returns a Str255
#endif
input
statement reads from stdin and the print
statement writes to stdout.dim as Str255 s
input s
print "The input was: " s
#if def _LP64 // constant defined by FBtoC when building in 64-bit mode
print "Compiled in 64-bit mode"
#endif
def tab 10
print "sizeof( long )", sizeof( long ) " bytes"
print "sizeof( pointer )", sizeof( pointer ) " bytes"