This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
fopub.bat
125 lines (101 loc) · 3.14 KB
/
fopub.bat
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem fopub script for Windows
@rem
@rem WARNING: This script has had limited testing!
@rem
@rem ##########################################################################
if "%OS%"=="Windows_NT" setlocal
@rem Store full-qualified drive + path of this script
set PRG_DIR=%~dps0
if "%PRG_DIR%" == "" set PRG_DIR=.
set GRADLEW_CMD=%PRG_DIR%gradlew
set FOPUB_DIR=%PRG_DIR%\build\fopub
set FOPUB_CMD=%FOPUB_DIR%\bin\fopub.bat
set APP_DIR=%FOPUB_DIR%
set DOCBOOK_DIR=%FOPUB_DIR%\docbook
@rem Default output type and config dir. These may be overridden by options
set TYPE=pdf
set DOCBOOK_XSL_DIR=%FOPUB_DIR%\docbook-xsl
@rem Parse command line options
:opt_parse
@rem Check for -H help
if "%~1" == "-h" GOTO :usage
@rem Check for -t XSL dir
if NOT "%~1" == "-t" GOTO :opt_output_type
shift
if "%~1" == "" GOTO :usage_error
set DOCBOOK_XSL_DIR=%~f1
shift
goto :opt_parse
:opt_output_type
@rem Check for -f output format type
if NOT "%~1" == "-f" GOTO :opt_hyphenate
shift
if "%1" == "" GOTO :usage_error
set TYPE=%~1
shift
goto :opt_parse
:opt_hyphenate
if NOT "%~1" == "-H" GOTO :opt_done
shift
set CONVERT_ARGS="-param hyphenate true"
:opt_done
@rem Done with parsing options
set XSLTHL_CONFIG_URI=file:///%DOCBOOK_XSL_DIR%\xslthl-config.xml
@rem Store fully-qualified drive+path+name+extension of source file
set SOURCE_FILE=%~f1
if "%SOURCE_FILE%" == "" goto :usage_error
@rem Store fully-qualified drive+path+name of first argument
set SOURCE_ROOTNAME=%~dpn1
shift
@rem collect any additional arguments to be passed on to FOP
:collect
if [%1] == [] goto :install
set CONVERT_ARGS=%CONVERT_ARGS% %1
shift
goto :collect
:install
if exist "%FOPUB_CMD%" goto endInstall
echo .
echo Initializing application...
"%GRADLEW_CMD%" -q -u installDist
if not "%ERRORLEVEL%"=="0" goto fail
echo Application initialized!
echo .
:endInstall
SETLOCAL ENABLEDELAYEDEXPANSION
@rem Add file protocol
set DOCBOOK_DIR_PARAM=file:///%DOCBOOK_DIR%
@rem replacing \ with /
set DOCBOOK_DIR_PARAM=!DOCBOOK_DIR_PARAM:\=/!
set XSLTHL_CONFIG_URI=!XSLTHL_CONFIG_URI:\=/!
if "%TYPE%" == "pdf" (
set OUTPUT_FILE=%SOURCE_ROOTNAME%.pdf
set OUTPUT_OPT=-pdf
)
if "%TYPE%" == "ps" (
set OUTPUT_FILE=%SOURCE_ROOTNAME%.ps
set OUTPUT_OPT=-ps
)
if "%TYPE%" == "fo" (
set OUTPUT_FILE=%SOURCE_ROOTNAME%.fo
set OUTPUT_OPT=-foout
)
if NOT "%OUTPUT_FILE%" == "" (
%FOPUB_CMD% -q -catalog -c "%DOCBOOK_XSL_DIR%\fop-config.xml" -xml "%SOURCE_FILE%" -xsl "%DOCBOOK_XSL_DIR%\fo-pdf.xsl" !OUTPUT_OPT! "!OUTPUT_FILE!" -param highlight.xslthl.config "%XSLTHL_CONFIG_URI%" -param admon.graphics.path "%DOCBOOK_DIR_PARAM%/images/" -param callout.graphics.path "%DOCBOOK_DIR_PARAM%/images/callouts/" %CONVERT_ARGS%
if not "%ERRORLEVEL%"=="0" goto fail else goto mainEnd
)
echo "Unsupported output type '%TYPE%'. Must be pdf, ps or fo."
:fail
exit /b 1
:usage_error
echo Syntax error!
:usage
@rem Don't use %FOPUB_CMD% here as that points somewhere else!
echo Usage: fopub [-t PATH] [-f FORMAT] [-H] FILE
echo Example: fopub -t \path\to\custom\docbook-xsl mydoc.xml
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal