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.

118 lines
4.8 KiB

  1. @ECHO off
  2. SETLOCAL ENABLEDELAYEDEXPANSION
  3. SETLOCAL ENABLEDELAYEDEXPANSION
  4. SET Display=
  5. SET Glob=
  6. SET Pwd=
  7. SET Verbose=
  8. SET Self=%~nx0
  9. :SwitchLoop
  10. FOR %%. in (./ .- .) do IF ".%1." == "%%.?." GOTO :Help
  11. IF "%1" == "" GOTO :EndSwitchLoop
  12. FOR /f "tokens=1* delims=:" %%a in ('echo %1') do (
  13. SET Switch=%%a
  14. SET Arg=%%b
  15. FOR %%. in (./ .-) do (
  16. IF ".!Switch!." == "%%.g." (SET Glob=!Arg!&&GOTO :ShiftArg)
  17. IF ".!Switch!." == "%%.d." (SET Pwd=!Arg!&&GOTO :ShiftArg)
  18. IF ".!Switch!." == "%%.w." (SET Display=X&&GOTO :ShiftArg)
  19. IF ".!Switch!." == "%%.v." (SET Verbose=X&&GOTO :ShiftArg)
  20. )
  21. GOTO :help
  22. )
  23. :ShiftArg
  24. shift
  25. GOTO :SwitchLoop
  26. :EndSwitchLoop
  27. PUSHD %Pwd%
  28. call :main %Glob% %Pwd% %Display%
  29. SET Display=
  30. popd
  31. ENDLOCAL
  32. GOTO :eof
  33. :main
  34. SET Display=%3
  35. SET Glob=%1
  36. SET Pwd=%~2
  37. FOR %%_ IN (perl.exe) DO IF NOT defined bin/perl SET bin/perl=%%~$PATH:_
  38. SET parser=CSCRIPT
  39. IF NOT "%Display%"== "" (
  40. SET parser=WSCRIPT
  41. )
  42. REM USEFUL FOR identifying files like helpsupportservices.
  43. SET files=
  44. SET broken=
  45. SET dummy=
  46. SET checker=%RAZZLETOOLPATH%\POSTBUILDSCRIPTS\checkXML.js
  47. SET /A testedfiles=0
  48. SET /A brokenfiles=0
  49. SET /A cnt=1
  50. IF NOT defined Glob goto :noglob
  51. FOR /F %%f in ('dir /s/b/a-d "%Glob%"') DO @(
  52. IF EXIST %%f (
  53. IF DEFINED Verbose ECHO add "%%f"
  54. SET files[!cnt!]=%%f
  55. SET /A cnt=!cnt!+1
  56. )
  57. )
  58. goto :checkfiles
  59. :Noglob
  60. SET Glob=*
  61. FOR /F %%f in ('findstr /imsrc:"\<.*\?.*x.*m.*l.* .*v.*e.*r.*s.*i.*o.*n.*=.*" "%Glob%"') DO @(
  62. IF EXIST %%f (
  63. IF DEFINED Verbose ECHO add "%%f"
  64. SET files[!cnt!]=%%f
  65. SET /A cnt=!cnt!+1
  66. )
  67. )
  68. :checkfiles
  69. SET /A testedfiles=!cnt!-1
  70. IF %testedfiles% LEQ 0 echo No files found & goto :eof
  71. ECHO checking %testedfiles% files
  72. SET /A cnt=1
  73. FOR /L %%k in (1 1 %testedfiles%) DO @(
  74. SET xmlfile=!files[%%k]!
  75. IF DEFINED Verbose ECHO Parse "!xmlfile!"
  76. %bin/perl% -e "use strict; use XML::Parser; use CGI qw(:all); new XML::Parser(Style => 'Debug')->parsefile($ARGV[0]);" !xmlfile! 1>NUL 2>NUL
  77. IF NOT !errorlevel!==0 (
  78. IF DEFINED Verbose ECHO suspicious "!xmlfile!"
  79. SET broken[!cnt!]=!xmlfile!
  80. SET /A cnt=!cnt!+1
  81. )
  82. SET files[%%k]=
  83. )
  84. SET /A brokenfiles=!cnt!-1
  85. FOR /L %%k in (1 1 %brokenfiles%) DO @(
  86. SET f=!broken[%%k]!
  87. IF NOT ".!f!."==".." (
  88. FOR %%i in (!f!) DO @(SET d=%%~nxi
  89. SET dummy[%%k]="%temp%\!D!.xml"
  90. )
  91. )
  92. )
  93. FOR /L %%k in (1 1 %brokenfiles%) DO @(
  94. ECHO ============================================================
  95. COPY !broken[%%k]! !dummy[%%k]! 1>NUL
  96. %parser% /NOLOGO %checker% !dummy[%%k]!
  97. set broken[%%k]=
  98. set dummy[%%k]=
  99. )
  100. IF NOT %brokenfiles% GTR 0 (
  101. echo No syntax errors found
  102. GOTO :eof
  103. ) ELSE (
  104. echo %brokenfiles% suspicious files detected.
  105. GOTO :eof
  106. )
  107. :help
  108. echo %Self% Validator FOR the XML files before submission.
  109. echo Usage: %Self% -d:^<DIR^> -g:^<GLOB^> -w -v [-?]
  110. echo w use the wscript (default is to use cscript)
  111. echo v be verbose (verbose same as debug).
  112. echo ^<GLOB^> use file name mask (semi obsolete, since
  113. echo %Self% can filter xml files from the rest
  114. GOTO :eof