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.

139 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. zwapi.c
  5. Abstract:
  6. This is the main module for the NT nt header file to zw
  7. header file converter.
  8. Author:
  9. Mark Lucovsky (markl) 28-Jan-1991
  10. Revision History:
  11. --*/
  12. #include "zwapi.h"
  13. char *ReturnType = "NTSTATUS";
  14. char *Decoration = "NTSYSAPI";
  15. char *CallType = "NTAPI";
  16. char *ProcedureNamePrefix = "Nt";
  17. char *EndPrototype = ");";
  18. int
  19. __cdecl main( argc, argv )
  20. int argc;
  21. char *argv[];
  22. {
  23. fUsage = 0;
  24. if (!ProcessParameters( argc, argv )) {
  25. fUsage = 1;
  26. }
  27. if (fUsage) {
  28. fprintf( stderr, "usage: ZWAPI [-?] display this message\n" );
  29. fprintf( stderr, " [-o filename ]\n" );
  30. return 1;
  31. }
  32. OutputFile = fopen(OutputFileName,"a");
  33. if (!OutputFile) {
  34. fprintf(stderr,"ZWAPI: Unable to open output file %s for write access\n",OutputFileName);
  35. return 1;
  36. }
  37. while ( SourceFileCount-- ) {
  38. SourceFileName = *SourceFileList++;
  39. SourceFile = fopen(SourceFileName,"r");
  40. if (!SourceFile) {
  41. fprintf(stderr,"ZWAPI: Unable to open source file %s for read access\n",SourceFileName);
  42. return 1;
  43. }
  44. ProcessSourceFile();
  45. }
  46. return( 0 );
  47. }
  48. int
  49. ProcessParameters(
  50. int argc,
  51. char *argv[]
  52. )
  53. {
  54. char c, *p;
  55. while (--argc) {
  56. p = *++argv;
  57. if (*p == '/' || *p == '-') {
  58. while (c = *++p)
  59. switch (toupper( c )) {
  60. case '?':
  61. fUsage = 1;
  62. return 0;
  63. break;
  64. case 'O': {
  65. argc--, argv++;
  66. OutputFileName = *argv;
  67. SourceFileList = &argv[1];
  68. SourceFileCount = argc-1;
  69. return 1;
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. return 0;
  76. }
  77. void
  78. ProcessSourceFile( void )
  79. {
  80. char *s;
  81. int CallTypeFound;
  82. while( s = fgets(StringBuffer,STRING_BUFFER_SIZE,SourceFile) ) {
  83. if (strstr(s,ReturnType) == s) {
  84. s = fgets(StringBuffer,STRING_BUFFER_SIZE,SourceFile);
  85. if ( s && (strstr(s,CallType) == s) ) {
  86. s = fgets(StringBuffer,STRING_BUFFER_SIZE,SourceFile);
  87. CallTypeFound = TRUE;
  88. }
  89. else {
  90. CallTypeFound = FALSE;
  91. }
  92. if ( s && (strstr(s,ProcedureNamePrefix) == s) ) {
  93. if (!CallTypeFound) {
  94. fprintf(stderr, "ZWAPI: '%s' call type missing for %s\n", CallType, s );
  95. }
  96. fprintf(OutputFile,"%s\n%s\n%s\nZw%s",
  97. Decoration,
  98. ReturnType,
  99. CallType,
  100. s + strlen(ProcedureNamePrefix)
  101. );
  102. while( s = fgets(StringBuffer,STRING_BUFFER_SIZE,SourceFile) ) {
  103. fputs(s,OutputFile);
  104. if (strstr(s,EndPrototype)) {
  105. break;
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }