home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / do_mci.zip / Do_MCI.C next >
C/C++ Source or Header  |  1993-11-28  |  4KB  |  153 lines

  1. #pragma title("Do_MCI $Revision$")
  2. #pragma subtitle("$Date$")
  3. /* $Header$ */
  4. /******************************************************************************
  5. *   $CONFIG$="/T8 /L*"
  6. *++
  7. *   $NAME$
  8. *         Do_MCI.C
  9. *
  10. *   $PATHS$
  11. *         Modules
  12. *   $/F3$
  13. *
  14. *   PRODUCT:    MIDI
  15. *   COMPONENT:    Do_MCI
  16. *   FILE NAME:    $Workfile$
  17. *   CREATED:    28-Nov-1993 - 12:13:48
  18. *
  19. *   IDENT:    $Revision$ $Modtime$
  20. *
  21. *    $Author$
  22. *    John J. McDonough
  23. *
  24. *   $1$
  25. *   PROGRAM DESCRIPTION:
  26. *
  27. *    This little program reads a script containing MCI commands and
  28. *    passes them on to the MCI API.    This allows any combination of
  29. *    WAV's, MIDI's, AVI's, etc. to be scripted.  For some reason, this
  30. *    turns out to be substantially faster than the same thing in REXX.
  31. *
  32. *   $/F4$
  33. *   MODIFICATION HISTORY:
  34. *    $Log$
  35. *
  36. *   ROUTINES CALLED:
  37. *
  38. *           Local                System
  39. *
  40. *                        feof
  41. *                        fgets
  42. *                        fopen
  43. *                        fprintf
  44. *                        mciGetErrorString
  45. *                        mciSendString
  46. *                        memset
  47. *                        perror
  48. *                        printf
  49. *                        strcpy
  50. *                        strnicmp
  51. *
  52. *   FILE:
  53. *
  54. *    Script file specified in commmand.
  55. *
  56. *   EFFECTS:
  57. *
  58. *   RESTRICTIONS:
  59. *
  60. *   $END$
  61. *    
  62. ******************************************************************************/
  63.  
  64. /*
  65. *
  66. *  INCLUDE FILES
  67. *
  68. */
  69. #include <os2.h>
  70. #include <stdio.h>
  71. #include <string.h>
  72. #include <process.h>
  73.  
  74. /* MCI API entries */
  75.  
  76. ULONG APIENTRY mciSendString (
  77.         PSZ             /* pszCommand */,
  78.         PSZ             /* pszReturnString */,
  79.         USHORT            /* usReturnLength */,
  80.         HWND            /* hwndCallback */,
  81.         USHORT            /* usUserParm */);
  82.  
  83. ULONG APIENTRY mciGetErrorString (
  84.         ULONG            /* ulError */,
  85.         PSZ             /* pszBuffer */,
  86.         USHORT            /* usLength */);
  87.  
  88. ULONG APIENTRY mciGetDeviceID (
  89.         PSZ             /* pszName */);
  90.  
  91.  
  92. void main( int argc, char *argv[] )
  93. {
  94.     int i;
  95.     ULONG ulReturn;
  96.     char szReturnString[80];
  97.     char szErrorString[80];
  98.     char szBuffer[80];
  99.     char szFileName[80];
  100.     FILE *F;
  101.  
  102.     /* Check that a file name was entered on command line */
  103.     if ( argc != 2 )
  104.         {
  105.     fprintf(stderr,"Usage Do_MCI <filename>\n\n");
  106.         exit(2);
  107.     }
  108.  
  109.     /* Go ahead and open the file */
  110.     strcpy(szFileName,argv[1]);
  111.     F = fopen(szFileName,"ra");
  112.     if ( !F )
  113.         {
  114.         perror("opening file");
  115.         exit(8);
  116.         }
  117.  
  118.     /* Read through the entire script */
  119.     while ( !feof(F) )
  120.         {
  121.         fgets(szBuffer,80,F);
  122.         if ( !feof(F) )
  123.             {
  124.             if ( szBuffer[strlen(szBuffer)-1] < ' ' )
  125.                 szBuffer[strlen(szBuffer)-1] = '\0';
  126.         printf("\033[0;36m%s\n",szBuffer);
  127.         /* If it's not an exit, assume it's an MCI string */
  128.             if ( strnicmp(szBuffer,"exit",4) )
  129.                 {
  130.                 memset(szReturnString,0,sizeof(szReturnString));
  131.                 ulReturn = mciSendString(   szBuffer,
  132.                                             szReturnString,
  133.                                             79,
  134.                                             0,
  135.                         0);
  136.         /* Possible Problem? (some strings will return data) */
  137.                 if ( ulReturn )
  138.                     {
  139.                     mciGetErrorString(ulReturn,szErrorString,79);
  140.                     printf("\t\033[37;41;1m%% %s\033[0;36m\n",szErrorString);
  141.                     }
  142.         if ( szReturnString[0] )
  143.                     printf("\t\033[0;33;1m+ %s\033[0;36m\n",szReturnString);
  144.                 }
  145.         }
  146.     /* If we're all done, we're all done */
  147.         if ( !strnicmp(szBuffer,"exit",4) )
  148.             break;
  149.     }
  150.  
  151.     printf("\n");
  152. }
  153.