#!/bin/bash
#
# texinfo_copyEntryChapter.sh -- This function standardizes chapter
# duplication inside manuals written in texinfo format.
#
# 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.
#
# ----------------------------------------------------------------------
# $Id$
# ----------------------------------------------------------------------
function texinfo_copyEntryChapter {
# Redefine documentation entry source's location.
MANUAL_ENTRY_SRC=${MANUAL_BASEDIR_L10N}/${MANUAL_CHAP[${MANUAL_DOCENTRY_ID}]}
# Redefine documentation entry target's location.
MANUAL_ENTRY_DST=${MANUAL_BASEDIR_L10N}/${MANUAL_CHAP[((${MANUAL_DOCENTRY_ID} + 1))]}
# Verify entry source and target locations.
texinfo_checkEntrySrcDst "${MANUAL_ENTRY_SRC}" "${MANUAL_ENTRY_DST}"
# When we are copying chapters, document structure actualization
# needs to be performed against the target chapter not the source
# one used to create the duplication. To achieve this goal,
# define both chapter's directory and chapter's name at this
# point.
local MANUAL_CHAPTER_DIR=$MANUAL_ENTRY_DST
local MANUAL_CHAPTER_NAME=${MANUAL_CHAP[((${MANUAL_DOCENTRY_ID} + 1))]}
# When we are copying chapters, the chapter itself cannot be
# copied as we regularly do with sections. Instead, the target
# chapter must be created as a new chapter and then sections from
# source chapter must be copied one by one to the recently created
# chapter. At this point then, is when menu, nodes and cross
# references for the new chapter are updated.
texinfo_createChapter
# Create list of sections from source chapter that need to be
# copied to target chapter. Don't include chapter's main
# definition files.
local MANUAL_ENTRIES=$(cli_getFilesList $MANUAL_ENTRY_SRC \
--pattern="^.+\.${MANUAL_EXTENSION}$" | egrep -v '/chapter')
for MANUAL_ENTRY in $MANUAL_ENTRIES;do
# Copy sections from source chapter to target chapter.
cli_runFnEnvironment vcs --copy $MANUAL_ENTRY $MANUAL_ENTRY_DST
# Update section menu, nodes and cross reference definitions
# to all sections inside the documentation manual.
texinfo_updateStructureSection "${MANUAL_ENTRY_DST}/$(basename ${MANUAL_ENTRY})"
done
# Update chapter menu and node definitions inside the manual
# structure.
texinfo_updateChapterMenu
texinfo_updateChapterNodes
}