home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / CW Examples / lib / nshc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-25  |  2.9 KB  |  117 lines  |  [TEXT/KAHL]

  1. /* =============== the nshc interface: ===============
  2.  
  3.     nshc.h - where entry points to NSH commands are kept.
  4.  
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.     
  13.    =============== the nshc interface: =============== */
  14.  
  15. #define __NSHC__
  16.  
  17. /* ========== Interface Constants and Types ========== */
  18.  
  19. #define NSHC_VERSION    10            // version of this header file
  20.  
  21. #define MAX_ARGS        100            // maximum value of argc
  22. #define LINE_MAX        2048        // maximum input line to be expected by all cmds
  23.  
  24. typedef enum { nsh_idle, nsh_start, nsh_continue, nsh_stop } t_nsh_state;
  25.  
  26. /* ======== Define some common return values ======== */
  27.  
  28. #define    NSHC_NO_ERR             0        // success
  29. #define    NSHC_ERR_GENERAL    -1        // unspecified error
  30. #define    NSHC_ERR_VERSION    -2        // NSHC_VERSION of application and command don't match
  31. #define    NSHC_ERR_PARMS        -3        // parameters don't match command definition
  32. #define    NSHC_ERR_MEMORY        -4        // memory allocation error
  33. #define    NSHC_ERR_FILE        -5        // file access error
  34.  
  35. /* ========== The Data Communication Block ========== */
  36.  
  37. typedef struct {
  38.  
  39.     // version is always first, so it can be used to detect a mismatch.
  40.  
  41.     int        version;
  42.     
  43.     // requested actions
  44.     
  45.     t_nsh_state    action;
  46.     
  47.     // returned status
  48.     
  49.     int        result;
  50.     
  51.     // passed parameters
  52.     
  53.     int        argc;
  54.     int        argv[MAX_ARGS];
  55.     char    arg_buf[LINE_MAX];
  56.     
  57.     // a handle at which the command may allocate (AND DISPOSE) storage
  58.     
  59.     Handle    data;
  60.     
  61. } t_nshc_parms;
  62.  
  63. /* ========== The Call-Back Communication Block ========== */
  64.  
  65. typedef struct {
  66.  
  67.     // NSH_putErrStr is always first, so it can be used to notify the operator
  68.     // of a version mismatch. NO OTHER CALLS ARE GUARANTEED ACROSS REVSIONS.
  69.  
  70.     void     (*NSH_putStr_err)(Str255 s);
  71.     
  72.     // output to stderr
  73.     
  74.     void     (*NSH_putchar_err)(char c);
  75.     void     (*NSH_puts_err)(char *);
  76.     void    (*NSH_printf_err)(const char *fmt, ...);
  77.     
  78.     // output to stdout
  79.     
  80.     void     (*NSH_putchar)(char c);
  81.     void     (*NSH_puts)(char *);
  82.     void     (*NSH_putStr)(Str255 s);
  83.     void    (*NSH_printf)(const char *fmt, ...);
  84.     
  85.     // input from stdin
  86.     
  87.     int     (*NSH_getchar)(void);
  88.     int     (*NSH_gets)(char *s, int max_len);
  89.     int     (*NSH_getStr)(Str255 s);
  90.     
  91.     // variable access functions
  92.     
  93.     int        (*NSH_var_set)(Str32 name, Str255 value);
  94.     int        (*NSH_var_unset)(Str32 name);
  95.     int        (*NSH_var_env)(Str32 name, Str255 value);
  96.     
  97.     // path expansion functions
  98.     
  99.     int        (*NSH_path_expand)(Str255 path);
  100.     int        (*NSH_path_to_FSSpec)( Str255 pathname, FSSpec *spec );
  101.     int        (*NSH_path_which)(Str255 path);
  102.     
  103.     // dialog functions
  104.     
  105.     void     (*NSH_notify)(Str255 s, int size);
  106.     int     (*NSH_ask)(Str255 s, int size);
  107.  
  108.     // misc
  109.     
  110.     int     (*NSH_match)( Str255 pattern, Str255 target );
  111.  
  112. } t_nshc_calls;
  113.  
  114. /* ========== The External Command Definition ========== */
  115.  
  116. typedef void (**nshc_hdl)(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls);
  117.