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