source: rtems/doc/tools/update @ ae68ff0

4.104.114.84.95
Last change on this file since ae68ff0 was ae68ff0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/27/97 at 12:40:11

Initial revision

  • Property mode set to 100644
File size: 4.2 KB
Line 
1#!/bin/ksh
2#
3# update,v 1.2 1995/05/31 17:20:58 joel Exp
4#
5# Either bash or ksh will be ok for this; requires 'test -ot'
6#  (-p above just says to not parse $ENV file; makes it faster for
7#   those of us who set $ENV)
8#
9#
10# NOTE
11#
12#   This is potentially a very dangerous program.
13
14# progname=`basename $0`
15progname=${0##*/}        # fast basename hack for ksh, bash
16
17USAGE=\
18"
19usage: $progname [ -vs ] [ -b base_directory ] [-p file] [-f] [files...]
20        -v          -- verbose
21        -p          -- file with replacement instructions
22        -s          -- skip prompt for backup verification
23        -f          -- do files at end of line
24
25base_directory is the root directory of the source code to update.  It
26defaults to the current directory.
27
28This program updates C, H, and .inl files.
29"
30
31fatal() {
32    if [ "$1" ]
33    then
34        echo    >&2
35        echo $* >&2
36        echo    >&2
37    fi
38    echo "$USAGE" 1>&2
39    exit 1
40}
41
42#
43#  KLUDGE to figure out at runtime how to echo a line without a
44#  newline.
45#
46count=`echo "\\c" | wc -c`
47if [ ${count} -ne 0 ] ; then
48  EARG="-n"
49  EOL=""
50else
51  EARG=""
52  EOL="\\c"
53fi
54
55#
56#  Function to make sure they do a backup
57#
58
59WARNING=\
60"
61
62*******************************************************************************
63*******************************************************************************
64*******************************************************************************
65****                                                                       ****
66****        WARNING!!!          WARNING!!!           WARNING!!!            ****
67****                                                                       ****
68****   ALL SOURCE CODE SHOULD BE BACKED UP BEFORE RUNNING THIS PROGRAM!!   ****
69****                                                                       ****
70****        WARNING!!!          WARNING!!!           WARNING!!!            ****
71****                                                                       ****
72*******************************************************************************
73*******************************************************************************
74*******************************************************************************
75
76"
77
78verify_backup()
79{
80  echo "$WARNING"
81  continue="yes"
82  while [ $continue = "yes" ]
83  do
84echo ${EARG} "Do you wish to update the source tree at this time [y|n]? " ${EOL}
85    read answer
86    case $answer in
87      [yY]*)
88        continue="no"
89        ;;
90      [nN]*)
91        echo
92        echo "Exitting at user request"
93        echo
94        exit 0
95        ;;
96    esac
97  done
98}
99
100#
101#  Default tools to use...
102#
103#  NOTE: The GNU versions of both of these are faster.
104#
105find_prog=find
106xargs_prog=xargs
107
108#
109# process the options
110#
111
112verbose=""
113suffix=""
114mode=""
115base_directory=.
116do_files="no"
117do_prompt="yes"
118replacement_file="${RTEMS_HOME}/update-tools/310_to_320_list"
119
120while getopts sfp:b:v OPT
121do
122    case "$OPT" in
123        v)
124          verbose="yes";;
125        s)
126          do_prompt="no";;
127        b)
128          base_directory=${OPTARG};;
129        p)
130          replacement_file=${OPTARG};;
131        f)
132          do_files="yes";;
133        *)
134          fatal
135    esac
136done
137
138let $((shiftcount = $OPTIND - 1))
139shift $shiftcount
140
141args=$*
142
143#
144#  Make sure they have done a backup
145#
146
147if [ ${do_prompt} = "yes" ]
148then
149  verify_backup
150fi
151
152#
153# Validate the base directory
154#
155
156if [ ! -d $base_directory ]
157then
158    fatal "${base_directory} does not exist"
159fi
160
161#
162# Validate the replacement file
163#
164
165if [ ! -r $replacement_file ]
166then
167    fatal "${replacement_file} does not exist or is not readable"
168fi
169
170
171#
172#  Verify enough of the RTEMS environment variables are set
173#
174
175if [ ! -d "${RTEMS_HOME}" ]
176then
177    fatal "RTEMS_HOME environment variable is not initialized"
178fi
179
180#
181# Update the files
182#
183
184generate_list()
185{
186  if [ ${do_files} = "yes" ]
187  then
188    for i in $args
189    do
190      echo $i
191    done
192  else
193    ${find_prog} ${base_directory} \(  -name "*.[ch]" -o -name "*.inl" \) -print
194  fi
195}
196
197generate_list | ${xargs_prog} |
198  while read line
199  do
200    ${RTEMS_HOME}/update-tools/word-replace -p ${replacement_file} ${line}
201    if [ $? -ne 0 ]
202    then
203      exit 1
204    fi
205    for file in ${line}
206    do
207      mv ${file}.fixed ${file}
208    done
209  done
210
211exit 0
212
213# Local Variables: ***
214# mode:ksh ***
215# End: ***
Note: See TracBrowser for help on using the repository browser.