home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / MM / CDMCIDRV / CDMCCOMN.C < prev    next >
C/C++ Source or Header  |  1995-08-24  |  7KB  |  140 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* SOURCE FILE NAME:  CDMCCOMN.C                                            */
  4. /*                                                                          */
  5. /* DESCRIPTIVE NAME:  CD MCD PARSER                                         */
  6. /*                                                                          */
  7. /* COPYRIGHT:  (c) IBM Corp. 1992, 1993                                     */
  8. /*                                                                          */
  9. /* FUNCTION:  This file contains the common functions between the CD MCD    */
  10. /*            and the IBM CD-ROM Drive VSD.                                 */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /* FUNCTIONS:                                                               */
  14. /*       parse_DevParm - Parses the device specific parameter.              */
  15. /*       get_token     - Gets next token and terminates it with a null.     */
  16. /*                                                                          */
  17. /****************************************************************************/
  18.  
  19. #include <os2.h>
  20. #include <string.h>
  21.  
  22. /* prototypes */
  23. static CHAR * get_token(CHAR *, USHORT);
  24.  
  25. /****************************************************************************/
  26. /*                                                                          */
  27. /* SUBROUTINE NAME:  parse_DevParm             DEVELOPER:  Garry Lewis      */
  28. /*                                                                          */
  29. /* DESCRIPTIVE NAME:  Parse Device Parameter                                */
  30. /*                                                                          */
  31. /* FUNCTION:  Parses the Device Specific Parameter that is supplied on      */
  32. /*            an MCI_OPEN message.  A pointer to the string to be parsed    */
  33. /*            is supplied, changed to upper case and sets NULLS after the   */
  34. /*            drive and model tokens.  Pointers to these tokens are         */
  35. /*            returned.  The pointer points to a NULL string if tokens are  */
  36. /*            not found.                                                    */
  37. /*                                                                          */
  38. /* PARAMETERS:                                                              */
  39. /*      CHAR *pSource  -- Pointer to input string to be parsed.             */
  40. /*      CHAR **ppDrive -- Pointer to Drive token.                           */
  41. /*      CHAR **ppModel -- Pointer to Model token.                           */
  42. /*                                                                          */
  43. /* EXIT CODES:  None                                                        */
  44. /*                                                                          */
  45. /* NOTES:  WARNING!! The input string will be modified.                     */
  46. /*         strtok() would have been cleaner to use, however, the global     */
  47. /*         memory used created system errors.                               */
  48. /*                                                                          */
  49. /****************************************************************************/
  50.  
  51. VOID parse_DevParm(CHAR *pSource, CHAR **ppDrive, CHAR **ppModel)
  52. {
  53.    CHAR *pDrive, *pModel;
  54.    int len;
  55.  
  56.    /* convert string to upper case */
  57.    strupr(pSource);
  58.    len = strlen(pSource);
  59.  
  60.    /* Find start of token labels */
  61.    pDrive = strstr(pSource, "DRIVE");
  62.    pModel = strstr(pSource, "MODEL");
  63.  
  64.    /* Find start of tokens */
  65.    if (pDrive == NULL)
  66.       *ppDrive = pSource + len;
  67.    else
  68.       *ppDrive = get_token(pDrive, FALSE);
  69.  
  70.    if (pModel == NULL)
  71.       *ppModel = pSource + len;
  72.    else
  73.       *ppModel = get_token(pModel, TRUE);
  74.  
  75. }  /* of parse_DevParm() */
  76.  
  77.  
  78. /****************************************************************************/
  79. /*                                                                          */
  80. /* SUBROUTINE NAME:  get_token                 DEVELOPER:  Garry Lewis      */
  81. /*                                                                          */
  82. /* DESCRIPTIVE NAME:  Get Token                                             */
  83. /*                                                                          */
  84. /* FUNCTION:  gets next token and terminates with a null.                   */
  85. /*                                                                          */
  86. /* PARAMETERS:                                                              */
  87. /*      CHAR *pToken     -- Pointer to input string to be parsed.           */
  88. /*      USHORT LastToken -- TRUE if it is the last token, Model, that       */
  89. /*                          uses the input EOL for the NUL.                 */
  90. /*                                                                          */
  91. /* EXIT CODES:  None                                                        */
  92. /*                                                                          */
  93. /* NOTES:  WARNING!! The input string will be modified.                     */
  94. /*         The Model= label needs to be the last label in the PASRMSTRING   */
  95. /*         because it could use white spaces and delimeters as valid        */
  96. /*         characters, so the EOL null is used for the EOS null.            */
  97. /*                                                                          */
  98. /****************************************************************************/
  99.  
  100. static CHAR * get_token(CHAR *pToken, USHORT LastToken)
  101. {
  102.    CHAR *pReturn;
  103.  
  104.    /* find end of label */
  105.    while (*pToken != ' '  && *pToken != '='  && *pToken != ','  &&
  106.           *pToken != '\t' && *pToken != '\n' && *pToken != '\r' &&
  107.           *pToken != '\0')
  108.       pToken++;
  109.  
  110.    /* find next token */
  111.    if (*pToken == '\0')
  112.       pReturn = pToken;
  113.    else
  114.    {
  115.       while (*pToken == ' '  || *pToken == '='  || *pToken == ','  ||
  116.              *pToken == '\t' || *pToken == '\n' || *pToken == '\r')
  117.          pToken++;
  118.  
  119.       pReturn = pToken;
  120.  
  121.       if (!LastToken)
  122.          /* terminate token */
  123.          if (*pToken != '\0')
  124.          {
  125.             while (*pToken != ' '  && *pToken != '='  && *pToken != ','  &&
  126.                    *pToken != '\t' && *pToken != '\n' && *pToken != '\r' &&
  127.                    *pToken != '\0')
  128.                pToken++;
  129.  
  130.             *pToken = '\0';                 // terminate string
  131.  
  132.          }  /* of if token is found */
  133.    }  /* of else white spaces exist */
  134.  
  135.    return(pReturn);
  136.  
  137. }  /* of get_token() */
  138.  
  139.  
  140.