Pārlūkot izejas kodu

add support for XML catalog, move old mkcatalog out of the way to avoid SGML-catalog-only updates from old packages

Michael van Elst 22 gadi atpakaļ
vecāks
revīzija
a56facb2f2
4 mainītis faili ar 191 papildinājumiem un 15 dzēšanām
  1. 22 0
      sgml/catalog2xml
  2. 3 9
      sgml/mkcatalog
  3. 16 6
      sgml/sgml.spec
  4. 150 0
      sgml/sgmlcatalog

+ 22 - 0
sgml/catalog2xml

@@ -0,0 +1,22 @@
+#!/bin/sh
+
+PATH=@l_prefix@/bin:${PATH}
+
+echo "<?xml version='1.0'?>"
+echo '<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">'
+echo '<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">'
+
+if test $# != 0 ; then
+sed -n \
+    -e ':input' \
+    -e '/PUBLIC[^"]*$/{ N; b input }' \
+    -e '/PUBLIC[^"]*"[^"]*$/{ N; b input }' \
+    -e '/PUBLIC[^"]*"[^"]*"[^"]*$/{ N; b input }' \
+    -e '/PUBLIC[^"]*"[^"]*"[^"]*"[^"]*$/{ N; b input }' \
+    -e 's/\n/ /g' \
+    -e 's/^ *\(--.*--\)/<!\1>/gp' \
+    -e 's/PUBLIC *\("[^"]*"\) *\("[^"]*"\)/<public publicId=\1 uri=\2\/>/gp' \
+    "$@"
+fi
+
+echo '</catalog>'

+ 3 - 9
sgml/mkcatalog

@@ -191,19 +191,13 @@ proc_catalog () {
             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
+            #   if "deinstall or delete" install the temporary catalog
+            #   ${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
+                    cp ${TMPCAT} ${l_upper_abs_cat} || exit 1
                     ;;
                 *)  rm -f ${TMPCAT}
                     exit 0

+ 16 - 6
sgml/sgml.spec

@@ -32,17 +32,19 @@ Packager:     The OpenPKG Project
 Distribution: OpenPKG [PLUS]
 Group:        SGML
 License:      PD
-Version:      20030530
-Release:      20030530
+Version:      20030605
+Release:      20030605
 
 #   list of sources
 Source0:      mkcatalog
+Source1:      sgmlcatalog
+Source2:      catalog2xml
 
 #   build information
 Prefix:       %{l_prefix}
 BuildRoot:    %{l_buildroot}
 BuildPreReq:  OpenPKG, openpkg >= 20020206
-PreReq:       OpenPKG, openpkg >= 20020206, bash
+PreReq:       OpenPKG, openpkg >= 20020206, bash, sed
 AutoReq:      no
 AutoReqProv:  no
 
@@ -58,15 +60,23 @@ AutoReqProv:  no
     rm -rf $RPM_BUILD_ROOT
     %{l_shtool} mkdir -f -p -m 755 \
         $RPM_BUILD_ROOT%{l_prefix}/bin \
-        $RPM_BUILD_ROOT%{l_prefix}/share/sgml
+        $RPM_BUILD_ROOT%{l_prefix}/share/sgml \
+        $RPM_BUILD_ROOT%{l_prefix}/libexec/sgml
     %{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/
+        %{SOURCE mkcatalog} \
+        %{SOURCE catalog2xml} \
+        $RPM_BUILD_ROOT%{l_prefix}/libexec/sgml/
+    %{l_shtool} install -c -m 755 -e 's;@l_prefix@;%{l_prefix};g' \
+        -e 's;@l_prefix@;%{l_prefix};' \
+        %{SOURCE sgmlcatalog} $RPM_BUILD_ROOT%{l_prefix}/bin/
+    PREFIX=$RPM_BUILD_ROOT%{l_prefix} $RPM_BUILD_ROOT%{l_prefix}/bin/sgmlcatalog
     %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
         %{l_files_std} \
-        '%config %{l_prefix}/share/sgml/catalog'
+        '%config %{l_prefix}/share/sgml/catalog' \
+        '%config %{l_prefix}/share/sgml/catalog.xml'
 
 %files -f files
 

+ 150 - 0
sgml/sgmlcatalog

@@ -0,0 +1,150 @@
+#!@l_prefix@/bin/bash
+
+PREFIX=${PREFIX-@l_prefix@}
+DIR=$PREFIX/share/sgml
+MASTER=$DIR/catalog.xml
+MK=$PREFIX/libexec/sgml/mkcatalog
+C2X=$PREFIX/libexec/sgml/catalog2xml
+
+init () {
+    p=()
+    s=()
+    u=()
+    P=()
+    S=()
+    U=()
+    X=0
+}
+
+setup () {
+    if test ! -s $MASTER
+    then
+        cat > $MASTER <<'EOFEOF'
+<?xml version="1.0"?>
+<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
+<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+</catalog>
+EOFEOF
+        ls -l $MASTER
+    fi
+}
+
+del () {
+    name="$1"
+
+    while read line
+    do
+        case "$line" in
+        "<!-- CATALOG $name -->"*)
+            ;;
+        *)
+            echo $line
+            ;;
+        esac
+    done < $MASTER > $MASTER.tmp && \
+    cp $MASTER.tmp $MASTER && \
+    rm -f $MASTER.tmp
+}
+
+ins () {
+    name="$1" ; shift
+    tag="$1" ; shift
+    att1="$1" ; shift
+    att2="$1" ; shift
+    val2="$1" ; shift
+
+    while read line
+    do
+        case "$line" in
+        "</catalog>")
+            for val1 in "$@"
+            do
+                echo '<!-- CATALOG' $name '--><'$tag $att1='"'$val1'"' $att2='"'$val2'"/>'
+            done
+            echo $line
+            ;;
+        *)
+            echo $line
+            ;;
+        esac
+    done < $MASTER > $MASTER.tmp && \
+    cp $MASTER.tmp $MASTER && \
+    rm -f $MASTER.tmp
+}
+
+install () {
+    name=$1
+    cat="file://$DIR/$name/catalog.xml"
+    pre="file://$DIR/$name"
+
+    $MK -q install $name
+
+    if test $X -gt 0
+    then
+        $C2X $DIR/$name/catalog > $DIR/$name/catalog.xml
+    fi
+
+    del $name
+
+    ins $name delegatePublic publicIdStartString catalog $cat "${p[@]}"
+    ins $name delegateSystem systemIdStartString catalog $cat "${s[@]}"
+    ins $name delegateURI    uriStartString      catalog $cat "${u[@]}"
+
+    ins $name rewritePublic publicIdStartString rewritePrefix $pre "${P[@]}"
+    ins $name rewriteSystem systemIdStartString rewritePrefix $pre "${S[@]}"
+    ins $name rewriteURI    uriStartString      rewritePrefix $pre "${U[@]}"
+}
+
+deinstall () {
+    name=$1
+
+    $MK -q deinstall $name
+
+    if test $X -gt 0
+    then
+        rm -f $DIR/$name/catalog.xml
+    fi
+
+    del $name
+}
+
+init
+setup
+
+while test $# -gt 0
+do
+    i="$1" ; shift
+    case "$i" in
+    -p)
+        p=("${p[@]}" "$1") ; shift
+        ;;
+    -s)
+        s=("${s[@]}" "$1") ; shift
+        ;;
+    -u)
+        u=("${u[@]}" "$1") ; shift
+        ;;
+    -P)
+        P=("${P[@]}" "$1") ; shift
+        ;;
+    -S)
+        S=("${S[@]}" "$1") ; shift
+        ;;
+    -U)
+        U=("${U[@]}" "$1") ; shift
+        ;;
+    -i)
+        name="$1" ; shift
+        install "$name"
+        init
+        ;;
+    -x)
+        X=1
+        ;;
+    -d)
+        name="$1" ; shift
+        deinstall "$name"
+        init
+        ;;
+    esac
+done