Source code of Windows XP (NT5)
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.

169 lines
5.8 KiB

  1. /*
  2. ** Copyright 1995-2095, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. */
  17. #include "glslib.h"
  18. #include <stdlib.h>
  19. __GLSparser* __glsParser_create(void) {
  20. __GLSparser *const outParser = __glsCalloc(1, sizeof(__GLSparser));
  21. GLint count, i, j;
  22. if (!outParser) return GLS_NONE;
  23. outParser->glAttribMaskDict = __glsStrDict_create(
  24. __GL_ATTRIB_MASK_COUNT, GL_TRUE
  25. );
  26. if (!outParser->glAttribMaskDict) return __glsParser_destroy(outParser);
  27. for (i = 0 ; i < __GL_ATTRIB_MASK_COUNT ; ++i) {
  28. if (!__glsStr2IntDict_add(
  29. outParser->glAttribMaskDict,
  30. __glAttribMaskString[i],
  31. (GLint)__glAttribMaskVal[i]
  32. )) {
  33. return __glsParser_destroy(outParser);
  34. }
  35. }
  36. /* GL_ZERO GL_ONE GL_FALSE GL_TRUE GL_NONE GL_NO_ERROR */
  37. count = 6;
  38. for (i = 0 ; i < __GL_ENUM_PAGE_COUNT ; ++i) {
  39. count += __glEnumStringCount[i];
  40. }
  41. outParser->glEnumDict = __glsStrDict_create(count, GL_TRUE);
  42. if (!outParser->glEnumDict) return __glsParser_destroy(outParser);
  43. if (
  44. !__glsStr2IntDict_add(outParser->glEnumDict, glsCSTR("GL_ZERO"), 0) ||
  45. !__glsStr2IntDict_add(outParser->glEnumDict, glsCSTR("GL_ONE"), 1) ||
  46. !__glsStr2IntDict_add(outParser->glEnumDict, glsCSTR("GL_FALSE"), 0) ||
  47. !__glsStr2IntDict_add(outParser->glEnumDict, glsCSTR("GL_TRUE"), 1) ||
  48. !__glsStr2IntDict_add(outParser->glEnumDict, glsCSTR("GL_NONE"), 0) ||
  49. !__glsStr2IntDict_add(outParser->glEnumDict, glsCSTR("GL_NO_ERROR"), 0)
  50. ) {
  51. return __glsParser_destroy(outParser);
  52. }
  53. for (i = 0 ; i < __GL_ENUM_PAGE_COUNT ; ++i) {
  54. for (j = 0 ; j < __glEnumStringCount[i] ; ++j) {
  55. if (__glEnumString[i][j] && !__glsStr2IntDict_add(
  56. outParser->glEnumDict,
  57. __glEnumString[i][j],
  58. __GL_ENUM(i, j)
  59. )) {
  60. return __glsParser_destroy(outParser);
  61. }
  62. }
  63. }
  64. /* GL_FALSE GL_TRUE */
  65. count = 2;
  66. for (i = 0 ; i < __GLS_ENUM_PAGE_COUNT ; ++i) {
  67. count += __glsEnumStringCount[i];
  68. }
  69. outParser->glsEnumDict = __glsStrDict_create(count, GL_TRUE);
  70. if (!outParser->glsEnumDict) return __glsParser_destroy(outParser);
  71. if (
  72. !__glsStr2IntDict_add(
  73. outParser->glsEnumDict, glsCSTR("GL_FALSE"), 0
  74. ) ||
  75. !__glsStr2IntDict_add(
  76. outParser->glsEnumDict, glsCSTR("GL_TRUE"), 1
  77. )
  78. ) {
  79. return __glsParser_destroy(outParser);
  80. }
  81. for (i = 0 ; i < __GLS_ENUM_PAGE_COUNT ; ++i) {
  82. for (j = 0 ; j < __glsEnumStringCount[i] ; ++j) {
  83. if (__glsEnumString[i][j] && !__glsStr2IntDict_add(
  84. outParser->glsEnumDict,
  85. __glsEnumString[i][j],
  86. __GLS_ENUM(i, j)
  87. )) {
  88. return __glsParser_destroy(outParser);
  89. }
  90. }
  91. }
  92. outParser->glsImageFlagsDict = __glsStrDict_create(
  93. __GLS_IMAGE_FLAGS_COUNT, GL_TRUE
  94. );
  95. if (!outParser->glsImageFlagsDict) return __glsParser_destroy(outParser);
  96. for (i = 0 ; i < __GLS_IMAGE_FLAGS_COUNT ; ++i) {
  97. if (!__glsStr2IntDict_add(
  98. outParser->glsImageFlagsDict,
  99. __glsImageFlagsString[i],
  100. (GLint)__glsImageFlagsVal[i]
  101. )) {
  102. return __glsParser_destroy(outParser);
  103. }
  104. }
  105. for (
  106. count = 0, i = __GLS_OPCODES_PER_PAGE ; i < __GLS_OPCODE_COUNT ; ++i
  107. ) {
  108. if (__glsOpcodeString[i]) ++count;
  109. }
  110. outParser->glsOpDict = __glsStrDict_create(count, GL_TRUE);
  111. if (!outParser->glsOpDict) return __glsParser_destroy(outParser);
  112. for (i = __GLS_OPCODES_PER_PAGE ; i < __GLS_OPCODE_COUNT ; ++i) {
  113. if (__glsOpcodeString[i] && !__glsStr2IntDict_add(
  114. outParser->glsOpDict,
  115. __glsOpcodeString[i],
  116. (GLint)__glsUnmapOpcode(i)
  117. )) {
  118. return __glsParser_destroy(outParser);
  119. }
  120. }
  121. return outParser;
  122. }
  123. __GLSparser* __glsParser_destroy(__GLSparser *inParser) {
  124. if (!inParser) return GLS_NONE;
  125. __glsStrDict_destroy(inParser->glAttribMaskDict);
  126. __glsStrDict_destroy(inParser->glEnumDict);
  127. __glsStrDict_destroy(inParser->glsEnumDict);
  128. __glsStrDict_destroy(inParser->glsImageFlagsDict);
  129. __glsStrDict_destroy(inParser->glsOpDict);
  130. free(inParser);
  131. return GLS_NONE;
  132. }
  133. GLboolean __glsParser_findCommand(
  134. const __GLSparser *inParser, const GLubyte *inCommand, GLSopcode *outOpcode
  135. ) {
  136. if (
  137. __glsStr2IntDict_find(inParser->glsOpDict, inCommand, (GLint*)outOpcode
  138. )) {
  139. return GL_TRUE;
  140. } else {
  141. __GLS_CALL_UNSUPPORTED_COMMAND(__GLS_CONTEXT);
  142. *outOpcode = GLS_OP_glsUnsupportedCommand;
  143. return GL_FALSE;
  144. }
  145. }
  146. void __glsParser_print(const __GLSparser *inParser) {
  147. __glsStrDict_print(
  148. inParser->glAttribMaskDict, glsCSTR("glAttribMaskDict")
  149. );
  150. __glsStrDict_print(
  151. inParser->glEnumDict, glsCSTR("glEnumDict")
  152. );
  153. __glsStrDict_print(
  154. inParser->glsEnumDict, glsCSTR("glsEnumDict")
  155. );
  156. __glsStrDict_print(
  157. inParser->glsImageFlagsDict, glsCSTR("glsImageFlagsDict")
  158. );
  159. __glsStrDict_print(
  160. inParser->glsOpDict, glsCSTR("glsOpDict")
  161. );
  162. }