[yelp-tools] tools/yelp-check: Adding 'yelp-check orphans'



commit 582850944326903242e554f81e7b99a1d8064411
Author: Shaun McCance <shaunm gnome org>
Date:   Sun Mar 20 16:08:01 2011 -0400

    tools/yelp-check: Adding 'yelp-check orphans'

 .gitignore          |    1 +
 configure.ac        |    4 +
 tools/Makefile.am   |    4 +-
 tools/yelp-check.in |  182 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 189 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c284cc4..598e2d4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,4 +17,5 @@ intltool-update.in
 missing
 py-compile
 tools/yelp-build
+tools/yelp-check
 tools/yelp-new
diff --git a/configure.ac b/configure.ac
index 4638d08..0f706eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,9 @@ XSL_PATH="`$PKG_CONFIG --variable=xsltdir yelp-xsl`"
 XSL_MAL_CACHE="$XSL_PATH""/mallard/cache/mal-cache.xsl"
 AC_SUBST(XSL_MAL_CACHE)
 
+XSL_MAL_LINK="$XSL_PATH""/mallard/common/mal-link.xsl"
+AC_SUBST(XSL_MAL_LINK)
+
 XSL_DB2HTML="`$PKG_CONFIG --variable=db2html yelp-xsl`"
 AC_SUBST(XSL_DB2HTML)
 
@@ -76,6 +79,7 @@ Makefile
 templates/Makefile
 tools/Makefile
 tools/yelp-build
+tools/yelp-check
 tools/yelp-new
 xml2po/Makefile
 xml2po/xml2po.pc
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 3d48378..fcbd6fc 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,6 +1,6 @@
 aclocaldir = $(datadir)/aclocal
 aclocal_DATA = yelp.m4
 
-bin_SCRIPTS = yelp-build yelp-new
+bin_SCRIPTS = yelp-build yelp-check yelp-new
 
-EXTRA_DIST = yelp-build.in yelp-new.in $(aclocal_DATA)
+EXTRA_DIST = yelp-build.in yelp-check.in yelp-new.in $(aclocal_DATA)
diff --git a/tools/yelp-check.in b/tools/yelp-check.in
new file mode 100755
index 0000000..e620aba
--- /dev/null
+++ b/tools/yelp-check.in
@@ -0,0 +1,182 @@
+#!/bin/sh
+# Copyright (C) 2011 Shaun McCance <shaunm gnome org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+xsl_mal_link='@XSL_MAL_LINK@'
+xsl_mal_cache='@XSL_MAL_CACHE@'
+
+urlencode () {
+    echo "$1" | LANG=C awk '
+BEGIN {
+  for (i = 1; i <= 255; i++) chars[sprintf("%c", i)] = i;
+}
+{
+  ret = "";
+  for (i = 1; i <= length($0); i++) {
+    c = substr($0, i, 1);
+    if (c ~ /[\/a-zA-Z0-9._-]/)
+      ret = ret c;
+    else
+      ret = ret sprintf("%%%X%X", int(chars[c] / 16), chars[c] % 16);
+  }
+  print ret;
+}'
+}
+
+urldecode () {
+    echo "$1" | LANG=C awk '
+BEGIN {
+  for(i = 0; i < 10; i++) hex[i] = i;
+  hex["A"] = hex["a"] = 10;
+  hex["B"] = hex["b"] = 11;
+  hex["C"] = hex["c"] = 12;
+  hex["D"] = hex["d"] = 13;
+  hex["E"] = hex["e"] = 14;
+  hex["F"] = hex["f"] = 15;
+}
+{
+  ret = "";
+  for (i = 1; i <= length($0); i++) {
+    c = substr($0, i, 1);
+    if (c == "+") {
+      ret = ret " ";
+    }
+    else if (c == "%") {
+      c = sprintf("%c", hex[substr($0, i + 1, 1)] * 16 + hex[substr($0, i + 2, 1)]);
+      ret = ret c;
+      i += 2;
+    }
+    else {
+      ret = ret c;
+    }
+  }
+  print ret;
+}'
+}
+
+yelp_usage () {
+    (
+        echo "Usage: yelp-check <COMMAND> [OPTIONS] [FILES]"
+        echo ""
+        echo "Commands:"
+        echo "  orphans       Find orphaned pages in a Mallard document"
+    ) 1>&2
+}
+yelp_usage_orphans () {
+    (
+        echo "Usage: yelp-build orphans <FILES>"
+        echo ""
+	echo "  Locate orphaned pages among <FILES> in a Mallard document."
+	echo "  Orphaned pages are any pages that cannot be reached by"
+	echo "  topic links alone from the index page."
+    ) 1>&2
+}
+
+if [ $# = 0 ]; then
+    yelp_usage
+    exit 1
+fi
+
+yelp_cache_ls () {
+    fbase=`basename "$1"`
+    fdir=`dirname "$1"`
+    fdir=`(cd "$fdir" && pwd)`
+    echo '<page cache:href="file://'`urlencode "$fdir/$fbase"`'"/>'
+}
+yelp_cache () {
+    cache_out="index.cache"
+    while [ "$#" != "0" ]; do
+        case "$1" in
+            "-o")
+                shift
+                cache_out="$1"
+                shift
+                ;;
+            *)
+                break
+                ;;
+        esac
+    done
+    if [ "$#" = "0" ]; then
+        exit 1
+    fi
+    (
+        echo '<cache:cache xmlns:cache="http://projectmallard.org/cache/1.0/";'
+        echo '  xmlns="http://projectmallard.org/1.0/";>'
+        for page in "$@"; do
+            if [ -d "$page" ]; then
+                for sub in "$page"/*.page; do
+                    yelp_cache_ls "$sub"
+                done
+            else
+                yelp_cache_ls "$page"
+            fi
+        done
+        echo '</cache:cache>'
+    ) | xsltproc --xinclude -o "$cache_out" "$xsl_mal_cache" -
+}
+
+yelp_orphans_page () {
+    (
+	echo '<xsl:stylesheet'
+	echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform";'
+	echo ' xmlns:mal="http://projectmallard.org/1.0/";'
+	echo ' xmlns:exsl="http://exslt.org/common";'
+	echo ' extension-element-prefixes="exsl"'
+	echo ' version="1.0">'
+        xsl='file://'`urlencode "$xsl_mal_link"`
+        echo '<xsl:import href="'"$xsl"'"/>'
+        check_cache_url='file://'`urlencode "$check_cache_file"`
+        echo '<xsl:param name="mal.cache.file" select="'"'$check_cache_url'"'"/>'
+	echo '<xsl:output method="text"/>'
+	echo '<xsl:template match="/mal:page">'
+	echo ' <xsl:variable name="trails">'
+	echo '  <xsl:call-template name="mal.link.linktrails"/>'
+	echo ' </xsl:variable>'
+	echo ' <xsl:if test="@id != '"'index'"' and count(exsl:node-set($trails)/*) = 0">'
+	echo '  <xsl:value-of select="@id"/>'
+	echo '  <xsl:text>&#x000A;</xsl:text>'
+	echo ' </xsl:if>'
+	echo '</xsl:template>'
+	echo '</xsl:stylesheet>'
+    ) | xsltproc --xinclude - "$1"
+}
+
+yelp_orphans () {
+    check_cache_file=`mktemp`
+    yelp_cache -o "$check_cache_file" "$@"
+    for xml in "$@"; do
+        if [ -d "$xml" ]; then
+            for page in "$xml"/*.page; do
+                yelp_orphans_page "$page"
+            done
+        else
+            yelp_orphans_page "$xml"
+        fi
+    done
+    rm "$check_cache_file"
+}
+
+cmd="$1"
+shift
+case "x$cmd" in
+    "xorphans")
+        yelp_orphans "$@"
+        ;;
+    *)
+        yelp_usage
+        ;;
+esac



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]