Windows NT 4.0 source code leak
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.

209 lines
6.3 KiB

5 years ago
  1. /*
  2. ** Copyright 1992, 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. ** $Revision: 1.4 $
  18. ** $Date: 1994/09/09 06:03:33 $
  19. */
  20. #ifdef NT
  21. #include <glos.h>
  22. #endif
  23. #include "gluint.h"
  24. #include <GL/glu.h>
  25. #ifndef NT
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #else
  29. #include "glstring.h"
  30. #endif
  31. #ifndef NT
  32. static const char *glErrorStrings[GL_OUT_OF_MEMORY - GL_INVALID_ENUM + 1] = {
  33. "invalid enumerant",
  34. "invalid value",
  35. "invalid operation",
  36. "stack overflow",
  37. "stack underflow",
  38. "out of memory",
  39. };
  40. static const char *gluErrorStrings[GLU_OUT_OF_MEMORY - GLU_INVALID_ENUM + 1] = {
  41. "invalid enumerant",
  42. "invalid value",
  43. "out of memory",
  44. };
  45. #define NERRORS (sizeof(errorStrings)/sizeof(errorStrings[0]))
  46. #else
  47. // For NT, rather using statically allocated strings, we use statically
  48. // allocated string resource identifiers. The string arrays are dynamically
  49. // initialized using the resource ids to load the appropriate string resource.
  50. // This make localization of the strings easier.
  51. static char *pszNoError; // "no error"
  52. static WCHAR *pwszNoError; // L"no error"
  53. static UINT auiGlErrorStrings[GL_OUT_OF_MEMORY - GL_INVALID_ENUM + 1] = {
  54. STR_GLU_INVALID_ENUM, // "invalid enumerant"
  55. STR_GLU_INVALID_VAL , // "invalid value"
  56. STR_GLU_INVALID_OP , // "invalid operation"
  57. STR_GLU_STACK_OVER , // "stack overflow"
  58. STR_GLU_STACK_UNDER , // "stack underflow"
  59. STR_GLU_OUT_OF_MEM // "out of memory"
  60. };
  61. static const char *glErrorStrings[GL_OUT_OF_MEMORY - GL_INVALID_ENUM + 1];
  62. static const WCHAR *glErrorStringsW[GL_OUT_OF_MEMORY - GL_INVALID_ENUM + 1];
  63. static UINT auiGluErrorStrings[GLU_OUT_OF_MEMORY - GLU_INVALID_ENUM + 1] = {
  64. STR_GLU_INVALID_ENUM, // "invalid enumerant"
  65. STR_GLU_INVALID_VAL , // "invalid value"
  66. STR_GLU_OUT_OF_MEM // "out of memory"
  67. };
  68. static const char *gluErrorStrings[GLU_OUT_OF_MEMORY - GLU_INVALID_ENUM + 1];
  69. static const WCHAR *gluErrorStringsW[GLU_OUT_OF_MEMORY - GLU_INVALID_ENUM + 1];
  70. char *pszGetResourceStringA(HINSTANCE hMod, UINT uiID)
  71. {
  72. char *pch;
  73. char ach[MAX_PATH+1];
  74. if (!LoadStringA(hMod, uiID, ach, MAX_PATH+1))
  75. ach[0] = '\0';
  76. pch = (char *) LocalAlloc(LMEM_FIXED, (lstrlenA(ach)+1) * sizeof(char));
  77. if (pch)
  78. lstrcpyA(pch, ach);
  79. return pch;
  80. }
  81. WCHAR *pwszGetResourceStringW(HINSTANCE hMod, UINT uiID)
  82. {
  83. WCHAR *pwch;
  84. WCHAR awch[MAX_PATH+1];
  85. if (!LoadStringW(hMod, uiID, awch, MAX_PATH+1))
  86. awch[0] = L'\0';
  87. pwch = (WCHAR *) LocalAlloc(LMEM_FIXED, (lstrlenW(awch)+1) * sizeof(WCHAR));
  88. if (pwch)
  89. lstrcpyW(pwch, awch);
  90. return pwch;
  91. }
  92. VOID vInitGluStrings(HINSTANCE hMod, BOOL bAnsi)
  93. {
  94. int i;
  95. if (bAnsi)
  96. {
  97. pszNoError = pszGetResourceStringA(hMod, STR_GLU_NO_ERROR);
  98. for (i = 0; i < (GL_OUT_OF_MEMORY - GL_INVALID_ENUM + 1); i++)
  99. glErrorStrings[i] = pszGetResourceStringA(hMod, auiGlErrorStrings[i]);
  100. for (i = 0; i < (GLU_OUT_OF_MEMORY - GLU_INVALID_ENUM + 1); i++)
  101. gluErrorStrings[i] = pszGetResourceStringA(hMod, auiGluErrorStrings[i]);
  102. }
  103. else
  104. {
  105. pwszNoError = pwszGetResourceStringW(hMod, STR_GLU_NO_ERROR);
  106. for (i = 0; i < (GL_OUT_OF_MEMORY - GL_INVALID_ENUM + 1); i++)
  107. glErrorStringsW[i] = pwszGetResourceStringW(hMod, auiGlErrorStrings[i]);
  108. for (i = 0; i < (GLU_OUT_OF_MEMORY - GLU_INVALID_ENUM + 1); i++)
  109. gluErrorStringsW[i] = pwszGetResourceStringW(hMod, auiGluErrorStrings[i]);
  110. }
  111. }
  112. VOID vInitErrorStrings(BOOL bAnsi)
  113. {
  114. static BOOL bInitializedAnsi = FALSE;
  115. static BOOL bInitializedUnicode = FALSE;
  116. if ( (bAnsi && !bInitializedAnsi) ||
  117. (!bAnsi && !bInitializedUnicode) )
  118. {
  119. HINSTANCE hMod = (HINSTANCE) GetModuleHandle("glu32.dll");
  120. vInitGluStrings(hMod, bAnsi);
  121. vInitNurbStrings(hMod, bAnsi);
  122. vInitTessStrings(hMod, bAnsi);
  123. if (bAnsi)
  124. bInitializedAnsi = TRUE;
  125. else
  126. bInitializedUnicode = TRUE;
  127. }
  128. }
  129. const wchar_t* APIENTRY gluErrorUnicodeStringEXT(GLenum errorCode)
  130. {
  131. vInitErrorStrings(FALSE);
  132. if (errorCode == 0) {
  133. return (LPCWSTR) pwszNoError;
  134. }
  135. if ((errorCode >= GL_INVALID_ENUM) && (errorCode <= GL_OUT_OF_MEMORY)) {
  136. return (LPCWSTR) glErrorStringsW[errorCode - GL_INVALID_ENUM];
  137. }
  138. if ((errorCode >= GLU_INVALID_ENUM) && (errorCode <= GLU_OUT_OF_MEMORY)) {
  139. return (LPCWSTR) gluErrorStringsW[errorCode - GLU_INVALID_ENUM];
  140. }
  141. if ((errorCode >= GLU_NURBS_ERROR1) && (errorCode <= GLU_NURBS_ERROR37)) {
  142. return (LPCWSTR) __glNURBSErrorStringW(errorCode - (GLU_NURBS_ERROR1 - 1));
  143. }
  144. if ((errorCode >= GLU_TESS_ERROR1) && (errorCode <= GLU_TESS_ERROR8)) {
  145. return (LPCWSTR) __glTessErrorStringW(errorCode - GLU_TESS_ERROR1);
  146. }
  147. return 0;
  148. }
  149. #endif
  150. const GLubyte* APIENTRY gluErrorString(GLenum errorCode)
  151. {
  152. #ifdef NT
  153. vInitErrorStrings(TRUE);
  154. #endif
  155. if (errorCode == 0) {
  156. #ifdef NT
  157. return (const unsigned char *) pszNoError;
  158. #else
  159. return (const unsigned char *) "no error";
  160. #endif
  161. }
  162. if ((errorCode >= GL_INVALID_ENUM) && (errorCode <= GL_OUT_OF_MEMORY)) {
  163. return (const unsigned char *) glErrorStrings[errorCode - GL_INVALID_ENUM];
  164. }
  165. if ((errorCode >= GLU_INVALID_ENUM) && (errorCode <= GLU_OUT_OF_MEMORY)) {
  166. return (const unsigned char *) gluErrorStrings[errorCode - GLU_INVALID_ENUM];
  167. }
  168. if ((errorCode >= GLU_NURBS_ERROR1) && (errorCode <= GLU_NURBS_ERROR37)) {
  169. return (const unsigned char *) __glNURBSErrorString(errorCode - (GLU_NURBS_ERROR1 - 1));
  170. }
  171. if ((errorCode >= GLU_TESS_ERROR1) && (errorCode <= GLU_TESS_ERROR8)) {
  172. return (const unsigned char *) __glTessErrorString(errorCode - GLU_TESS_ERROR1);
  173. }
  174. return 0;
  175. }