home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmpm21tk.zip / TK / ADMCT / ADMCINI.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  10KB  |  247 lines

  1. /***************************************************************************
  2. *                                                                          *
  3. * SOURCE FILE NAME:  ADMCINI.C                                             *
  4. *                                                                          *
  5. * DESCRIPTIVE NAME:  Audio MCD Ini PARSER                                  *
  6. *                                                                          *
  7. *              Copyright (c) IBM Corporation  1991, 1993
  8. *                        All Rights Reserved
  9. *
  10. * FUNCTION:  This file contains the routines which will retrieve the       *
  11. *            defaults values from the ini file for the amp/mixer.          *
  12. *                                                                          *
  13. ****************************************************************************/
  14.  
  15. #define INCL_BASE
  16. #define INCL_DOSMODULEMGR
  17. #define INCL_DOSSEMAPHORES
  18.  
  19. #include <os2.h>                        // OS2 defines.
  20. #include <string.h>                     // String functions.
  21. #include <os2medef.h>                   // MME includes files.
  22. #include <math.h>                       // Standard Math Lib
  23. #include <stdlib.h>                     // Standard Library
  24. #include <audio.h>                      // Audio Device defines
  25. #include <ssm.h>                        // SSM spi includes.
  26. #include <meerror.h>                    // MM Error Messages.
  27. #include <mmioos2.h>                    // MMIO Include.
  28. #include <mcios2.h>                     // MM System Include.
  29. #include <mmdrvos2.h>                   // MCI Driver include.
  30. #include <mcd.h>                        // AudioIFDriverInterface.
  31. #include <hhpheap.h>                    // Heap Manager Definitions
  32. #include <admcdat.h>
  33. #include <qos.h>
  34. #include <audiomcd.h>                   // Component Definitions.
  35. #include <admcfunc.h>
  36.  
  37.  
  38. /***************************************************************************
  39. *                                                                          *
  40. * SUBROUTINE NAME:  parse_DevParm             DEVELOPER:  Garry Lewis      *
  41. *                                                                          *
  42. * DESCRIPTIVE NAME:  Parse Device Parameter                                *
  43. *                                                                          *
  44. * FUNCTION:  Parses the Device Specific Parameter that is supplied on      *
  45. *            an MCI_OPEN message.  A pointer to the string to be parsed    *
  46. *            is supplied, changed to upper case and sets NULLS after the   *
  47. *            drive and model tokens.  Pointers to these tokens are         *
  48. *            returned.  The pointer points to a NULL string if tokens are  *
  49. *            not found.                                                    *
  50. *                                                                          *
  51. * PARAMETERS:                                                              *
  52. *                                                                          *
  53. * EXIT CODES:  None                                                        *
  54. *                                                                          *
  55. * NOTES:  WARNING!! The input string will be modified.                     *
  56. *         strtok() would have been cleaner to use, however, the global     *
  57. *         memory used created system errors.                               *
  58. *                                                                          *
  59. ****************************************************************************/
  60.  
  61. ULONG GetDefaults( PCHAR               pOrigSource,
  62.                    INSTANCE            *pInstance )
  63. {
  64.    PCHAR        pDataType;
  65.    PCHAR        pSamplingRate;
  66.    PCHAR        pBitsPerSample;
  67.    PCHAR        pChannels;
  68.    PCHAR        pSource;
  69.    PCHAR        pOperation;
  70.    CHAR         chTemp[ 256 ] ;
  71.    PCHAR        pTemp;
  72.  
  73.    ULONG        ulrc;
  74.    ULONG        ulLength;
  75.  
  76.    /* convert string to upper case */
  77.  
  78.    strupr( pOrigSource );
  79.  
  80.  
  81.    ulLength = strlen( pOrigSource );
  82.  
  83.    memmove( chTemp, pOrigSource, ulLength );
  84.  
  85.    pSource = chTemp;
  86.  
  87.  
  88.    /* Find start of token labels */
  89.  
  90.    pDataType      = strstr(pSource, "FORMAT");
  91.    pSamplingRate  = strstr(pSource, "SAMPRATE");
  92.    pBitsPerSample = strstr(pSource, "BPS");
  93.    pChannels      = strstr(pSource, "CHANNELS");
  94.    pOperation     = strstr(pSource, "DIRECTION");
  95.  
  96.  
  97.    /* Find start of tokens */
  98.  
  99.    ulrc = PutInInstance( &(pInstance->lDefaultFormat),  pDataType );
  100.  
  101.    if ( ulrc )
  102.       {
  103.       pInstance->lDefaultFormat = DATATYPE_WAVEFORM;
  104.       }
  105.  
  106.    PutInInstance( &(pInstance->lDefaultSRate),   pSamplingRate   );
  107.  
  108.    if ( ulrc )
  109.       {
  110.       pInstance->lDefaultSRate = 22050;
  111.       }
  112.  
  113.    PutInInstance( &(pInstance->lDefaultBPS),     pBitsPerSample   );
  114.  
  115.  
  116.    if ( ulrc )
  117.       {
  118.       pInstance->lDefaultBPS = 8;
  119.       }
  120.  
  121.    ulrc = PutInInstance( &(pInstance->lDefaultChannels),pChannels);
  122.  
  123.  
  124.    if ( ulrc )
  125.       {
  126.       pInstance->lDefaultChannels = 1;
  127.       }
  128.  
  129.  
  130.    if ( pOperation == NULL )
  131.       {
  132.       pInstance->lDefaultOperation = OPERATION_PLAY;
  133.       }
  134.    else
  135.       {
  136.       pTemp = GetToken( pOperation, TRUE);
  137.       if ( !strncmp( pTemp, "PLAY", 4 ) )
  138.          {
  139.          pInstance->lDefaultOperation = OPERATION_PLAY;
  140.          }
  141.       else
  142.          {
  143.          pInstance->lDefaultOperation = OPERATION_RECORD;
  144.          }
  145.       }
  146.  
  147.  
  148.    return ( MCIERR_SUCCESS );
  149.  
  150. }  /* GetDefaults */
  151.  
  152.  
  153. /****************************************************************************/
  154. /*                                                                          */
  155. /* SUBROUTINE NAME:  get_token                 DEVELOPER:  Garry Lewis      */
  156. /*                                                                          */
  157. /* DESCRIPTIVE NAME:  Get Token                                             */
  158. /*                                                                          */
  159. /* FUNCTION:  gets next token and terminates with a null.                   */
  160. /*                                                                          */
  161. /* PARAMETERS:                                                              */
  162. /*      CHAR *pToken     -- Pointer to input string to be parsed.           */
  163. /*      USHORT LastToken -- TRUE if it is the last token, Model, that       */
  164. /*                          uses the input EOL for the NUL.                 */
  165. /*                                                                          */
  166. /* EXIT CODES:  None                                                        */
  167. /*                                                                          */
  168. /* NOTES:  WARNING!! The input string will be modified.                     */
  169. /*         The Model= label needs to be the last label in the PASRMSTRING   */
  170. /*         because it could use white spaces and delimeters as valid        */
  171. /*         characters, so the EOL null is used for the EOS null.            */
  172. /*                                                                          */
  173. /****************************************************************************/
  174.  
  175. static PCHAR GetToken(PCHAR    pToken, 
  176.                       USHORT   LastToken)
  177. {
  178.    CHAR *pReturn;
  179.  
  180.    /* find end of label */
  181.    while (*pToken != ' '  && *pToken != '='  && *pToken != '\0')
  182.       pToken++;
  183.  
  184.    /* find next token */
  185.    if (*pToken == '\0')
  186.       pReturn = pToken;
  187.    else
  188.    {
  189.       while (*pToken == ' '  || *pToken == '='  || *pToken == '\0' )
  190.          pToken++;
  191.  
  192.       pReturn = pToken;
  193.  
  194.       if (!LastToken)
  195.          /* terminate token */
  196.          if (*pToken != '\0')
  197.          {
  198.             while (*pToken != ' '  && *pToken != ','  && *pToken != '\0' )
  199.                pToken++;
  200.  
  201.             *pToken = '\0';                 // terminate string
  202.  
  203.          }  /* of if token is found */
  204.    }  /* of else white spaces exist */
  205.  
  206.    return(pReturn);
  207.  
  208. }  /* GetToken */
  209.  
  210.  
  211. /***************************************************************************
  212. *                                                                          *
  213. * SUBROUTINE NAME:  PutInInstance                                          *
  214. *                                                                          *
  215. * DESCRIPTIVE NAME:  PutInInstance                                         *
  216. *                                                                          *
  217. * FUNCTION:  Places a string value from the INI file into the MCD          *
  218. *            instance.                                                     *
  219. *                                                                          *
  220. * PARAMETERS:                                                              *
  221. *                                                                          *
  222. * EXIT CODES:  None                                                        *
  223. *                                                                          *
  224. * NOTES:                                                                   *
  225. *                                                                          *
  226. ****************************************************************************/
  227.  
  228. ULONG PutInInstance( PLONG   pValue,
  229.                     PCHAR   pString )
  230.  
  231. {
  232.   PCHAR         pTemp;
  233.  
  234.    if ( pString == NULL)
  235.       {
  236.       return ( MCIERR_INI_FILE );
  237.       }
  238.    else
  239.       {
  240.       pString = GetToken( pString, FALSE);
  241.       *pValue = atol( pString );
  242.       }
  243.  
  244.   return ( MCIERR_SUCCESS );
  245.  
  246. } /* PutInInstance */
  247.