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.

171 lines
2.8 KiB

  1. #include "stdafx.hxx"
  2. #include "vs_inc.hxx"
  3. static unsigned s_iwcDocBegin;
  4. static unsigned s_iwcDocEnd;
  5. unsigned PrintStringToFile(FILE *file, LPCWSTR wsz, bool bPrintRootElement)
  6. {
  7. const WCHAR *pwc = wsz;
  8. fputc('{', file);
  9. unsigned ich = 0;
  10. if (bPrintRootElement)
  11. {
  12. fputs("L'<', L'r', L'o', L'o', L't', L'>', L'\\n', ", file);
  13. ich = 7;
  14. }
  15. s_iwcDocBegin = ich;
  16. while(*pwc != L'\0')
  17. {
  18. if ((ich++ % 10) == 0)
  19. fputc('\n', file);
  20. fprintf(file, "L'");
  21. if (*pwc == L'\\')
  22. {
  23. fputc('\\', file);
  24. fputc('\\', file);
  25. }
  26. else if (*pwc == L'\n')
  27. {
  28. fputc('\\', file);
  29. fputc('n', file);
  30. }
  31. else if (*pwc == L'\r')
  32. {
  33. fputc('\\', file);
  34. fputc('r', file);
  35. }
  36. else if (*pwc == L'\t')
  37. {
  38. fputc('\\', file);
  39. fputc('t', file);
  40. }
  41. else
  42. fputc((char) *pwc, file);
  43. fprintf(file, "', ");
  44. pwc++;
  45. }
  46. s_iwcDocEnd = ich;
  47. if (bPrintRootElement)
  48. {
  49. fputc('\n', file);
  50. fputs("L'\\n', L'<', L'/', L'r', L'o', L'o', L't', L'>', L'\\n', ", file);
  51. ich += 9;
  52. }
  53. fprintf(file, "L'\\0'\n};");
  54. return ich;
  55. }
  56. extern "C" __cdecl wmain(int, WCHAR **)
  57. {
  58. CVssFunctionTracer ft(VSSDBG_GEN, L"main");
  59. CXMLDocument doc;
  60. try
  61. {
  62. ft.hr = CoInitialize(NULL);
  63. if (ft.HrFailed())
  64. ft.Throw
  65. (
  66. VSSDBG_XML,
  67. E_UNEXPECTED,
  68. L"CoInitialize failed. hr = 0x%08lx",
  69. ft.hr
  70. );
  71. if (!doc.LoadFromFile(L"writermetadata.xml"))
  72. {
  73. printf("Cannot load writermetadata.xml\n");
  74. exit(-1);
  75. }
  76. CComBSTR bstr = doc.SaveAsXML();
  77. FILE *f = fopen("wmxml.c", "w");
  78. if (f == NULL)
  79. {
  80. printf("create of wmxml.c failed\n");
  81. exit(-1);
  82. }
  83. fprintf(f, "WCHAR g_WriterMetadataXML[] = \n");
  84. unsigned cwc = PrintStringToFile(f, bstr, false);
  85. fprintf
  86. (
  87. f,
  88. "\nconst unsigned g_cwcWriterMetadataXML = %d;\n\n",
  89. cwc
  90. );
  91. bstr.Empty();
  92. fclose(f);
  93. if (!doc.LoadFromFile(L"componentmetadata.xml"))
  94. {
  95. printf("Cannot load componentmetadata.xml\n");
  96. exit(-1);
  97. }
  98. bstr = doc.SaveAsXML();
  99. f = fopen("cmxml.c", "w");
  100. if (f == NULL)
  101. {
  102. printf("create of cmxml.c failed\n");
  103. exit(-1);
  104. }
  105. fprintf(f, "WCHAR g_ComponentMetadataXML[] = \n");
  106. cwc = PrintStringToFile(f, bstr, true);
  107. fprintf
  108. (
  109. f,
  110. "\nconst unsigned g_cwcComponentMetadataXML = %d;\n\n",
  111. cwc
  112. );
  113. fprintf
  114. (
  115. f,
  116. "\nconst unsigned g_iwcComponentMetadataXMLBegin = %d;\n\n",
  117. s_iwcDocBegin
  118. );
  119. fprintf
  120. (
  121. f,
  122. "\nconst unsigned g_iwcComponentMetadataXMLEnd = %d;\n\n",
  123. s_iwcDocEnd
  124. );
  125. fclose(f);
  126. }
  127. VSS_STANDARD_CATCH(ft)
  128. if (ft.HrFailed())
  129. {
  130. printf("Unexpected exception, hr = 0x%08lx", ft.hr);
  131. exit(-1);
  132. }
  133. return 0;
  134. }