home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / WINSPAWN.CMM < prev    next >
Text File  |  1994-08-02  |  4KB  |  107 lines

  1. //*****************************************************************
  2. //*** WinSpawn.cmm - Run from CEnvi for Windows to allow the    ***
  3. //*** ver.1          WinSpawn() routine in WinSpawn.lib to      ***
  4. //***                call the spawn command in Windows sessions ***
  5. //***                running under WINOS2.                      ***
  6. //*****************************************************************
  7.  
  8. if ( !defined(_WINDOWS_) ) {
  9.    printf("\a\nThis program must be executed from CEnvi for Windows\n");
  10.    printf("to serve the OS/2 WinSpawn() routine from CEnvi for OS/2.\n");
  11.    printf("Press any key to exit...");
  12.    getch();
  13.    printf("\n");
  14.    exit(EXIT_FAILURE);
  15. }
  16.  
  17. #include <OptParms.lib>
  18.  
  19. main(argc,argv)
  20. {
  21.    Hide = OptionalParameter(argc,argv,"HIDE");
  22.    FileName = argv[1];
  23.    WaitTime = atoi(argv[2]);
  24.  
  25.    if ( 3 != argc  ||  WaitTime < 1 ) {
  26.       Instructions();
  27.       return EXIT_FAILURE;
  28.    }
  29.  
  30.    // Give this session the name of the file
  31.    sprintf(NewTitle,"WinSpawn: %s",FileName);
  32.    DynamicLink("USER","SETWINDOWTEXT",SWORD16,PASCAL,ScreenHandle(),NewTitle);
  33.  
  34.    // If want to be hidden, then hide it
  35.    if ( Hide )
  36.       DynamicLink("USER","SHOWWINDOW",SWORD16,PASCAL,ScreenHandle(),0);
  37.  
  38.    SpawnForever(FileName,WaitTime);
  39.    return EXIT_SUCCESS;
  40. }
  41.  
  42. #define WIN_SPAWN       0  // spawn command and return immediately
  43. #define WIN_SPAWN_WAIT  1  // spawn and wait until command is finished
  44. #define WIN_SPAWN_EXIT  2  // spawn and then exit WinSpawn.cmm
  45.  
  46. SpawnForever(pFileSpec,pDelay)
  47.    // get all messages from WinSpawn.lib and spawn them
  48. {
  49.    sprintf(FullPipeSpec,"\\PIPE\\%s",pFileSpec);
  50.    lExit = False;
  51.    do {
  52.       suspend(pDelay);
  53.  
  54.       // try to read command from pipe file
  55.       if ( fp = fopen(FullPipeSpec,"r+b") ) {
  56.  
  57.          // read the action to perform, how many bytes in the message,
  58.          // and then the message
  59.          if ( fread(lAction,UWORD32,fp)
  60.            && fread(lCommandLen,UWORD32,fp) && lCommandLen
  61.            && fread(lCommand,lCommandLen,fp) ) {
  62.  
  63.             // final check that Command is CommandLen long
  64.             if ( strlen(lCommand) == (lCommandLen-1) ) {
  65.  
  66.                // perform spawn command
  67.                if ( 1 == lCommandLen ) {
  68.                   lResult = 0;   // nothing happened
  69.                } else {
  70.                   lResult = spawn(WIN_SPAWN_WAIT == lAction ? P_WAIT : P_NOWAIT,
  71.                                   lCommand);
  72.                }
  73.  
  74.                // send back return code
  75.                rewind(fp);
  76.                BLObPut(lResultBLOb,0,lResult,SWORD32);
  77.                fwrite(lResultBLOb,BLObSize(lResultBLOb),fp);
  78.  
  79.                if ( WIN_SPAWN_EXIT == lAction )
  80.                   lExit = True;
  81.             }
  82.          }
  83.          fclose(fp);
  84.       }
  85.    } while ( !lExit );
  86. }
  87.  
  88. Instructions()
  89. {
  90.    puts("\a");
  91.    puts(`WinSpawn - Perform the CEnvi spawn() function from WINOS2`);
  92.    puts(``)
  93.    puts(`SYNTAX: CENVI WINSPAWN <PipeSpec> <Delay> [/HIDE]`)
  94.    puts(``)
  95.    puts(`WHERE: PipeSpec - Unique 8.3 name to identify this WINSPAWN session`)
  96.    puts(`       Delay - time (milliseconds) to delay between checks`)
  97.    puts(`       HIDE - Optional; hide thise CEnvi program icon`)
  98.    puts(``)
  99.    puts(`Examples: the following examples run from OS/2`)
  100.    puts(`  START /FS /F C:\CENVIWIN\CENVI.EXE D:\CENVIOS2\WinSpawn FAXER 3000`)
  101.    puts(`  START /WIN C:\CENVIWIN\CENVI.EXE FAXER 5000 /HIDE`)
  102.    puts(``)
  103.    puts(`Press any key to exit...`)
  104.    getch()
  105. }
  106.  
  107.