#!@KSH@ -p
|
#!@KSH@ -p
|
#
|
#
|
# $Id: update.in,v 1.2 2001-09-27 12:02:54 chris Exp $
|
# $Id: update.in,v 1.2 2001-09-27 12:02:54 chris Exp $
|
#
|
#
|
# Either bash or ksh will be ok for this; requires 'test -ot'
|
# Either bash or ksh will be ok for this; requires 'test -ot'
|
# (-p above just says to not parse $ENV file; makes it faster for
|
# (-p above just says to not parse $ENV file; makes it faster for
|
# those of us who set $ENV)
|
# those of us who set $ENV)
|
#
|
#
|
# Update RTEMS applications for the API changes from 3.1.0 to 3.2.0
|
# Update RTEMS applications for the API changes from 3.1.0 to 3.2.0
|
#
|
#
|
# NOTE
|
# NOTE
|
#
|
#
|
# This is potentially a very dangerous program.
|
# This is potentially a very dangerous program.
|
|
|
# progname=`basename $0`
|
# progname=`basename $0`
|
progname=${0##*/} # fast basename hack for ksh, bash
|
progname=${0##*/} # fast basename hack for ksh, bash
|
|
|
USAGE=\
|
USAGE=\
|
"
|
"
|
usage: $progname [ -vs ] [ -b base_directory ] [-p file] [-f] [files...]
|
usage: $progname [ -vs ] [ -b base_directory ] [-p file] [-f] [files...]
|
-v -- verbose
|
-v -- verbose
|
-p -- file with replacement instructions
|
-p -- file with replacement instructions
|
-s -- skip prompt for backup verification
|
-s -- skip prompt for backup verification
|
-f -- do files at end of line
|
-f -- do files at end of line
|
|
|
base_directory is the root directory of the source code to update. It
|
base_directory is the root directory of the source code to update. It
|
defaults to the current directory.
|
defaults to the current directory.
|
|
|
This program updates C, H, and .inl files.
|
This program updates C, H, and .inl files.
|
"
|
"
|
|
|
fatal() {
|
fatal() {
|
if [ "$1" ]
|
if [ "$1" ]
|
then
|
then
|
echo >&2
|
echo >&2
|
echo $* >&2
|
echo $* >&2
|
echo >&2
|
echo >&2
|
fi
|
fi
|
echo "$USAGE" 1>&2
|
echo "$USAGE" 1>&2
|
exit 1
|
exit 1
|
}
|
}
|
|
|
#
|
#
|
# KLUDGE to figure out at runtime how to echo a line without a
|
# KLUDGE to figure out at runtime how to echo a line without a
|
# newline.
|
# newline.
|
#
|
#
|
count=`echo "\\c" | wc -c`
|
count=`echo "\\c" | wc -c`
|
if [ ${count} -ne 0 ] ; then
|
if [ ${count} -ne 0 ] ; then
|
EARG="-n"
|
EARG="-n"
|
EOL=""
|
EOL=""
|
else
|
else
|
EARG=""
|
EARG=""
|
EOL="\\c"
|
EOL="\\c"
|
fi
|
fi
|
|
|
#
|
#
|
# Function to make sure they do a backup
|
# Function to make sure they do a backup
|
#
|
#
|
|
|
WARNING=\
|
WARNING=\
|
"
|
"
|
|
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
**** ****
|
**** ****
|
**** WARNING!!! WARNING!!! WARNING!!! ****
|
**** WARNING!!! WARNING!!! WARNING!!! ****
|
**** ****
|
**** ****
|
**** ALL SOURCE CODE SHOULD BE BACKED UP BEFORE RUNNING THIS PROGRAM!! ****
|
**** ALL SOURCE CODE SHOULD BE BACKED UP BEFORE RUNNING THIS PROGRAM!! ****
|
**** ****
|
**** ****
|
**** WARNING!!! WARNING!!! WARNING!!! ****
|
**** WARNING!!! WARNING!!! WARNING!!! ****
|
**** ****
|
**** ****
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
*******************************************************************************
|
|
|
"
|
"
|
|
|
verify_backup()
|
verify_backup()
|
{
|
{
|
echo "$WARNING"
|
echo "$WARNING"
|
continue="yes"
|
continue="yes"
|
while [ $continue = "yes" ]
|
while [ $continue = "yes" ]
|
do
|
do
|
echo ${EARG} "Do you wish to update the source tree at this time [y|n]? " ${EOL}
|
echo ${EARG} "Do you wish to update the source tree at this time [y|n]? " ${EOL}
|
read answer
|
read answer
|
case $answer in
|
case $answer in
|
[yY]*)
|
[yY]*)
|
continue="no"
|
continue="no"
|
;;
|
;;
|
[nN]*)
|
[nN]*)
|
echo
|
echo
|
echo "Exitting at user request"
|
echo "Exitting at user request"
|
echo
|
echo
|
exit 0
|
exit 0
|
;;
|
;;
|
esac
|
esac
|
done
|
done
|
}
|
}
|
|
|
#
|
#
|
# Default tools to use...
|
# Default tools to use...
|
#
|
#
|
# NOTE: The GNU versions of both of these are faster.
|
# NOTE: The GNU versions of both of these are faster.
|
#
|
#
|
find_prog=find
|
find_prog=find
|
xargs_prog=xargs
|
xargs_prog=xargs
|
|
|
#
|
#
|
# process the options
|
# process the options
|
#
|
#
|
|
|
verbose=""
|
verbose=""
|
suffix=""
|
suffix=""
|
mode=""
|
mode=""
|
base_directory=.
|
base_directory=.
|
do_files="no"
|
do_files="no"
|
do_prompt="yes"
|
do_prompt="yes"
|
replacement_file="${RTEMS_ROOT}/update-tools/310_to_320_list"
|
replacement_file="${RTEMS_ROOT}/update-tools/310_to_320_list"
|
|
|
while getopts sfp:b:v OPT
|
while getopts sfp:b:v OPT
|
do
|
do
|
case "$OPT" in
|
case "$OPT" in
|
v)
|
v)
|
verbose="yes";;
|
verbose="yes";;
|
s)
|
s)
|
do_prompt="no";;
|
do_prompt="no";;
|
b)
|
b)
|
base_directory=${OPTARG};;
|
base_directory=${OPTARG};;
|
p)
|
p)
|
replacement_file=${OPTARG};;
|
replacement_file=${OPTARG};;
|
f)
|
f)
|
do_files="yes";;
|
do_files="yes";;
|
*)
|
*)
|
fatal
|
fatal
|
esac
|
esac
|
done
|
done
|
|
|
let $((shiftcount = $OPTIND - 1))
|
let $((shiftcount = $OPTIND - 1))
|
shift $shiftcount
|
shift $shiftcount
|
|
|
args=$*
|
args=$*
|
|
|
#
|
#
|
# Make sure they have done a backup
|
# Make sure they have done a backup
|
#
|
#
|
|
|
if [ ${do_prompt} = "yes" ]
|
if [ ${do_prompt} = "yes" ]
|
then
|
then
|
verify_backup
|
verify_backup
|
fi
|
fi
|
|
|
#
|
#
|
# Validate the base directory
|
# Validate the base directory
|
#
|
#
|
|
|
if [ ! -d $base_directory ]
|
if [ ! -d $base_directory ]
|
then
|
then
|
fatal "${base_directory} does not exist"
|
fatal "${base_directory} does not exist"
|
fi
|
fi
|
|
|
#
|
#
|
# Validate the replacement file
|
# Validate the replacement file
|
#
|
#
|
|
|
if [ ! -r $replacement_file ]
|
if [ ! -r $replacement_file ]
|
then
|
then
|
fatal "${replacement_file} does not exist or is not readable"
|
fatal "${replacement_file} does not exist or is not readable"
|
fi
|
fi
|
|
|
|
|
#
|
#
|
# Verify enough of the RTEMS environment variables are set
|
# Verify enough of the RTEMS environment variables are set
|
#
|
#
|
|
|
if [ ! -d "${RTEMS_ROOT}" ]
|
if [ ! -d "${RTEMS_ROOT}" ]
|
then
|
then
|
fatal "RTEMS_ROOT environment variable is not initialized"
|
fatal "RTEMS_ROOT environment variable is not initialized"
|
fi
|
fi
|
|
|
#
|
#
|
# Update the files
|
# Update the files
|
#
|
#
|
|
|
generate_list()
|
generate_list()
|
{
|
{
|
if [ ${do_files} = "yes" ]
|
if [ ${do_files} = "yes" ]
|
then
|
then
|
for i in $args
|
for i in $args
|
do
|
do
|
echo $i
|
echo $i
|
done
|
done
|
else
|
else
|
${find_prog} ${base_directory} \( -name "*.[ch]" -o -name "*.inl" \) -print
|
${find_prog} ${base_directory} \( -name "*.[ch]" -o -name "*.inl" \) -print
|
fi
|
fi
|
}
|
}
|
|
|
generate_list | ${xargs_prog} |
|
generate_list | ${xargs_prog} |
|
while read line
|
while read line
|
do
|
do
|
${RTEMS_ROOT}/update-tools/word-replace -p ${replacement_file} ${line}
|
${RTEMS_ROOT}/update-tools/word-replace -p ${replacement_file} ${line}
|
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
then
|
then
|
exit 1
|
exit 1
|
fi
|
fi
|
for file in ${line}
|
for file in ${line}
|
do
|
do
|
mv ${file}.fixed ${file}
|
mv ${file}.fixed ${file}
|
done
|
done
|
done
|
done
|
|
|
exit 0
|
exit 0
|
|
|
# Local Variables: ***
|
# Local Variables: ***
|
# mode:ksh ***
|
# mode:ksh ***
|
# End: ***
|
# End: ***
|
|
|