History

ver_linux: Assign constant RE to variable name for clarity

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.

Alexander Kapshuk committed 7 years ago

Commit 2ca46ed1 parent d7ac3c61 file · +4 −2Browse files

Showing the changes to scripts/ver_linux (1 of 1 file). Show all

Unified · Split

scripts/ver_linux+4−2
@@ -13,6 +13,8 @@ BEGIN { · 12 unmodified lines
1313 system("uname -a")
1414 printf("\n")
1515
16+ vernum = "[0-9]+([.]?[0-9]+)+"
17+
1618 printversion("GNU C", version("gcc -dumpversion"))
1719 printversion("GNU Make", version("make --version"))
1820 printversion("Binutils", version("ld -v"))
@@ -34,7 +36,7 @@ BEGIN { · 15 unmodified lines
3436 while (getline <"/proc/self/maps" > 0) {
3537 if (/libc.*\.so$/) {
3638 n = split($0, procmaps, "/")
37− if (match(procmaps[n], /[0-9]+([.]?[0-9]+)+/)) {
39+ if (match(procmaps[n], vernum)) {
3840 ver = substr(procmaps[n], RSTART, RLENGTH)
3941 printversion("Linux C Library", ver)
4042 break
@@ -70,7 +72,7 @@ BEGIN { · 29 unmodified lines
7072 function version(cmd, ver) {
7173 cmd = cmd " 2>&1"
7274 while (cmd | getline > 0) {
73− if (match($0, /[0-9]+([.]?[0-9]+)+/)) {
75+ if (match($0, vernum)) {
7476 ver = substr($0, RSTART, RLENGTH)
7577 break
7678 }