![]() |
<< Index >> |
FutureBasic 5 |
| Appendix J - Command Line Tools | appendix | |
|
|
||
_buildAsCommandLineTool = _true // _true or _false#if _buildAsCommandLineToolinclude "CommandLineTool"#elseinclude "ConsoleWindow"#endiftool_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 consoledim as long jprint "Number of arguments =" tool_argcfor j = 0 to tool_argc - 1 print fn tool_arg( j ) // fn tool_arg() returns a Str255nextprint#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 consoleprint fn tool_getenv( "HOME" ) // fn tool_getenv() returns a Str255#endifinput statement reads from stdin and the print statement writes to stdout.dim as Str255 sinput sprint "The input was: " s#if def _LP64 // constant defined by FBtoC when building in 64-bit modeprint "Compiled in 64-bit mode"#endifdef tab 10print "sizeof( long )", sizeof( long ) " bytes"print "sizeof( pointer )", sizeof( pointer ) " bytes"