The regular expression that matches the version number of a utility being queried is used as a constant expression in the current implementation. Assigning the RE in question to a variable gives it a meaningful name that clearly expresses the intended use of the expression without having to think about the details of implementation.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -13,6 +13,8 @@ BEGIN { · 12 unmodified lines | ||
| 13 | 13 | system("uname -a") |
| 14 | 14 | printf("\n") |
| 15 | 15 | |
| 16 | + vernum = "[0-9]+([.]?[0-9]+)+" | |
| 17 | + | |
| 16 | 18 | printversion("GNU C", version("gcc -dumpversion")) |
| 17 | 19 | printversion("GNU Make", version("make --version")) |
| 18 | 20 | printversion("Binutils", version("ld -v")) |
| @@ -34,7 +36,7 @@ BEGIN { · 15 unmodified lines | ||
| 34 | 36 | while (getline <"/proc/self/maps" > 0) { |
| 35 | 37 | if (/libc.*\.so$/) { |
| 36 | 38 | n = split($0, procmaps, "/") |
| 37 | − if (match(procmaps[n], /[0-9]+([.]?[0-9]+)+/)) { | |
| 39 | + if (match(procmaps[n], vernum)) { | |
| 38 | 40 | ver = substr(procmaps[n], RSTART, RLENGTH) |
| 39 | 41 | printversion("Linux C Library", ver) |
| 40 | 42 | break |
| @@ -70,7 +72,7 @@ BEGIN { · 29 unmodified lines | ||
| 70 | 72 | function version(cmd, ver) { |
| 71 | 73 | cmd = cmd " 2>&1" |
| 72 | 74 | while (cmd | getline > 0) { |
| 73 | − if (match($0, /[0-9]+([.]?[0-9]+)+/)) { | |
| 75 | + if (match($0, vernum)) { | |
| 74 | 76 | ver = substr($0, RSTART, RLENGTH) |
| 75 | 77 | break |
| 76 | 78 | } |