[CRIU] [PATCH 1/6] gen-offsets.h: refactor
Kir Kolyshkin
kir at openvz.org
Tue Feb 21 17:09:12 EST 2012
These changes are mostly for better readability and style.
The only actual difference (in the output produced) is the last item.
(1) Use UPPERCASE variable names
(2) Simplify names (get rid of name_ prefix for everything)
(3) Rename variables:
- name_ifndef to INC_GUARD,
- name_prefix_offset to PREFIX,
- name_bin to BINARY.
(4) Replace sed with tr for simplicity
(5) Replace grep with awk condition
(6) Don't escape every $ and " inside AWK_CMD, just quote the full string
(7) Use cat and 'here document' instead of many echoes
(8) Simplify hexdump arguments, use single -e option
(9) Insert our name into 'Generated by' comment.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
gen-offsets.sh | 47 ++++++++++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/gen-offsets.sh b/gen-offsets.sh
index 70158fb..838f986 100644
--- a/gen-offsets.sh
+++ b/gen-offsets.sh
@@ -1,22 +1,31 @@
#!/bin/sh
-name_ifndef=$1
-name_prefix_offset=$2
-name_blob=$3
-name_objname=$4
-name_bin=$5
-
-awk_cmd="{ print \"#define $name_prefix_offset\" \$3 \" 0x\" \$1; }"
-
-echo "/* Autogenerated file, don't edit */"
-echo "#ifndef $name_ifndef"
-echo "#define $name_ifndef"
-echo ""
-nm $name_objname | grep ' [Tt] ' | sed -e 's/\./_/g' | awk "$awk_cmd"
-echo ""
-echo "static char $name_blob[] = {"
-hexdump -v -e '"\t"' -e '8/1 "0x%02x, "' -e '"\n"' $name_bin
-echo "};"
-echo ""
-echo "#endif /* $name_ifndef */"
+INC_GUARD=$1
+PREFIX=$2
+BLOB=$3
+OBJNAME=$4
+BINARY=$5
+AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
+
+cat << EOF
+/* Autogenerated by $0, do not edit */
+#ifndef $INC_GUARD
+#define $INC_GUARD
+
+EOF
+
+nm $OBJNAME | tr . _ | awk "$AWK_CMD"
+
+cat << EOF
+
+static char $BLOB[] = {
+EOF
+
+hexdump -v -e '"\t" 8/1 "0x%02x, " "\n"' $BINARY
+
+cat << EOF
+};
+
+#endif /* $INC_GUARD */
+EOF
--
1.7.7.6
More information about the CRIU
mailing list