[PATCH 31/32] ver_linux: 'version()' function definition

From: Alexander Kapshuk
Date: Tue Jun 28 2016 - 06:26:09 EST


Definition of the 'version()' function. The function encapsulates the
algorithm that extracts the version number of the utility being queried,
and returns it as a value.

Signed-off-by: Alexander Kapshuk <alexander.kapshuk@xxxxxxxxx>
---
scripts/ver_linux | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/scripts/ver_linux b/scripts/ver_linux
index 3bf72ad..27b43ae 100755
--- a/scripts/ver_linux
+++ b/scripts/ver_linux
@@ -69,3 +69,14 @@ BEGIN {
printversion("Modules Loaded", mods)
}
}
+
+function version(cmd, ver) {
+ while (cmd | getline > 0) {
+ if (!/ver_linux/ && match($0, /[0-9]+([.]?[0-9]+)+/)) {
+ ver = substr($0, RSTART, RLENGTH)
+ break
+ }
+ }
+ close(cmd)
+ return ver
+}
--
2.7.3