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.

992 lines
31 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 <ctype.h>
  19. #include <errno.h>
  20. #include <float.h>
  21. #include <limits.h>
  22. #include <locale.h>
  23. #include <math.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. /******************************************************************************
  27. Helpers
  28. ******************************************************************************/
  29. #define __GLS_BEGIN_PARAM(inoutReader) \
  30. if ( \
  31. inoutReader->error || \
  32. inoutReader->paramCount++ && \
  33. !__glsReader_getChar_text(inoutReader, ',', GL_TRUE) \
  34. ) { \
  35. return GL_FALSE; \
  36. }
  37. #define __GLS_GET_TEXT(inType, inBase) \
  38. __GLS_GET_TEXT_VAL(inType, inBase) \
  39. __GLS_GET_TEXT_VEC(inType, inBase)
  40. #define __GLS_GET_TEXT_VAL(inType, inBase) \
  41. GLboolean __glsReader_get##inType##_text( \
  42. __GLSreader *inoutReader, inType *outVal \
  43. ) { \
  44. __GLSstring token; \
  45. __glsString_init(&token); \
  46. __GLS_BEGIN_PARAM(inoutReader); \
  47. if ( \
  48. __glsReader_getToken_text(inoutReader, &token) && \
  49. __glsTokenTo##inBase(token.head, outVal) \
  50. ) { \
  51. __glsString_final(&token); \
  52. return GL_TRUE; \
  53. } else { \
  54. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR); \
  55. __glsString_final(&token); \
  56. return GL_FALSE; \
  57. } \
  58. }
  59. #define __GLS_GET_TEXT_VEC(inType, inBase) \
  60. GLboolean __glsReader_get##inType##v_text( \
  61. __GLSreader *inoutReader, GLuint inCount, inType *outVec \
  62. ) { \
  63. __GLSstring token; \
  64. __GLS_BEGIN_PARAM(inoutReader); \
  65. if (!__glsReader_getChar_text(inoutReader, '{', GL_TRUE)) { \
  66. return GL_FALSE; \
  67. } \
  68. __glsString_init(&token); \
  69. while (inCount-- > 0) if ( \
  70. !__glsReader_getToken_text(inoutReader, &token) || \
  71. !__glsTokenTo##inBase(token.head, outVec++) || \
  72. inCount > 0 && !__glsReader_getChar_text(inoutReader, ',', GL_TRUE) \
  73. ) { \
  74. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR); \
  75. __glsString_final(&token); \
  76. return GL_FALSE; \
  77. } \
  78. __glsString_final(&token); \
  79. __glsReader_getChar_text(inoutReader, ',', GL_FALSE); \
  80. if (!__glsReader_getChar_text(inoutReader, '}', GL_TRUE)) { \
  81. return GL_FALSE; \
  82. } \
  83. return GL_TRUE; \
  84. }
  85. #define __GLS_READER_APPEND_CHAR(inoutReader, inoutString, inChar) \
  86. if (!__glsString_appendChar(inoutString, inChar)) { \
  87. __glsReader_raiseError(inoutReader, GLS_OUT_OF_MEMORY); \
  88. return GL_FALSE; \
  89. }
  90. /******************************************************************************
  91. Token converters
  92. ******************************************************************************/
  93. __GLS_FORWARD static GLboolean __glsTokenToGLulong(
  94. const GLubyte *inToken, GLulong *outVal
  95. );
  96. __GLS_FORWARD static GLboolean __glsTokenToGLuint(
  97. const GLubyte *inToken, GLuint *outVal
  98. );
  99. static GLubyte __glsQuotedChar(const GLubyte *inToken, GLubyte **outPtr) {
  100. if (
  101. inToken[0] == '\''&&
  102. inToken[2] == '\'' &&
  103. !inToken[3] &&
  104. __GLS_CHAR_IS_GRAPHIC(inToken[1])
  105. ) {
  106. if (outPtr) *outPtr = (GLubyte *)inToken + 3;
  107. return inToken[1];
  108. } else {
  109. if (outPtr) *outPtr = (GLubyte *)inToken;
  110. return 0;
  111. }
  112. }
  113. static GLboolean __glsTokenToGLboolean(
  114. const GLubyte *inToken, GLboolean *outVal
  115. ) {
  116. GLubyte *ptr;
  117. unsigned long val;
  118. if (!strcmp((const char *)inToken, "GL_FALSE")) {
  119. *outVal = GL_FALSE;
  120. return GL_TRUE;
  121. } else if (!strcmp((const char *)inToken, "GL_TRUE")) {
  122. *outVal = GL_TRUE;
  123. return GL_TRUE;
  124. }
  125. val = strtoul((const char *)inToken, (char **)&ptr, 0);
  126. *outVal = (GLboolean)val;
  127. return (GLboolean)(!*ptr && val <= UCHAR_MAX);
  128. }
  129. static GLboolean __glsTokenToGLbyte(const GLubyte *inToken, GLbyte *outVal) {
  130. GLubyte *ptr;
  131. long val;
  132. val = strtol((const char *)inToken, (char **)&ptr, 0);
  133. if (*ptr) val = __glsQuotedChar(inToken, &ptr);
  134. *outVal = (GLbyte)val;
  135. return (GLboolean)(!*ptr && val >= SCHAR_MIN && val <= SCHAR_MAX);
  136. }
  137. static GLboolean __glsTokenToGLdouble(
  138. const GLubyte *inToken, GLdouble *outVal
  139. ) {
  140. GLubyte *ptr;
  141. GLdouble sign;
  142. __GLS_C_LOCALE_DECLARE;
  143. __GLS_PUT_ERRNO(0);
  144. __GLS_C_LOCALE_BEGIN;
  145. *outVal = strtod((const char *)inToken, (char **)&ptr);
  146. __GLS_C_LOCALE_END;
  147. if (!*ptr) return (GLboolean)(__GLS_ERRNO != ERANGE);
  148. if (
  149. inToken[0] == '0' && __glsTokenToGLulong(inToken, (GLulong *)outVal)
  150. ) {
  151. return GL_TRUE;
  152. }
  153. if (!strcmp((const char *)inToken, "nan")) {
  154. *outVal = *(const GLdouble *)__glsQuietNaN;
  155. return GL_TRUE;
  156. }
  157. sign = 1.;
  158. if (*inToken == '-') {
  159. sign = -1.;
  160. ++inToken;
  161. } else if (*inToken == '+') {
  162. ++inToken;
  163. }
  164. if (!strcmp((const char *)inToken, "inf")) {
  165. *outVal = sign * HUGE_VAL;
  166. return GL_TRUE;
  167. }
  168. {
  169. GLint intVal;
  170. if (
  171. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, &intVal) ||
  172. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, &intVal)
  173. ) {
  174. *outVal = (GLdouble)intVal;
  175. return GL_TRUE;
  176. }
  177. }
  178. return GL_FALSE;
  179. }
  180. static GLboolean __glsTokenToGLfloat(
  181. const GLubyte *inToken, GLfloat *outVal
  182. ) {
  183. GLdouble doubleVal;
  184. GLubyte *ptr;
  185. GLdouble sign;
  186. __GLS_C_LOCALE_DECLARE;
  187. __GLS_PUT_ERRNO(0);
  188. __GLS_C_LOCALE_BEGIN;
  189. doubleVal = strtod((const char *)inToken, (char **)&ptr);
  190. *outVal = (GLfloat)doubleVal;
  191. __GLS_C_LOCALE_END;
  192. if (doubleVal < 0.) doubleVal = -doubleVal;
  193. if (!*ptr) return (GLboolean)(
  194. __GLS_ERRNO != ERANGE &&
  195. (
  196. !doubleVal ||
  197. doubleVal >= (GLdouble)FLT_MIN && doubleVal <= (GLdouble)FLT_MAX
  198. )
  199. );
  200. if (
  201. inToken[0] == '0' && __glsTokenToGLuint(inToken, (GLuint *)outVal)
  202. ) {
  203. return GL_TRUE;
  204. }
  205. if (!strcmp((const char *)inToken, "nan")) {
  206. *outVal = *(const GLfloat *)__glsQuietNaN;
  207. return GL_TRUE;
  208. }
  209. sign = 1.;
  210. if (*inToken == '-') {
  211. sign = -1.;
  212. ++inToken;
  213. } else if (*inToken == '+') {
  214. ++inToken;
  215. }
  216. if (!strcmp((const char *)inToken, "inf")) {
  217. *outVal = (GLfloat)(sign * HUGE_VAL);
  218. return GL_TRUE;
  219. }
  220. {
  221. GLint intVal;
  222. if (
  223. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, &intVal) ||
  224. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, &intVal)
  225. ) {
  226. *outVal = (GLfloat)intVal;
  227. return GL_TRUE;
  228. }
  229. }
  230. return GL_FALSE;
  231. }
  232. static GLboolean __glsTokenToGLint(const GLubyte *inToken, GLint *outVal) {
  233. GLubyte *ptr;
  234. long val;
  235. __GLS_PUT_ERRNO(0);
  236. val = strtol((const char *)inToken, (char **)&ptr, 0);
  237. if (*ptr) {
  238. __GLS_PUT_ERRNO(0);
  239. val = __glsQuotedChar(inToken, &ptr);
  240. }
  241. if (!*ptr) {
  242. *outVal = (GLint)val;
  243. return (GLboolean)(
  244. __GLS_ERRNO != ERANGE && val >= INT_MIN && val <= INT_MAX
  245. );
  246. }
  247. return (GLboolean)(
  248. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, outVal) ||
  249. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, outVal)
  250. );
  251. }
  252. #if defined(__GLS_STR_TO_INT64)
  253. static GLboolean __glsTokenToGLlong(const GLubyte *inToken, GLlong *outVal) {
  254. GLint intVal;
  255. GLubyte *ptr;
  256. __GLS_PUT_ERRNO(0);
  257. *outVal = __GLS_STR_TO_INT64((const char *)inToken, (char **)&ptr, 0);
  258. if (*ptr) {
  259. __GLS_PUT_ERRNO(0);
  260. *outVal = __glsQuotedChar(inToken, &ptr);
  261. }
  262. if (!*ptr) return (GLboolean)(__GLS_ERRNO != ERANGE);
  263. if (
  264. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, &intVal) ||
  265. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, &intVal)
  266. ) {
  267. *outVal = intVal;
  268. return GL_TRUE;
  269. }
  270. return GL_FALSE;
  271. }
  272. #else /* !defined(__GLS_STR_TO_INT64) */
  273. static GLboolean __glsTokenToGLlong(const GLubyte *inToken, GLlong *outVal) {
  274. GLubyte *ptr;
  275. GLint intVal;
  276. long val;
  277. if (
  278. inToken[0] == '0' &&
  279. (inToken[1] == 'x' || inToken[1] == 'X') &&
  280. strlen((const char *)inToken) == 18
  281. ) {
  282. GLint high;
  283. GLuint low;
  284. __GLSstringBuf strBuf;
  285. strcpy((char *)strBuf, (const char *)inToken);
  286. strBuf[10] = 0;
  287. high = (GLint)strtol((const char *)strBuf, (char **)&ptr, 0);
  288. if (*ptr) return GL_FALSE;
  289. strcpy((char *)(strBuf + 2), (const char *)(inToken + 10));
  290. low = (GLuint)strtoul((const char *)strBuf, (char **)&ptr, 0);
  291. *outVal = glsLong(high, low);
  292. return !*ptr;
  293. }
  294. __GLS_PUT_ERRNO(0);
  295. val = strtol((const char *)inToken, (char **)&ptr, 0);
  296. if (!*ptr) {
  297. *outVal = glsLong((val & 0x80000000) ? -1 : 0, (GLuint)val);
  298. return __GLS_ERRNO != ERANGE && val >= INT_MIN && val <= INT_MAX;
  299. }
  300. if (
  301. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, &intVal) ||
  302. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, &intVal)
  303. ) {
  304. *outVal = glsLong(0, intVal);
  305. return GL_TRUE;
  306. }
  307. *outVal = glsLong(0, __glsQuotedChar(inToken, &ptr));
  308. return !*ptr;
  309. }
  310. #endif /* defined(__GLS_STR_TO_INT64) */
  311. static GLboolean __glsTokenToGLshort(const GLubyte *inToken, GLshort *outVal) {
  312. GLubyte *ptr;
  313. long val;
  314. val = strtol((const char *)inToken, (char **)&ptr, 0);
  315. if (*ptr) val = __glsQuotedChar(inToken, &ptr);
  316. *outVal = (GLshort)val;
  317. return (GLboolean)(!*ptr && val >= SHRT_MIN && val <= SHRT_MAX);
  318. }
  319. static GLboolean __glsTokenToGLubyte(const GLubyte *inToken, GLubyte *outVal) {
  320. GLubyte *ptr;
  321. unsigned long val;
  322. val = strtoul((const char *)inToken, (char **)&ptr, 0);
  323. if (*ptr) val = __glsQuotedChar(inToken, &ptr);
  324. *outVal = (GLubyte)val;
  325. return (GLboolean)(!*ptr && val <= UCHAR_MAX);
  326. }
  327. static GLboolean __glsTokenToGLuint(const GLubyte *inToken, GLuint *outVal) {
  328. GLubyte *ptr;
  329. unsigned long val;
  330. __GLS_PUT_ERRNO(0);
  331. val = strtoul((const char *)inToken, (char **)&ptr, 0);
  332. if (*ptr) {
  333. __GLS_PUT_ERRNO(0);
  334. val = __glsQuotedChar(inToken, &ptr);
  335. }
  336. if (!*ptr) {
  337. *outVal = (GLuint)val;
  338. return (GLboolean)(__GLS_ERRNO != ERANGE && val <= UINT_MAX);
  339. }
  340. return (GLboolean)(
  341. __glsStr2IntDict_find(
  342. __glsParser->glEnumDict, inToken, (GLint *)outVal
  343. ) ||
  344. __glsStr2IntDict_find(
  345. __glsParser->glsEnumDict, inToken, (GLint *)outVal
  346. )
  347. );
  348. }
  349. #if defined(__GLS_STR_TO_INT64U)
  350. static GLboolean __glsTokenToGLulong(
  351. const GLubyte *inToken, GLulong *outVal
  352. ) {
  353. GLint intVal;
  354. GLubyte *ptr;
  355. __GLS_PUT_ERRNO(0);
  356. *outVal = __GLS_STR_TO_INT64U((const char *)inToken, (char **)&ptr, 0);
  357. if (*ptr) {
  358. __GLS_PUT_ERRNO(0);
  359. *outVal = __glsQuotedChar(inToken, &ptr);
  360. }
  361. if (!*ptr) return (GLboolean)(__GLS_ERRNO != ERANGE);
  362. if (
  363. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, &intVal) ||
  364. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, &intVal)
  365. ) {
  366. *outVal = intVal;
  367. return GL_TRUE;
  368. }
  369. return GL_FALSE;
  370. }
  371. #else /* !defined(__GLS_STR_TO_INT64U) */
  372. static GLboolean __glsTokenToGLulong(const GLubyte *inToken, GLulong *outVal) {
  373. GLubyte *ptr;
  374. GLint intVal;
  375. unsigned long val;
  376. if (
  377. inToken[0] == '0' &&
  378. (inToken[1] == 'x' || inToken[1] == 'X') &&
  379. strlen((const char *)inToken) == 18
  380. ) {
  381. GLuint high, low;
  382. __GLSstringBuf strBuf;
  383. strcpy((char *)strBuf, (const char *)inToken);
  384. strBuf[10] = 0;
  385. high = (GLuint)strtoul((const char *)strBuf, (char **)&ptr, 0);
  386. if (*ptr) return GL_FALSE;
  387. strcpy((char *)(strBuf + 2), (const char *)(inToken + 10));
  388. low = (GLuint)strtoul((const char *)strBuf, (char **)&ptr, 0);
  389. *outVal = glsULong(high, low);
  390. return !*ptr;
  391. }
  392. __GLS_PUT_ERRNO(0);
  393. val = strtoul((const char *)inToken, (char **)&ptr, 0);
  394. if (!*ptr) {
  395. *outVal = glsULong(0, (GLuint)val);
  396. return __GLS_ERRNO != ERANGE && val <= UINT_MAX;
  397. }
  398. if (
  399. __glsStr2IntDict_find(__glsParser->glEnumDict, inToken, &intVal) ||
  400. __glsStr2IntDict_find(__glsParser->glsEnumDict, inToken, &intVal)
  401. ) {
  402. *outVal = glsULong(0, intVal);
  403. return GL_TRUE;
  404. }
  405. *outVal = glsULong(0, __glsQuotedChar(inToken, &ptr));
  406. return !*ptr;
  407. }
  408. #endif /* defined(__GLS_STR_TO_INT64U) */
  409. static GLboolean __glsTokenToGLushort(
  410. const GLubyte *inToken, GLushort *outVal
  411. ) {
  412. GLubyte *ptr;
  413. unsigned long val;
  414. val = strtoul((const char *)inToken, (char **)&ptr, 0);
  415. if (*ptr) val = __glsQuotedChar(inToken, &ptr);
  416. *outVal = (GLushort)val;
  417. return (GLboolean)(!*ptr && val <= USHRT_MAX);
  418. }
  419. /******************************************************************************
  420. Private readers
  421. ******************************************************************************/
  422. __GLS_FORWARD static GLboolean __glsReader_getChar_text(
  423. __GLSreader *inoutReader, GLubyte inChar, GLboolean inRequired
  424. );
  425. __GLS_FORWARD static GLboolean __glsReader_getToken_text(
  426. __GLSreader *inoutReader, __GLSstring *outToken
  427. );
  428. static GLboolean __glsReader_getBitfield_text(
  429. __GLSreader *inoutReader, const __GLSdict *inDict, GLbitfield *outBits
  430. ) {
  431. __GLSstring token;
  432. GLbitfield val = 0;
  433. __glsString_init(&token);
  434. __GLS_BEGIN_PARAM(inoutReader);
  435. *outBits = GLS_NONE;
  436. while (__glsReader_getToken_text(inoutReader, &token)) {
  437. if (
  438. __glsStr2IntDict_find(inDict, token.head, (GLint *)&val) ||
  439. __glsTokenToGLuint(token.head, &val)
  440. ) {
  441. *outBits |= val;
  442. } else {
  443. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  444. __glsString_final(&token);
  445. return GL_FALSE;
  446. }
  447. if (!__glsReader_getChar_text(inoutReader, '|', GL_FALSE)) {
  448. __glsString_final(&token);
  449. return GL_TRUE;
  450. }
  451. }
  452. __glsString_final(&token);
  453. return GL_FALSE;
  454. }
  455. static GLboolean __glsReader_getChar_text(
  456. __GLSreader *inoutReader, GLubyte inChar, GLboolean inRequired
  457. ) {
  458. GLubyte readChar;
  459. __GLS_GET_SPACE(inoutReader);
  460. __GLS_READ_CHAR(inoutReader, readChar);
  461. if (readChar != inChar) {
  462. __GLS_UNREAD_CHAR(inoutReader);
  463. if (inRequired) __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  464. }
  465. return (GLboolean)(readChar == inChar);
  466. }
  467. static GLboolean __glsReader_getEnum_text(
  468. __GLSreader *inoutReader, const __GLSdict *inDict, GLuint *outVal
  469. ) {
  470. __GLSstring token;
  471. __glsString_init(&token);
  472. __GLS_BEGIN_PARAM(inoutReader);
  473. if (
  474. __glsReader_getToken_text(inoutReader, &token) &&
  475. (
  476. __glsStr2IntDict_find(inDict, token.head, (GLint *)outVal) ||
  477. __glsTokenToGLuint(token.head, outVal)
  478. )
  479. ) {
  480. __glsString_final(&token);
  481. return GL_TRUE;
  482. } else {
  483. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  484. __glsString_final(&token);
  485. return GL_FALSE;
  486. }
  487. }
  488. static GLboolean __glsReader_getIntOrEnum_text(
  489. __GLSreader *inoutReader, const __GLSdict *inDict, GLint *outVal
  490. ) {
  491. __GLSstring token;
  492. __glsString_init(&token);
  493. __GLS_BEGIN_PARAM(inoutReader);
  494. if (
  495. __glsReader_getToken_text(inoutReader, &token) &&
  496. (
  497. __glsTokenToGLint(token.head, outVal) ||
  498. __glsStr2IntDict_find(inDict, token.head, outVal)
  499. )
  500. ) {
  501. __glsString_final(&token);
  502. return GL_TRUE;
  503. } else {
  504. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  505. __glsString_final(&token);
  506. return GL_FALSE;
  507. }
  508. }
  509. static GLboolean __glsReader_getToken_text(
  510. __GLSreader *inoutReader, __GLSstring *outToken
  511. ) {
  512. GLint count = 0;
  513. GLubyte readChar;
  514. __GLS_GET_SPACE(inoutReader);
  515. __glsString_reset(outToken);
  516. for (;;) {
  517. __GLS_READ_CHAR(inoutReader, readChar);
  518. if (__GLS_CHAR_IS_TOKEN(readChar)) {
  519. __GLS_READER_APPEND_CHAR(inoutReader, outToken, readChar);
  520. ++count;
  521. } else if (!count && readChar == '\'') {
  522. __GLS_READER_APPEND_CHAR(inoutReader, outToken, readChar);
  523. __GLS_READ_CHAR(inoutReader, readChar);
  524. if (__GLS_CHAR_IS_GRAPHIC(readChar)) {
  525. __GLS_READER_APPEND_CHAR(inoutReader, outToken, readChar);
  526. } else {
  527. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  528. break;
  529. }
  530. __GLS_READ_CHAR(inoutReader, readChar);
  531. if (readChar == '\'') {
  532. __GLS_READER_APPEND_CHAR(inoutReader, outToken, readChar);
  533. return GL_TRUE;
  534. } else {
  535. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  536. break;
  537. }
  538. } else {
  539. __GLS_UNREAD_CHAR(inoutReader);
  540. if (count && count < __GLS_STRING_BUF_BYTES - 1) {
  541. return GL_TRUE;
  542. } else {
  543. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  544. break;
  545. }
  546. }
  547. }
  548. return GL_FALSE;
  549. }
  550. /******************************************************************************
  551. Public functions
  552. ******************************************************************************/
  553. GLboolean __glsReader_abortCommand_text(__GLSreader *inoutReader) {
  554. GLubyte prevChar = 0;
  555. GLubyte readChar;
  556. GLboolean string = GL_FALSE;
  557. for (;;) {
  558. if (
  559. inoutReader->readPtr >= inoutReader->readTail &&
  560. !__glsReader_fillBuf(inoutReader, 1, GL_FALSE)
  561. ) {
  562. break;
  563. }
  564. readChar = *inoutReader->readPtr++;
  565. if (readChar == '"') {
  566. if (string) {
  567. if (prevChar != '\\') string = GL_FALSE;
  568. } else {
  569. string = GL_TRUE;
  570. }
  571. }
  572. if (readChar == ';' && !string) return GL_TRUE;
  573. prevChar = readChar;
  574. }
  575. return GL_FALSE;
  576. }
  577. GLboolean __glsReader_beginCommand_text(
  578. __GLSreader *inoutReader, __GLSstring *outCommand
  579. ) {
  580. inoutReader->error = GLS_NONE;
  581. inoutReader->paramCount = 0;
  582. return (GLboolean)(
  583. __glsReader_getToken_text(inoutReader, outCommand) &&
  584. __glsReader_getChar_text(inoutReader, '(', GL_TRUE)
  585. );
  586. }
  587. GLboolean __glsReader_call_text(__GLSreader *inoutReader) {
  588. __GLSstring command;
  589. GLSopcode opcode;
  590. if (!__glsParser) {
  591. __glsBeginCriticalSection();
  592. if (!__glsParser) __glsParser = __glsParser_create();
  593. __glsEndCriticalSection();
  594. if (!__glsParser) {
  595. __GLS_RAISE_ERROR(GLS_OUT_OF_MEMORY);
  596. return GL_FALSE;
  597. }
  598. }
  599. __glsString_init(&command);
  600. for (;;) {
  601. if (__GLS_CONTEXT->abortMode) {
  602. __glsString_final(&command);
  603. break;
  604. }
  605. if (__glsReader_beginCommand_text(inoutReader, &command)) {
  606. if (__glsParser_findCommand(__glsParser, command.head, &opcode)) {
  607. if (opcode == GLS_OP_glsEndGLS) {
  608. if (__glsReader_endCommand_text(inoutReader)) {
  609. __glsString_final(&command);
  610. return GL_TRUE;
  611. } else {
  612. __GLS_CALL_ERROR(__GLS_CONTEXT, opcode, GLS_DECODE_ERROR);
  613. __glsString_final(&command);
  614. return __glsReader_abortCommand_text(inoutReader);
  615. }
  616. }
  617. #ifndef __GLS_PLATFORM_WIN32
  618. // DrewB
  619. __glsDispatchDecode_text[__glsMapOpcode(opcode)](inoutReader);
  620. #else
  621. __glsDispatchDecode_text[__glsMapOpcode(opcode)](__GLS_CONTEXT,
  622. inoutReader);
  623. #endif
  624. __glsReader_endCommand_text(inoutReader);
  625. if (inoutReader->error) {
  626. __GLS_CALL_ERROR(__GLS_CONTEXT, opcode, inoutReader->error);
  627. if (!__glsReader_abortCommand_text(inoutReader)) {
  628. __glsString_final(&command);
  629. break;
  630. }
  631. }
  632. } else {
  633. if (!__glsReader_abortCommand_text(inoutReader)) {
  634. __glsString_final(&command);
  635. break;
  636. }
  637. }
  638. } else {
  639. __GLS_CALL_UNSUPPORTED_COMMAND(__GLS_CONTEXT);
  640. if (!__glsReader_abortCommand_text(inoutReader)) {
  641. __glsString_final(&command);
  642. break;
  643. }
  644. }
  645. }
  646. return GL_FALSE;
  647. }
  648. GLboolean __glsReader_endCommand_text(__GLSreader *inoutReader) {
  649. return (GLboolean)(
  650. !inoutReader->error &&
  651. __glsReader_getChar_text(inoutReader, ')', GL_TRUE) &&
  652. __glsReader_getChar_text(inoutReader, ';', GL_TRUE)
  653. );
  654. }
  655. GLboolean __glsReader_getGLSenum_text(
  656. __GLSreader *inoutReader, GLSenum *outVal
  657. ) {
  658. return __glsReader_getEnum_text(
  659. inoutReader, __glsParser->glsEnumDict, outVal
  660. );
  661. }
  662. GLboolean __glsReader_getGLSimageFlags_text(
  663. __GLSreader *inoutReader, GLbitfield *outVal
  664. ) {
  665. return __glsReader_getBitfield_text(
  666. inoutReader, __glsParser->glsImageFlagsDict, outVal
  667. );
  668. }
  669. GLboolean __glsReader_getGLSopcode_text(
  670. __GLSreader *inoutReader, GLSopcode *outVal
  671. ) {
  672. __GLSstring token;
  673. __glsString_init(&token);
  674. __GLS_BEGIN_PARAM(inoutReader);
  675. if (
  676. __glsReader_getToken_text(inoutReader, &token) &&
  677. (
  678. !strncmp((const char *)token.head, "GLS_OP_", 7) &&
  679. __glsStr2IntDict_find(
  680. __glsParser->glsOpDict,
  681. token.head + 7,
  682. (GLint *)outVal
  683. ) ||
  684. __glsTokenToGLuint(token.head, outVal)
  685. )
  686. ) {
  687. __glsString_final(&token);
  688. return GL_TRUE;
  689. } else {
  690. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  691. __glsString_final(&token);
  692. return GL_FALSE;
  693. }
  694. }
  695. GLboolean __glsReader_getGLattribMask_text(
  696. __GLSreader *inoutReader, GLbitfield *outVal
  697. ) {
  698. return __glsReader_getBitfield_text(
  699. inoutReader, __glsParser->glAttribMaskDict, outVal
  700. );
  701. }
  702. GLboolean __glsReader_getGLblendingFactor_text(
  703. __GLSreader *inoutReader, GLenum *outVal
  704. ) {
  705. return __glsReader_getEnum_text(
  706. inoutReader, __glsParser->glEnumDict, outVal
  707. );
  708. }
  709. __GLS_GET_TEXT(GLboolean, GLboolean)
  710. __GLS_GET_TEXT(GLbyte, GLbyte)
  711. GLboolean __glsReader_getGLcharv_text(
  712. __GLSreader *inoutReader, __GLSstring *outString
  713. ) {
  714. GLint hexCount = -1;
  715. GLboolean outVal = GL_TRUE;
  716. GLubyte prevChar = 0;
  717. GLubyte readChar;
  718. __GLS_BEGIN_PARAM(inoutReader);
  719. if (!__glsReader_getChar_text(inoutReader, '"', GL_TRUE)) return GL_FALSE;
  720. __glsString_reset(outString);
  721. for (;;) {
  722. __GLS_READ_CHAR(inoutReader, readChar);
  723. if (!readChar) {
  724. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  725. break;
  726. } else if (hexCount >= 0) {
  727. if (!isxdigit(readChar)) {
  728. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  729. outVal = GL_FALSE;
  730. hexCount = -1;
  731. } else if (++hexCount == 2) {
  732. GLubyte buf[3];
  733. buf[0] = prevChar;
  734. buf[1] = readChar;
  735. buf[2] = 0;
  736. readChar = (GLubyte)strtoul((const char *)buf, GLS_NONE, 16);
  737. __GLS_READER_APPEND_CHAR(inoutReader, outString, readChar);
  738. hexCount = -1;
  739. }
  740. } else if (readChar == '\\') {
  741. if (prevChar == '\\') {
  742. __GLS_READER_APPEND_CHAR(inoutReader, outString, readChar);
  743. readChar = 0;
  744. }
  745. } else if (readChar == '"') {
  746. if (prevChar == '\\') {
  747. __GLS_READER_APPEND_CHAR(inoutReader, outString, readChar);
  748. } else if (__glsReader_getChar_text(inoutReader, '"', GL_FALSE)) {
  749. continue;
  750. } else {
  751. if (outVal && !glsIsUTF8String(outString->head)) {
  752. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  753. outVal = GL_FALSE;
  754. }
  755. return outVal;
  756. }
  757. } else if (readChar == 'x' && prevChar == '\\') {
  758. hexCount = 0;
  759. } else if (!__GLS_CHAR_IS_GRAPHIC(readChar) || prevChar == '\\') {
  760. __glsReader_raiseError(inoutReader, GLS_DECODE_ERROR);
  761. outVal = GL_FALSE;
  762. } else {
  763. __GLS_READER_APPEND_CHAR(inoutReader, outString, readChar);
  764. }
  765. prevChar = readChar;
  766. }
  767. return GL_FALSE;
  768. }
  769. GLboolean __glsReader_getGLclearBufferMask_text(
  770. __GLSreader *inoutReader, GLbitfield *outVal
  771. ) {
  772. return __glsReader_getBitfield_text(
  773. inoutReader, __glsParser->glAttribMaskDict, outVal
  774. );
  775. }
  776. GLboolean __glsReader_getGLcompv_text(
  777. __GLSreader *inoutReader, GLenum inType, GLuint inBytes, GLvoid *outVec
  778. ) {
  779. switch (inType) {
  780. case __GLS_BOOLEAN:
  781. return __glsReader_getGLbooleanv_text(
  782. inoutReader, inBytes, (GLboolean *)outVec
  783. );
  784. case GL_BITMAP:
  785. return __glsReader_getGLubytev_text(
  786. inoutReader, (inBytes + 7) / 8, (GLubyte *)outVec
  787. );
  788. case GL_BYTE:
  789. return __glsReader_getGLbytev_text(
  790. inoutReader, inBytes, (GLbyte *)outVec
  791. );
  792. case GL_FLOAT:
  793. return __glsReader_getGLfloatv_text(
  794. inoutReader, inBytes / 4, (GLfloat *)outVec
  795. );
  796. case GL_INT:
  797. return __glsReader_getGLintv_text(
  798. inoutReader, inBytes / 4, (GLint *)outVec
  799. );
  800. case GL_SHORT:
  801. return __glsReader_getGLshortv_text(
  802. inoutReader, inBytes / 2, (GLshort *)outVec
  803. );
  804. case GL_2_BYTES:
  805. case GL_3_BYTES:
  806. case GL_4_BYTES:
  807. case GL_UNSIGNED_BYTE:
  808. #if __GL_EXT_packed_pixels
  809. case GL_UNSIGNED_BYTE_3_3_2_EXT:
  810. #endif /* __GL_EXT_packed_pixels */
  811. return __glsReader_getGLubytev_text(
  812. inoutReader, inBytes, (GLubyte *)outVec
  813. );
  814. case GL_UNSIGNED_INT:
  815. #if __GL_EXT_packed_pixels
  816. case GL_UNSIGNED_INT_8_8_8_8_EXT:
  817. case GL_UNSIGNED_INT_10_10_10_2_EXT:
  818. #endif /* __GL_EXT_packed_pixels */
  819. return __glsReader_getGLuintv_text(
  820. inoutReader, inBytes / 4, (GLuint *)outVec
  821. );
  822. case GL_UNSIGNED_SHORT:
  823. #if __GL_EXT_packed_pixels
  824. case GL_UNSIGNED_SHORT_4_4_4_4_EXT:
  825. case GL_UNSIGNED_SHORT_5_5_5_1_EXT:
  826. #endif /* __GL_EXT_packed_pixels */
  827. return __glsReader_getGLushortv_text(
  828. inoutReader, inBytes / 2, (GLushort *)outVec
  829. );
  830. #if __GL_EXT_vertex_array
  831. case GL_DOUBLE_EXT:
  832. return __glsReader_getGLdoublev_text(
  833. inoutReader, inBytes / 8, (GLdouble *)outVec
  834. );
  835. #endif /* __GL_EXT_vertex_array */
  836. default:
  837. return __glsReader_getGLbytev_text(inoutReader, 0, GLS_NONE);
  838. }
  839. }
  840. __GLS_GET_TEXT(GLdouble, GLdouble)
  841. GLboolean __glsReader_getGLdrawBufferMode_text(
  842. __GLSreader *inoutReader, GLenum *outVal
  843. ) {
  844. return __glsReader_getEnum_text(
  845. inoutReader, __glsParser->glEnumDict, outVal
  846. );
  847. }
  848. GLboolean __glsReader_getGLenum_text(
  849. __GLSreader *inoutReader, GLenum *outVal
  850. ) {
  851. return __glsReader_getEnum_text(
  852. inoutReader, __glsParser->glEnumDict, outVal
  853. );
  854. }
  855. __GLS_GET_TEXT(GLfloat, GLfloat)
  856. __GLS_GET_TEXT(GLint, GLint)
  857. __GLS_GET_TEXT(GLlong, GLlong)
  858. __GLS_GET_TEXT(GLshort, GLshort)
  859. GLboolean __glsReader_getGLstencilOp_text(
  860. __GLSreader *inoutReader, GLenum *outVal
  861. ) {
  862. return __glsReader_getEnum_text(
  863. inoutReader, __glsParser->glEnumDict, outVal
  864. );
  865. }
  866. GLboolean __glsReader_getGLtextureComponentCount_text(
  867. __GLSreader *inoutReader, GLint *outVal
  868. ) {
  869. return __glsReader_getIntOrEnum_text(
  870. inoutReader, __glsParser->glEnumDict, outVal
  871. );
  872. }
  873. __GLS_GET_TEXT(GLubyte, GLubyte)
  874. __GLS_GET_TEXT(GLuint, GLuint)
  875. __GLS_GET_TEXT(GLulong, GLulong)
  876. __GLS_GET_TEXT(GLushort, GLushort)
  877. GLboolean __glsReader_nextList_text(__GLSreader *inoutReader) {
  878. inoutReader->paramCount = 0;
  879. return (GLboolean)(
  880. !inoutReader->error &&
  881. __glsReader_getChar_text(inoutReader, ')', GL_TRUE) &&
  882. __glsReader_getChar_text(inoutReader, '(', GL_TRUE)
  883. );
  884. }
  885. GLSenum __glsReader_readBeginGLS_text(
  886. __GLSreader *inoutReader, __GLSversion *outVersion
  887. ) {
  888. __GLSstring beginGLS;
  889. __GLSversion version;
  890. __glsString_init(&beginGLS);
  891. if (
  892. __glsReader_beginCommand_text(inoutReader, &beginGLS) &&
  893. !strcmp((const char *)beginGLS.head, "glsBeginGLS") &&
  894. __glsReader_getGLint_text(inoutReader, &version.major) &&
  895. __glsReader_getGLint_text(inoutReader, &version.minor) &&
  896. __glsReader_endCommand_text(inoutReader) &&
  897. (!version.major || version.major == __GLS_VERSION_MAJOR)
  898. ) {
  899. __glsString_final(&beginGLS);
  900. *outVersion = version;
  901. return GLS_TEXT;
  902. } else {
  903. __glsString_final(&beginGLS);
  904. return GLS_NONE;
  905. }
  906. }