home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / ACDCR032.ZIP / source / launchers / cdr2lnch.cpp next >
Encoding:
C/C++ Source or Header  |  1999-08-08  |  3.5 KB  |  131 lines

  1. /*
  2.  * This file is (C) Chris Wohlgemuth 1999
  3.  */
  4. /*
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; see the file COPYING.  If not, write to
  17.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19. #define INCL_DOS
  20. #define INCL_WIN
  21.  
  22. #include <os2.h>
  23. #include <time.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <io.h>
  28.  
  29. void changeChar(char* text, char which, char with)
  30. {
  31.   char * chrPtr;
  32.   
  33.   chrPtr=strchr(text,which);
  34.  
  35.   while(chrPtr!=NULL) {
  36.     *chrPtr=with;
  37.     chrPtr=strchr(text,which);
  38.   }
  39. }
  40.  
  41.  
  42. void main(int argc, char * argv[])
  43. {
  44.     int i;
  45.     char cmdLine[CCHMAXPATH*4]={0};
  46.     char cmdLineBuff[CCHMAXPATH*4];
  47.     char * chrPtr;
  48.     char * chrPtr2;    
  49.     HWND hwndNotify;
  50.     char exeName[CCHMAXPATH];//"g:\\projects_working\\audiocpy\\show.exe";
  51.     char chrError[CCHMAXPATH];
  52.     char logName[CCHMAXPATH];
  53.     RESULTCODES resultCodes;
  54.     ULONG rc,ulAction;
  55.     HFILE hf,hfNew;
  56.     time_t ltime;
  57.     
  58.     hwndNotify=atol(argv[1]);
  59.  
  60.     /* Build grabber input */
  61.     sprintf(exeName,"%s",argv[2]);
  62.     sprintf(logName,"%s\\write.log",argv[3]);
  63.     
  64.     sprintf(cmdLine,exeName);
  65.     chrPtr=strrchr(cmdLine,0);
  66.     chrPtr++;
  67.  
  68.     /* Build parameters */
  69.     for(i=4;i<argc;i++) {
  70.       sprintf(cmdLineBuff,"%s",chrPtr);
  71.       sprintf(chrPtr,"%s %s",cmdLineBuff,argv[i]);
  72.     }
  73.     /* Replace ' with " */
  74.     changeChar(chrPtr,'\'','\"');
  75.  
  76.     /* Replace ^ with space */
  77.     changeChar(chrPtr,'^',' ');
  78.  
  79.     printf("HWND: %d",hwndNotify);
  80.     printf("\n");    
  81.     printf("cdrecord-executable: %s",exeName);
  82.     printf("\n");
  83.     printf("Logname: %s\n",logName);
  84.     printf("cdrecord parameter: %s",chrPtr);
  85.     printf("\n");
  86.  
  87.     /* Redirect stderr */
  88.     rc=DosOpen(logName,&hf,&ulAction,0,FILE_NORMAL,OPEN_ACTION_CREATE_IF_NEW|OPEN_ACTION_OPEN_IF_EXISTS,
  89.                OPEN_ACCESS_WRITEONLY|OPEN_SHARE_DENYWRITE,0);
  90.     if(!rc) {
  91.         DosSetFilePtr(hf,0,FILE_END,&ulAction);
  92.         hfNew=2;
  93.         DosDupHandle(hf,&hfNew);
  94.         
  95.         sprintf(logName,"---------------------------------------------------------------------\n");
  96.         write(2,logName,strlen(logName));
  97.  
  98.         sprintf(logName,"\n");
  99.         write(2,logName,strlen(logName));    
  100.         
  101.         /*    time(<ime);        
  102.         sprintf(logName,"%s",ctime(<ime));
  103.         write(2,logName,strlen(logName));    
  104.         sprintf(logName,"\n");
  105.         write(2,logName,strlen(logName));    */
  106.     
  107.         sprintf(logName,"Starting to write using %s\n",exeName);
  108.         write(2,logName,strlen(logName));
  109.         
  110.         sprintf(logName,"with the following parameters: %s\n",chrPtr);
  111.         write(2,logName,strlen(logName));
  112.     }
  113.     
  114.     DosExecPgm(chrError,sizeof(chrError),EXEC_SYNC,cmdLine,0,&resultCodes,exeName);
  115.     sprintf(logName,"Return code is: %d\n ",resultCodes.codeResult);
  116.     write(2,logName,strlen(logName));
  117.     /*    sprintf(logName,"---------------------------------------------------------------------\n");
  118.     write(2,logName,strlen(logName));*/
  119.     DosClose(hf);
  120.     WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,0,MPFROMLONG(resultCodes.codeResult));
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.