home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / cdmct / cdmccomn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  6.8 KB  |  142 lines

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