From 7d215516e51b984319a11b314a917c3fb50ccf04 Mon Sep 17 00:00:00 2001 From: "Ralf S. Engelschall" Date: Thu, 16 Jan 2003 16:38:47 +0000 Subject: [PATCH] fully work off this package --- sgml/mkcatalog | 267 +++++++++++++++++++++++++++++++++++++++++++++++++ sgml/sgml.spec | 7 +- 2 files changed, 271 insertions(+), 3 deletions(-) create mode 100644 sgml/mkcatalog diff --git a/sgml/mkcatalog b/sgml/mkcatalog new file mode 100644 index 0000000000..ca0196a393 --- /dev/null +++ b/sgml/mkcatalog @@ -0,0 +1,267 @@ +#!@l_prefix@/bin/bash +## +## mkcatalog - script for managing SGML catalog file +## Created: 20001015 Shigeyuki Fukushima . +## Modified: 20001019 Hiroki Sato . +## + +sh_basename () { + l_value=$1 + IFS_old=${IFS}; IFS=" /"; set -- ${l_value}; IFS=${IFS_old} + case $# in + 0) ;; + *) echo `eval echo \\$$#` ;; + esac +} + +sh_dirname () { + l_value=$1 + IFS_old=${IFS}; IFS=" /"; set -- ${l_value}; IFS=${IFS_old} + l_dirname=$1 + shift + while + case $# in + 0) break ;; + 1) echo ${l_dirname}; break ;; + *) ;; + esac + do + l_dirname="${l_dirname}/$1"; + shift; + done +} + +norm_dir () { + [ -d "$1" ] && echo `exec 2>/dev/null; cd $1; echo ${PWD}` +} + +verbose_msg () { + case ${F_VERBOSE} in + 1) echo " ===> $*" ;; + *) ;; + esac +} + +PREFIX=@l_prefix@ +TMPDIR=/tmp +ARGV0=`sh_basename $0` +CAT_DIR=${PREFIX}/share/sgml +CAT_FILE=catalog +F_PRESERVE_OLD="" +F_VERBOSE="" + +args=`getopt pqvc: $*` ; set -- $args +for i +do + case "$i" in + -c) CAT_DIR=`sh_dirname $2`; CAT_FILE=`sh_basename $2`; shift; shift ;; + -p) F_PRESERVE_OLD=1; shift ;; + -q) exec 1>/dev/null 2>&1; shift ;; + -v) F_VERBOSE=1; shift ;; + --) shift; break ;; + esac +done + +dtd_act=$1 +dtd_dir=$2 +dtd_catalog=`sh_basename "$3"` + +# option check and normalize ${dtd_dir} +case "${dtd_act}" in + add|install|delete|deinstall|enable|disable) + if [ ! -d "${CAT_DIR}" ]; then + echo "${ARGV0}: top-level catalog dir \"${CAT_DIR}\" not found." + exit 1 + elif [ ! -n "${dtd_dir}" ]; then + echo "${ARGV0}: DTD directory is not specified." + exit 1 + elif [ ! -d "${CAT_DIR}/${dtd_dir}"\ + -a ! -d "${dtd_dir}" ]; then + echo "${ARGV0}: DTD directory \"${dtd_dir}\" not found." + exit 1 + elif [ ! -f "${CAT_DIR}/${dtd_dir}/${dtd_catalog:-catalog}"\ + -a ! -f "${dtd_dir}/${dtd_catalog:-catalog}" ]; then + echo "${ARGV0}: DTD catalog \"${dtd_dir}/${dtd_catalog:-catalog}\" not found." + exit 1 + fi + verbose_msg "top-level catalog dir (specified): ${CAT_DIR}" + CAT_DIR=`norm_dir ${CAT_DIR}` + verbose_msg "top-level catalog dir (normalized): ${CAT_DIR}" + verbose_msg "target catalog dir (specified): ${dtd_dir}" + dtd_dir=`norm_dir ${CAT_DIR}/${dtd_dir} || norm_dir ${dtd_dir}` + verbose_msg "target catalog dir (normalized): ${dtd_dir}" + + case "${dtd_dir}" in + ${CAT_DIR}/*) ;; + *) echo "${ARGV0}: DTD directory \"${dtd_dir}\" is invalid." + exit 1 ;; + esac + # keep dtd_dir relative + dtd_dir=${dtd_dir#"${CAT_DIR}/"} + ;; + *) + echo "${ARGV0}: missing options." + cat < relative path from ${CAT_DIR} + # l_lower_cat -> relative path from l_upper + l_upper_cat="${l_upper}/${CAT_FILE}" + l_lower_cat="`sh_basename ${l_lower}`/${catalog}" + + # l_*_abs_* -> absolute path respectively + l_upper_abs="${CAT_DIR}/${l_upper}" + l_lower_abs="${CAT_DIR}/${l_lower}" + l_upper_abs_cat="${CAT_DIR}/${l_upper}/${CAT_FILE}" + l_lower_abs_cat="${CAT_DIR}/${l_lower}/${catalog}" + + l_cat_line="CATALOG \"${l_lower_cat}\"" + l_abs_path_head=`cd ${l_upper_abs}; echo ${PWD}` + + # first, create temporary catalog from l_upper_cat + # not including CATALOG line of l_lower_cat (if no catalog, + # create empty one). + # + # NOTE: file manipulations require absolute path, but + # CATALOG line do relative from upper's one. + # + touch ${l_upper_abs_cat} || exit 1 + grep -v "\( *-- *\)\?CATALOG *\"\(${l_abs_path_head}/\)\?${l_lower_cat}\"\( *-- *\)\?" \ + ${l_upper_abs_cat} >${TMPCAT} + + # preserve old catalog as necessary + if [ "x${F_PRESERVE_OLD}" != "x" ]; then + cp ${l_upper_abs_cat} ${l_upper_abs_cat}.old || exit 1 + fi + + case "${dtd_act}" in + add|install|enable) + # if "install or add or enable", + # create "the temporary catalog + l_cat_line" and install it. + echo " - ${dtd_act} ${l_cat_line} line in ${l_upper_cat}" + echo "${l_cat_line}" >>${TMPCAT} + cp ${TMPCAT} ${l_upper_abs_cat} || exit 1 + ;; + disable) + # if "disable", install the same above but l_cat_line is + # commented out. + case ${first_p} in + [Yy][Ee][Ss]) + echo " - ${dtd_act} ${l_cat_line} line in ${l_upper_cat}" + echo "-- ${l_cat_line} --" >>${TMPCAT} + cp ${TMPCAT} ${l_upper_abs_cat} || exit 1 + ;; + *) rm -f ${TMPCAT} + exit 0 + ;; + esac + ;; + delete|deinstall) + # if "deinstall or delete" and the temporary catalog is + # not empty, install the catalog itself (in the case of being + # empty, delete it). ${l_bottom_p}=YES means that + # ${l_upper_cat} can be deleted safely, otherwise not. + case ${l_bottom_p} in + [Yy][Ee][Ss]) + echo " - ${dtd_act} ${l_cat_line} line from ${l_upper_cat}" + if [ ! -s ${TMPCAT} ]; then + echo " - delete empty catalog ${l_upper_cat}" + rm -f ${l_upper_abs_cat} + else + cp ${TMPCAT} ${l_upper_abs_cat} || exit 1 + fi + ;; + *) rm -f ${TMPCAT} + exit 0 + ;; + esac + ;; + esac + + # when flag "preserve old" is specified but + # there is no difference between new file and old one, + # preservation is silently denied. + if [ "x${F_PRESERVE_OLD}" != "x" ] && \ + cmp -s ${l_upper_abs_cat}.old ${l_upper_abs_cat}; then + rm -f ${l_upper_abs_cat}.old + fi + rm -f ${TMPCAT} +} + +compose_dir_list () { + l_dir=$1 + # Creates dirlist such as the following. + # input: docbook/4.1/my_extension + # return: docbook/4.1/my_extension docbook/4.1 docbook + IFS_old=${IFS}; IFS=" /"; set -- ${l_dir} + l_dir_top=$1 + shift + l_dir_rest="$*" + IFS=${IFS_old} + + l_dir_item=${l_dir_top} + l_dir_list=${l_dir_top} + + for i in ${l_dir_rest}; do + l_dir_item="${l_dir_item}/${i}" + l_dir_list="${l_dir_item} ${l_dir_list}" + done + echo ${l_dir_list} +} + +bottom_p=YES +first_p=YES +set -- `compose_dir_list ${dtd_dir}` . +verbose_msg "process catalog (relative to top one): $*" +while + case $# in + 1) break ;; + *) ;; + esac +do + lower=$1 + upper=$2 + proc_catalog "${bottom_p}" "${upper}" "${lower}" + first_p=NO + if [ -f ${CAT_DIR}/${upper}/${CAT_FILE} ]; then + bottom_p=NO + fi + shift +done + +exit 0 + diff --git a/sgml/sgml.spec b/sgml/sgml.spec index 6f7e6b10c5..7e9f6b5feb 100644 --- a/sgml/sgml.spec +++ b/sgml/sgml.spec @@ -32,8 +32,8 @@ Packager: The OpenPKG Project Distribution: OpenPKG [PLUS] Group: SGML License: PD -Version: 1.0 -Release: 20020822 +Version: 20030116 +Release: 20030116 # list of sources Source0: mkcatalog @@ -42,7 +42,7 @@ Source0: mkcatalog Prefix: %{l_prefix} BuildRoot: %{l_buildroot} BuildPreReq: OpenPKG, openpkg >= 20020206 -PreReq: OpenPKG, openpkg >= 20020206 +PreReq: OpenPKG, openpkg >= 20020206, bash AutoReq: no AutoReqProv: no @@ -62,6 +62,7 @@ AutoReqProv: no %{l_shtool} install -c -m 644 \ /dev/null $RPM_BUILD_ROOT%{l_prefix}/share/sgml/catalog %{l_shtool} install -c -m 755 -e 's;@l_prefix@;%{l_prefix};g' \ + -e 's;@l_prefix@;%{l_prefix};' \ %{SOURCE mkcatalog} $RPM_BUILD_ROOT%{l_prefix}/bin/ %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}