]> granicus.if.org Git - strace/commitdiff
Consistently use extended regular expressions where appropriate
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 28 Jul 2016 16:51:58 +0000 (16:51 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 28 Jul 2016 18:32:18 +0000 (18:32 +0000)
When grep or sed is used with basic regular expressions containing
'(', ')', '{', '}', '|', '?', and '+' special characters, convert them
to extended regular expressions for better portability and readability.

* generate_mpers_am.sh: Convert grep and sed BREs to EREs.
* Makefile.am (ioctl_redefs%.h, m%_type_defs.h, m%_funcs.h,
mpers_printer_decl_pattern, printers.h, %_printer_decls.h,
%_printer_defs.h): Convert sed BREs to EREs.
* generate_sen.sh: Likewise.
* linux/mips/genstub.sh: Likewise.
* make-dsc: Likewise.
* mpers.sh: Likewise.
* xlat/gen.sh: Likewise.
* tests/Makefile.am (ksysent.h): Likewise.
* tests/ksysent.sed: Likewise.
* tests/pc.test: Likewise.
* tests/strace-S.test: Likewise.
* tests/strace-V.test: Likewise.
* tests/strace-k.test: Likewise.

13 files changed:
Makefile.am
generate_mpers_am.sh
generate_sen.sh
linux/mips/genstub.sh
make-dsc
mpers.sh
tests/Makefile.am
tests/ksysent.sed
tests/pc.test
tests/strace-S.test
tests/strace-V.test
tests/strace-k.test
xlat/gen.sh

index 1e7554e1a2786412c8196d74bb2cfbedcbe79f28..cb0bd92c9e983dcb73d38dca8cee8730e3388c17 100644 (file)
@@ -713,7 +713,7 @@ ioctl_redefs_h = $(filter-out ioctl_redefs0.h,$(subst ioctlent,ioctl_redefs,$(io
 ioctl_redefs%.h: ioctlent%.h ioctlent0.h
        sort $< > $<-t
        sort ioctlent0.h | comm -23 $<-t - | \
-               sed -n 's/^{ "\([^"]\+\)", \(0x[[:xdigit:]]\+\) },$$/#ifdef \1\n# undef \1\n# define \1 \2\n#endif/p' \
+               sed -r -n 's/^\{ "([^"]+)", (0x[[:xdigit:]]+) \},$$/#ifdef \1\n# undef \1\n# define \1 \2\n#endif/p' \
                > $@-t
        rm -f $<-t
        mv $@-t $@
@@ -762,7 +762,7 @@ mpers-m%.stamp: $(srcdir_mpers_source_files) | printers.h
 
 m%_type_defs.h: $(srcdir_mpers_source_files)
        for f in $^; do \
-               sed -n 's/^#include DEF_MPERS_TYPE(\([^)]\+\))/#ifdef MPERS_$(mpers_PREFIX)\1\n# define \1 MPERS_$(mpers_PREFIX)\1\n#endif/p' $$f || exit; \
+               sed -r -n 's/^#include DEF_MPERS_TYPE\(([^)]+)\)/#ifdef MPERS_$(mpers_PREFIX)\1\n# define \1 MPERS_$(mpers_PREFIX)\1\n#endif/p' $$f || exit; \
        done > $@-t
        echo '#undef MPERS_PRINTER_NAME' >> $@-t
        echo '#define MPERS_PRINTER_NAME(printer_name) printer_name' >> $@-t
@@ -772,7 +772,7 @@ m%_type_defs.h: $(srcdir_mpers_source_files)
 
 m%_funcs.h: $(srcdir_mpers_source_files)
        for f in $^; do \
-               sed -n 's/^SYS_FUNC(\([^)]\+\))/#undef sys_\1\n#define sys_\1 $(mpers_PREFIX)sys_\1/p' $$f || exit; \
+               sed -r -n 's/^SYS_FUNC\(([^)]+)\)/#undef sys_\1\n#define sys_\1 $(mpers_PREFIX)sys_\1/p' $$f || exit; \
        done > $@-t && \
        echo '#include "sys_func.h"' >> $@-t
        mv $@-t $@
@@ -782,13 +782,13 @@ m%_funcs.h: $(srcdir_mpers_source_files)
 %.c.mpers.i: $(srcdir)/%.c
        $(CPP) -P $(mpers_sh_opts) -DIN_MPERS_BOOTSTRAP $< -o $@
 
-mpers_printer_decl_pattern = ^MPERS_PRINTER_DECL(\([^,)]\+\),[[:space:]]*\([^,)]\+\),[[:space:]]*\([^)]\+\))$$
+mpers_printer_decl_pattern = ^MPERS_PRINTER_DECL\(([^,)]+),[[:space:]]*([^,)]+),[[:space:]]*([^)]+)\)$$
 
 printers.h: $(mpers_preproc_files)
        echo '/* Generated by Makefile from $^; do not edit. */' > $@-t
        echo 'typedef struct {' >> $@-t
        for f in $^; do \
-               sed -n 's/$(mpers_printer_decl_pattern)/ \1 (*\2)(\3);\n#define \2 MPERS_PRINTER_NAME(\2)\n/p' $$f \
+               sed -r -n 's/$(mpers_printer_decl_pattern)/ \1 (*\2)(\3);\n#define \2 MPERS_PRINTER_NAME(\2)\n/p' $$f \
                || exit; \
        done >> $@-t
        echo '} struct_printers;' >> $@-t
@@ -799,7 +799,7 @@ printers.h: $(mpers_preproc_files)
 %_printer_decls.h: $(mpers_preproc_files)
        echo '/* Generated by Makefile from $^; do not edit. */' > $@-t
        for f in $^; do \
-               sed -n 's/$(mpers_printer_decl_pattern)/extern \1 $(mpers_PREFIX)\2(\3);/p' $$f \
+               sed -r -n 's/$(mpers_printer_decl_pattern)/extern \1 $(mpers_PREFIX)\2(\3);/p' $$f \
                || exit; \
        done >> $@-t
        mv $@-t $@
@@ -807,7 +807,7 @@ printers.h: $(mpers_preproc_files)
 %_printer_defs.h: $(mpers_preproc_files)
        echo '/* Generated by Makefile from $^; do not edit. */' > $@-t
        for f in $^; do \
-               sed -n 's/$(mpers_printer_decl_pattern)/\.\2 = $(mpers_PREFIX)\2,/p' $$f \
+               sed -r -n 's/$(mpers_printer_decl_pattern)/.\2 = $(mpers_PREFIX)\2,/p' $$f \
                || exit; \
        done >> $@-t
        mv $@-t $@
@@ -869,7 +869,7 @@ $(srcdir)/CREDITS: $(srcdir)/CREDITS.in $(srcdir)/.mailmap \
        (                                                               \
          cd $(srcdir);                                                 \
          sed '/^##/,$$d' CREDITS.in;                                   \
-         { sed -n '1,/^##>/d; s/  \+/\t/; s/^./&/p' CREDITS.in;        \
+         { sed -n '1,/^##>/d; s/   */\t/; s/^./&/p' CREDITS.in;        \
            git log --pretty=format:'%aN        %aE';                   \
          } | LC_ALL=C sort -u                                          \
            | awk -F'\t' '{printf("\t%s <%s>\n",$$1,$$2)}';             \
index 1ee4791be51bf5bf63044fc64219510470bc63b3..833cd29b3cac10868055ad5fd905c6ac1dc8251f 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh -e
 
-list="$(sed -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*\([[:alnum:]][^.]*\.c\)[[:space:]]*\\$/\1/p' Makefile.am |
-       xargs -r grep -lx '#[[:space:]]*include[[:space:]]\+MPERS_DEFS' |
+list="$(sed -r -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*([[:alnum:]][^.]*\.c)[[:space:]]*\\$/\1/p' Makefile.am |
+       xargs -r grep -Elx '#[[:space:]]*include[[:space:]]+MPERS_DEFS' |
        tr '\n' ' ')"
 
 cat > mpers.am <<EOF
@@ -9,5 +9,5 @@ cat > mpers.am <<EOF
 mpers_source_files = $list
 EOF
 
-sed -n 's/^#[[:space:]]*include[[:space:]]*"xlat\/\([^."]\+\)\.h".*/extern const struct xlat \1[];/p' \
+sed -r -n 's/^#[[:space:]]*include[[:space:]]*"xlat\/([a-z][a-z_0-9]*)\.h".*/extern const struct xlat \1[];/p' \
        $list > mpers_xlat.h
index 6c177abf7d434cd1fb5219253e93bb92724568c1..854c15b34f0099a09a6650d1b5715b3faa07e938 100755 (executable)
@@ -2,7 +2,7 @@
 
 echo 'enum {'
 echo 'SEN_printargs = 0,'
-    sed -n '/printargs/! s/.*SEN(\([^)]*\)).*/\1/p' |
+    sed -r -n '/printargs/! s/.*SEN\(([^)]+)\).*/\1/p' |
     sort -u |
     sed 's/.*/SEN_&,/'
 echo '};'
index 5ebb1d44386f624b7fc2606be375a74f55edd77a..11f141f538504c6d25511966bf6b9dbeda1c6bf7 100755 (executable)
@@ -6,5 +6,5 @@ dstdir="$1"; shift
 for n in n32 n64 o32; do
        in="$srcdir/syscallent-$n.h"
        out="$dstdir/syscallent-$n-stub.h"
-       sed -n '/^#if/,/^#else/ {s/^\([^{]*{[^,]*,[^,]*,[[:space:]]*\)[^,[:space:]]\+,[[:space:]]*"\([^"]\+".*\)/\1SEN(printargs), "'$n'_\2/; s/^\[.*/&/p}' < "$in" > "$out"
+       sed -r -n '/^#if/,/^#else/ {s/^([^{]*\{[^,]*,[^,]*,[[:space:]]*)[^,[:space:]]+,[[:space:]]*"([^"]+".*)/\1SEN(printargs), "'$n':\2/; s/^\[.*/&/p}' < "$in" > "$out"
 done
index 951c5a9ef02ae4d44c441343a77ef362b8387a4c..f0e958ad6f849936b26e1fae4bcb4fa0549906c9 100755 (executable)
--- a/make-dsc
+++ b/make-dsc
@@ -8,7 +8,7 @@ $(sed '/^Source:[[:space:]]*/!d;q' debian/control)
 Binary: $(sed '/^Package:[[:space:]]*/!d;s///' debian/control |
        tr '\n' ' ' | sed 's/ ./,&/g')
 $(sed '/^Architecture:[[:space:]]*/!d;q' debian/control)
-Version: $(sed -n '1s/^[^(]*(\([^)]\+\)).*/\1/p' debian/changelog)
+Version: $(sed -r -n '1s/^[^(]*\(([^)]+)\).*/\1/p' debian/changelog)
 $(sed '/^Maintainer:[[:space:]]*/!d;q' debian/control)
 $(sed '/^Homepage:[[:space:]]*/!d;q' debian/control)
 $(sed '/^Standards-Version:[[:space:]]*/!d;q' debian/control)
index 559d1f4e53f42fdc70b3f42d31312e58a8b183b6..36913e7d04ff03c133f8682587688173c2a4b149 100755 (executable)
--- a/mpers.sh
+++ b/mpers.sh
@@ -40,8 +40,8 @@ VAR_NAME='mpers_target_var'
 BITS_DIR="mpers${ARCH_FLAG}"
 
 mkdir -p ${BITS_DIR}
-set -- $(sed -n \
-       's/^#[[:space:]]*include[[:space:]]\+DEF_MPERS_TYPE(\([^)[:space:]]*\))$/\1/p' \
+set -- $(sed -r -n \
+       's/^#[[:space:]]*include[[:space:]]+DEF_MPERS_TYPE\(([^)[:space:]]*)\)$/\1/p' \
                "${PARSER_FILE}")
 for m_type; do
        f_h="${BITS_DIR}/${m_type}.h"
@@ -53,8 +53,8 @@ for m_type; do
        sed -e '
                /DEF_MPERS_TYPE('"${m_type}"')$/n
                /DEF_MPERS_TYPE/d
-               /^[[:space:]]*#[[:space:]]*include[[:space:]]\+\"xlat\//d
-               /^#[[:space:]]*include[[:space:]]\+MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q}
+               /^[[:space:]]*#[[:space:]]*include[[:space:]]*"xlat\//d
+               /^#[[:space:]]*include[[:space:]][[:space:]]*MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q}
                ' "${PARSER_FILE}" > "${f_c}"
        $CPP $CPPFLAGS "${f_c}" > "${f_i}"
        grep -F -q "${m_type}.h" "${f_i}" ||
@@ -62,12 +62,12 @@ for m_type; do
        sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}"
        $CC $CFLAGS $ARCH_FLAG "${f_c}" -o "${f_o}"
        readelf --debug-dump=info "${f_o}" > "${f_d1}"
-       sed -n '
-               /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]\+>: Abbrev Number: 0/!d
-               /^[[:space:]]*<[^>]\+><[^>]\+>: Abbrev Number: 0/d
-               s/^[[:space:]]*<[[:xdigit:]]\+>[[:space:]]\+//
-               s/^[[:space:]]*\(\(<[[:xdigit:]]\+>\)\{2\}\):[[:space:]]\+/\1\n/
-               s/[[:space:]]\+$//
+       sed -r -n '
+               /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]+>: Abbrev Number: 0/!d
+               /^[[:space:]]*<[^>]*><[^>]*>: Abbrev Number: 0/d
+               s/^[[:space:]]*<[[:xdigit:]]+>[[:space:]]+//
+               s/^[[:space:]]*((<[[:xdigit:]]+>){2}):[[:space:]]+/\1\n/
+               s/[[:space:]]+$//
                p' "${f_d1}" > "${f_d2}"
        gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG#-}" \
                -f "$MPERS_AWK" "${f_d2}" > "${f_h}"
index 90230293801c64ace86a05ca2873ffa640fead28..1e99c44a3229b50bf4bbb96c01c38680972a444e 100644 (file)
@@ -778,7 +778,7 @@ EXTRA_DIST = init.sh run.sh match.awk \
 ksysent.h: $(srcdir)/ksysent.sed
        echo '#include <asm/unistd.h>' | \
                $(CPP) $(AM_CPPFLAGS) $(CPPFLAGS) -dM - > $@.t1
-       LC_COLLATE=C sed -n -f $(srcdir)/ksysent.sed < $@.t1 > $@.t2
+       LC_COLLATE=C sed -r -n -f $(srcdir)/ksysent.sed < $@.t1 > $@.t2
        mv -f $@.t2 $@
        rm -f $@.t1
 
index 56fe042e71789aede4ddba5d70f626ae50c2e024..63ded4a99aba97c2ef29dd9d458f6d17e5a73482 100644 (file)
@@ -1,10 +1,10 @@
-#!/bin/sed -nf
+#!/bin/sed -rnf
 
 # should not have been exported at all
-/#define[[:space:]]\+__NR_\(sys_epoll_\|arch_specific_syscall\|syscalls\|syscall_count\|syscall_max\|available\|reserved\|unused\)/d
+/#define[[:space:]]+__NR_(sys_epoll_|arch_specific_syscall|syscalls|syscall_count|syscall_max|available|reserved|unused)/d
 
-# should not be named this way
-s/__NR_\(arm\|xtensa\)_fadvise64_64/__NR_fadvise64_64/
+# should not  have been named this way
+s/__NR_(arm|xtensa)_fadvise64_64/__NR_fadvise64_64/
 
 # legacy names
 s/__NR_get_cpu/__NR_getcpu/
@@ -12,4 +12,4 @@ s/__NR_madvise1/__NR_madvise/
 s/__NR_paccept/__NR_accept4/
 
 # generate
-s/#define[[:space:]]\+__NR_\([a-z_][^[:space:]]\+\)\([[:space:]].*\)\?$/#ifdef __NR_\1\n[__NR_\1 \& 0xffff] = "\1",\n#endif/p
+s/#define[[:space:]]+__NR_([a-z_][^[:space:]]+)([[:space:]].*)?$/#ifdef __NR_\1\n[__NR_\1 \& 0xffff] = "\1",\n#endif/p
index cc5587869659b2dd3bf372553e46ca769ea45682..beadb7d78b285ecb9e0ebf4490383be707e24cb4 100755 (executable)
@@ -37,13 +37,13 @@ args="-if $args"
 $STRACE $args 2> "$LOG" ||
        dump_log_and_fail_with "$STRACE $args failed"
 
-len="$(sed -n 's/^\[[[:xdigit:]]\+\] write(-1, NULL, \([[:digit:]]\{1,2\}\))[[:space:]]\+= -1 .*/\1/p' "$LOG")" &&
+len="$(sed -r -n 's/^\[[[:xdigit:]]+\] write\(-1, NULL, ([[:digit:]]{1,2})\)[[:space:]]+= -1 .*/\1/p' "$LOG")" &&
 [ -n "$len" ] &&
-pid="$(sed -n 's/^\[[[:xdigit:]]\{'"$len"'\}\] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_\(KILLED\|DUMPED\), si_pid=\([[:digit:]]\+\), .*/\2/p' "$LOG")" &&
+pid="$(sed -r -n 's/^\[[[:xdigit:]]{'"$len"'}\] --- SIGCHLD \{si_signo=SIGCHLD, si_code=CLD_(KILLED|DUMPED), si_pid=([[:digit:]]+), .*/\2/p' "$LOG")" &&
 [ -n "$pid" ] &&
-ip="$(sed -n 's/^\[pid \+'"$pid"'\] \[\([[:xdigit:]]\{'"$len"'\}\)] --- SIGSEGV {.*} ---$/\1/p' "$LOG")" &&
+ip="$(sed -r -n 's/^\[pid +'"$pid"'\] \[([[:xdigit:]]{'"$len"'})] --- SIGSEGV \{.*\} ---$/\1/p' "$LOG")" &&
 [ -n "$ip" ] &&
-addr="$(echo "$ip" |sed 's/^0\+//')" &&
+addr="$(echo "$ip" |sed -r 's/^0+//')" &&
 [ -n "$addr" ] ||
        dump_log_and_fail_with
 
index 44c15ccd6ce1ad14d1c39d61ade61ce6e33c5a4c..3ea315cefc8be37b33fc088f91a79f6ed223eb96 100755 (executable)
@@ -14,7 +14,7 @@ test_c()
        sedexpr="$1"; shift
 
        run_strace -c -w -S "$sortby" ./readv > /dev/null
-       sed -ne "$sedexpr" < "$LOG" > "$OUT"
+       sed -r -n -e "$sedexpr" < "$LOG" > "$OUT"
 
        [ -s "$OUT" ] ||
                fail_ "$STRACE $args output mismatch"
@@ -25,8 +25,8 @@ test_c()
        }
 }
 
-c='[[:space:]]\+\([^[:space:]]\+\)'
-test_c calls '-n -r' '/^[[:space:]]\+[0-9]/ s/^'"$c$c$c$c"'[[:space:]].*/\4/p'
-test_c name '' '/^[[:space:]]\+[0-9]/ s/^'"$c$c$c$c"'\([[:space:]]\+[0-9]\+\)\?'"$c"'$/\6/p'
+c='[[:space:]]+([^[:space:]]+)'
+test_c calls '-n -r' '/^[[:space:]]+[0-9]/ s/^'"$c$c$c$c"'[[:space:]].*/\4/p'
+test_c name '' '/^[[:space:]]+[0-9]/ s/^'"$c$c$c$c"'([[:space:]]+[0-9]+)?'"$c"'$/\6/p'
 
 rm -f "$OUT"
index 91093acb8cf0c779b20436c093656100c67c41d3..d441371e5727857e68bf4da2efa41818898c9804 100755 (executable)
@@ -8,7 +8,7 @@ run_strace -V > "$LOG"
 
 getval()
 {
-       sed -n 's/#define[[:space:]]*'"$1"'[[:space:]]*"\([^"]*\)".*/\1/p' ../config.h
+       sed -r -n 's/#define[[:space:]]*'"$1"'[[:space:]]*"([^"]*)".*/\1/p' ../config.h
 }
 
 printf "%s -- version %s\n" "$(getval PACKAGE_NAME)" "$(getval VERSION)" > "$EXP"
index 5919bacbb9fa333ef2972262a153db878f63bc17..d5e8ed2bc57d58591a7cdef82b632a2ebe0f5346 100755 (executable)
@@ -41,7 +41,7 @@ run_prog ./stack-fcall
 run_strace -e getpid -k $args
 
 expected='getpid f3 f2 f1 f0 main '
-result=$(sed -n '1,/(main+0x[a-f0-9]\+) .*/ s/^.*(\([^+]\+\)+0x[a-f0-9]\+) .*/\1/p' "$LOG" |
+result=$(sed -r -n '1,/\(main\+0x[a-f0-9]+\) .*/ s/^.*\(([^+]+)\+0x[a-f0-9]+\) .*/\1/p' "$LOG" |
        tr '\n' ' ')
 
 test "$result" = "$expected" || {
index cf78c47fcce61d2a9aacc7f4873b2804545ccee0..ec632803a23818e005147e85242f7cfa9f745654 100755 (executable)
@@ -44,11 +44,11 @@ cond_def()
 
        local val
        val="$(printf %s "$line" |
-               sed -n 's/^\([^[:space:]]\+\).*$/\1/p')"
+               sed -r -n 's/^([^[:space:]]+).*$/\1/p')"
 
        local def
        def="$(printf %s "${line}" |
-               sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
+               sed -r -n 's/^[^[:space:]]+[[:space:]]+([^[:space:]].*)$/\1/p')"
 
        if [ -n "$def" ]; then
                cat <<-EOF
@@ -89,10 +89,10 @@ cond_xlat()
        local line val m def xlat
        line="$1"; shift
 
-       val="$(printf %s "${line}" | sed -n 's/^\([^[:space:]]\+\).*$/\1/p')"
+       val="$(printf %s "${line}" | sed -r -n 's/^([^[:space:]]+).*$/\1/p')"
        m="${val%%|*}"
        def="$(printf %s "${line}" |
-              sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
+              sed -r -n 's/^[^[:space:]]+[[:space:]]+([^[:space:]].*)$/\1/p')"
 
        if [ "${m}" = "${m#1<<}" ]; then
                xlat="$(print_xlat "${val}")"