mtd/patches patchin.sh,1.39,1.40
lavinen at infradead.org
lavinen at infradead.org
Thu Mar 3 06:58:10 EST 2005
Update of /home/cvs/mtd/patches
In directory phoenix.infradead.org:/tmp/cvs-serv2652/patches
Modified Files:
patchin.sh
Log Message:
Peplace the old Kconfig subsystem with new one without changing its position.
Index: patchin.sh
===================================================================
RCS file: /home/cvs/mtd/patches/patchin.sh,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- patchin.sh 1 Mar 2005 10:24:38 -0000 1.39
+++ patchin.sh 3 Mar 2005 11:58:03 -0000 1.40
@@ -33,28 +33,28 @@
# moved file selection to variables
-#
-# Finds the first and last lines numbers of block of Kconfig file entries
-# containing pattern $2. $1 contains the file name where to search for.
-# Helper function for patch_Kconfig();
+# Finds the first and the last line numbers of nonempty lines of
+# Kconfig subsystem $2. $1 contains the file name where to search for.
#
# Returns the result in FIRSTLINE and LASTLINE variables.
#
function find_lines () {
# find the line number of the first and the last $2 entries
- FIRSTLINE=`grep -m1 -n $2 $1 | sed -e 's/:.*//'`;
+ FIRSTLINE=`awk '/'"$2"'/ { print NR; exit }' <$1`
+
if [ "x$FIRSTLINE" = "x" ]; then
FIRSTLINE=0;
LASTLINE=0;
return 0;
fi;
- LASTLINE=`grep -n $2 $1 | sed -n -e '$s/:.*// p'`;
- let LASTLINE=$LASTLINE+1;
- LASTLINEADD=`sed -n $1 -e "$LASTLINE,$ p" | sed -n -e '/^\(choice\)\|\(config\)\|\(menu\)\s*/{=; q}'`;
- if [ "x$LASTLINEADD" = "x" ]; then
- let LASTLINEADD=`cat $1 | wc -l`-$LASTLINE+2;
- fi;
- let LASTLINE=$LASTLINE+$LASTLINEADD-2;
+
+ LASTLINE=`awk '
+ BEGIN{ accept=0 }
+ /'"$2"'/ { accept=1; last=NR; next }
+ /^(choice|config|menu)/ { accept=0; } # Possible subsystem end
+ accept && ! /^[ \t]*$/ { last=NR } # Matches nonempty lines
+ END{ print last } # print the last nonempty line of the susystem
+ '<$1 `
}
#
@@ -108,6 +108,55 @@
return 0;
}
+function appendrange() {
+ local INFILE=$1;
+ local OUTFILE=$2;
+ local FIRSTLINE=$3;
+ local LASTLINE=$4;
+
+ if [ "$FIRSTLINE" -le "$LASTLINE" ]; then
+ sed -n "$INFILE" -e "$FIRSTLINE,$LASTLINE p" >> $OUTFILE
+ fi
+}
+
+
+# Replaces a range in file by another range in another file. Meant to
+# for example replace old JFFS2 entris Kconfig by new entries in a
+# template file.
+#
+# Function requires the following positional parameters:
+#
+# $1: The input file containing the replacing range,
+# $2: The output file containing the range to be replaced.
+# $3: The first line of replacing range in input file
+# $4: The last line of replacing range in input file
+# $5: The first line of the range to be replaced in output file
+# $6: The last line of the range to be replaced in output file
+#
+function replace_range () {
+ local INFILE=$1;
+ local OUTFILE=$2;
+ local FIRSTLINEIN=$3;
+ local LASTLINEIN=$4;
+ local FIRSTLINEOUT=$5;
+ local LASTLINEOUT=$6;
+
+ local TMPFILE="${OUTFILE}.$$";
+ rm -f $TMPFILE
+ touch $TMPFILE
+
+ let FIRSTLINEOUT=FIRSTLINEOUT-1
+ appendrange $OUTFILE $TMPFILE 1 $FIRSTLINEOUT
+
+ appendrange $INFILE $TMPFILE $FIRSTLINEIN $LASTLINEIN
+
+ let LASTLINEOUT=LASTLINEOUT+1
+ local LINES=`wc -l < $OUTFILE`
+ appendrange $OUTFILE $TMPFILE $LASTLINEOUT $LINES
+
+ mv -f $TMPFILE $OUTFILE
+}
+
#
# Patch the Kconfig file. This function assumes that there is some input Kconfig file
# (one placed in mtd) containing (among other) a block of continguous entries for
@@ -144,39 +193,20 @@
return 1;
fi;
+ find_lines "$INFILE" "$SUBSYS"
+ local FIRSTLINEIN=$FIRSTLINE
+ local LASTLINEIN=$LASTLINE
+
find_lines $OUTFILE "$SUBSYS";
- if [ $FIRSTLINE -gt $LASTLINE ]; then
- # Bug in find_lines function. Fix it.
- echo -n "Internal error: last > first";
- return 1;
- fi;
- local TOTALIN=`cat $OUTFILE | wc -l`;
- if [ $LASTLINE -gt $TOTALIN ]; then
- # Bug in find_lines function. Fix it.
- echo -n "Internal error: last > total";
- return 1;
- fi;
+ local FIRSTLINEOUT=$FIRSTLINE
+ local LASTLINEOUT=$LASTLINE
- # remove older SUBSYS-related entries from Kconfig
- local TMPFILE=$OUTFILE.$$;
- if [ $LASTLINE -ne "0" ]; then
- cat $OUTFILE | sed -n -e "$FIRSTLINE,$LASTLINE ! p" > $TMPFILE;
- mv $TMPFILE $OUTFILE;
- fi;
-
- find_lines "$INFILE" "$SUBSYS";
- if [ $FIRSTLINE -gt $LASTLINE ]; then
- # Bug in find_lines function. Fix it.
- echo -n "Internal error: last > first";
- return 1;
- fi;
- local TOTALIN=`cat $INFILE | wc -l`;
- if [ $LASTLINE -gt $TOTALIN ]; then
- # Bug in find_lines function. Fix it.
- echo -n "Internal error: last > total";
- return 1;
- fi;
- do_patch_Kconfig $INFILE $OUTFILE $FIRSTLINE $LASTLINE $MENUNAME;
+ if [ "$FIRSTLINEOUT" -gt 0 -a "$LASTLINEOUT" -gt 0 ]; then
+ replace_range $INFILE $OUTFILE $FIRSTLINEIN $LASTLINEIN $FIRSTLINEOUT $LASTLINEOUT
+ else
+ # There is no such subsystem in Kconfig. Add new one
+ do_patch_Kconfig $INFILE $OUTFILE $FIRSTLINEIN $LASTLINEIN $MENUNAME;
+ fi
}
#
More information about the linux-mtd-cvs
mailing list