ver_linux: Assign constant RE to variable name for clarity
authorAlexander Kapshuk <alexander.kapshuk@gmail.com>
Sat, 5 Jan 2019 17:09:23 +0000 (19:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Jan 2019 12:34:35 +0000 (13:34 +0100)
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.

Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
scripts/ver_linux

index a6c728db05ce06ab3d82cd1be9944ace1789b114..810e608baa2409f7e4dd6c78f52b48b0bb101885 100755 (executable)
@@ -13,6 +13,8 @@ BEGIN {
        system("uname -a")
        printf("\n")
 
+       vernum = "[0-9]+([.]?[0-9]+)+"
+
        printversion("GNU C", version("gcc -dumpversion"))
        printversion("GNU Make", version("make --version"))
        printversion("Binutils", version("ld -v"))
@@ -34,7 +36,7 @@ BEGIN {
        while (getline <"/proc/self/maps" > 0) {
                if (/libc.*\.so$/) {
                        n = split($0, procmaps, "/")
-                       if (match(procmaps[n], /[0-9]+([.]?[0-9]+)+/)) {
+                       if (match(procmaps[n], vernum)) {
                                ver = substr(procmaps[n], RSTART, RLENGTH)
                                printversion("Linux C Library", ver)
                                break
@@ -70,7 +72,7 @@ BEGIN {
 function version(cmd,    ver) {
        cmd = cmd " 2>&1"
        while (cmd | getline > 0) {
-               if (match($0, /[0-9]+([.]?[0-9]+)+/)) {
+               if (match($0, vernum)) {
                        ver = substr($0, RSTART, RLENGTH)
                        break
                }