#!/bin/bash
#
# This file can be completely replaced with a better tool written in 
# $LANGUAGE of someone's choice
#
# Original shell script - 29-Jan-2005
# kwade@redhat.com

# Manually rename some files to include their wiki namespace
#echo "Renaming Wiki files."
#mv Beats/PPC.xml Beats/ArchSpecificPPC.xml
#mv Beats/x86_64.xml Beats/ArchSpecificx86_64.xml
#mv Beats/x86.xml Beats/ArchSpecificx86.xml
#mv Beats/GCC.xml Beats/DevelToolsGCC.xml
#mv Beats/SELinux.xml Beats/SecuritySELinux.xml
#echo "Finished renaming files."

# Fix the DocType header from bad Wiki output
#ls Beats/ > xmlfiles
#for i in `cat xmlfiles`;
#do
#  sed s'/DocBook V4\.4/DocBook XML V4\.4/g' Beats/$i > tmpfile;
#  mv tmpfile Beats/$i;
#  echo "DOCTYPE header fixed for" $i
#done
#rm xmlfiles
#echo "Done"


# Add the base language extension to the files
#ls Beats/ > xmlfiles
#for i in `cat xmlfiles`;
#  do
#  echo $i | sed 's/.xml/-en.xml/g' > newfilename;
#  mv Beats/$i Beats/`cat newfilename`;
#done
#rm xmlfiles newfilename
#echo "done"

# Right here is where we want to call perl-fu or python-fu
# to follow this pseudo-code
# 
# for each(<section>); 
#  do
#    get(contents of <title></title>) == $title;
#    replace(" " with "-") == $idattrib;
#    insert($idattrib) -> <section id="$idattrib">;
#  done

# We need to convert the targets of XREFs somehow

# This script uses the FDP implementation of xmldiff
# found in cvs.fedora:/cvs/docs/docs-common/bin/
#
# This script expects to be run in-place in
# the release-notes/xmlbeats module, as the paths
# are relative to that point
#
# $Id:
#
# First version kwade@redhat.com 2006-01-04 -- 0.1

# Variables
#XMLDIFF="../../docs-common/bin/xmldiff"
#XMLDIFF_OPTIONS="-p" # colored unified diff
#BEATPATH="./Beats"
#DBPATH=".."
#FILEEXT="*xml"

# Actions
# Run xmldiff against the beat and canonical XML

#for i in $BEATPATH/$FILEEXT;
#  do $XMLDIFF $XMLDIFF_OPTIONS $i

# Move the XML to the build directory
# mv Beats/*.xml ../

# Fix section names for the top-level
for i in `ls *.xml`;
  do
  echo $i | sed 's/\.xml//' > snID;
  echo "Section name sn-"`cat snID`" for "`echo $i`;
  sed 's/  <\/articleinfo>\n
  <section>/  <\/articleinfo>
  <section id="`cat snID`">/' $i > tmpfile;
  mv tmpfile $i;
  echo $i" has a new section id";
done