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

  1. /* ========== the commmand file: ==========
  2.  
  3.     ps.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 <GestaltEqu.h>
  20. #include <Processes.h>
  21.  
  22. #include "nshc.h"
  23.                     
  24. #include "nshc_utl.proto.h"
  25.  
  26. int    Pre7( void );
  27.  
  28. int    Pre7( void )
  29. {
  30.     OSErr    error;
  31.     long    response;
  32.     
  33.     if ( error = Gestalt( 'sysv', &response ) )
  34.         return(true);
  35.         
  36.     if ( response < 0x700 )
  37.         return(true);
  38.     else
  39.         return(false);
  40. }
  41.  
  42.                     
  43. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  44. {
  45.     char                    got_one;
  46.     Str255                    name;
  47.     ProcessSerialNumber        psn_p;
  48.     ProcessInfoRec          pi;
  49.     OSErr                    error;
  50.     long                    response;
  51.     
  52. #ifdef __MWERKS__
  53.     long oldA4  = SetCurrentA4();
  54. #endif
  55.     
  56.     if (nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION )) goto Exit;
  57.     
  58.     if ( Pre7() ) {
  59.         nshc_calls->NSH_putStr_err("\pps: This command requires System 7.\r");
  60.         nshc_parms->result = NSHC_ERR_GENERAL;
  61.         nshc_parms->action = nsh_idle;
  62.         goto Exit;
  63.         }
  64.         
  65.     pi.processName       = name;
  66.     pi.processInfoLength = sizeof(pi);
  67.     pi.processAppSpec    = NULL;
  68.     
  69.     psn_p.highLongOfPSN = 0;
  70.     psn_p.lowLongOfPSN  = kNoProcess;
  71.     
  72.     got_one = 0;
  73.     
  74.     while(!GetNextProcess(&psn_p))
  75.         if(!GetProcessInformation(&psn_p,&pi)) {
  76.             if (!got_one) {
  77.                 nshc_calls->NSH_puts("\r Process Crea Type  Mem Size   Mem Free  Name\r");
  78.                   nshc_calls->NSH_puts(" ------- ---- ---- ---------- ---------- ----\r");
  79.                 got_one = 1;
  80.                 }
  81.             nshc_calls->NSH_printf( " %7ld", psn_p.lowLongOfPSN );
  82.             nshc_calls->NSH_printf( " %.4s %.4s", &pi.processSignature, &pi.processType );
  83.             nshc_calls->NSH_printf( " %10ld", pi.processSize );
  84.             nshc_calls->NSH_printf( " %10ld ", pi.processFreeMem );
  85.             name[++name[0]] = '\r';
  86.             nshc_calls->NSH_putStr( name );
  87.             }
  88.  
  89.     if (got_one) nshc_calls->NSH_putchar('\r');
  90.     
  91.     nshc_parms->result = !got_one;    //    success if we found any processes
  92.     nshc_parms->action = nsh_idle;
  93.  
  94. Exit:
  95.  
  96. #ifdef __MWERKS__
  97.     SetA4(oldA4);        // CodeWarrior needs to restore A4
  98. #else
  99.     ;                    // Think needs a ; to go with the Exit label
  100. #endif
  101. }
  102.