The code that acquires the version strings for libc and libcpp is identical, as is the printversion call. The only difference being the name of the library being printed. Refactor the code by unifying the bits that are common to both libraries.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -15,7 +15,7 @@ BEGIN { · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | vernum = "[0-9]+([.]?[0-9]+)+" | 16 | vernum = "[0-9]+([.]?[0-9]+)+" |
| 17 | libc = "libc[.]so[.][0-9]+$" | 17 | libc = "libc[.]so[.][0-9]+$" |
| 18 | libcpp = "(libg|stdc)[+]+[.]so[.][0-9]+$" | 18 | libcpp = "(libg|stdc)[+]+[.]so([.][0-9]+)+$" |
| 19 | 19 | ||
| 20 | printversion("GNU C", version("gcc -dumpversion")) | 20 | printversion("GNU C", version("gcc -dumpversion")) |
| 21 | printversion("GNU Make", version("make --version")) | 21 | printversion("GNU Make", version("make --version")) |
| @@ -37,12 +37,10 @@ BEGIN { · 15 unmodified lines | |||
| 37 | printversion("Bison", version("bison --version")) | 37 | printversion("Bison", version("bison --version")) |
| 38 | printversion("Flex", version("flex --version")) | 38 | printversion("Flex", version("flex --version")) |
| 39 | 39 | ||
| 40 | while ("ldconfig -p 2>/dev/null" | getline > 0) { | 40 | while ("ldconfig -p 2>/dev/null" | getline > 0) |
| 41 | if ($NF ~ libc && !seen[ver = version("readlink " $NF)]++) | 41 | if ($NF ~ libc || $NF ~ libcpp) |
| 42 | printversion("Linux C Library", ver) | 42 | if (!seen[ver = version("readlink " $NF)]++) |
| 43 | else if ($NF ~ libcpp && !seen[ver = version("readlink " $NF)]++) | 43 | printversion("Linux C" ($NF ~ libcpp? "++" : "") " Library", ver) |
| 44 | printversion("Linux C++ Library", ver) | ||
| 45 | } | ||
| 46 | 44 | ||
| 47 | printversion("Dynamic linker (ldd)", version("ldd --version")) | 45 | printversion("Dynamic linker (ldd)", version("ldd --version")) |
| 48 | printversion("Procps", version("ps --version")) | 46 | printversion("Procps", version("ps --version")) |