home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / ACDCR032.ZIP / source / launchers / msinfo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-04  |  3.3 KB  |  122 lines

  1. /* This wrapper prog starts cdrecord/2 to retrieve multisession information
  2.  */
  3. /*
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2, or (at your option)
  7.  * any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; see the file COPYING.  If not, write to
  16.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18. #define INCL_DOS
  19. #define INCL_WIN
  20.  
  21. #include <os2.h>
  22. #include <time.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <io.h>
  27.  
  28. void main(int argc, char * argv[])
  29. {
  30.     int i;
  31.     char cmdLine[CCHMAXPATH*4]={0};
  32.     char * chrPtr;    
  33.     char * chrPtr2;
  34.     HWND hwndNotify;
  35.     char exeName[CCHMAXPATH];//="g:\\projects_working\\audiocpy\\cdrecord.exe";
  36.     char chrError[CCHMAXPATH];
  37.     RESULTCODES resultCodes;
  38.     ULONG rc,ulAction;
  39.  
  40.  
  41.     HFILE SaveStdOut;
  42.     HFILE NewStdOut;
  43.     HPIPE readPipe;
  44.     HPIPE writePipe;
  45.     char puffer[1024];
  46.     ULONG ulBytesRead;
  47.     LONG lValue1=0;
  48.     LONG lValue2=0;
  49.  
  50.     hwndNotify=atol(argv[1]);
  51.     /* Error: no cdrecord options given */
  52.     if(argc<4) {
  53.       WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(lValue1),MPFROMLONG(lValue2));
  54.       return;
  55.     }
  56.  
  57.     /* Get input */
  58.     sprintf(exeName,"%s",argv[2]);// cdrecord/2 path
  59.  
  60.     for(i=3;i<argc;i++) {
  61.       /* Find 'dev=' in option string */
  62.       chrPtr=strstr(argv[i],"dev=");
  63.       if(chrPtr!=NULL)i=argc;
  64.     }
  65.  
  66.     /* Error: dev not found */
  67.     if(chrPtr==NULL) {
  68.       WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(lValue1),MPFROMLONG(lValue2));
  69.       return;
  70.     }
  71.     /* Build cdrecord/2 cmd-line */
  72.     sprintf(cmdLine,"%s",exeName);
  73.     chrPtr2=strrchr(cmdLine,0)+1;
  74.     sprintf(chrPtr2,"%s -msinfo",chrPtr);
  75.     *(strrchr(chrPtr2,0)+1)=0;
  76.     
  77.     if(DosCreatePipe(&readPipe,&writePipe,1024)) {
  78.       WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(lValue1),MPFROMLONG(lValue2));
  79.       return;
  80.     }
  81.  
  82.     /* Save stdout */
  83.     SaveStdOut=-1;
  84.     DosDupHandle(1,&SaveStdOut);
  85.  
  86.     /* Redirect stdout */
  87.     NewStdOut=1;
  88.     DosDupHandle(writePipe,&NewStdOut);
  89.  
  90.     /* start cdrecord/2 */
  91.     DosExecPgm(chrError,sizeof(chrError),EXEC_SYNC,cmdLine,0,&resultCodes,exeName);
  92.  
  93.     /* Retrieve output */
  94.     rc=DosRead(readPipe,puffer,sizeof(puffer),&ulBytesRead);
  95.  
  96.     if(ulBytesRead>2) {
  97.       lValue1=atol(puffer);// Previous session start sector
  98.       puffer[1023]=0; //Make sure we have a terminating zero!
  99.       chrPtr=strchr(puffer,',');
  100.       chrPtr++;
  101.       lValue2=atol(chrPtr);
  102.     }
  103.   
  104.     DosClose(readPipe);
  105.     DosClose(writePipe);
  106.     //    sprintf(options,"Wert1: %d Wert2: %d\n",lValue1,lValue2);
  107.     // DosWrite(2,options,strlen(options),&ulBytesRead);
  108.    
  109.   
  110.     /* Send the two values to our notification window */
  111.     WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(lValue1),MPFROMLONG(lValue2));
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.