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.

174 lines
5.9 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 "glsutil.h"
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #if __GLS_PLATFORM_WIN32
  21. #include <fcntl.h>
  22. #include <io.h>
  23. #define __MAIN_LINKAGE __cdecl
  24. #else /* !__GLS_PLATFORM_WIN32 */
  25. #define __MAIN_LINKAGE
  26. #endif /* __GLS_PLATFORM_WIN32 */
  27. static struct {
  28. GLubyte **argv;
  29. } global;
  30. static void glscat_configStdio(void) {
  31. setbuf(stdin, GLS_NONE);
  32. setbuf(stdout, GLS_NONE);
  33. #if __GLS_PLATFORM_WIN32
  34. _setmode(_fileno(stdin), _O_BINARY);
  35. _setmode(_fileno(stdout), _O_BINARY);
  36. _setmode(_fileno(stderr), _O_BINARY);
  37. #endif /* __GLS_PLATFORM_WIN32 */
  38. }
  39. static void glscat_checkError(void) {
  40. const GLSenum error = glsGetError(GL_TRUE);
  41. if (error) {
  42. fprintf(
  43. stderr,
  44. "%s fatal: %s\n",
  45. global.argv[0],
  46. glsEnumString(GLS_API_GLS, error)
  47. );
  48. exit(EXIT_FAILURE);
  49. }
  50. }
  51. static void glscat_usage(void) {
  52. fprintf(
  53. stderr,
  54. "usage: %s "
  55. "[-a] [-c] [-d dir]* [-h] [-o out] [-r] [-t type] [in]*\n"
  56. " -a: append\n"
  57. " -c: copy through context\n"
  58. " -d: prepend dir to search path\n"
  59. " -h: help\n"
  60. " -o: output stream (default: standard output)\n"
  61. " -r: recursive copy\n"
  62. " -t: type of output stream, one of:\n"
  63. " GLS_NONE (default: same as input stream)\n"
  64. " GLS_BINARY_LSB_FIRST (little-endian binary)\n"
  65. " GLS_BINARY_MSB_FIRST (big-endian binary)\n"
  66. " GLS_BINARY_SWAP0 (native binary)\n"
  67. " GLS_BINARY_SWAP1 (swapped binary)\n"
  68. " GLS_TEXT (human-editable)\n",
  69. global.argv[0]
  70. );
  71. exit(EXIT_FAILURE);
  72. }
  73. int __MAIN_LINKAGE main(const GLsizei inArgc, GLubyte *inArgv[]) {
  74. GLint arg;
  75. GLboolean context = GL_FALSE;
  76. __GLSstring dir;
  77. __GLSstring inStream;
  78. __GLSstring outStream;
  79. GLboolean recursive = GL_FALSE;
  80. GLSenum type = GLS_NONE;
  81. GLbitfield writeFlags = GLS_NONE;
  82. glscat_configStdio();
  83. __glsString_init(&dir);
  84. __glsString_init(&inStream);
  85. __glsString_init(&outStream);
  86. global.argv = inArgv;
  87. glsContext(glsGenContext());
  88. for (arg = 1 ; arg < inArgc && inArgv[arg][0] == '-' ; ++arg) {
  89. if (inArgv[arg][2]) glscat_usage();
  90. switch (inArgv[arg][1]) {
  91. case 'a':
  92. writeFlags |= GLS_WRITE_APPEND_BIT;
  93. break;
  94. case 'c':
  95. context = GL_TRUE;
  96. break;
  97. case 'd':
  98. if (++arg >= inArgc) glscat_usage();
  99. __glsString_assign(&dir, inArgv[arg]);
  100. __glsString_appendChar(&dir, '/');
  101. glsReadPrefix(GLS_PREPEND, dir.head);
  102. break;
  103. case 'o':
  104. if (++arg >= inArgc) glscat_usage();
  105. __glsString_assign(&outStream, inArgv[arg]);
  106. break;
  107. case 'r':
  108. recursive = GL_TRUE;
  109. break;
  110. case 't':
  111. if (++arg >= inArgc) glscat_usage();
  112. if (
  113. !strcmp((const char *)inArgv[arg], "GLS_NONE")
  114. ) {
  115. type = GLS_NONE;
  116. } else if (
  117. !strcmp((const char *)inArgv[arg], "GLS_BINARY_LSB_FIRST")
  118. ) {
  119. type = GLS_BINARY_LSB_FIRST;
  120. } else if (
  121. !strcmp((const char *)inArgv[arg], "GLS_BINARY_MSB_FIRST")
  122. ) {
  123. type = GLS_BINARY_MSB_FIRST;
  124. } else if (
  125. !strcmp((const char *)inArgv[arg], "GLS_BINARY_SWAP0")
  126. ) {
  127. type = glsBinary(GL_FALSE);
  128. } else if (
  129. !strcmp((const char *)inArgv[arg], "GLS_BINARY_SWAP1")
  130. ) {
  131. type = glsBinary(GL_TRUE);
  132. } else if (
  133. !strcmp((const char *)inArgv[arg], "GLS_TEXT")
  134. ) {
  135. type = GLS_TEXT;
  136. } else {
  137. glscat_usage();
  138. }
  139. break;
  140. case 'h':
  141. default:
  142. glscat_usage();
  143. }
  144. }
  145. glscat_checkError();
  146. if (recursive) {
  147. glsCaptureFlags(GLS_OP_glsCallStream, GLS_CAPTURE_EXECUTE_BIT);
  148. }
  149. do {
  150. if (arg < inArgc) __glsString_assign(&inStream, inArgv[arg]);
  151. if (context) {
  152. GLSenum copyType = glsCopyStream(
  153. inStream.head, glsCSTR(""), GLS_CONTEXT, GLS_NONE
  154. );
  155. if (type != GLS_NONE) copyType = type;
  156. glsCopyStream(glsCSTR(""), outStream.head, copyType, writeFlags);
  157. } else {
  158. glsCopyStream(inStream.head, outStream.head, type, writeFlags);
  159. }
  160. glscat_checkError();
  161. writeFlags |= GLS_WRITE_APPEND_BIT;
  162. } while (++arg < inArgc);
  163. return EXIT_SUCCESS;
  164. }