trans-coord-devel
[Top][All Lists]
Advanced

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

trans-coord/gnun/server/gnun gnun-validate-html...


From: Pavel Kharitonov
Subject: trans-coord/gnun/server/gnun gnun-validate-html...
Date: Mon, 22 Aug 2011 15:30:52 +0000

CVSROOT:        /sources/trans-coord
Module name:    trans-coord
Changes by:     Pavel Kharitonov <ineiev>       11/08/22 15:30:52

Modified files:
        gnun/server/gnun: gnun-validate-html validate-html-notify 

Log message:
        regenerate

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/gnun-validate-html?cvsroot=trans-coord&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/validate-html-notify?cvsroot=trans-coord&r1=1.5&r2=1.6

Patches:
Index: gnun-validate-html
===================================================================
RCS file: /sources/trans-coord/trans-coord/gnun/server/gnun/gnun-validate-html,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- gnun-validate-html  7 Jan 2010 14:43:04 -0000       1.11
+++ gnun-validate-html  22 Aug 2011 15:30:52 -0000      1.12
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 # This file is part of GNUnited Nations.
 
@@ -19,8 +19,8 @@
 
 function version () {
 cat <<EOF
-gnun-validate-html (GNUnited Nations) 0.3.1
-Copyright (C) 2010 Free Software Foundation, Inc.
+gnun-validate-html (GNUnited Nations) 0.4
+Copyright (C) 2011 Free Software Foundation, Inc.
 You may redistribute copies of GNUnited Nations
 under the terms of the GNU General Public License.
 For more information about these matters, see the file named COPYING.
@@ -63,33 +63,98 @@
 fi
 
 ROOT=../..
-DTD=$HOME/dtd
+DTD=dtd
 
 # Create two tempfiles and mark them for deletion on exit.
 TMP1=`mktemp -t gnun.1.XXXXXX`
 TMP2=`mktemp -t gnun.2.XXXXXX`
-TMP3=`mktemp -t gnun.3.XXXXXX`
-trap "rm -f $TMP1 $TMP2 $TMP3" EXIT
+trap "rm -f $TMP1 $TMP2" EXIT
 
 # Expand input file's #include directives and save the result in
 # $TMP1.
-cat $1 > $TMP1
+cat > $TMP2 <<"EOF"
+# Limitations: CGI includes would be expanded in a wrong way
+BEGIN {
+  relative_dir_name = ARGV[1];
+  sub (/[^\/]*$/, "", relative_dir_name);
+  sub (/\/*$/, "/", relative_dir_name);
+}
+
+/<!--#include +(virtual)|(file)=["`']/ {
+  n = split ($0, names, "<!--#include ");
+  printf ("%s", names[1]);
+  for (i = 2; i <= n; i++)
+    {
+      # Extract the next included file name
+      if (names[i] !~ /^ *(virtual)|(file)=["'`]/)
+        {
+          # Pass it unchanged: this is not an Apache include directive
+          printf ("<!--#include %s", names[i]);
+          continue;
+        }
+      m = index (names[i], "-->");
+      if (m == 0) # This shouldn't happen: the "-->" must be on the same line
+        m = length (names[i]) + 1;
+      name = substr (names[i], 1, m-1);
+      # Absolute paths are not allowed with "file=" type of includes,
+      # but we process them in the same way for simplicity
+      sub (/^ *((virtual)|(file))=/, "", name);
+      quote_symbol = substr (name, 1, 1);
+      name = substr (name, 2);
+      sub (quote_symbol "[^" quote_symbol "]*$", "", name);
+
+      # Construct the real path to the file
+      if (name ~ /^\//)
+        name = root name;
+      else
+        name = relative_dir_name name;
+
+      # Invoke the script recursively
+      system ("gawk -v script_name='" script_name "' -v root='" \
+               root "' -f '" script_name "' " name);
+
+      # Output the part remaining after the include directive
+      print (substr (names[i], m + 3));
+    }
+  next;
+}
+
+{ print; }
+EOF
+
+gawk -v script_name=$TMP2 -v root="$ROOT" -f $TMP2 $1 > $TMP1
 
-while true; do
-    grep --quiet '<!--#include virtual' $TMP1 || break
-    sed --in-place \
-      "s/<\!--#include virtual=\"\/\?\(.*\)\" -->/m4_include(\`\1')/g" $TMP1
-    m4 -P -EE -I $ROOT $TMP1 > $TMP3
-    cp $TMP3 $TMP1
-done
+if gawk '
+  # Check whether we are validating HTML5 or some other flavor of HTML
+  /<!DOCTYPE/ {
+     exit $0 ~ /<!DOCTYPE[ \t\f\n\r\v]+html[ \t\f\n\r\v]*>/;
+  }' $TMP1;
+then
+  # Use our old procedure
+  VALIDATE=--valid
+else
+  # We are "validating" HTML5
+  gawk '
+    # Replace the DOCTYPE clause to make it work with xmllint
+    /<!DOCTYPE/ {
+      if (!vex)
+        {
+          head = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
+          head = head " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>"
+          sub (/<!DOCTYPE[^>]*>/, head);
+          vex = 1;
+        }
+    }
+    { print; }' $TMP1 > $TMP2
+  mv $TMP2 $TMP1
+  VALIDATE="--dtdvalid $DTD/html5.dtd"
+fi
 
 # Execute xmllint on $TMP1 and save its output to $TMP2.
-set +o pipefail
 set +e
-cat $TMP1 | xmllint --path "$DTD" --valid --nonet --noout - 2> $TMP2
+xmllint --path "$DTD" $VALIDATE --nonet --noout $TMP1 2> $TMP2
 LINTSTATUS=$?
 set -e
-set -o pipefail
 
 # Parse xmllint's error output (if any) and print it by inserting
 # additional context line after every occurrence of "line X" where X
@@ -97,12 +162,12 @@
 # mentioned lines, since xmllint runs on intermediate input file (with
 # expanded #include directives) and the translator can not easily look
 # up for references in it.
-cat $TMP2 | sed '
+sed '
   /line [[:digit:]]\+/ {
      p
      s=^.*line \([[:digit:]]\+\).*$=head -n \1 '"$TMP1"' | tail -n 1=
      e
-  }'
+  }' $TMP2
 
 # Exit with xmlint's original exit status.
 exit $LINTSTATUS

Index: validate-html-notify
===================================================================
RCS file: 
/sources/trans-coord/trans-coord/gnun/server/gnun/validate-html-notify,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- validate-html-notify        7 Jan 2010 14:43:04 -0000       1.5
+++ validate-html-notify        22 Aug 2011 15:30:52 -0000      1.6
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 # This file is part of GNUnited Nations.
 
@@ -49,4 +49,5 @@
 
 SUBJ="[GNUN Error] ${FILE#../../} is not valid XHTML"
 
-./mailfail $DRY_RUN "$RCPT" "$SUBJ" ./gnun-validate-html "$FILE"
+./mailfail $DRY_RUN "$RCPT" "$SUBJ" \
+  ./gnun-validate-html "$FILE"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]