www-el-commits
[Top][All Lists]
Advanced

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

[www-el-commits] www-el/__make__ comp-format functions.sh


From: Georgios Zarkadas
Subject: [www-el-commits] www-el/__make__ comp-format functions.sh
Date: Tue, 05 May 2015 08:21:00 +0000

CVSROOT:        /cvsroot/www-el
Module name:    www-el
Changes by:     Georgios Zarkadas <gzarkadas>   15/05/05 08:20:59

Modified files:
        __make__       : comp-format functions.sh 

Log message:
        more robust handling in comp-format, library additions

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/www-el/__make__/comp-format?cvsroot=www-el&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/www-el/__make__/functions.sh?cvsroot=www-el&r1=1.1&r2=1.2

Patches:
Index: comp-format
===================================================================
RCS file: /cvsroot/www-el/www-el/__make__/comp-format,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- comp-format 3 May 2015 19:42:58 -0000       1.1
+++ comp-format 5 May 2015 08:20:56 -0000       1.2
@@ -122,8 +122,13 @@
 
 if [ "X${COMPENDIA}" = "X" ]
 then
+    # The easy case: just msgcat the file to re-wrap long lines.
+
     for file in "$@"
     do
+        # To avoid false positives from long comment lines,
+        # remove comments before max-line-length check.
+
         mlen=$(grep -vE '^[[:space:]]*#' "${file}" | wc --max-line-length)
         if [ ${mlen} -le 80 ]
         then
@@ -136,6 +141,14 @@
             error 14 \
               "Error at msgcat-ing '${file}'; check format of translation." 
         fi
+
+        # If the processed file did not change, don't update it.
+
+        if diff --brief "${file}" "${tempfile}" >/dev/null
+        then
+            rm --force "${tmpfile}"
+            continue
+        fi
         if ! mv --backup "${tmpfile}" "${file}"
         then
             rm --force "${tmpfile}"
@@ -146,51 +159,45 @@
         print_msg "  ${file}"
     done
 else
+    # The hard case: msgcat using compendia to enforce translations
+    # and comments for some messages.
+
     # In order to preserve the translation's header and the relative ordering
     # of the messages inside the translation we need to convolute the process
-    # a bit: (a) isolate the header, (b) make an untranslated copy (c) call:
-    # msgcat --use-first <header> <empty> <compendia> <original>
-    # As a final step we call:  msgcomm <processed> <original> , in order to
-    # remove extraneous messages from the compendia that do not exist in the
-    # original.
+    # a bit:
+    # (a)  msgfilter [original] > untranslated copy with the header intact,
+    # (b)  msgcat --use-first [untranslated] [compendia] [original],
+    # (c)  msgcomm [processed] [original], to remove extraneous messages from
+    # the compendia that do not exist in the original.
+    # NOTE:
+    # Fuzzy translations are removed; thus we test for them and exclude files
+    # with fuzzy translations from the processing. 
 
     for file in "$@"
     do
-        headerfile=$(tempfile_or_die)
-        if ! awk '
-          BEGIN {
-            RS="";FS="\n";ORS="\n\n";OFS=FS
-          }
-          NR==1 {
-            print
-          }' <"${file}" >"${headerfile}"
+        if has_fuzzy_translations "${file}"
         then
-            rm --force "${headerfile}"
-            error 12 \
-              "Error at extracting header of '${file}'; ${EMSG_CHK_AWKFULL}"
+            warn "Warning: '${file}' has fuzzy translations; skipping."
+            continue
         fi
         emptyfile=$(tempfile_or_die)
-        if ! msgfilter --input="${file}" \
-          --output-file="${emptyfile}" sed -z 's/^.*$//'
+        if ! msgfilter --input="${file}" --output-file="${emptyfile}" sh -c \
+          '[ "X${MSGFILTER_MSGID}" != "X" ] && sed -z 's/^.*$//' || cat'
         then
-            rm --force "${headerfile}" "${emptyfile}"
-            error 13 \
+            rm --force "${emptyfile}"
+            error 12 \
               "Error at msgfilter-ing '${file}'; check format" \
               "of translation."
         fi
         tmpfile=$(tempfile_or_die)
-
-        # The emptyfile header will result in a warning; discard &2.
-
         if ! msgcat --use-first --output-file="${tmpfile}" \
-          "${headerfile}" "${emptyfile}" ${COMPENDIA} "${file}" 2>/dev/null
+          "${emptyfile}" ${COMPENDIA} "${file}"
         then
-            rm --force "${headerfile}" "${emptyfile}" "${tmpfile}"
-            error 14 \
+            rm --force "${emptyfile}" "${tmpfile}"
+            error 13 \
               "Error at msgcat-ing '${file}'; check format of translation" \
               "and compendia."
         fi
-        rm --force "${headerfile}"
 
         # Reuse emptyfile; processed file must be first,
         # else changes to comments will be discarded.
@@ -198,11 +205,19 @@
         if ! msgcomm --output-file="${emptyfile}" "${tmpfile}" "${file}"
         then
             rm --force "${emptyfile}" "${tmpfile}"
-            error 13 \
+            error 14 \
               "Error at msgcomm-ing '${file}' ; check format" \
               "of translation."
         fi
         rm --force "${tmpfile}"
+
+        # If the processed file did not change, don't update it.
+
+        if same_files "${file}" "${emptyfile}"
+        then
+            rm --force "${emptyfile}"
+            continue
+        fi
         if ! mv --backup "${emptyfile}" "${file}"
         then
             rm --force "${emptyfile}"

Index: functions.sh
===================================================================
RCS file: /cvsroot/www-el/www-el/__make__/functions.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- functions.sh        3 May 2015 19:42:58 -0000       1.1
+++ functions.sh        5 May 2015 08:20:58 -0000       1.2
@@ -101,11 +101,13 @@
     fi
     local errcode=${1}
     shift
-    if [ "X${errcode}" = "X-" ]
-    then
-        errcode=1
-    fi
-    echo "$@"
+    [ "X${errcode}" = "X-" ] && errcode=1
+    local arg
+    for arg in "$@"
+    do
+        printf "${arg}" >&2
+    done
+    printf "\n" >&2
     exit ${errcode}
 }
 
@@ -117,9 +119,14 @@
     if [ $# -eq 0 ]
     then
         echo "${EMSG_INT_WARNING}" >&2
-    else
-        echo "$@" >&2
+        return
     fi
+    local arg
+    for arg in "$@"
+    do
+        printf "${arg}" >&2
+    done
+    printf "\n" >&2
 }
 
 # Create a temporary file or exit with an error.
@@ -248,3 +255,51 @@
         error 5 "${errmsg}"
     fi
 }
+
+# The following functions return information about a translation catalog.
+# Note that in general they are expensive (they operate on an entire file).
+# Args: #1=catalog filename
+
+has_fuzzy_tanslations ()
+{
+    [ $# -eq 1 ] \
+      || error 7 "${EMSG_INT_ARGNUM}" \
+      "\nLocation: has_fuzzy_translations"
+
+    msgfmt --statistics -o /dev/null "${file}" 2>&1 \
+      | grep -q fuzzy >/dev/null 2>/dev/null
+}
+
+has_untranslated_messages ()
+{
+    [ $# -eq 1 ] \
+      || error 7 "${EMSG_INT_ARGNUM}" \
+      "\nLocation: has_untranslated_messages"
+
+    msgfmt --statistics -o /dev/null "${file}" 2>&1 \
+      | grep -q untranslated >/dev/null 2>/dev/null
+}
+
+has_obsolete_messages ()
+{
+    [ $# -eq 1 ] \
+      || error 7 "${EMSG_INT_ARGNUM}" \
+      "\nLocation: has_obsolete_messages"
+
+    local obs=$(msgattrib --only-obsolete "${1}" 2>/dev/null \
+         | awk 'BEGIN{RS="";FS="\n"} END{print (NR>0)?NR-1:NR}' 2>/dev/null)
+    [ $obs -eq 0 ]
+}
+
+# Compare two catalogs with diff, and return true if equal, false otherwise.
+# Note: since diff supports - in either argument to use stdin, the function
+# supports it also.
+# Args: #1,#2=filename of catalog to compare
+#
+same_files ()
+{
+    [ $# -eq 2 ] \
+      || error 7 "${EMSG_INT_ARGNUM}" "\nLocation: same_files"
+
+    diff --brief "${1}" "${2}" >/dev/null 2>/dev/null
+}
\ No newline at end of file



reply via email to

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