home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Tools / nShell™ 1.0.3 / src / Programmer's Guide / 03 The Command Interface < prev    next >
Encoding:
Text File  |  1994-09-04  |  3.2 KB  |  65 lines  |  [TEXT/ttxt]

  1. 03 The Command Interface
  2. ========================
  3.  
  4. The following rules define the nShell external command interface.
  5.  
  6. File Types
  7. ----------
  8.  
  9. nShell command files have a creator of ‘NSHA’, and a type of ‘NSHC’.
  10.  
  11. Code Resource Types
  12. -------------------
  13.  
  14. The nShell environment supports single-segment code resources.  The code resource for a command should have a type of ‘NSHC’ and a name of "command".
  15.  
  16. Resource Numbers
  17. ----------------
  18.  
  19. With the exception of ‘vers’ resources, all resources within nShell command files have I.D. numbers of 16000 or higher.  See the section called “An Example Command” for more about setting up command resources.
  20.  
  21. The File “nshc.h” Defines The C Interface
  22. -----------------------------------------
  23.  
  24. The “main” for nShell commands is defined in nshc.h.  At run time, this main is passed pointers for two parameter blocks, also defined in nshc.h.  The “nshc_calls” block defines the callback interface to the nShell application.  The “nshc_parms” block defines the data available to the command.
  25.  
  26. Passing Arguments
  27. -----------------
  28.  
  29. Three fields within nshc_parms contain arguments to nShell commands:
  30.  
  31.     argc        The number of arguments (including the command itself)
  32.     argv        An array of indexes into the command line buffer
  33.     arg_buf        The command line buffer
  34.  
  35. The arg_buf contains a series of null-terminated strings, one for each command argument.  The start of a particular string is arg_buf[ argv[ n ] ], where n is the argument number 0..(argc-1).
  36.  
  37. The Command Must Accept Start/Continue/Stop Messages From The Application
  38. -------------------------------------------------------------------------
  39.  
  40. External commands base their actions upon the “action” scalar within the nshc_parms record:
  41.  
  42.     nsh_idle        do nothing
  43.     nsh_start        do part or all
  44.     nsh_continue        continue processing
  45.     nsh_stop        clean up and exit
  46.  
  47. The Command Must Give Up Time For Multitasking
  48. ----------------------------------------------
  49.  
  50. Task switches in the nShell environment occur only when a command "returns" to the main application.  If a command requires more than a small amount of time to execute or if it requires keyboard input from the operator, the command should give time back to the application.  In this procedure, a command should set it's action scalar to nsh_continue and return back to the application.  When other tasks have been satisfied the application will again call the command.  The command should then use the action scalar or custom data to determine what internal actions are required.  See the "delay" command for an example.
  51.  
  52. The Command Must Signal Completion
  53. ----------------------------------
  54.  
  55. Whenever a command completes its task, it must set two variables in the nshc_parms data structure.  The ‘action’ scalar must be set to to nsh_idle, and the ‘result’ variable must be set to reflect success or failure ( <0 = error, 0 = success, >0 = non-error return values ).
  56.  
  57. Data Allocation
  58. ---------------
  59.  
  60. Commands allocate storage in two ways:
  61.  
  62. First, local variables may be defined within each routine.
  63.  
  64. Secondly, data may be allocated using NewHandle.  Any such data structure must be hung off the “data” handle within nshc_parms.  The command is responsible for disposing of this data before going into an nsh_idle state.
  65.