home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / mega src / Source / echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  1.6 KB  |  75 lines  |  [TEXT/KAHL]

  1. /* ========== the commmand file: ==========
  2.  
  3.     echo.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.    ========== the commmand file: ========== */
  14.  
  15. #include "nshc.h"
  16. #include "str_utl.proto.h"
  17. #include "nshc_utl.proto.h"
  18.  
  19. /* ======================================== */
  20.  
  21. void add_char( Str255 string, char c, int *length );
  22.  
  23. void add_char( Str255 string, char c, int *length )
  24. {
  25.     if ( *length < 255 )
  26.         string[ ++(*length) ] = c;
  27.     else
  28.         *length = 500;
  29. }
  30.  
  31. /* ======================================== */
  32.  
  33. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  34. {
  35.     int                arg;
  36.     int                got_one;
  37.     int                length;
  38.     char            c;
  39.     char            *p;
  40.     Str255            theString;
  41.     
  42.     if (nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION )) return;
  43.         
  44.     nshc_parms->action = nsh_idle;
  45.     nshc_parms->result = NSHC_NO_ERR;
  46.     
  47.     arg = 1;
  48.     got_one = 0;
  49.     length = 0;
  50.     theString[0] = 0;
  51.     
  52.     while ( arg < nshc_parms->argc ) {
  53.         if (got_one)
  54.             add_char( theString, ' ', &length );
  55.         p = &nshc_parms->arg_buf[nshc_parms->argv[arg]];
  56.         while (c = *p++)
  57.             add_char( theString, c, &length );
  58.         got_one = 1;
  59.         arg++;
  60.         }
  61.         
  62.     if (got_one)
  63.         if (length <= 255) {
  64.             theString[0] = length;
  65.             nshc_calls->NSH_putStr( theString );    
  66.             nshc_calls->NSH_putchar( '\r' );    
  67.             nshc_parms->result = NSHC_NO_ERR;
  68.             }
  69.         else{
  70.             nshc_calls->NSH_putStr_err("\pecho: stdin exceeds 255 chars.\r");
  71.             nshc_parms->result = NSHC_ERR_GENERAL;
  72.             }
  73.  
  74. }
  75.