autoconf-patches
[Top][All Lists]
Advanced

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

07AT_ARG_OPTION.diff


From: derek
Subject: 07AT_ARG_OPTION.diff
Date: Sat, 29 Mar 2003 00:57:19 +0000

Index: ChangeLog
2003-03-28  Derek Price  <address@hidden>

        * lib/autotest/general.m4: Comment various HELP_* diversions.
        (PARSE_ARGS_BEGIN): New section for option parsing related
        initialization.
        (AT_INIT): Reformat default help to delineate standard Autotest
        options from package specific ones.  Alter at_prev handling for
        arguments with options.
        (AT_ARG_OPTION,AT_ARG_OPTION_ARG): New macros to define package
        specific options and associated help.

--- autoconf-AS_HELP_STRING-robust-to-commas/lib/autotest/general.m4    
2003-03-28 19:54:12.000000000 -0500
+++ autoconf/lib/autotest/general.m4    2003-03-28 19:40:13.000000000 -0500
@@ -66,14 +66,23 @@
 # Defined below:
 #  - DEFAULTS
 #    Overall initialization, value of $at_groups_all.
+#  - PARSE_ARGS_BEGIN
+#    Setup defaults required for option processing.
 #  - PARSE_ARGS
 #    Option processing.  After AT_INIT, user options can be entered here as
 #    cases of a case statement.
 #  - PARSE_ARGS_END
 #    Finish up the option processing.
 #  - HELP
-#    Start printing the help message.  User help can be appended to this as
-#    self-contained cat'd here-docs.
+#    Start printing the help message.
+#  - HELP_MODES
+#    Modes help text.  Additional modes can be appended as self-contained
+#    cat'd here-docs as generated by AS_HELP_STRING.
+#  - HELP_TUNING
+#    TUning help text.  Additional tuning options can be appended as
+#    self-contained cat'd here-docs as generated by AS_HELP_STRING.
+#  - HELP_OTHER
+#    User help can be appended to this as self-contained cat'd here-docs.
 #  - HELP_END
 #    Finish up the help texts.
 #  - PREPARE_TESTS
@@ -87,8 +96,9 @@
 #    overall wrap up, generation of debugging scripts and statistics.
 
 m4_define([_m4_divert(DEFAULTS)],           100)
-m4_define([_m4_divert(PARSE_ARGS)],         200)
-m4_define([_m4_divert(PARSE_ARGS_END)],     201)
+m4_define([_m4_divert(PARSE_ARGS_BEGIN)],   200)
+m4_define([_m4_divert(PARSE_ARGS)],         201)
+m4_define([_m4_divert(PARSE_ARGS_END)],     202)
 m4_define([_m4_divert(HELP)],               300)
 m4_define([_m4_divert(HELP_MODES)],         301)
 m4_define([_m4_divert(HELP_TUNING)],        302)
@@ -213,13 +223,15 @@
 for at_option
 do
   # If the previous option needs an argument, assign it.
+  # else look for $at_option=.* format.
   if test -n "$at_prev"; then
-    eval "$at_prev=\$at_option"
+    at_optarg=$at_option
+    at_option=${at_prev}=
     at_prev=
-    continue
+  else
+    at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'`
   fi
 
-  at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'`
 
   # Accept the important Cygnus configure options, so we can diagnose typos.
 
@@ -295,7 +307,7 @@
 
     # Keywords.
     --keywords | -k )
-       at_prev=at_keywords
+       at_prev=--keywords
        ;;
     --keywords=* )
        at_keywords=$at_optarg
@@ -675,6 +687,128 @@
 ])# AT_INIT
 
 
+# _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
+#                [ACTION-IF-NOT-GIVEN])
+# ---------------------------------------------------------------------------
+# Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
+m4_defun([_AT_ARG_OPTION],
+[m4_divert_once([HELP_OTHER],
+[cat <<_ATEOF
+
+Other options:
+_ATEOF
+])dnl m4_divert_once HELP_OTHER
+m4_divert_text([HELP_OTHER],
+[cat <<_ATEOF
+$2
+_ATEOF])dnl
+dnl Turn our options into our desired strings
+m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
+m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
+m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
+m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
+m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
+[m4_define_default([AT_first_option],AT_option)dnl
+m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
+m4_append([AT_case_no],[--no]AT_option, [ | ])dnl
+m4_append([AT_case_arg],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | 
])dnl
+])dnl m4_foreach AT_option
+dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
+m4_divert_once([PARSE_ARGS_BEGIN],
+[
+##
+## Set up package specific options.
+##
+])dnl
+m4_divert_text([PARSE_ARGS_BEGIN],
+[dnl Provide a default value for options without arguments.
+m4_ifvaln([$3],,[at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false])dnl
+at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=false
+])dnl m4_divert_text DEFAULTS
+m4_ifval([$3],[m4_divert_once([PARSE_ARGS_END],
+[
+##
+## Verify our last option didn't require an argument
+##
+AS_IF([test -n "$at_prev"],[AS_ERROR([`$at_prev' requires an argument.])])])])
+m4_divert_text([PARSE_ARGS],
+[dnl Parse the options and args when necessary.
+m4_ifvaln([$3],
+[    AT_case )
+       at_prev=--m4_bpatsubst([AT_first_option], -, _)
+       ;;
+    AT_case_arg )
+       at_arg_[]m4_bpatsubst([AT_first_option], -, _)=$at_optarg
+       at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
+       $4
+       ;;],
+[    AT_case )
+       at_optarg=:
+       at_arg_[]m4_bpatsubst([AT_first_option], -, _)=:
+       at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
+       m4_ifval([$4],[$4])dnl
+       ;;
+    AT_case_no )
+       at_optarg=false
+       at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false
+       at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
+       m4_ifval([$4],[$4])dnl
+       ;;])dnl m4_ifvaln $3
+])dnl m4_divert_text PARSE_ARGS
+m4_ifvaln([$5],
+[m4_divert_once([PARSE_ARGS_END],
+[
+##
+## Process package specific options when _not_ supplied.
+##])dnl m4_divert_once PARSE_ARGS_END
+m4_divert_text([PARSE_ARGS_END],
+[
+AS_IF([$at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)],,[$5])dnl
+])dnl m4_divert_text PARSE_ARGS_END
+])dnl m4_ifvaln $5
+])dnl _AT_ARG_OPTION
+
+
+# AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
+# ------------------------------------------------------------------------
+# Accept a set of OPTIONS with arguments.  Add HELP-TEXT to the HELP_OTHER
+# diversion.
+#
+# Preceding dashes should not be passed into OPTIONS.  Users will be required
+# to pass `--' before long options and `-' before single character options.
+#
+# $at_arg_OPTION will be set to `:' if this option is received, `false' if
+# if --noOPTION is received, and `false' by default.
+#
+# Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with 
+# $at_optarg set to `:' or `false' as appropriate.  $opt_arg is actually
+# just a copy of $at_arg_OPTION.
+#
+# ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
+# if no option from OPTIONS was found.
+m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
+
+
+# AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
+# ---------------------------------------------------------------------------
+# Accept a set of OPTIONS with arguments, seperated by commas.  Add HELP-TEXT
+# to the HELP_OTHER diversion.
+#
+# Preceding dashes should not be passed into OPTIONS.  Users will be required
+# to pass `--' before long options and `-' before single character options.
+#
+# By default, any argument to these options will be assigned to the shell
+# variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
+# any `-' characters replaced with `_'.
+#
+# Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with 
+# $at_optarg set.  $at_optarg is actually just a copy of $at_arg_OPTION.
+#
+# ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
+# if no option from OPTIONS was found.
+m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
+
+
 # AT_TESTED(PROGRAMS)
 # -------------------
 # Specify the list of programs exercised by the test suite.  Their




reply via email to

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