From 29da0878e362ebdd8d4445e685ffc41761537a85 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 15 Jul 2009 15:55:20 +0000 Subject: [PATCH] Added support for partial evaluation of && and || expressions. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@957 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scripts/specialize-patch | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/specialize-patch b/scripts/specialize-patch index c2aec8902..cb25c063b 100755 --- a/scripts/specialize-patch +++ b/scripts/specialize-patch @@ -42,8 +42,10 @@ function version_code(kver) { # it is the same order as the order of operators in C. function evaluate(stmnt) { + # Remove C-style comments. gsub(" *\\/\\*[^*]*\\*\\/ *", "", stmnt) + # Remove the spaces before the #-sign. gsub("^+ *# *", "+#", stmnt) if (match(stmnt, "^+#ifdef (.*)$", arg)) @@ -99,7 +101,7 @@ function evaluate(stmnt) { sub(pattern, op[1] == 0, stmnt) } - pattern="KERNEL_VERSION\\(([0-9]+) *, *([0-9]+) *, *([0-9]+) *\\)" + pattern="KERNEL_VERSION\\( *([0-9]+) *, *([0-9]+) *, *([0-9]+) *\\)" while (match(stmnt, pattern, op) != 0) { sub(pattern, op[1] * 65536 + op[2] * 256 + op[3], stmnt) @@ -123,12 +125,24 @@ function evaluate(stmnt) { sub(pattern, (op[1] != 0) && (op[2] != 0), stmnt) } + pattern="([0-9]+) *\\&\\& *(!* *defined\\([^)]*\\))" + while (match(stmnt, pattern, op) != 0) + { + sub(pattern, (op[1] != 0) ? op[2] : "0", stmnt) + } + pattern="([0-9]+) *\\|\\| *([0-9]+)" while (match(stmnt, pattern, op) != 0) { sub(pattern, (op[1] != 0) || (op[2] != 0), stmnt) } + pattern="([0-9]+) *\\|\\| *(!* *defined\\([^)]*\\))" + while (match(stmnt, pattern, op) != 0) + { + sub(pattern, (op[1] != 0) ? "1" : op[2], stmnt) + } + pattern="\\(([0-9]+)\\)" while (match(stmnt, pattern, op) != 0) {