Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. cpinfo.c
  5. Abstract:
  6. Copepage information handling.
  7. Extract codepage information from codepage text file.
  8. Environment:
  9. Windows NT PostScript driver
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. //
  14. // Macros
  15. //
  16. #define IS_COMMENT(c) ((c) == (BYTE)';')
  17. #define EOL '\n'
  18. //
  19. // Local function prototypes
  20. //
  21. PBYTE PubSkipComment( PBYTE );
  22. INT IGetCommand(PBYTE, PBYTE);
  23. //
  24. // Main function
  25. //
  26. BOOL
  27. BGetInfo(
  28. PBYTE pData,
  29. DWORD dwSize,
  30. DWORD *pdwCodePage,
  31. PBYTE pSelectCmd,
  32. PBYTE pUnSelectCmd)
  33. {
  34. BYTE aubType[32];
  35. PBYTE pstrType;
  36. PBYTE pTextData;
  37. INT iRet;
  38. ASSERT(pData != NULL &&
  39. pdwCodePage != NULL &&
  40. pSelectCmd != NULL &&
  41. pUnSelectCmd != NULL );
  42. pstrType = aubType;
  43. pTextData = pData;
  44. do
  45. {
  46. pTextData = PubSkipComment(pTextData);
  47. if (pTextData == NULL)
  48. {
  49. iRet = EOF;
  50. break;
  51. }
  52. iRet = sscanf( pTextData, "%s:", pstrType);
  53. if (iRet != 0 && iRet != EOF)
  54. {
  55. pTextData += strlen(pstrType);
  56. }
  57. pTextData = PubSkipComment(pTextData);
  58. switch(*pstrType)
  59. {
  60. case 'c':
  61. case 'C':
  62. if(!_stricmp(pstrType, "codepage:"))
  63. {
  64. iRet = sscanf(pTextData, "%d", pdwCodePage);
  65. if (iRet != 0 && iRet != EOF)
  66. {
  67. while (*pTextData != EOL)
  68. pTextData ++;
  69. pTextData ++;
  70. }
  71. }
  72. break;
  73. case 's':
  74. case 'S':
  75. if(!_stricmp(pstrType, "selectcmd:"))
  76. {
  77. iRet = IGetCommand(pTextData, pSelectCmd);
  78. if (iRet != 0 && iRet != EOF)
  79. {
  80. while (*pTextData != EOL)
  81. pTextData ++;
  82. pTextData ++;
  83. }
  84. }
  85. break;
  86. case 'u':
  87. case 'U':
  88. if(!_stricmp(pstrType, "unselectcmd:"))
  89. {
  90. iRet = IGetCommand(pTextData, pUnSelectCmd);
  91. if (iRet != 0 && iRet != EOF)
  92. {
  93. while (*pTextData != EOL)
  94. pTextData ++;
  95. pTextData ++;
  96. }
  97. }
  98. break;
  99. default:
  100. pTextData++;
  101. }
  102. }
  103. while(*pTextData != EOF && dwSize > (DWORD)(pTextData - pData));
  104. return TRUE;
  105. }
  106. PBYTE
  107. PubSkipComment(
  108. PBYTE pData)
  109. {
  110. ASSERT(pData != NULL);
  111. do
  112. {
  113. if (IS_COMMENT(*pData))
  114. {
  115. while (*pData != EOL)
  116. pData++;
  117. pData++;
  118. }
  119. else if (*pData == ' ')
  120. {
  121. pData++;
  122. }
  123. else if (*pData == 0x0d)
  124. {
  125. pData++;
  126. }
  127. else if (*pData == EOL)
  128. {
  129. pData++;
  130. }
  131. else if (*pData == EOF)
  132. {
  133. pData = NULL;
  134. break;
  135. }
  136. else
  137. break;
  138. } while (TRUE);
  139. return pData;
  140. }
  141. INT
  142. IGetCommand(
  143. PBYTE pData,
  144. PBYTE pDestBuf)
  145. {
  146. INT iCount;
  147. if (*pData == EOF)
  148. {
  149. return EOF;
  150. }
  151. if (*pData == '"')
  152. {
  153. pData ++;
  154. }
  155. else
  156. {
  157. return 0;
  158. }
  159. iCount = 0;
  160. while (*pData != '"')
  161. {
  162. *pDestBuf = *pData;
  163. pDestBuf ++;
  164. pData++;
  165. iCount++;
  166. }
  167. *pDestBuf = (BYTE)NULL;
  168. iCount++;
  169. return iCount;
  170. }