-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2xpath.bat
More file actions
42 lines (34 loc) · 1.17 KB
/
Copy path2xpath.bat
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@echo off
if "%1"=="" echo %~xn0 [file1.^<json^|xml^>] [file2.^<json^|xml^>] [fileN.^<json^|xml^>]
set "tmp_file=%~dpnx1.$tmp$"
set "native_dir=%~dp0"
:run_more
if "%1"=="" goto :eof
rem Remove comments
set "perl=C:\Program Files (x86)\Git\usr\bin\perl.exe"
"%perl%" -pe "BEGIN { $/=undef } s|<!--.*-->\r\n\r\n||gs" %1 > "%tmp_file%"
rem Check the file format
for /f %%i in (%tmp_file%) do set "first_line=%%i"&goto :break
:break
set "first_char=%first_line:~0,1%"
if "%first_char%"=="<" goto :convert_xml
if "%first_char%"=="{" goto :convert_json
echo Format of '%1' is unknown
exit
rem Convertion into xpath
:convert_xml
call py32.bat %native_dir%\xml2xpath.py -xns %tmp_file% > "%~xn1.xpath"
:: 1) remove line started with ***
:: 2) add struct['
:: 3) \t==\t into ']\t= "
:: 4) add to the end "
"%perl%" -pe "s|^\*\*\*.*$/||gs" "%~xn1.xpath" | "%perl%" -pe "s|^\/|struct['/|gs" | "%perl%" -pe "s|\t==\t'|']\t= \x22|gs" | "%perl%" -pe "s|\r|\x22|" > "%~xn1.xpath.py"
goto :finish
:convert_json
call py32.bat %native_dir%\json2xpath.py %tmp_file% > "%~xn1.xpath"
"%perl%" -pe "s|^\[|struct[|gs" "%~xn1.xpath" > "%~xn1.xpath.py"
goto :finish
:finish
::del %tmp_file%
shift
goto :run_more