From 9f4d864ea97247be1626eb38c8cdedee5902717a Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Mar 01 2011 15:57:09 +0000 Subject: Update manual functionality: - Add `--rename' option to manual functionality through manual_renameEntry.sh and manual_renameCrossReferences.sh files. --- diff --git a/Scripts/Bash/centos-art/Functions/Manual/manual_getActions.sh b/Scripts/Bash/centos-art/Functions/Manual/manual_getActions.sh index a4a8d22..6a2dabf 100755 --- a/Scripts/Bash/centos-art/Functions/Manual/manual_getActions.sh +++ b/Scripts/Bash/centos-art/Functions/Manual/manual_getActions.sh @@ -30,7 +30,7 @@ function manual_getActions { local ARGSS="" # Define long options we want to support. - local ARGSL="read:,search:,edit:,delete:,update:,copy:,to:" + local ARGSL="read:,search:,edit:,delete:,update:,copy:,rename:,to:" # Parse arguments using getopt(1) command parser. cli_doParseArguments @@ -79,6 +79,12 @@ function manual_getActions { shift 2 ;; + --rename ) + ACTIONVAL="$2" + ACTIONNAM="${FUNCNAM}_renameEntry" + shift 2 + ;; + --to ) FLAG_TO="$(manual_getEntry "$2")" shift 2 @@ -140,7 +146,7 @@ function manual_getActions { # Syncronize changes between the working copy and the central # repository to bring down changes. - cli_commitRepoChanges ${MANUAL_DIR} + cli_syncroRepoChanges ${MANUAL_DIR} # Execute action name. if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then diff --git a/Scripts/Bash/centos-art/Functions/Manual/manual_renameCrossReferences.sh b/Scripts/Bash/centos-art/Functions/Manual/manual_renameCrossReferences.sh new file mode 100755 index 0000000..4d701fe --- /dev/null +++ b/Scripts/Bash/centos-art/Functions/Manual/manual_renameCrossReferences.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# +# manual_renameCrossReferences.sh -- This function replaces a node +# pattern with a node replacement and updates cross-reference +# definitions to reflect the changes. +# +# Copyright (C) 2009-2011 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function manual_renameCrossReferences { + + local NODE='' + local COUNT=1 + local ENTRIES='' + local NODE_SRC='' + local NODE_DST='' + + # Define node pattern for source documenation entry. + NODE_SRC=$(echo "$ENTRY" \ + | cut -d / -f8- \ + | tr '/' ' ' \ + | sed -r \ + -e "s/(chapter-intro\.texi|\.texi)$//" \ + -e 's! !( |\\n)!g') + + # Define node replacement for target documentation entry. + NODE_DST=$(echo "$FLAG_TO" \ + | cut -d / -f8- \ + | tr '/' ' ' \ + | sed -r \ + -e "s/(chapter-intro\.texi|\.texi)$//") + + # Sanitate node replacement for target documentation entry to make + # use of regular expression positional markers, so the word + # separator character found by node pattern could be used. + for NODE in $NODE_DST;do + if [[ $COUNT -eq 1 ]];then + NODE_DST="${NODE}\\${COUNT}" + else + NODE_DST="${NODE_DST}$(echo "${NODE}\\${COUNT}")" + fi + COUNT=$(($COUNT + 1)) + done + + # Remove last positional marker from node replacement. + NODE_DST=$(echo $NODE_DST | sed -r 's!\\[[:digit:]]$!!') + + # Define list of entries to process. + ENTRIES=$(cli_getFilesList "${MANUAL_DIR}" '.*\.texi') + + # Set action preamble. + cli_printActionPreamble "$ENTRIES" + + # Update node-related cross-references. The node-related cross + # reference definition, long ones specially, could require more + # than one line to be set. By default, GNU sed does not matches + # newline characters in the pattern space, so we need to make use + # of `label' feature and the `N' command in order to build a + # pattern space that includes the newline character in it. Here we + # use the `a' letter to name the label we use, followed by N + # command to add a newline to the pattern space, the s command to + # make the pattern replacement using the `g' flag to make it + # global and finaly the command `b' to branch label named `a'. + sed -r -i ":a;N;s!${NODE_SRC}!${NODE_DST}!g;ba" ${ENTRIES} + + # At this point, source documentation entry has been renamed from + # source to target documentation entry, but they are still + # commented. So, restore target documentation entries. + manual_restoreCrossReferences "${FLAG_TO}" + +} diff --git a/Scripts/Bash/centos-art/Functions/Manual/manual_renameEntry.sh b/Scripts/Bash/centos-art/Functions/Manual/manual_renameEntry.sh new file mode 100755 index 0000000..1f56f81 --- /dev/null +++ b/Scripts/Bash/centos-art/Functions/Manual/manual_renameEntry.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# manual_renameEntry.sh -- This function renames documentation entries +# and updates documentation structure to reflect changes. +# +# Copyright (C) 2009-2011 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function manual_renameEntry { + + # Copy source documentation entry. + manual_copyEntry + + # Print separator line. + cli_printMessage '-' 'AsSeparatorLine' + + # Delete source documentation entry. The source documentation + # entry has been copied already, so to create the rename effect + # delete it from repository filesystem. + manual_deleteEntry + + # At this point, source documentation entry has been removed and + # all menu, nodes and cross-references have been commented. So, + # replace commented menu, nodes and cross-reference information + # from source to target documentation entry. + manual_renameCrossReferences + +}