Skip to content

Commit

Permalink
'analyzer.sh' can now run 'report' result format.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgraham-antenna committed Sep 3, 2020
1 parent 62d2b7b commit 03d3508
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 38 deletions.
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,45 @@ The stylesheet generates a PDF report . An alternative XSLT stylesheet can be sp
## Linux

````
usage: analyzer.sh -d file [-opt "options"] [-lang lang] [-ahfcmd AHFCmd]
usage: analyzer.sh -d file [-format format] [-lang lang]
[-ahfcmd AHFCmd] [-opt "options\]
[-xslt xslt] [-xsltparam "xslt-params" ]
[-pdfver pdfver]
echo
file : File to format and analyze
options : Additional AHFCmd command-line parameters
format : Analysis result format -- annotate or report
Default is 'annotate'
lang : Language for error messages -- en or ja
AHFCmd : Location of 'run.sh'
Default is 'en'
AHFCmd : Path to 'AHFCmd' or 'run.sh'
options : Additional AHFCmd command-line parameters
xslt : XSLT stylesheet to use
xslt-params : XSLT processor options and parameters
xslt-params : XSLT processor options and parameters
pdfver : PDF version of reports. Default is 'PDF1.7'
````

Requires `xsltproc` and `getopt` to be on the path.
`analyzer.sh` generates a report in one of two formats:

- `-format annotate` (the default) generates a PDF version of the formatted source document that has additional PDF annotations and PDF layers.
- `-format report` generates a PDF report that includes a copy of every page that contains an analysis error.

Requires `getopt` to be on the path.

Expects AH Formatter to be installed at `/usr/AHFormatterV70_64/run.sh`. An alternative AH Formatter may be specified with `-ahfcmd`.

Expects AH Formatter to be installed at `/usr/AHFormatterV70_64/run.sh`.
### `-format annotate`

This runs an XSLT 1.0 stylesheet and requires `xsltproc` to be on the path.

The script uses its built-in `annotate.xsl` stylesheet to annotate the Area Tree XML for the formatted document with indications of the error areas. An alternative XSLT stylesheet can be specified with the `-xslt` parameter. Additional options and parameters can be passed to the XSLT processor with the `-xsltparam` parameter. The options and parameters must be in the correct syntax for the XSLT processor that will be used, since the `-xsltparam` value is not modified before being used.

### `-format report`

This runs the built-in `compact-report.xsl` XSLT 3.0 stylesheet and requires `java` to be on the PATH.


The stylesheet generates a PDF report . An alternative XSLT stylesheet can be specified with the `-xslt` parameter. Additional options and parameters can be passed to the XSLT processor with the `-xsltparam` parameter. The options and parameters must be in the correct syntax for the XSLT processor that will be used, since the `-xsltparam` value is not modified before being used.

## Apache Ant

### Annotated PDF
Expand Down
2 changes: 1 addition & 1 deletion analyzer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ goto start

:usage
echo.
echo Analyze a formatted file and generate annotated PDF
echo Analyze a formatted file and generate a PDF report

:usage_command_line
echo.
Expand Down
111 changes: 81 additions & 30 deletions analyzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,37 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Command-line parameter defaults (possibly used in 'usage' message)
AHFCMD=
FILE=
FORCE=
FORMAT=annotate
LANG=en
OPT=
PDFVER=PDF1.7
XSLT=
XSLT_OPT=

if [ "$1" == "" ] ; then
echo
echo "Analyze a formatted file and generate annotated PDF"
echo "Analyze a formatted file and generate a PDF report"
echo
echo "usage: analyzer.sh -d file [-opt \"options\"] [-lang lang] [-ahfcmd AHFCmd]"
echo "usage: analyzer.sh -d file [-format format] [-lang lang]"
echo " [-ahfcmd AHFCmd] [-opt \"options\"]"
echo " [-xslt xslt] [-xsltparam \"xslt-params\" ]"
echo " [-pdfver pdfver]"
echo
echo " file : File to format and analyze"
echo " format : Analysis result format -- annotate or report"
echo " Default is '${FORMAT}'"
echo " lang : Language for error messages -- en or ja"
echo " Default is '${LANG}'"
echo " AHFCmd : Path to 'AHFCmd' or 'run.sh'"
echo " options : Additional AHFCmd command-line parameters"
echo " AHFCmd : Path to AHFCmd.exe"
echo " file : File to format and analyze"
echo " xslt : XSLT stylesheet to use"
echo " xslt-params : XSLT processor options and parameters"
echo " pdfver : PDF version of reports. Default is '${PDFVER}'"
# echo " -force yes : Force all stages to run"
echo

exit 0
Expand All @@ -38,34 +56,31 @@ PWD=`pwd`
# From https://stackoverflow.com/a/44644933
# ${ANALYZER_DIR} does not include a trailing '/'.
ANALYZER_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LIB_DIR=${ANALYZER_DIR}/lib
XSL_DIR=${ANALYZER_DIR}/xsl

# From https://stackoverflow.com/a/7948533
# NOTE: This requires GNU getopt. On Mac OS X and FreeBSD, you have
# to install this separately.
# ':' after '--long' option names indicates that it must be followed
# by a parameter value.
TEMP=`getopt -a -o d: --long lang:,ahfcmd:,opt:,xslt:,xsltparam: \
TEMP=`getopt -a -o d: --long lang:,ahfcmd:,format:,opt:,pdfver:,xslt:,xsltparam: \
-n 'analyzer' -- "$@"`

if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

AHFCMD=
FILE=
LANG=en
OPT=
XSLT=
XSLT_OPT=

while true; do
case "$1" in
--ahfcmd ) AHFCMD="$2"; shift 2 ;;
-d ) FILE="$2"; shift 2 ;;
--force ) FORCE="$2"; shift 2 ;;
--format ) FORMAT="$2"; shift 2 ;;
--lang ) LANG="$2"; shift 2 ;;
--opt ) OPT="$2"; shift 2 ;;
--pdfver ) PDFVER="$2"; shift 2 ;;
--xslt ) XSLT="$2"; shift 2 ;;
--xsltparam ) XSLT_OPT="$2"; shift 2 ;;
-- ) shift; break ;;
Expand Down Expand Up @@ -95,21 +110,31 @@ if [ "x$AHFCMD" == "x" ] ; then
RUN_SH=${AHF70_64_HOME}/run.sh
else
if [ ! -e "$AHFCMD" ] ; then
echo "Formatter file does not exist: $AHFCMD" >&2 ; exit 1
echo "Formatter file does not exist: ${AHFCMD}" >&2 ; exit 1
else
RUN_SH=$AHFCMD
fi
fi

if [ "x$XSLT" == "x" ] ; then
REPORTER_XSLT=${XSL_DIR}/annotate.xsl
# 'compact' was used internally but never in a public release.
if [ "x$FORMAT" == "xreport" ] || [ "x$FORMAT" == "xcompact" ] ; then
REPORTER_XSLT=${XSL_DIR}/compact-report.xsl
fi
else
if [ ! -e "$XSLT" ] ; then
echo "XSLT file does not exist: $XSLT" >&2 ; exit 1
echo "XSLT file does not exist: ${XSLT}" >&2 ; exit 1
else
REPORTER_XSLT=$XSLT
fi
fi

# Check format value before taking time to generate Area Tree XML.
if [ "x$FORMAT" != "xannotate" ] && [ "x$FORMAT" != "xcompact" ] && [ "x$FORMAT" != "xreport" ] ; then
echo "Unrecognized result format: ${FORMAT}" >&2 ; exit 1
fi

BASENAME_FO=`basename $FILE .fo`
BASENAME=`basename $BASENAME_FO .html`

Expand All @@ -122,24 +147,50 @@ if [ $? != 0 ] ; then
exit 1
fi

xsltproc --stringparam logfile ${PWD}/${BASENAME}.log.xml --stringparam lang ${LANG} ${XSLT_OPT} -o ${BASENAME}.annotated.AT.xml ${REPORTER_XSLT} ${PWD}/${BASENAME}.AT.xml
if [ "x$FORMAT" == "xannotate" ] ; then
xsltproc --stringparam logfile ${PWD}/${BASENAME}.log.xml --stringparam lang ${LANG} ${XSLT_OPT} -o ${BASENAME}.annotated.AT.xml ${REPORTER_XSLT} ${PWD}/${BASENAME}.AT.xml

if [ $? != 0 ] ; then
echo "An error occurred when creating the annotated Area Tree XML file." >&2
exit 1
fi
if [ $? != 0 ] ; then
echo "An error occurred when creating the annotated Area Tree XML file." >&2
exit 1
fi

if [ -e "${BASENAME}.annotated.pdf" ] && [ ! -w "${BASENAME}.annotated.pdf" ] ; then
echo "Unable to replace '${BASENAME}.annotated.pdf'." >&2
exit 1
fi
if [ -e "${BASENAME}.annotated.pdf" ] && [ ! -w "${BASENAME}.annotated.pdf" ] ; then
echo "Unable to replace '${BASENAME}.annotated.pdf'." >&2
exit 1
fi

"${RUN_SH}" -x 4 -d ${BASENAME}.annotated.AT.xml -o ${BASENAME}.annotated.pdf 2> ${BASENAME}.annotated.log.txt
"${RUN_SH}" -x 4 -d ${BASENAME}.annotated.AT.xml -o ${BASENAME}.annotated.pdf 2> ${BASENAME}.annotated.log.txt

if [ $? != 0 ] ; then
echo "An error occurred when generating '${BASENAME}.annotated.pdf'. Check log file '${BASENAME}.annotated.log.txt'." >&2
exit 1
fi
if [ $? != 0 ] ; then
echo "An error occurred when generating '${BASENAME}.annotated.pdf'. Check log file '${BASENAME}.annotated.log.txt'." >&2
exit 1
fi

echo Analysis completed.
echo Annotated PDF: ${BASENAME}.annotated.pdf
echo Analysis completed.
echo Annotated PDF: ${BASENAME}.annotated.pdf
else
"${RUN_SH}" -x 4 -d ${FILE} -o ${BASENAME}.pdf -pdfver ${PDFVER} 2> ${BASENAME}.pdf.log

java -jar "${LIB_DIR}/saxon9he.jar" "-s:${PWD}/${BASENAME}.AT.xml" "-xsl:${REPORTER_XSLT}" "-o:${BASENAME}.report.fo" "logfile=file:///${PWD}/${BASENAME}.log.xml" lang=${LANG} "file=${PWD}/${BASENAME}.fo" file-date="${FO_DATE}" "pdf-file=${PWD}/${BASENAME}.pdf" ${XSLTPARAM}

if [ $? != 0 ] ; then
echo "An error occurred when creating the report XSL-FO file." >&2
exit 1
fi

if [ -e "${BASENAME}.report.pdf" ] && [ ! -w "${BASENAME}.report.pdf" ] ; then
echo "Unable to replace '${BASENAME}.report.pdf'." >&2
exit 1
fi

"${RUN_SH}" -x 4 -d ${BASENAME}.report.fo -o ${BASENAME}.report.pdf -pdfver ${PDFVER} 2> ${BASENAME}.report.pdf.log

if [ $? != 0 ] ; then
echo "An error occurred when generating '${BASENAME}.report.pdf'. Check log file '${BASENAME}.report.pdf.log'." >&2
exit 1
fi

echo Analysis completed.
echo Report PDF: ${BASENAME}.report.pdf
fi

0 comments on commit 03d3508

Please sign in to comment.