[99497] | 1 | #!/usr/bin/env kmk_ash
|
---|
| 2 | # $Id: dita-refentry-flat-to-single-topic.sh 99514 2023-04-22 01:59:25Z vboxsync $
|
---|
| 3 | ## @file
|
---|
| 4 | # Helper Script for splitting up a convert manpage into separate topic
|
---|
| 5 | # files (named by @id).
|
---|
| 6 | #
|
---|
| 7 |
|
---|
| 8 | #
|
---|
| 9 | # Copyright (C) 2023 Oracle and/or its affiliates.
|
---|
| 10 | #
|
---|
| 11 | # This file is part of VirtualBox base platform packages, as
|
---|
| 12 | # available from https://www.virtualbox.org.
|
---|
| 13 | #
|
---|
| 14 | # This program is free software; you can redistribute it and/or
|
---|
| 15 | # modify it under the terms of the GNU General Public License
|
---|
| 16 | # as published by the Free Software Foundation, in version 3 of the
|
---|
| 17 | # License.
|
---|
| 18 | #
|
---|
| 19 | # This program is distributed in the hope that it will be useful, but
|
---|
| 20 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 22 | # General Public License for more details.
|
---|
| 23 | #
|
---|
| 24 | # You should have received a copy of the GNU General Public License
|
---|
| 25 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 26 | #
|
---|
| 27 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
| 28 | #
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | #
|
---|
| 32 | # This script is very internal, so we got the following fixed position parameters:
|
---|
| 33 | # 1: The input DITA file (output from docbook-refentry-to-manual-dita.xsl).
|
---|
| 34 | # 2: dita-refentry-flat-topic-ids.xsl
|
---|
| 35 | # 3: dita-refentry-flat-to-single-topic.xsl
|
---|
| 36 | # 4: The out directory.
|
---|
| 37 | # 5: '--'
|
---|
| 38 | # 6+: xsltproc invocation (sans output, input and xslt file).
|
---|
| 39 | #
|
---|
| 40 | if test $# -lt 6; then
|
---|
| 41 | echo "syntax error: too few arguments" 1>&2;
|
---|
| 42 | exit 2;
|
---|
| 43 | fi
|
---|
| 44 | MY_INPUT_FILE="$1"
|
---|
| 45 | MY_XSLT_TOPIC_IDS="$2"
|
---|
| 46 | MY_XSLT_TO_SINGLE_TOPIC="$3"
|
---|
| 47 | MY_OUTPUT_DIR="$4"
|
---|
| 48 | if test "$5" != "--"; then
|
---|
[99514] | 49 | echo "syntax error: Expected '--' as the 5th parameter, got: $5" 1>&2;
|
---|
[99497] | 50 | exit 2;
|
---|
| 51 | fi
|
---|
| 52 | shift 5
|
---|
| 53 |
|
---|
| 54 | if ! test -f "${MY_INPUT_FILE}"; then
|
---|
| 55 | echo "error: Input file does not exists or is not a regular file: ${MY_INPUT_FILE}" 1>&2;
|
---|
| 56 | exit 1;
|
---|
| 57 | fi
|
---|
| 58 | if ! test -f "${MY_XSLT_TOPIC_IDS}"; then
|
---|
| 59 | echo "error: The given dita-refentry-flat-topic-ids.xsl file does not exists or is not a regular file: ${MY_XSLT_TOPIC_IDS}" 1>&2;
|
---|
| 60 | exit 1;
|
---|
| 61 | fi
|
---|
| 62 | if ! test -f "${MY_XSLT_TO_SINGLE_TOPIC}"; then
|
---|
| 63 | echo "error: The given dita-refentry-flat-to-single-topic.xsl file does not exists or is not a regular file: ${MY_XSLT_TO_SINGLE_TOPIC}" 1>&2;
|
---|
| 64 | exit 1;
|
---|
| 65 | fi
|
---|
| 66 | if ! test -d "${MY_OUTPUT_DIR}"; then
|
---|
| 67 | echo "error: Destination directory does not exists or not a directory: ${MY_OUTPUT_DIR}" 1>&2;
|
---|
| 68 | exit 1;
|
---|
| 69 | fi
|
---|
| 70 |
|
---|
| 71 | # Exit on failure.
|
---|
| 72 | set -e
|
---|
| 73 |
|
---|
| 74 | #
|
---|
| 75 | # First get the ID list from it.
|
---|
| 76 | #
|
---|
| 77 | MY_TOPIC_IDS=$($* "${MY_XSLT_TOPIC_IDS}" "${MY_INPUT_FILE}")
|
---|
| 78 |
|
---|
| 79 | #
|
---|
| 80 | # Extract each topic.
|
---|
| 81 | #
|
---|
| 82 | for MY_ID in ${MY_TOPIC_IDS};
|
---|
| 83 | do
|
---|
| 84 | $* \
|
---|
| 85 | --stringparam g_sMode topic \
|
---|
| 86 | --stringparam g_idTopic "${MY_ID}" \
|
---|
| 87 | --output "${MY_OUTPUT_DIR}/${MY_ID}.dita" "${MY_XSLT_TO_SINGLE_TOPIC}" "${MY_INPUT_FILE}"
|
---|
| 88 | done
|
---|
| 89 | exit 0
|
---|