libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: [PATCH] options-parser: provide a saner pluggable API.


From: Gary V. Vaughan
Subject: FYI: [PATCH] options-parser: provide a saner pluggable API.
Date: Wed, 16 Nov 2011 12:53:44 +0700

Applied as on obvious and straight-forward improvement.

I have a few more cleanups to implement, and then I'll try
again to move all of bootstrap and it's supporting code into
gnulib, leaving just bootstrap.conf in libtool as it should
be.

It's much too easy to forget that the functions you hook into
the option parser need to return unconsumed options in the
variable `func_run_hooks_result'; better to follow the
convention used in the rest of bootstrap and return results in a
variable named after the function with `_result' appended.
* libltdl/config/options-parser (func_run_hooks): implement this
new API.
(Option parsing): Update the example in the header comment for
this section to reflect the changes.
* bootstrap (bootstrap_options_prep, bootstrap_parse_options)
(bootstrap_validate_options): Adjust.
* bootstrap.conf (libtool_options_prep, libtool_parse_options)
(libtool_validate_options): Ditto.

Signed-off-by: Gary V. Vaughan <address@hidden>
---
 bootstrap                     |   11 ++++-------
 bootstrap.conf                |   10 ++++------
 libltdl/config/options-parser |   25 ++++++++++++-------------
 3 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/bootstrap b/bootstrap
index d18316a..b0413ff 100755
--- a/bootstrap
+++ b/bootstrap
@@ -2336,17 +2336,14 @@ bootstrap_options_prep ()
 
     # Pass back the list of options we consumed.
     func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result="$func_quote_for_eval_result"
+    bootstrap_options_prep_result="$func_quote_for_eval_result"
 }
 func_add_hook func_options_prep bootstrap_options_prep
 
 
 # bootstrap_parse_options [ARG]...
 # --------------------------------
-# Provide handling for Bootstrap specific options.  Note
-# `func_parse_options' passes in the unconsumed positional parameters, and
-# this function has to pass back whatever remains after its own
-# processing in the `func_run_hooks_result' variable.
+# Provide handling for Bootstrap specific options.
 bootstrap_parse_options ()
 {
     $debug_cmd
@@ -2417,7 +2414,7 @@ bootstrap_parse_options ()
 
     # save modified positional parameters for caller
     func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result="$func_quote_for_eval_result"
+    bootstrap_parse_options_result="$func_quote_for_eval_result"
 }
 func_add_hook func_parse_options bootstrap_parse_options
 
@@ -2439,7 +2436,7 @@ bootstrap_validate_options ()
 
     # Pass back the list of unconsumed options left.
     func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result="$func_quote_for_eval_result"
+    bootstrap_validate_options_result="$func_quote_for_eval_result"
 }
 
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 0f89559..e1537e2 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -177,7 +177,7 @@ Libtool Specific Options:
 
     # pass back the list of options we consumed
     func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result="$func_quote_for_eval_result"
+    libtool_options_prep_result="$func_quote_for_eval_result"
 }
 func_add_hook func_options_prep libtool_options_prep
 
@@ -185,9 +185,7 @@ func_add_hook func_options_prep libtool_options_prep
 # libtool_parse_options [ARG...]
 # ------------------------------
 # Provide handling for additional Libtool options inside the main option
-# parsing loop.  Note that `bootstrap' passes in the current positional
-# parameters, and this function has to pass back whatever is left after
-# its own processing in the `func_run_hooks_result' variable.
+# parsing loop.
 libtool_parse_options ()
 {
     $debug_cmd
@@ -217,7 +215,7 @@ libtool_parse_options ()
 
     # pass back the list of options we consumed
     func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result="$func_quote_for_eval_result"
+    libtool_parse_options_result="$func_quote_for_eval_result"
 }
 func_add_hook func_parse_options libtool_parse_options
 
@@ -246,7 +244,7 @@ libtool_validate_options ()
 
     # pass back the list of options we consumed
     func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result="$func_quote_for_eval_result"
+    libtool_validate_options_result="$func_quote_for_eval_result"
 }
 func_add_hook func_validate_options libtool_validate_options
 
diff --git a/libltdl/config/options-parser b/libltdl/config/options-parser
index 5400833..decddb7 100644
--- a/libltdl/config/options-parser
+++ b/libltdl/config/options-parser
@@ -1,7 +1,7 @@
 #! /bin/sh
 
 # Set a version string for this script.
-scriptversion=2011-11-04.03; # UTC
+scriptversion=2011-11-16.05; # UTC
 
 # A pluggable option parser for Bourne shell.
 # Written by Gary V. Vaughan, 2010
@@ -272,20 +272,18 @@ func_run_hooks ()
       *) func_fatal_error "\`$1' does not support hook funcions.n" ;;
     esac
 
-    eval _G_hook_fns="\$$1_hooks"
-
-    # shift away the first argument (FUNC_NAME)
-    shift
-    func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result=$func_quote_for_eval_result
+    eval _G_hook_fns="\$$1_hooks"; shift
 
     for _G_hook in $_G_hook_fns; do
       eval $_G_hook '"$@"'
 
       # store returned options list back into positional
       # parameters for next `cmd' execution.
-      eval set dummy $func_run_hooks_result; shift
+      eval set dummy \$${_G_hook}_result; shift
     done
+
+    func_quote_for_eval ${1+"$@"}
+    func_run_hooks_result=$func_quote_for_eval_result
 }
 
 
@@ -297,8 +295,8 @@ func_run_hooks ()
 # In order to add your own option parsing hooks, you must accept the
 # full positional parameter list in your hook function, remove any
 # options that you action, and then pass back the remaining unprocessed
-# options in `func_run_hooks_result', escaped suitably for `eval'.  Like
-# this:
+# options in `<hooked_function_name>_result', escaped suitably for
+# `eval'.  Like this:
 #
 #    my_options_prep ()
 #    {
@@ -310,7 +308,7 @@ func_run_hooks ()
 #    '
 #
 #        func_quote_for_eval ${1+"$@"}
-#        func_run_hooks_result=$func_quote_for_eval_result
+#        my_options_prep_result=$func_quote_for_eval_result
 #    }
 #    func_add_hook func_options_prep my_options_prep
 #
@@ -337,7 +335,7 @@ func_run_hooks ()
 #        done
 #
 #        func_quote_for_eval ${1+"$@"}
-#        func_run_hooks_result=$func_quote_for_eval_result
+#        my_silent_option_result=$func_quote_for_eval_result
 #    }
 #    func_add_hook func_parse_options my_silent_option
 #
@@ -350,8 +348,9 @@ func_run_hooks ()
 #    \`--silent' and \`--verbose' options are mutually exclusive."
 #
 #        func_quote_for_eval ${1+"$@"}
-#        func_run_hooks_result=$func_quote_for_eval_result
+#        my_option_validation_result=$func_quote_for_eval_result
 #    }
+#    func_add_hook func_validate_options my_option_validation
 #
 # You'll alse need to manually amend $usage_message to reflect the extra
 # options you parse.  It's preferable to append if you can, so that
-- 
1.7.7.3

Cheers,
-- 
Gary V. Vaughan (gary AT gnu DOT org)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]