From b29c5b502b66a68fafc611be192888548b76a40b Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Dec 13 2013 01:48:17 +0000 Subject: Add tcar-scripts-tuneup to a branch of its own. --- 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/tuneup.sh b/tcar-scripts-tuneup/tuneup.sh new file mode 100755 index 0000000..c1c55f7 --- /dev/null +++ b/tcar-scripts-tuneup/tuneup.sh @@ -0,0 +1,75 @@ +#!/bin/bash +###################################################################### +# +# tuneup.sh -- This module standardizes source code file +# maintainance 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 tuneup { + + # Define file extensions tuneup module will look for processing. + local FILE_EXTENSION_REGEX='\.(svgz|svg|shtml|xhtml|html|sh)$' + + tuneup_getOptions + + for ARGUMENT in ${TCAR_MODULE_ARGUMENT};do + + # Sanitate non-option arguments to be sure they match the + # directory conventions established by centos-art.sh script + # against source directory locations in the working copy. + local ARGUMENT=$(tcar_checkRepoDirSource ${ARGUMENT}) + + # Build list of files to process. + if [[ -f ${ARGUMENT} ]];then + local FILES=${ARGUMENT} + elif [[ -d ${ARGUMENT} ]];then + local FILES=$(tcar_getFilesList ${ARGUMENT} \ + --pattern=".+${FILE_EXTENSION_REGEX}" \ + --type='f' | egrep ${TCAR_FLAG_FILTER}) + else + tcar_printMessage "`gettext "The argument provided isn't valid."`" --as-error-line + fi + + # Process list of files. + for FILE in ${FILES};do + + # Print action message. + tcar_printMessage "${FILE}" --as-tuningup-line + + # Retrieve module name to apply based on file extension . + local FILE_EXTENSION=$(echo ${FILE} \ + | sed -r "s/.+${FILE_EXTENSION_REGEX}/\1/") + + # Set module aliases. + if [[ ${FILE_EXTENSION} =~ '(shtml|html|htm)' ]];then + FILE_EXTENSION='xhtml' + fi + + # Initiate module's environment for processing file. + tcar_setModuleEnvironment -m "${FILE_EXTENSION}" -t "child" "${FILE}" + + done + + done + +} diff --git a/tcar-scripts-tuneup/tuneup_getOptions.sh b/tcar-scripts-tuneup/tuneup_getOptions.sh new file mode 100755 index 0000000..47bd426 --- /dev/null +++ b/tcar-scripts-tuneup/tuneup_getOptions.sh @@ -0,0 +1,71 @@ +#!/bin/bash +###################################################################### +# +# tuneup_getOptions.sh -- This file initialize the command-line +# options used by tuneup module. +# +# 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 tuneup_getOptions { + + # Define short options we want to support. + local ARGSS="h::,v,f:" + + # Define long options we want to support. + local ARGSL="help::,version,filter::" + + # Redefine arguments using getopt(1) command parser. + tcar_setModuleArguments + + # Reset positional parameters on this function, using output + # produced from (getopt) arguments parser. + eval set -- "${TCAR_MODULE_ARGUMENT}" + + # Look for options passed through command-line. + while true; do + case "${1}" in + + -h | --help ) + tcar_printHelp "${2}" + ;; + + -v | --version ) + tcar_printVersion "${TCAR_MODULE_NAME}" + ;; + + -f | --filter ) + TCAR_FLAG_FILTER="${2:-${TCAR_FLAG_FILTER}}" + shift 2 + ;; + + -- ) + shift 1 + break + ;; + esac + done + + # Redefine arguments using current positional parameters. Only + # paths should remain as arguments, at this point. + TCAR_MODULE_ARGUMENT="${@}" + +}