diff --git a/tcar-scripts-tuneup/Locales/es_ES/tuneup.sh.po b/tcar-scripts-tuneup/Locales/es_ES/tuneup.sh.po new file mode 100644 index 0000000..72d358b --- /dev/null +++ b/tcar-scripts-tuneup/Locales/es_ES/tuneup.sh.po @@ -0,0 +1,16 @@ +msgid "" +msgstr "" +"Project-Id-Version: tuneup.sh 0.6\n" +"Report-Msgid-Bugs-To: centos-l10n-es@centos.org.cu\n" +"POT-Creation-Date: 2013-10-07 15:20-0400\n" +"PO-Revision-Date: 2013-10-07 15:20-0400\n" +"Last-Translator: Localization SIG \n" +"Language-Team: Spanish\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: Automation/Modules/Tuneup/tuneup.sh:50 +msgid "The argument provided isn't valid." +msgstr "El argumento suministado no es válido." diff --git a/tcar-scripts-tuneup/Modules/Sh/Configs/topcomment.sed b/tcar-scripts-tuneup/Modules/Sh/Configs/topcomment.sed new file mode 100755 index 0000000..a5fef74 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Sh/Configs/topcomment.sed @@ -0,0 +1,57 @@ +#!/bin/sed +###################################################################### +# +# topcomment.sed -- This file standardizes the top comment inside +# centos-art.sh scripts. +# +# Written by: +# * Alain Reguera Delgado +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### +/^#[[:space:]]*Written by:[[:space:]]*$/a\ +# Written by:\ +# * Alain Reguera Delgado , =COPYRIGHT_YEAR_FIRST=-=COPYRIGHT_YEAR_LAST=\ +#\ +# Copyright (C) =COPYRIGHT_YEAR_FIRST=-=COPYRIGHT_YEAR_LAST= =COPYRIGHT_HOLDER=\ +#\ +# 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., 675 Mass Ave, Cambridge, MA 02139, USA.\ +#\ +###################################################################### + +# Remove previous copyright notice, just to be sure the one above be +# used always. +/^#[[:space:]]*Written by:[[:space:]]*$/,/^#{70}$/{ +d +} + +# Define script first line. +1c\ +#!/bin/bash diff --git a/tcar-scripts-tuneup/Modules/Sh/sh.sh b/tcar-scripts-tuneup/Modules/Sh/sh.sh new file mode 100755 index 0000000..27ef589 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Sh/sh.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# sh.sh -- This module standardizes file Bash scripts maintenance +# tasks inside the repository. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function sh { + + sh_setTopComment + sh_setVariableNames + +} diff --git a/tcar-scripts-tuneup/Modules/Sh/sh_setTopComment.sh b/tcar-scripts-tuneup/Modules/Sh/sh_setTopComment.sh new file mode 100755 index 0000000..87c1314 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Sh/sh_setTopComment.sh @@ -0,0 +1,44 @@ +#!/bin/bash +###################################################################### +# +# sh_setTopComment.sh -- This function standardizes presentation for +# top comment section of shell scripts (*.sh) using a predefined +# template. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function sh_setTopComment { + + local COMMENT_TEMPLATE="${TCAR_MODULE_DIR_CONFIGS}/topcomment.sed" + + tcar_checkFiles -ef ${COMMENT_TEMPLATE} + + local COMMENT_INSTANCE=$(tcar_getTemporalFile ${COMMENT_TEMPLATE}) + + cp ${COMMENT_TEMPLATE} ${COMMENT_INSTANCE} + + tcar_setTranslationMarkers ${COMMENT_INSTANCE} + + sed -r -i -f ${COMMENT_INSTANCE} ${FILE} + + if [[ -f ${COMMENT_INSTANCE} ]];then + rm ${COMMENT_INSTANCE} + fi + +} diff --git a/tcar-scripts-tuneup/Modules/Sh/sh_setVariableNames.sh b/tcar-scripts-tuneup/Modules/Sh/sh_setVariableNames.sh new file mode 100755 index 0000000..588f325 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Sh/sh_setVariableNames.sh @@ -0,0 +1,37 @@ +#!/bin/bash +###################################################################### +# +# sh_setVariableNames.sh -- This function standardizes presentation +# of variable's names inside shell scripts. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function sh_setVariableNames { + + local -a COMMANDS + + # Write non-array variable names all in upper case and between + # brackets. For example: ${VARIABLE} -> ${VARIABLE} + COMMANDS[++((${#COMMANDS[*]}))]='s/\$(\w+\b|@)/${\U\1}/g' + + for COMMAND in ${COMMANDS[*]};do + sed -r -i ${COMMAND} ${FILE} + done + +} diff --git a/tcar-scripts-tuneup/Modules/Svg/Configs/metadata.sed b/tcar-scripts-tuneup/Modules/Svg/Configs/metadata.sed new file mode 100755 index 0000000..199c44d --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Svg/Configs/metadata.sed @@ -0,0 +1,64 @@ +# This file is the metadata information used by CentOS Artwork SIG on +# its scalable vector graphics (SVG) files. This files is used with +# the regular expression '.*\.svg$' only. +# --------------------------------------------------- +# $Id$ +# --------------------------------------------------- +/\ + \ + \ + image/svg+xml\ + \ + \ + =TITLE=\ + =DATE=\ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + =URL=\ + =URL=\ + =URL=\ + =LOCALE=\ + \ + \ +=KEYWORDS=\ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + diff --git a/tcar-scripts-tuneup/Modules/Svg/svg.sh b/tcar-scripts-tuneup/Modules/Svg/svg.sh new file mode 100755 index 0000000..b124cb0 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Svg/svg.sh @@ -0,0 +1,34 @@ +#!/bin/bash +###################################################################### +# +# svg.sh -- This module standardizes source code maintainance of SVG +# files inside the repository. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function svg { + + svg_doMetadata + + svg_doVacuumDefs + +} diff --git a/tcar-scripts-tuneup/Modules/Svg/svg_setMetadata.sh b/tcar-scripts-tuneup/Modules/Svg/svg_setMetadata.sh new file mode 100755 index 0000000..ec897bd --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Svg/svg_setMetadata.sh @@ -0,0 +1,92 @@ +#!/bin/bash +###################################################################### +# +# svg_setMetadata.sh -- This function updates metadata values inside +# scalable vector graphic (SVG) files using default values from The +# CentOS Project. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function svg_setMetadata { + + # Define template file name. + local TEMPLATE="${TCAR_MODULE_DIR_CONFIGS}/metadata.sed" + + # Check template file existence. + tcar_checkFiles -ef ${TEMPLATE} + + # Build title from file path. + local TITLE=$(basename "${FILE}") + + # Build url from file path. + local URL=$(echo ${FILE} \ + | sed 's!/home/centos!https://projects.centos.org/svn!') + + # Build keywords from file path. Do not include filename, it is + # already on title. + local KEY='' + local KEYS=$(dirname "${FILE}" | cut -d/ -f6- | tr '/' '\n') + + # Build keywords using SVG standard format. Note that this + # information is inserted inside template file. The template file + # is a replacement set of sed commands so we need to escape the + # new line of each line using one backslash (\). As we are doing + # this inside bash, it is required to escape the backslash with + # another backslash so one of them passes literally to template + # file. + KEYS=$(\ + for KEY in ${KEYS};do + echo " ${KEY}\\" + done) + + # Redefine template instance file name. + local INSTANCE=$(tcar_getTemporalFile ${TEMPLATE}) + + # Create instance. + cp ${TEMPLATE} ${INSTANCE} + + # Check template instance. We cannot continue if the template + # instance couldn't be created. + tcar_checkFiles -e ${INSTANCE} + + # Expand translation markers inside template instance. + sed -r -i \ + -e "s!=TITLE=!${TITLE}!" \ + -e "s!=URL=!${URL}!" \ + -e "s!=DATE=!$(date "+%Y-%m-%d")!" ${INSTANCE} + sed -i -r "/=KEYWORDS=/c\\${KEYS}" ${INSTANCE} + sed -i -r 's/>$/>\\/g' ${INSTANCE} + + tcar_setTranslationMarkers ${INSTANCE} + + # Update scalable vector graphic using template instance. + sed -i -f ${INSTANCE} ${FILE} + + # Remove template instance. + if [[ -f ${INSTANCE} ]];then + rm ${INSTANCE} + fi + + # Sanitate scalable vector graphic. + sed -i -r '/^[[:space:]]*$/d' ${FILE} + +} diff --git a/tcar-scripts-tuneup/Modules/Svg/svg_setVacuumDefs.sh b/tcar-scripts-tuneup/Modules/Svg/svg_setVacuumDefs.sh new file mode 100755 index 0000000..dae1648 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Svg/svg_setVacuumDefs.sh @@ -0,0 +1,32 @@ +#!/bin/bash +###################################################################### +# +# svg_setVacuumDefs.sh -- This function removes all unused items from +# the defs section of the SVG file. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function svg_setVacuumDefs { + + inkscape --vacuum-defs ${FILE} 2&> /dev/null + +} diff --git a/tcar-scripts-tuneup/Modules/Xhtml/Configs/toc.awk b/tcar-scripts-tuneup/Modules/Xhtml/Configs/toc.awk new file mode 100755 index 0000000..ad47670 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Xhtml/Configs/toc.awk @@ -0,0 +1,80 @@ +#!/usr/bin/gawk +# +# toc.awk -- This file provides the output format required by +# `xhtml_setToc' function, inside centos-art.sh script, to produce +# the table of contents correctly. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Pubdtc License as pubdtshed 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 usefdl, but +# WITHOUT ANY WARRANTY; without even the impdted warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Pubdtc License for more details. +# +# You shodld have received a copy of the GNU General Pubdtc License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +###################################################################### + +BEGIN {FS=":"} + +{ + if ($1 == 0 && $2 == $3) { + opentags = "
" + closetags = "" + } + + if ($1 > 0 && $2 > $3) { + opentags = "
" + closetags = "" + } + + if ($1 > 0 && $2 == $3) { + opentags = "
" + closetags = "" + } + + if ($1 > 0 && $2 < $3) { + opentags = "" + for (i = 1; i <= ($3 - $2); i++) { + opentags = opentags "
" + closetags = "" + } + opentags = opentags "
" + } + + printf "%s%s%s\n",opentags,$4,closetags + +} + +END { + + if ($1 > 0 && $2 >= $3 && $3 > 1) { + for (i = 1; i <= $3; i++) { + print "
" + } + } + + if ($1 > 0 && $2 >= $3 && $3 == 1) { + print "" + print "" + } + + if ($1 > 0 && $2 < $3) { + for (i = 1; i <= $2; i++) { + print "" + } + } + + print "" +} diff --git a/tcar-scripts-tuneup/Modules/Xhtml/xhtml.sh b/tcar-scripts-tuneup/Modules/Xhtml/xhtml.sh new file mode 100755 index 0000000..bb0207f --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Xhtml/xhtml.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# xhtml.sh -- This function standardizes maintainance tasks for +# HTML-like files. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function xhtml { + + xhtml_setToc + xhtml_setCleanUp + +} diff --git a/tcar-scripts-tuneup/Modules/Xhtml/xhtml_setCleanUp.sh b/tcar-scripts-tuneup/Modules/Xhtml/xhtml_setCleanUp.sh new file mode 100755 index 0000000..95de440 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Xhtml/xhtml_setCleanUp.sh @@ -0,0 +1,42 @@ +#!/bin/bash +###################################################################### +# +# xhtml_setCleanUp.sh -- This function creates valid XHTML files +# from (probably malformed) HTML files. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function xhtml_setCleanUp { + + grep ' /dev/null \ + || egrep '\-//W3C//DTD XHTML 1.0 (Strict|Transitional)//EN' ${FILE} > /dev/null + if [[ $? -eq 0 ]];then + /usr/bin/xmllint --xmlout --format --noblanks \ + --nonet --nowarning \ + --output ${FILE} ${FILE} 2&> /dev/null + else + /usr/bin/xmllint --html --xmlout --format --noblanks \ + --nonet --nowarning \ + --output ${FILE} ${FILE} 2&> /dev/null + fi + +} diff --git a/tcar-scripts-tuneup/Modules/Xhtml/xhtml_setToc.sh b/tcar-scripts-tuneup/Modules/Xhtml/xhtml_setToc.sh new file mode 100755 index 0000000..e75a2b3 --- /dev/null +++ b/tcar-scripts-tuneup/Modules/Xhtml/xhtml_setToc.sh @@ -0,0 +1,162 @@ +#!/bin/bash +###################################################################### +# +# xhtml_setToc.sh -- This functionality transforms web page headings +# to make them accessible through a table of contents. The table of +# contents is expanded in place, wherever the
piece of code be in the page. Once the
piece of code has be expanded, there is no need +# to put anything else in the page. +# +# In order for the tuneup functionality to transform headings, you +# need to put headings in just one line using one of the following +# forms: +# +#

Title

+#

Title

+#

Title

+# +# In the example above, h1 can vary from h1 to h6. Closing tag must +# be present and also match the openning tag. The value of `name' +# and `href' options from the anchor element are set dynamically +# using the md5sum output of combining the page location, the head- +# string and the heading string. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function xhtml_setToc { + + # Define variables as local to avoid conflicts outside. + local COUNT=0 + local PREVCOUNT=0 + local -a FINAL + local -a TITLE + local -a MD5SM + local -a OPTNS + local -a CLASS + local -a LEVEL + local -a PARENT + local -a TOCENTRIES + local -a LINK + + # Define table of content configuration file, the file used to + # produce the table of content XHTML output code. + local TOC_CONFIG=${TCAR_MODULE_DIR_CONFIGS}/toc.awk + + # Verify table of content configuration file. + tcar_checkFiles -ef ${TOC_CONFIG} + + # Define html heading regular expression pattern. Use parenthisis + # to save html action name, action value, and heading title. + local PATTERN='(]>)(.*[^<])' + + # Verify list of html files. Are files really html files? If they + # don't, continue with the next one in the list. + if [[ ! $(file --brief ${FILE}) =~ '^(XHTML|HTML|XML)' ]];then + continue + fi + + # Define list of headings to process. When building the heading, + # it is required to change spaces characters from its current + # decimal output to something different (e.g., its \040 octal + # alternative). This is required because the space character is + # used as egrep default field separator and spaces can be present + # inside heading strings we don't want to separate. + for HEADING in $(egrep "${PATTERN}" ${FILE} \ + | sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do + + # Define previous counter value using current counter + # value as reference. + if [[ ${COUNT} -ne 0 ]];then + PREVCOUNT=$((${COUNT}-1)) + fi + + # Define initial heading information. + FIRST[${COUNT}]=$(echo "${HEADING}" | sed -r "s!\\\040! !g") + TITLE[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\4!") + MD5SM[${COUNT}]=$(echo "${TITLE[${COUNT}]}" | md5sum | sed -r 's![[:space:]]+-$!!') + OPTNS[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\3!") + CLASS[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\2!") + LEVEL[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\1!") + PARENT[${COUNT}]=${LEVEL[${PREVCOUNT}]} + + # Transform heading information using initial heading + # information as reference. + if [[ ${OPTNS[${COUNT}]} =~ '^$' ]];then + OPTNS[${COUNT}]='' + elif [[ ${OPTNS[${COUNT}]} =~ '^$' ]];then + OPTNS[${COUNT}]='' + elif [[ ${OPTNS[${COUNT}]} =~ '^$' ]];then + OPTNS[${COUNT}]='' + fi + + # Build final html heading structure. + FINAL[${COUNT}]=''${OPTNS[${COUNT}]}${TITLE[${COUNT}]}'' + + # Build html heading link structure. These links are used by + # the table of contents later. + LINK[${COUNT}]=''${TITLE[${COUNT}]}'' + + # Build table of contents entry with numerical + # identifications. The numerical identification is what we use + # to determine the correct position of each heading link on + # the table of content. + TOCENTRIES[${COUNT}]="${COUNT}:${LEVEL[${COUNT}]}:${PARENT[${COUNT}]}:${LINK[${COUNT}]}" + + # Update heading information inside the current file being + # processed. Use the first and final heading information. + sed -i -r "s!${FIRST[${COUNT}]}!${FINAL[${COUNT}]}!" ${FILE} + + # Increase heading counter. + COUNT=$((${COUNT} + 1)) + + done + + # Build the table of contents using heading numerical + # identifications as reference. The numerical identification + # describes the order of headings in one xhtml file. This + # information is processed by awk to make the appropriate + # replacements. Finnally, the result is stored in the TOC + # variable. + TOC=$(echo '
' + echo "

`gettext "Table of contents"`

" + for TOCENTRY in "${TOCENTRIES[@]}";do + echo ${TOCENTRY} + done \ + | awk -f ${TOC_CONFIG}) + + # Update table of contents inside the current file being + # processed. + sed -i -r '/
[^<\/div].*<\/div>/c'"$(echo -e ${TOC})" ${FILE} + + # Clean up variables to receive the next file. + unset FINAL + unset TITLE + unset MD5SM + unset OPTNS + unset CLASS + unset LEVEL + unset PARENT + unset TOCENTRIES + unset LINK + +} diff --git a/tcar-scripts-tuneup/locales/es_ES/tuneup.sh.po b/tcar-scripts-tuneup/locales/es_ES/tuneup.sh.po deleted file mode 100644 index 72d358b..0000000 --- a/tcar-scripts-tuneup/locales/es_ES/tuneup.sh.po +++ /dev/null @@ -1,16 +0,0 @@ -msgid "" -msgstr "" -"Project-Id-Version: tuneup.sh 0.6\n" -"Report-Msgid-Bugs-To: centos-l10n-es@centos.org.cu\n" -"POT-Creation-Date: 2013-10-07 15:20-0400\n" -"PO-Revision-Date: 2013-10-07 15:20-0400\n" -"Last-Translator: Localization SIG \n" -"Language-Team: Spanish\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" - -#: Automation/Modules/Tuneup/tuneup.sh:50 -msgid "The argument provided isn't valid." -msgstr "El argumento suministado no es válido." diff --git a/tcar-scripts-tuneup/modules/sh/configs/topcomment.sed b/tcar-scripts-tuneup/modules/sh/configs/topcomment.sed deleted file mode 100755 index a5fef74..0000000 --- a/tcar-scripts-tuneup/modules/sh/configs/topcomment.sed +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sed -###################################################################### -# -# topcomment.sed -- This file standardizes the top comment inside -# centos-art.sh scripts. -# -# Written by: -# * Alain Reguera Delgado -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### -/^#[[:space:]]*Written by:[[:space:]]*$/a\ -# Written by:\ -# * Alain Reguera Delgado , =COPYRIGHT_YEAR_FIRST=-=COPYRIGHT_YEAR_LAST=\ -#\ -# Copyright (C) =COPYRIGHT_YEAR_FIRST=-=COPYRIGHT_YEAR_LAST= =COPYRIGHT_HOLDER=\ -#\ -# 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., 675 Mass Ave, Cambridge, MA 02139, USA.\ -#\ -###################################################################### - -# Remove previous copyright notice, just to be sure the one above be -# used always. -/^#[[:space:]]*Written by:[[:space:]]*$/,/^#{70}$/{ -d -} - -# Define script first line. -1c\ -#!/bin/bash diff --git a/tcar-scripts-tuneup/modules/sh/sh.sh b/tcar-scripts-tuneup/modules/sh/sh.sh deleted file mode 100755 index 27ef589..0000000 --- a/tcar-scripts-tuneup/modules/sh/sh.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# sh.sh -- This module standardizes file Bash scripts maintenance -# tasks inside the repository. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function sh { - - sh_setTopComment - sh_setVariableNames - -} diff --git a/tcar-scripts-tuneup/modules/sh/sh_setTopComment.sh b/tcar-scripts-tuneup/modules/sh/sh_setTopComment.sh deleted file mode 100755 index 87c1314..0000000 --- a/tcar-scripts-tuneup/modules/sh/sh_setTopComment.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -###################################################################### -# -# sh_setTopComment.sh -- This function standardizes presentation for -# top comment section of shell scripts (*.sh) using a predefined -# template. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function sh_setTopComment { - - local COMMENT_TEMPLATE="${TCAR_MODULE_DIR_CONFIGS}/topcomment.sed" - - tcar_checkFiles -ef ${COMMENT_TEMPLATE} - - local COMMENT_INSTANCE=$(tcar_getTemporalFile ${COMMENT_TEMPLATE}) - - cp ${COMMENT_TEMPLATE} ${COMMENT_INSTANCE} - - tcar_setTranslationMarkers ${COMMENT_INSTANCE} - - sed -r -i -f ${COMMENT_INSTANCE} ${FILE} - - if [[ -f ${COMMENT_INSTANCE} ]];then - rm ${COMMENT_INSTANCE} - fi - -} diff --git a/tcar-scripts-tuneup/modules/sh/sh_setVariableNames.sh b/tcar-scripts-tuneup/modules/sh/sh_setVariableNames.sh deleted file mode 100755 index 588f325..0000000 --- a/tcar-scripts-tuneup/modules/sh/sh_setVariableNames.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -###################################################################### -# -# sh_setVariableNames.sh -- This function standardizes presentation -# of variable's names inside shell scripts. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function sh_setVariableNames { - - local -a COMMANDS - - # Write non-array variable names all in upper case and between - # brackets. For example: ${VARIABLE} -> ${VARIABLE} - COMMANDS[++((${#COMMANDS[*]}))]='s/\$(\w+\b|@)/${\U\1}/g' - - for COMMAND in ${COMMANDS[*]};do - sed -r -i ${COMMAND} ${FILE} - done - -} diff --git a/tcar-scripts-tuneup/modules/svg/configs/metadata.sed b/tcar-scripts-tuneup/modules/svg/configs/metadata.sed deleted file mode 100755 index 199c44d..0000000 --- a/tcar-scripts-tuneup/modules/svg/configs/metadata.sed +++ /dev/null @@ -1,64 +0,0 @@ -# This file is the metadata information used by CentOS Artwork SIG on -# its scalable vector graphics (SVG) files. This files is used with -# the regular expression '.*\.svg$' only. -# --------------------------------------------------- -# $Id$ -# --------------------------------------------------- -/\ - \ - \ - image/svg+xml\ - \ - \ - =TITLE=\ - =DATE=\ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - =URL=\ - =URL=\ - =URL=\ - =LOCALE=\ - \ - \ -=KEYWORDS=\ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - diff --git a/tcar-scripts-tuneup/modules/svg/svg.sh b/tcar-scripts-tuneup/modules/svg/svg.sh deleted file mode 100755 index b124cb0..0000000 --- a/tcar-scripts-tuneup/modules/svg/svg.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -###################################################################### -# -# svg.sh -- This module standardizes source code maintainance of SVG -# files inside the repository. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function svg { - - svg_doMetadata - - svg_doVacuumDefs - -} diff --git a/tcar-scripts-tuneup/modules/svg/svg_setMetadata.sh b/tcar-scripts-tuneup/modules/svg/svg_setMetadata.sh deleted file mode 100755 index ec897bd..0000000 --- a/tcar-scripts-tuneup/modules/svg/svg_setMetadata.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash -###################################################################### -# -# svg_setMetadata.sh -- This function updates metadata values inside -# scalable vector graphic (SVG) files using default values from The -# CentOS Project. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function svg_setMetadata { - - # Define template file name. - local TEMPLATE="${TCAR_MODULE_DIR_CONFIGS}/metadata.sed" - - # Check template file existence. - tcar_checkFiles -ef ${TEMPLATE} - - # Build title from file path. - local TITLE=$(basename "${FILE}") - - # Build url from file path. - local URL=$(echo ${FILE} \ - | sed 's!/home/centos!https://projects.centos.org/svn!') - - # Build keywords from file path. Do not include filename, it is - # already on title. - local KEY='' - local KEYS=$(dirname "${FILE}" | cut -d/ -f6- | tr '/' '\n') - - # Build keywords using SVG standard format. Note that this - # information is inserted inside template file. The template file - # is a replacement set of sed commands so we need to escape the - # new line of each line using one backslash (\). As we are doing - # this inside bash, it is required to escape the backslash with - # another backslash so one of them passes literally to template - # file. - KEYS=$(\ - for KEY in ${KEYS};do - echo " ${KEY}\\" - done) - - # Redefine template instance file name. - local INSTANCE=$(tcar_getTemporalFile ${TEMPLATE}) - - # Create instance. - cp ${TEMPLATE} ${INSTANCE} - - # Check template instance. We cannot continue if the template - # instance couldn't be created. - tcar_checkFiles -e ${INSTANCE} - - # Expand translation markers inside template instance. - sed -r -i \ - -e "s!=TITLE=!${TITLE}!" \ - -e "s!=URL=!${URL}!" \ - -e "s!=DATE=!$(date "+%Y-%m-%d")!" ${INSTANCE} - sed -i -r "/=KEYWORDS=/c\\${KEYS}" ${INSTANCE} - sed -i -r 's/>$/>\\/g' ${INSTANCE} - - tcar_setTranslationMarkers ${INSTANCE} - - # Update scalable vector graphic using template instance. - sed -i -f ${INSTANCE} ${FILE} - - # Remove template instance. - if [[ -f ${INSTANCE} ]];then - rm ${INSTANCE} - fi - - # Sanitate scalable vector graphic. - sed -i -r '/^[[:space:]]*$/d' ${FILE} - -} diff --git a/tcar-scripts-tuneup/modules/svg/svg_setVacuumDefs.sh b/tcar-scripts-tuneup/modules/svg/svg_setVacuumDefs.sh deleted file mode 100755 index dae1648..0000000 --- a/tcar-scripts-tuneup/modules/svg/svg_setVacuumDefs.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -###################################################################### -# -# svg_setVacuumDefs.sh -- This function removes all unused items from -# the defs section of the SVG file. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function svg_setVacuumDefs { - - inkscape --vacuum-defs ${FILE} 2&> /dev/null - -} diff --git a/tcar-scripts-tuneup/modules/xhtml/configs/toc.awk b/tcar-scripts-tuneup/modules/xhtml/configs/toc.awk deleted file mode 100755 index ad47670..0000000 --- a/tcar-scripts-tuneup/modules/xhtml/configs/toc.awk +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/gawk -# -# toc.awk -- This file provides the output format required by -# `xhtml_setToc' function, inside centos-art.sh script, to produce -# the table of contents correctly. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Project -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Pubdtc License as pubdtshed 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 usefdl, but -# WITHOUT ANY WARRANTY; without even the impdted warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Pubdtc License for more details. -# -# You shodld have received a copy of the GNU General Pubdtc License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA. -# -###################################################################### - -BEGIN {FS=":"} - -{ - if ($1 == 0 && $2 == $3) { - opentags = "
" - closetags = "" - } - - if ($1 > 0 && $2 > $3) { - opentags = "
" - closetags = "" - } - - if ($1 > 0 && $2 == $3) { - opentags = "
" - closetags = "" - } - - if ($1 > 0 && $2 < $3) { - opentags = "" - for (i = 1; i <= ($3 - $2); i++) { - opentags = opentags "
" - closetags = "" - } - opentags = opentags "
" - } - - printf "%s%s%s\n",opentags,$4,closetags - -} - -END { - - if ($1 > 0 && $2 >= $3 && $3 > 1) { - for (i = 1; i <= $3; i++) { - print "
" - } - } - - if ($1 > 0 && $2 >= $3 && $3 == 1) { - print "" - print "" - } - - if ($1 > 0 && $2 < $3) { - for (i = 1; i <= $2; i++) { - print "" - } - } - - print "
" -} diff --git a/tcar-scripts-tuneup/modules/xhtml/xhtml.sh b/tcar-scripts-tuneup/modules/xhtml/xhtml.sh deleted file mode 100755 index bb0207f..0000000 --- a/tcar-scripts-tuneup/modules/xhtml/xhtml.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# xhtml.sh -- This function standardizes maintainance tasks for -# HTML-like files. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function xhtml { - - xhtml_setToc - xhtml_setCleanUp - -} diff --git a/tcar-scripts-tuneup/modules/xhtml/xhtml_setCleanUp.sh b/tcar-scripts-tuneup/modules/xhtml/xhtml_setCleanUp.sh deleted file mode 100755 index 95de440..0000000 --- a/tcar-scripts-tuneup/modules/xhtml/xhtml_setCleanUp.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -###################################################################### -# -# xhtml_setCleanUp.sh -- This function creates valid XHTML files -# from (probably malformed) HTML files. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function xhtml_setCleanUp { - - grep ' /dev/null \ - || egrep '\-//W3C//DTD XHTML 1.0 (Strict|Transitional)//EN' ${FILE} > /dev/null - if [[ $? -eq 0 ]];then - /usr/bin/xmllint --xmlout --format --noblanks \ - --nonet --nowarning \ - --output ${FILE} ${FILE} 2&> /dev/null - else - /usr/bin/xmllint --html --xmlout --format --noblanks \ - --nonet --nowarning \ - --output ${FILE} ${FILE} 2&> /dev/null - fi - -} diff --git a/tcar-scripts-tuneup/modules/xhtml/xhtml_setToc.sh b/tcar-scripts-tuneup/modules/xhtml/xhtml_setToc.sh deleted file mode 100755 index e75a2b3..0000000 --- a/tcar-scripts-tuneup/modules/xhtml/xhtml_setToc.sh +++ /dev/null @@ -1,162 +0,0 @@ -#!/bin/bash -###################################################################### -# -# xhtml_setToc.sh -- This functionality transforms web page headings -# to make them accessible through a table of contents. The table of -# contents is expanded in place, wherever the
piece of code be in the page. Once the
piece of code has be expanded, there is no need -# to put anything else in the page. -# -# In order for the tuneup functionality to transform headings, you -# need to put headings in just one line using one of the following -# forms: -# -#

Title

-#

Title

-#

Title

-# -# In the example above, h1 can vary from h1 to h6. Closing tag must -# be present and also match the openning tag. The value of `name' -# and `href' options from the anchor element are set dynamically -# using the md5sum output of combining the page location, the head- -# string and the heading string. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function xhtml_setToc { - - # Define variables as local to avoid conflicts outside. - local COUNT=0 - local PREVCOUNT=0 - local -a FINAL - local -a TITLE - local -a MD5SM - local -a OPTNS - local -a CLASS - local -a LEVEL - local -a PARENT - local -a TOCENTRIES - local -a LINK - - # Define table of content configuration file, the file used to - # produce the table of content XHTML output code. - local TOC_CONFIG=${TCAR_MODULE_DIR_CONFIGS}/toc.awk - - # Verify table of content configuration file. - tcar_checkFiles -ef ${TOC_CONFIG} - - # Define html heading regular expression pattern. Use parenthisis - # to save html action name, action value, and heading title. - local PATTERN='(]>)(.*[^<])' - - # Verify list of html files. Are files really html files? If they - # don't, continue with the next one in the list. - if [[ ! $(file --brief ${FILE}) =~ '^(XHTML|HTML|XML)' ]];then - continue - fi - - # Define list of headings to process. When building the heading, - # it is required to change spaces characters from its current - # decimal output to something different (e.g., its \040 octal - # alternative). This is required because the space character is - # used as egrep default field separator and spaces can be present - # inside heading strings we don't want to separate. - for HEADING in $(egrep "${PATTERN}" ${FILE} \ - | sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do - - # Define previous counter value using current counter - # value as reference. - if [[ ${COUNT} -ne 0 ]];then - PREVCOUNT=$((${COUNT}-1)) - fi - - # Define initial heading information. - FIRST[${COUNT}]=$(echo "${HEADING}" | sed -r "s!\\\040! !g") - TITLE[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\4!") - MD5SM[${COUNT}]=$(echo "${TITLE[${COUNT}]}" | md5sum | sed -r 's![[:space:]]+-$!!') - OPTNS[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\3!") - CLASS[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\2!") - LEVEL[${COUNT}]=$(echo "${FIRST[${COUNT}]}" | sed -r "s!${PATTERN}!\1!") - PARENT[${COUNT}]=${LEVEL[${PREVCOUNT}]} - - # Transform heading information using initial heading - # information as reference. - if [[ ${OPTNS[${COUNT}]} =~ '^$' ]];then - OPTNS[${COUNT}]='' - elif [[ ${OPTNS[${COUNT}]} =~ '^$' ]];then - OPTNS[${COUNT}]='' - elif [[ ${OPTNS[${COUNT}]} =~ '^$' ]];then - OPTNS[${COUNT}]='' - fi - - # Build final html heading structure. - FINAL[${COUNT}]=''${OPTNS[${COUNT}]}${TITLE[${COUNT}]}'' - - # Build html heading link structure. These links are used by - # the table of contents later. - LINK[${COUNT}]=''${TITLE[${COUNT}]}'' - - # Build table of contents entry with numerical - # identifications. The numerical identification is what we use - # to determine the correct position of each heading link on - # the table of content. - TOCENTRIES[${COUNT}]="${COUNT}:${LEVEL[${COUNT}]}:${PARENT[${COUNT}]}:${LINK[${COUNT}]}" - - # Update heading information inside the current file being - # processed. Use the first and final heading information. - sed -i -r "s!${FIRST[${COUNT}]}!${FINAL[${COUNT}]}!" ${FILE} - - # Increase heading counter. - COUNT=$((${COUNT} + 1)) - - done - - # Build the table of contents using heading numerical - # identifications as reference. The numerical identification - # describes the order of headings in one xhtml file. This - # information is processed by awk to make the appropriate - # replacements. Finnally, the result is stored in the TOC - # variable. - TOC=$(echo '
' - echo "

`gettext "Table of contents"`

" - for TOCENTRY in "${TOCENTRIES[@]}";do - echo ${TOCENTRY} - done \ - | awk -f ${TOC_CONFIG}) - - # Update table of contents inside the current file being - # processed. - sed -i -r '/
[^<\/div].*<\/div>/c'"$(echo -e ${TOC})" ${FILE} - - # Clean up variables to receive the next file. - unset FINAL - unset TITLE - unset MD5SM - unset OPTNS - unset CLASS - unset LEVEL - unset PARENT - unset TOCENTRIES - unset LINK - -}