home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / isrun01.zip / main.cpp < prev    next >
C/C++ Source or Header  |  1997-10-12  |  3KB  |  88 lines

  1. #define INCL_DOSMEMMGR
  2. #define INCL_DOSERRORS
  3. #define INCL_WINSWITCHLIST
  4.  
  5. #include <iostream.h>
  6. #include <stdlib.h>
  7. #include <os2.h>
  8.  
  9. #include "Class_WindowList.hpp"
  10.  
  11. //------------------------------------------------------------------------
  12.  
  13. main( int argc, char *argv[] )
  14. {
  15.      // Create an instance of the window list class
  16.      Class_WindowList wl;
  17.  
  18.      if( argc == 1 || strstr( "/?-?/help-help", argv[1] )  )
  19.      {
  20.           // The user requested help
  21.           cout << "IsRunning v1.0\n";
  22.           cout << "by Stephane Bessette (stephb7@usa.net), 1997\n\n";
  23.           cout << "Syntax:\n";
  24.           cout << "\tIsRunning <name>\n";
  25.           cout << "\tIsRunning -e\n";
  26.           cout << "Where\n";
  27.           cout << "\t<name>\tcorresponds to the name of the program\n";
  28.           cout << "\t-e \tinstructs to enumerate the running tasks\n";
  29.           cout << "\nReturns:\n";
  30.           cout << "\t0. The program is not running\n";
  31.           cout << "\t1. The program is running\n";
  32.           cout << "\t2.  Displayed help or enumerated the running tasks\n";
  33.           cout << "\n\tMessages through standard error\n";
  34.           cout << "\t    to discard output:  IsRunning <name> 2> NUL\n";
  35.           cout << "\nExample:\n";
  36.           cout << "\tIsRunning Desktop\n\n";
  37.      }
  38.      else if( argc == 2 && !strcmp( argv[1], "-e" ) )
  39.      {
  40.           // Enumerate the running tasks
  41.           SWCNTRL sw;
  42.           while( wl.Enumerate( sw ) )
  43.                cout << '"' << sw.szSwtitle << '"' << "\n";
  44.      }
  45.      else
  46.      {
  47.           // The user specified a name
  48.           // If the name contains spaces, then it will span
  49.           // more than one parameter
  50.  
  51.           // Determine the total length of the parameters
  52.           int nLength = 0;
  53.           for( int x = 1; x < argc; x++ )
  54.                nLength += strlen( argv[x] ) + 1;
  55.  
  56.           // Then concatenate the parameters
  57.           char *szProgram = new char [ nLength + 1 ];
  58.           if( !szProgram )
  59.                // Memory allocation error
  60.                return 0;
  61.  
  62.           strcpy( szProgram, "" );
  63.           for( x = 1; x < argc - 1; x++ )
  64.           {
  65.                strcat( szProgram, argv[x] );
  66.                strcat( szProgram, " " );
  67.           }
  68.           strcat( szProgram, argv[argc - 1] );
  69.  
  70.           // Determine whether the program is running or not
  71.           if( wl.InList( szProgram ) )
  72.           {
  73.                cerr << '"' << szProgram << '"' << " is running\n";
  74.                delete [] szProgram;
  75.                return 1;
  76.           }
  77.           else
  78.           {
  79.                // The parameter is not present in the switch entry
  80.                cerr << '"' << szProgram << '"' << " is not running\n";
  81.                delete [] szProgram;
  82.                return 0;
  83.           }
  84.      }
  85.      return 2;
  86. }
  87.  
  88.