home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / P Examples / lib source / nShellLib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-28  |  4.9 KB  |  198 lines  |  [TEXT/KAHL]

  1. /* ========================================
  2.  
  3.     nShellLib.c
  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.    ======================================== */
  14.  
  15. #ifdef __MWERKS__            // CodeWarrior requires an A4 setup
  16. #include <A4Stuff.h>
  17. #endif
  18.  
  19. #include "nshc.h"            // Get the C definitions for the nShell interface
  20.  
  21. /* ======================================== */
  22. // Prototypes for internal use
  23. /* ======================================== */
  24.  
  25.     // output to stderr
  26.     
  27. pascal    void     NSH_putchar_err(t_nshc_calls *nshc_calls, short c);
  28. pascal    void     NSH_puts_err(t_nshc_calls *nshc_calls, short *c);
  29. pascal    void     NSH_putStr_err(t_nshc_calls *nshc_calls, Str255 s);
  30.     
  31.     // output to stdout
  32.     
  33. pascal    void     NSH_putchar(t_nshc_calls *nshc_calls, short c);
  34. pascal    void     NSH_puts(t_nshc_calls *nshc_calls, short *c);
  35. pascal    void     NSH_putStr(t_nshc_calls *nshc_calls, Str255 s);
  36.     
  37.     // input from stdin
  38.     
  39. pascal    int     NSH_getchar(t_nshc_calls *nshc_calls);
  40. pascal    int     NSH_gets(t_nshc_calls *nshc_calls, short *s, int max_len);
  41. pascal    int     NSH_getStr(t_nshc_calls *nshc_calls, Str255 s);
  42.     
  43.     // variable access functions
  44.     
  45. pascal    int        NSH_var_set(t_nshc_calls *nshc_calls, Str32 name, Str255 value);
  46. pascal    int        NSH_var_unset(t_nshc_calls *nshc_calls, Str32 name);
  47. pascal    int        NSH_var_env(t_nshc_calls *nshc_calls, Str32 name, Str255 value);
  48.     
  49.     // path expansion functions
  50.     
  51. pascal    int        NSH_path_expand(t_nshc_calls *nshc_calls, Str255 path);
  52. pascal    int        NSH_path_to_FSSpec(t_nshc_calls *nshc_calls,  Str255 pathname, FSSpec *spec );
  53. pascal    int        NSH_path_which(t_nshc_calls *nshc_calls, Str255 path);
  54.     
  55.     // dialog functions
  56.     
  57. pascal    void     NSH_notify(t_nshc_calls *nshc_calls, Str255 s, int size);
  58. pascal    int     NSH_ask(t_nshc_calls *nshc_calls, Str255 s, int size);
  59.  
  60.     // misc
  61.     
  62. pascal    int     NSH_match(t_nshc_calls *nshc_calls,  Str255 pattern, Str255 target );
  63.  
  64. /* ======================================== */
  65. // Callback vectors
  66. /* ======================================== */
  67.  
  68.     // output to stderr
  69.     
  70. pascal void NSH_putchar_err(t_nshc_calls *nshc_calls, short c)
  71. {
  72.     nshc_calls->NSH_putchar_err( c );
  73. }
  74.  
  75. pascal void NSH_puts_err(t_nshc_calls *nshc_calls, short *p)
  76. {
  77.     nshc_calls->NSH_puts_err( (char *)p );
  78. }
  79.  
  80. pascal void NSH_putStr_err(t_nshc_calls *nshc_calls, Str255 s)
  81. {
  82.     nshc_calls->NSH_putStr_err( s );
  83. }
  84.     
  85.     // output to stdout
  86.     
  87. pascal void NSH_putchar(t_nshc_calls *nshc_calls, short c)
  88. {
  89.     nshc_calls->NSH_putchar( c );
  90. }
  91.  
  92. pascal void NSH_puts(t_nshc_calls *nshc_calls, short *p)
  93. {
  94.     nshc_calls->NSH_puts( (char *)p );
  95. }
  96.  
  97. pascal void NSH_putStr(t_nshc_calls *nshc_calls, Str255 s)
  98. {
  99.     nshc_calls->NSH_putStr( s );
  100. }
  101.     
  102.     // input from stdin
  103.     
  104. pascal int NSH_getchar(t_nshc_calls *nshc_calls)
  105. {
  106.     return( nshc_calls->NSH_getchar() );
  107. }
  108.  
  109. pascal int NSH_gets(t_nshc_calls *nshc_calls, short *s, int max_len)
  110. {
  111.     return( nshc_calls->NSH_gets((char *)s, max_len) );
  112. }
  113.  
  114. pascal int NSH_getStr(t_nshc_calls *nshc_calls, Str255 s)
  115. {
  116.     return( nshc_calls->NSH_getStr(s) );
  117. }
  118.  
  119.     // variable access functions
  120.     
  121. pascal int NSH_var_set(t_nshc_calls *nshc_calls, Str32 name, Str255 value)
  122. {
  123.     return( nshc_calls->NSH_var_set(name,value) );
  124. }
  125.  
  126. pascal int NSH_var_unset(t_nshc_calls *nshc_calls, Str32 name)
  127. {
  128.     return( nshc_calls->NSH_var_unset(name) );
  129. }
  130.  
  131. pascal int NSH_var_env(t_nshc_calls *nshc_calls, Str32 name, Str255 value)
  132. {
  133.     return( nshc_calls->NSH_var_env(name,value) );
  134. }
  135.  
  136.     // path expansion functions
  137.     
  138. pascal int NSH_path_expand(t_nshc_calls *nshc_calls, Str255 path)
  139. {
  140.     return( nshc_calls->NSH_path_expand(path) );
  141. }
  142.  
  143. pascal int NSH_path_to_FSSpec(t_nshc_calls *nshc_calls,  Str255 pathname, FSSpec *spec )
  144. {
  145.     return( nshc_calls->NSH_path_to_FSSpec(pathname,spec) );
  146. }
  147.  
  148. pascal int NSH_path_which(t_nshc_calls *nshc_calls, Str255 path)
  149. {
  150.     return( nshc_calls->NSH_path_which(path) );
  151. }
  152.  
  153.     // dialog functions
  154.     
  155. pascal void NSH_notify(t_nshc_calls *nshc_calls, Str255 s, int size)
  156. {
  157.     nshc_calls->NSH_notify( s, size );
  158. }
  159.  
  160. pascal int NSH_ask(t_nshc_calls *nshc_calls, Str255 s, int size)
  161. {
  162.     return( nshc_calls->NSH_ask( s, size ) );
  163. }
  164.  
  165.     // misc
  166.     
  167. pascal int NSH_match(t_nshc_calls *nshc_calls,  Str255 pattern, Str255 target )
  168. {
  169.     return( nshc_calls->NSH_match(pattern,target) );
  170. }
  171.  
  172. /* ======================================== */
  173. // Prototype for pascal callout
  174. /* ======================================== */
  175.  
  176. extern pascal void theCommand(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls);
  177.  
  178. /* ======================================== */
  179. // A main, in C, which calls Pascal commands
  180. /* ======================================== */
  181.  
  182. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  183. {
  184. #ifdef __MWERKS__
  185.     long oldA4  = SetCurrentA4();
  186. #endif
  187.     
  188.     theCommand( nshc_parms, nshc_calls );
  189.  
  190. #ifdef __MWERKS__
  191.     SetA4(oldA4);        // CodeWarrior needs to restore A4
  192. #else
  193.     ;                    // Think needs a ; to go with the Exit label
  194. #endif
  195. }
  196.  
  197. /* ======================================== */
  198.