summaryrefslogtreecommitdiff
path: root/prefix_patch/lwext4_rename.sh
blob: 0c90ff219b220c1e010f329a1f90f243c853c120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh

MACRO_NAME=LWEXT4
EXT4_ERRNO_H=ext4_errno.h
EXT4_OFLAGS_H=ext4_oflags.h
USED_ERRNO_FILE=/tmp/used_errno
USED_OFLAGS_FILE=/tmp/used_oflags

usage()
{
	printf "Usage: %s <lwext4_source_patch>" $1
	exit 1
}

if [[ $# -ne 1 ]];then
	usage $0
fi

# First change the working directory to destination.
cd $1
if [[ $? -ne 0 ]];then
	exit $?
fi

# Extract definitions from 2 files.
sed -n "s/[[:blank:]]*#define \(E[[:alnum:]]\+\)[[:blank:]]\+[[:alnum:]]\+[[:blank:]]*.*/\1/gp" ./include/$EXT4_ERRNO_H > $USED_ERRNO_FILE
sed -n "s/[[:blank:]]*#define \(O_[[:alpha:]]\+\)[[:blank:]]\+[[:alnum:]]\+[[:blank:]]*.*/\1/gp" ./include/$EXT4_OFLAGS_H > $USED_OFLAGS_FILE
sed -n "s/[[:blank:]]*#define \(SEEK_[[:alpha:]]\+\)[[:blank:]]\+[[:alnum:]]\+[[:blank:]]*.*/\1/gp" ./include/$EXT4_OFLAGS_H >> $USED_OFLAGS_FILE

# Add prefix to those definjtions.

for errno in $(cat $USED_ERRNO_FILE);do
	echo "For $errno"
	for file in $(find . -name "*.c" | xargs -n 1);do
		if [[ $(basename $file) != $EXT4_ERRNO_H ]];then
			sed -i "/${MACRO_NAME}_ERRNO(${errno})/b;s/\\<${errno}\\>/${MACRO_NAME}_ERRNO(${errno})/g" $file
		fi
	done
	for file in $(find . -name "*.h" | xargs -n 1);do
		if [[ $(basename $file) != $EXT4_ERRNO_H ]];then
			sed -i "/${MACRO_NAME}_ERRNO(${errno})/b;s/\\<${errno}\\>/${MACRO_NAME}_ERRNO(${errno})/g" $file
		fi
	done
done

for oflags in $(cat $USED_OFLAGS_FILE);do
	echo "For $oflags"
	for file in $(find . -name "*.c" | xargs -n 1);do
		if [[ $(dirname $file) != "./blockdev/"* &&  \
		      $(basename $file) != $EXT4_OFLAGS_H ]];then
		sed -i "/${MACRO_NAME}_FLAGS(${oflags})/b;s/\\<${oflags}\\>/${MACRO_NAME}_FLAGS(${oflags})/g" $file
		fi
	done
	for file in $(find . -name "*.h" | xargs -n 1);do
		if [[ $(dirname $file) != "./blockdev/"* &&  \
		      $(basename $file) != $EXT4_OFLAGS_H ]];then
		sed -i "/${MACRO_NAME}_FLAGS(${oflags})/b;s/\\<${oflags}\\>/${MACRO_NAME}_FLAGS(${oflags})/g" $file
		fi
	done
done

# Do final patching.
for patches in $(dirname $0)/*.patch ;do
	patch -p1 < $patches
done