ext4_mkfs: add journal node creation support
[lwext4.git] / prefix_patch / lwext4_rename.sh
1 #!/bin/sh
2
3 MACRO_NAME=LWEXT4
4 EXT4_ERRNO_H=ext4_errno.h
5 EXT4_OFLAGS_H=ext4_oflags.h
6 USED_ERRNO_FILE=/tmp/used_errno
7 USED_OFLAGS_FILE=/tmp/used_oflags
8
9 usage()
10 {
11         printf "Usage: %s <lwext4_source_patch>" $1
12         exit 1
13 }
14
15 if [[ $# -ne 1 ]];then
16         usage $0
17 fi
18
19 # First change the working directory to destination.
20 cd $1
21 if [[ $? -ne 0 ]];then
22         exit $?
23 fi
24
25 # Extract definitions from 2 files.
26 sed -n "s/[[:blank:]]*#define \(E[[:alnum:]]\+\)[[:blank:]]\+[[:alnum:]]\+[[:blank:]]*.*/\1/gp" ./include/$EXT4_ERRNO_H > $USED_ERRNO_FILE
27 sed -n "s/[[:blank:]]*#define \(O_[[:alpha:]]\+\)[[:blank:]]\+[[:alnum:]]\+[[:blank:]]*.*/\1/gp" ./include/$EXT4_OFLAGS_H > $USED_OFLAGS_FILE
28 sed -n "s/[[:blank:]]*#define \(SEEK_[[:alpha:]]\+\)[[:blank:]]\+[[:alnum:]]\+[[:blank:]]*.*/\1/gp" ./include/$EXT4_OFLAGS_H >> $USED_OFLAGS_FILE
29
30 # Add prefix to those definjtions.
31
32 for errno in $(cat $USED_ERRNO_FILE);do
33         echo "For $errno"
34         for file in $(find . -name "*.c" | xargs -n 1);do
35                 if [[ $(basename $file) != $EXT4_ERRNO_H ]];then
36                         sed -i "/${MACRO_NAME}_ERRNO(${errno})/b;s/\\<${errno}\\>/${MACRO_NAME}_ERRNO(${errno})/g" $file
37                 fi
38         done
39         for file in $(find . -name "*.h" | xargs -n 1);do
40                 if [[ $(basename $file) != $EXT4_ERRNO_H ]];then
41                         sed -i "/${MACRO_NAME}_ERRNO(${errno})/b;s/\\<${errno}\\>/${MACRO_NAME}_ERRNO(${errno})/g" $file
42                 fi
43         done
44 done
45
46 for oflags in $(cat $USED_OFLAGS_FILE);do
47         echo "For $oflags"
48         for file in $(find . -name "*.c" | xargs -n 1);do
49                 if [[ $(dirname $file) != "./blockdev/"* &&  \
50                       $(basename $file) != $EXT4_OFLAGS_H ]];then
51                 sed -i "/${MACRO_NAME}_FLAGS(${oflags})/b;s/\\<${oflags}\\>/${MACRO_NAME}_FLAGS(${oflags})/g" $file
52                 fi
53         done
54         for file in $(find . -name "*.h" | xargs -n 1);do
55                 if [[ $(dirname $file) != "./blockdev/"* &&  \
56                       $(basename $file) != $EXT4_OFLAGS_H ]];then
57                 sed -i "/${MACRO_NAME}_FLAGS(${oflags})/b;s/\\<${oflags}\\>/${MACRO_NAME}_FLAGS(${oflags})/g" $file
58                 fi
59         done
60 done
61
62 # Do final patching.
63 for patches in $(dirname $0)/*.patch ;do
64         patch -p1 < $patches
65 done