This patch implements a generalized <select> list builder for htsearch.
It's usage is a bit complicated, but it's extremely flexible, allowing
you do define any htsearch input parameter as a select list for use in
templates, provided you also define the corresponding name list attribute
which enumerates all the choices to put in the list.

Each octuple specified in build_select_lists has these values:
<tempvar> <inparm> <namelistattr> <ntuple> <ivalue> <ilabel> <defattr> <deflabel>
where <tempvar> is the template variable to be defined as a list, <inpar>
is the input parameter name that the select list will set, <namelistattr>
is the user-defined list of values and labels for the select list items,
<ntuple> is the tuple size used in <namelistattr>, <ivalue> is the index
into a <namelistattr> tuple for the value, <ilabel> is the index for the
corresponding label to be used on the selector, <defattr> is the config
attribute where the default value for this input parameter is defined,
and <deflabel> (if not an empty string) will be used as the label for an
additional list item for the current input parameter value if it doesn't
match any value in the given list.

The patch is designed for 3.1.4 (soon to be released), but it can probably
be applied to earlier versions.  However, a bug in the quoted string list
handling may pose a problem in earlier versions - if a quoted string list
ended with an empty string, that string was ignored.  If you have this
bug, you can either apply a patch to QuotedStringList.cc to fix this, or
you can add an extra empty string at the end of your build_select_lists
attribute definition.

Here are a couple examples of its usage:

build_select_lists:     MATCH_LIST matchesperpage matches_per_page_list \
                                1 1 1 matches_per_page "Previous Amount" \
                RESTRICT_LIST restrict restrict_names 2 1 2 restrict "" \
                FORMAT_LIST format template_map 3 2 1 template_name ""
matches_per_page_list:  1 5 10 20 100 500
restrict_names: "http://www.scrc.umanitoba.ca/SCRC/" "SCRC Web Pages" \
                "http://www.scrc.umanitoba.ca/Physiology/" "Physiology Web Pages" \
                "http://www.scrc.umanitoba.ca/wcsn/" "WCSN Web Pages" \
                "" "Whole Web Site"

The FORMAT_LIST example should give something equivalent to the FORMAT
template variable, which is already set by htsearch.  It is included as
an additional example of how to specify the tuple size and indices of
values and labels in a tuple.

Here's the patch, with apologies for lack of documentation...

--- htcommon/defaults.cc.orig   Mon Dec  6 16:14:04 1999
+++ htcommon/defaults.cc        Wed Dec  8 13:53:37 1999
@@ -36,6 +36,7 @@ ConfigDefaults        defaults[] =
     {"bad_extensions",                 ".wav .gz .z .sit .au .zip .tar .hqx .exe .com 
.gif .jpg .jpeg .aiff .class .map .ram .tgz .bin .rpm .mpg .mov .avi"},
     {"bad_querystr",                    ""},
     {"bad_word_list",                  "${common_dir}/bad_words"},
+    {"build_select_lists",             ""},
     {"case_sensitive",                  "true"},
     {"common_url_parts",                "http:// http://www. ftp:// ftp://ftp. /pub/ 
.html .htm .gif .jpg .jpeg /index.html /index.htm .com/ .com mailto:"},
     {"create_image_list",              "false"},
--- htsearch/Display.cc.orig    Tue Dec  7 10:32:21 1999
+++ htsearch/Display.cc Wed Dec  8 13:41:34 1999
@@ -478,6 +478,47 @@ Display::setVariables(int pageNumber, Li
     *str << "</select>\n";
     vars.Add("SORT", str);
     vars.Add("SELECTED_SORT", new String(st));
+
+    // Handle user-defined select lists.
+    // Uses octuples containing these values:
+    // <tempvar> <inparm> <namelistattr> <ntuple> <ivalue> <ilabel> 
+    //                                 <defattr> <deflabel>
+    // e.g.:
+    // METHOD_LIST method method_names 2 1 2 match_method ""
+    // FORMAT_LIST format template_map 3 2 1 template_name ""
+    // EXCLUDE_LIST exclude exclude_names 2 1 2 exclude ""
+    // MATCH_LIST matchesperpage matches_per_page_list 1 1 1 \
+    //                                 matches_per_page "Previous Amount"
+    QuotedStringList   builds(config["build_select_lists"], " \t\r\n");
+    for (int b = 0; b <= builds.Count()-8; b += 8)
+    {
+       int     ntuple = atoi(builds[b+3]);
+       int     ivalue = atoi(builds[b+4]);
+       int     ilabel = atoi(builds[b+5]);
+       int     nsel = 0;
+       QuotedStringList        namelist(config[builds[b+2]], " \t\r\n");
+       if (ntuple > 0 && ivalue > 0 && ivalue <= ntuple
+         && ilabel > 0 && ilabel <= ntuple && namelist.Count() % ntuple == 0)
+       {
+           str = new String();
+           *str << "<select name="<<builds[b+1]<<">\n";
+           for (i = 0; i < namelist.Count(); i += ntuple)
+           {
+               *str << "<option value=\"" << namelist[i+ivalue-1] << '"';
+               if (mystrcasecmp(namelist[i+ivalue-1],config[builds[b+6]]) == 0)
+               {
+                   *str << " selected";
+                   ++nsel;
+               }
+               *str << '>' << namelist[i+ilabel-1] << '\n';
+           }
+           if (!nsel && builds[b+7][0] && input->exists(builds[b+1]))
+               *str << "<option value=" << input->get(builds[b+1])
+                    << " selected>" << builds[b+7] << '\n';
+           *str << "</select>\n";
+           vars.Add(builds[b], str);
+       }
+    }
        
     //
     // If a paged output is required, set the appropriate variables


-- 
Gilles R. Detillieux              E-mail: <[EMAIL PROTECTED]>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/~grdetil
Dept. Physiology, U. of Manitoba  Phone:  (204)789-3766
Winnipeg, MB  R3E 3J7  (Canada)   Fax:    (204)789-3930

------------------------------------
To unsubscribe from the htdig mailing list, send a message to
[EMAIL PROTECTED]
You will receive a message to confirm this.

Reply via email to