home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / nshellmegasource1.50 / mega src / commands / date.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-28  |  1.5 KB  |  73 lines  |  [TEXT/KAHL]

  1. /* ========== the commmand file: ==========
  2.  
  3.     date.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. #ifdef __MWERKS__            // CodeWarrior requires an A4 setup
  16. #include <A4Stuff.h>
  17. #endif
  18.  
  19. #include <OSUtils.h>
  20. #include <Packages.h>
  21.  
  22. #include "nshc.h"
  23.  
  24. #include "nshc_utl.proto.h"
  25.  
  26. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  27. {
  28.     int date_fmt;
  29.     int seconds;
  30.     unsigned long secs;
  31.     Str255 resultStr;
  32.     
  33. #ifdef __MWERKS__
  34.     long oldA4  = SetCurrentA4();
  35. #endif
  36.     
  37.     if ( !nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION ) ) {
  38.     
  39.         if (nshc_got_option( nshc_parms, 's' )) 
  40.             date_fmt = shortDate;
  41.         else
  42.             if (nshc_got_option( nshc_parms, 'a' )) 
  43.                 date_fmt = abbrevDate;
  44.             else
  45.                 date_fmt = longDate;
  46.     
  47.         GetDateTime( &secs );
  48.         
  49.         IUDateString( secs, date_fmt, resultStr );
  50.         nshc_calls->NSH_putStr(resultStr);
  51.         
  52.         if ( ! nshc_got_option( nshc_parms, 'd' ) ) {
  53.             nshc_calls->NSH_putchar(' ');
  54.             if (nshc_got_option( nshc_parms, 'm' ))
  55.                 seconds = 0;
  56.             else
  57.                 seconds = 1;
  58.             IUTimeString( secs, seconds, resultStr );
  59.             nshc_calls->NSH_putStr(resultStr);
  60.             }
  61.         
  62.         nshc_calls->NSH_putchar('\r');
  63.         
  64.         nshc_parms->result = NSHC_NO_ERR;
  65.         nshc_parms->action = nsh_idle;
  66.  
  67.         }
  68.  
  69. #ifdef __MWERKS__
  70.     SetA4(oldA4);
  71. #endif
  72. }
  73.