52b229168cf1bdb37e1401f0410a7b4f98462d32
[feisty_meow.git] / huffware / huffotronic_scripts / mu_tester_v6.0.txt
1 
2 // huffware script: mu tester, by fred huffhines.
3 //
4 // a script that puts the set comparator library through its paces
5 // while providing a textual method for creating and comparing sets.
6 //
7 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
8 // do not use it in objects without fully realizing you are implicitly accepting that license.
9 //
10
11 // these are the commands a user can say:
12 string DEFINE_WORD = "create";
13 string DELETE_WORD = "delete";
14 string LIST_WORD = "list";
15 string GET_WORD = "get";
16 string ADD_TO_WORD = "add";
17 string CUT_FROM_WORD = "cut";
18 string INTERSECT_WORD = "intersect";
19 string UNION_WORD = "union";
20 string DIFFERENCE_WORD = "differ";
21 string MU_WORD = "mu";
22 string CLEAR_ALL_WORD = "clearall";
23 string RESET_WORD = "reset!";
24
25 integer NOISY_OY = FALSE;
26   // produces more chatty logging when set to TRUE.  this is adjusted during
27   // startup to be off.
28
29 // requires set comparator 2.8 or better.
30 // API for set operations.
31 //////////////
32 integer SET_COMPARATOR_HUFFWARE_ID = 10020;
33     // a unique ID within the huffware system for this script.
34 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
35     // this pattern is an uncommon thing to see in text, so we use it to separate
36     // our commands in link messages.
37 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
38     // used to separate lists of items from each other when stored inside a parameter.
39     // this allows lists to be passed as single string parameters if needed.
40 integer REPLY_DISTANCE = 100008;  // offset added to service's huffware id in reply IDs.
41 //////////////
42 string DEFINE_SET_CMD = "#def-set";
43     // adds a new set or replaces existing one with same name.  first parm is name of set,
44     // second parm is a wrapped list of elements that should be in the set.  return value
45     // is a boolean for success.
46 string REMOVE_SET_CMD = "#rm-set";
47     // trashes a named set.  first parm is the name.  returns a bool for success.
48 string ADD_ELEMENTS_CMD = "#add-elem";
49     // adds more elements to an existing set.  first parm is the name, second is a wrapped
50     // list of new elements.  set must already exist.  returns a bool for success.
51 string CUT_ELEMENTS_CMD = "#cut-elem";
52     // removes a set of elements from an existing set.  first parm is set name, second is
53     // wrapped list of elements to remove.  set must already exist.  returns bool.
54 string INTERSECT_CMD = "#inter-set";
55     // reports the set of elements in the intersection of two sets.  first and second parm
56     // are the set names.  returns a wrapped list of elements that are common members of both sets.
57 string UNION_CMD = "#union-set";
58     // returns the union of two named sets.  results sent similar to intersection.
59 string DIFFERENCE_CMD = "#diff-set";
60     // returns the difference of set A (parm 1) minus set B (parm 2).  results are similar
61     // to intersection.
62 string WHAT_MU_CMD = "#mu-set";
63     // returns one of the possibility values below to describe the relationship between
64     // two sets.
65 string GET_SET_CMD = "#get-set";
66     // retrieves the contents of the set named in first parameter.
67 string LIST_SET_NAMES_CMD = "#whichunz";
68     // retrieves the list of set names that exist.
69 string CLEAR_ALL_CMD = "#clearall";
70     // throws out all set definitions.        
71 //////////////
72 // joins a list of parameters using the parameter sentinel for the library.
73 string wrap_parameters(list to_flatten)
74 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
75 //////////////
76
77 // requires noteworthy library v8.4 or better.
78 //////////////
79 // do not redefine these constants.
80 integer NOTEWORTHY_HUFFWARE_ID = 10010;
81     // the unique id within the huffware system for the noteworthy script to
82     // accept commands on.  this is used in llMessageLinked as the num parameter.
83 // commands available via the noteworthy library:
84 string READ_NOTECARD_COMMAND = "#read_note#";
85     // command used to tell the script to read notecards.  needs a signature to find
86     // in the card as the first parameter, and a randomly generated response code for
87     // the second parameter.  the response code is used to uniquely identify a set of
88     // pending notecard readings (hopefully).  the signature can be empty or missing.
89     // the results will be fired back as the string value returned, which will have
90     // as first element the notecard's name (or "bad_notecard" if none was found) and
91     // as subsequent elements an embedded list that was read from the notecard.  this
92     // necessarily limits the size of the notecards that we can read and return.
93 string BAD_NOTECARD_INDICATOR = "bad_notecard";
94     // indicates that the notecard reading process has failed to find an appropriate one.
95 string BUSY_READING_INDICATOR = "busy_already";
96     // this return value indicates that the script is already in use by some other script.
97     // the calling script should try again later.
98 string NOTECARD_READ_CONTINUATION = "continue!";
99     // returned as first parameter if there is still more data to handle.
100 //
101 //////////////
102
103 string MU_SIGNATURE = "#mu";
104     // the notecard must begin with this as its first line for it to be
105     // recognized as our configuration card.
106
107 // global variables...
108
109 string global_notecard_name;  // name of our notecard in the object's inventory.
110 integer response_code;  // set to uniquely identify the notecard read in progress.
111 list global_config_list;  // a collection of configuration parameters from our notecard.
112 integer global_config_index;  // allows wrap-around feature, which we don't use here.
113
114 show_instructions()
115 {
116     string c = ", ";  // speed of light.
117     string help_text = "\nThis object will operate on a collection of sets and understands the following commands:\n";
118     help_text += "  " + DEFINE_WORD + c + DELETE_WORD + c + CLEAR_ALL_WORD + c + ADD_TO_WORD + c
119         + CUT_FROM_WORD + c + INTERSECT_WORD + c + UNION_WORD + c + DIFFERENCE_WORD + c + GET_WORD + c
120         + LIST_WORD + c + RESET_WORD + c + "and " + MU_WORD + ".\n";
121     help_text += "Generally each command takes a set name or two, and sometimes a list of items.\n";
122     help_text += "If an item or set name has a space in it, surround it in quote characters.\n";
123     help_text += "For Example:\n";
124     help_text += "  " + DEFINE_WORD + " \"jed yo\" upsa dooba gorp : create a set named \"jed yo\" with three items.\n";
125     help_text += "  " + INTERSECT_WORD + " jed pfaltzgraff : returns the intersection of the two sets.\n";
126     help_text += "  " + ADD_TO_WORD + " foon a \"b c\" d e : adds four elements to the set \"foon\".\n";
127     help_text += "(Free Memory=" + (string)llGetFreeMemory() + ")\n";
128     llSay(0, help_text);
129 }
130
131 // makes a request of the set comparator.
132 send_command(string msg, list parms)
133 { llMessageLinked(LINK_THIS, SET_COMPARATOR_HUFFWARE_ID, msg, wrap_parameters(parms)); }
134
135 // processes verbal commands.
136 hearing_some_voices(integer chan, string name, key id, string msg_in)
137 {
138     // clean up the string before starting.
139     msg_in = llStringTrim(msg_in, STRING_TRIM);  // remove leading and trailing spaces.
140     msg_in = compress_spaces(msg_in);  // turn multiple spaces into a single one.
141     // separate out the separate words in what was said.
142     list members = parse_quoted_strings(msg_in);
143 //log_it("got membs as: " + dump_list(members));
144     // break out the first few to make the below cases easier.
145     string first_word = llList2String(members, 0);
146     string second_word = llList2String(members, 1);
147     string third_word = llList2String(members, 2);
148
149     if (first_word == DEFINE_WORD) {
150         send_command(DEFINE_SET_CMD, llDeleteSubList(members, 0, 0));
151     } else if (first_word == DELETE_WORD) {
152         send_command(REMOVE_SET_CMD, [ second_word ]);
153     } else if (first_word == GET_WORD) {
154         send_command(GET_SET_CMD, [ second_word ]);
155     } else if (first_word == LIST_WORD) {
156         send_command(LIST_SET_NAMES_CMD, []);
157     } else if (first_word == ADD_TO_WORD) {
158         send_command(ADD_ELEMENTS_CMD, llDeleteSubList(members, 0, 0));
159     } else if (first_word == CUT_FROM_WORD) {
160         send_command(CUT_ELEMENTS_CMD, llDeleteSubList(members, 0, 0));
161     } else if (first_word == INTERSECT_WORD) {
162         send_command(INTERSECT_CMD, [ second_word, third_word ]);
163     } else if (first_word == UNION_WORD) {
164         send_command(UNION_CMD, [ second_word, third_word ]);
165     } else if (first_word == DIFFERENCE_WORD) {
166         send_command(DIFFERENCE_CMD, [ second_word, third_word ]);
167     } else if (first_word == MU_WORD) {
168         send_command(WHAT_MU_CMD, [ second_word, third_word ]);
169     } else if (first_word == CLEAR_ALL_WORD) {
170         send_command(CLEAR_ALL_CMD, []);
171     } else if (first_word == RESET_WORD) {
172         if (id != llGetOwner()) {
173             llSay(0, "Sorry, only the owner is allowed to reset this object.");
174         } else {
175             // tell the set manager to drop any contents also.
176             send_command(CLEAR_ALL_CMD, []);
177             llResetScript();
178         }
179     }
180     // we cannot have a catch-all here for if we didn't understand; that will always be
181     // getting hit whenever anyone talks nearby.
182 }
183
184 handle_link_message(integer sender, integer huff_id, string msg, key id)
185 {
186     if (huff_id != SET_COMPARATOR_HUFFWARE_ID + REPLY_DISTANCE) {
187         handle_notecard_message(sender, huff_id, msg, id);
188         return;
189     }
190     list parms = llParseString2List(id, [HUFFWARE_PARM_SEPARATOR], []);
191     string to_show;  // what to tell the user.
192     if (llGetListLength(parms) == 1) {
193         // mono-syllabic responses.
194         string arf = llList2String(parms, 0);
195         if (arf == "0") {
196             to_show = "request failed";
197         } else if (arf == "1") {
198             to_show = "successful request";
199         } else if (msg != WHAT_MU_CMD) {
200             // don't know this one; assume it's a list.
201             to_show = "[ " + arf + " ]";
202         } else {
203             // otherwise we assume it's a well-known answer we should just emit.
204             to_show = arf;
205         }
206     } else {
207         to_show = "[ " + dump_list(parms) + " ]";
208     }
209     if (NOISY_OY) log_it("reply says: " + to_show);
210 }
211
212 // this function fires off a request to the noteworthy library via a link message.
213 // noteworthy will look for a notecard with our particular signature in it and
214 // if it finds one, it will read the configuration therein.  an empty string is
215 // returned if noteworthy couldn't find anything.
216 request_configuration()
217 {
218     log_it("reading configuration...");
219     global_notecard_name = "";  // reset any previous card.
220     // try to find a notecard with our configuration.
221     response_code = -1 * (integer)randomize_within_range(23, 80000, FALSE);
222     string parms_sent = wrap_parameters([MU_SIGNATURE, response_code]);
223     llMessageLinked(LINK_THIS, NOTEWORTHY_HUFFWARE_ID, READ_NOTECARD_COMMAND,
224          parms_sent);
225 }
226
227 // processes link messages received from the noteworthy library.
228 handle_notecard_message(integer which, integer num, string msg, key id)
229 {
230     if ( (num != NOTEWORTHY_HUFFWARE_ID + REPLY_DISTANCE)
231             || (msg != READ_NOTECARD_COMMAND) )
232         return;  // not for us.
233     // process the result of reading the notecard.
234     list parms = llParseString2List(id, [HUFFWARE_PARM_SEPARATOR], []);
235     string notecard_name = llList2String(parms, 0);
236     integer response_for = llList2Integer(parms, 1);
237     if (response_for != response_code) return;  // oops, this isn't for us.
238 //log_it("read more from: " + notecard_name);
239     if (notecard_name == NOTECARD_READ_CONTINUATION) {
240         // just save these items for now.
241         global_config_list += llList2List(parms, 2, -1);
242     } else if (notecard_name != BAD_NOTECARD_INDICATOR) {
243         // a valid notecard has been found.
244         global_notecard_name = notecard_name;  // record its name for later use.
245         global_config_index = 0;  // we are starting over in the config list.
246         // snag all but the first two elements for our config now.
247         global_config_list += llList2List(parms, 2, -1);
248         process_ini_config();
249         log_it("now configured.");
250         llSetTimerEvent(6);  // pause a bit before turning chat back on.
251     } else {
252         // we hated the notecards we found, or there were none.
253         log_it("There seem to be no notecards with a first line of '"
254             + MU_SIGNATURE
255             + "', so no additional sets are defined.");
256     }
257 }
258
259 ///////////////
260
261 // eats a file with section names in square brackets, where every line defines a set element.
262 process_ini_config()
263 {
264     integer indy;
265     integer count = llGetListLength(global_config_list);
266     string section_name;
267
268     // iterate across the items in our configuration to look for ones that are not done yet.            
269     for (indy = global_config_index; indy < count; indy++) {
270         string line = llList2String(global_config_list, indy);
271         // search for a section beginning.
272         if (llGetSubString(line, 0, 0) == "[") {
273             // we found the start of a section name.  now read the contents.
274             indy++;  // skip section line.
275             section_name = llGetSubString(line, 1, -2);
276             if (NOISY_OY) log_it("set '" + section_name + "' is being defined.");
277         }
278         integer sec_indy;
279         for (sec_indy = indy; sec_indy < count; sec_indy++) {
280             // read the lines in the section.
281             line = llList2String(global_config_list, sec_indy);
282             if (llGetSubString(line, 0, 0) != "[") {
283                 if (NOISY_OY) log_it(line);
284                 hearing_some_voices(0, llGetScriptName(), llGetOwner(), line);
285                 indy = sec_indy;  // track that we've passed this line.
286             } else {
287                 // we're at the beginning of a new section now, so start processing its
288                 // configuration in the outer loop.
289                 indy = sec_indy - 1;  // set indy to proper beginning of section.
290                 global_config_index = indy;  // remember where we had read to.
291                 sec_indy = count + 3;  // skip remainder of inner loop.
292             }
293         }
294     }
295
296     global_config_index = 0;  // reset outer position if want to re-read.
297 }
298
299 //////////////
300 // from hufflets:
301
302 integer debug_num = 0;
303 // a debugging output method.  can be disabled entirely in one place.
304 log_it(string to_say)
305 {
306     debug_num++;
307     // tell this to the owner.    
308 //    llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
309     // say this on an unusual channel for chat if it's not intended for general public.
310 //    llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
311     // say this on open chat that anyone can hear.  we take off the bling for this one.
312     llSay(0, to_say);
313 }
314
315 // the string processing methods are not case sensitive.
316   
317 // returns TRUE if the "pattern" is found in the "full_string".
318 integer matches_substring(string full_string, string pattern)
319 { return (find_substring(full_string, pattern) >= 0); }
320
321 // returns the index of the first occurrence of "pattern" inside
322 // the "full_string".  if it is not found, then a negative number is returned.
323 integer find_substring(string full_string, string pattern)
324 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
325
326 // returns TRUE if the "prefix" string is the first part of "compare_with".
327 integer is_prefix(string compare_with, string prefix)
328 { return find_substring(compare_with, prefix) == 0; }
329
330 // locates the item with "name_to_find" in the inventory items with the "type".
331 // a value from 0 to N-1 is returned if it's found, where N is the number of
332 // items in the inventory.
333 integer find_in_inventory(string name_to_find, integer inv_type)
334 {
335     integer num_inv = llGetInventoryNumber(inv_type);
336     if (num_inv == 0) return -1;  // nothing there!
337     integer inv;
338     for (inv = 0; inv < num_inv; inv++) {
339         if (llGetInventoryName(inv_type, inv) == name_to_find)
340             return inv;
341     }
342     return -2;  // failed to find it.
343 }
344
345 // returns a printable form of the list.
346 string dump_list(list to_show)
347 {
348     integer len = llGetListLength(to_show);
349     integer i;
350     string text;
351     for (i = 0; i < len; i++) {
352         string next_line = llList2String(to_show, i);
353         if (find_substring(next_line, " ") >= 0) {
354             // this guy has a space in it, so quote it.
355             next_line = "\"" + next_line + "\"";
356         }
357         text += next_line;
358         if (i < len - 1) text += " ";
359     }
360     return text;
361 }
362
363 // parses a variable definition to find the name of the variable and its value.
364 // this returns two strings [X, Y], if "to_split" is in the form X=Y.
365 list separate_variable_definition(string to_split)
366 {
367     integer equals_indy = llSubStringIndex(to_split, "=");
368     // we don't support missing an equals sign, and we don't support it as the first character.
369     if (equals_indy <= 0) return [];  // no match.
370     string x = llGetSubString(to_split, 0, equals_indy - 1);
371     string y = llGetSubString(to_split, equals_indy + 1, -1);
372     to_split = "";  // save space.
373     return [ llStringTrim(x, STRING_TRIM), llStringTrim(y, STRING_TRIM) ];
374 }
375
376 // returns a non-empty string if "to_check" defines a value for "variable_name".
377 // this must be in the form "X=Y", where X is the variable_name and Y is the value.
378 string get_variable_value(string to_check, string variable_name)
379 {
380     list x_y = separate_variable_definition(to_check);
381     if (llGetListLength(x_y) != 2) return "";  // failure to parse a variable def at all.
382     if (!is_prefix(llList2String(x_y, 0), variable_name)) return "";  // no match.
383     return llList2String(x_y, 1);  // a match!
384 }
385
386 // locates the string "text" in the list to "search_in".
387 integer find_in_list(list search_in, string text)
388
389     integer len = llGetListLength(search_in);
390     integer i; 
391     for (i = 0; i < len; i++) { 
392         if (llList2String(search_in, i) == text) 
393             return i; 
394     } 
395     return -1;
396 }
397
398 // returns a number at most "maximum" and at least "minimum".
399 // if "allow_negative" is TRUE, then the return may be positive or negative.
400 float randomize_within_range(float minimum, float maximum, integer allow_negative)
401 {
402     if (minimum > maximum) {
403         // flip the two if they are reversed.
404         float temp = minimum; minimum = maximum; maximum = temp;
405     }
406     float to_return = minimum + llFrand(maximum - minimum);
407     if (allow_negative) {
408         if (llFrand(1.0) < 0.5) to_return *= -1.0;
409     }
410     return to_return;
411 }
412
413 // extracts space separated elements from a string, and honors quoting of either
414 // variety as long as the quotes come in pairs.  this enables the inclusion of
415 // spaces in the elements of the set.  note that this function requires a well-formed
416 // string where there are no multiple space characters in a row.
417 list parse_quoted_strings(string to_parse)
418 {
419     list to_return;  // will pile up what we find in the string.
420     integer quoting = FALSE;  // are we inside quotes?
421     string curr_quote = "";  // what is current quote char, if any?
422     string accum;  // accumulates parts of the current element.
423     // loop over the string and apply our rules.
424     integer i;
425     for (i = 0; i < llStringLength(to_parse); i++) {
426         string c = llGetSubString(to_parse, i, i);
427         if (!quoting && (c == " ")) {
428             // this space marks the end of a word.
429             if (llStringLength(accum) > 0) {
430 //log_it("space adding to set: " + accum);
431                 to_return += [ accum ];
432                 accum = "";
433             }
434         } else if (quoting && (c == curr_quote)) {
435             quoting = FALSE;
436         } else if (!quoting && ( (c == "'") || (c == "\"") ) ) {
437             // we've started into quoting mode.
438             quoting = TRUE;
439             curr_quote = c;
440         } else {
441             // if no condition applies, just add this to the accumulator.
442             accum += c;
443         }
444     }
445     // add the last thing we accumulated.
446     if (llStringLength(accum) > 0) {
447 //log_it("last add to set: " + accum);
448         to_return += [ accum ];
449     }
450     return to_return;
451 }
452
453 // returns the portion of the list between start and end, but only if they are
454 // valid compared with the list length.  an attempt to use negative start or
455 // end values also returns a blank list.
456 list chop_list(list to_chop, integer start, integer end)
457 {
458     integer last_len = llGetListLength(to_chop) - 1;
459     if ( (start < 0) || (end < 0) || (start > last_len) || (end > last_len) ) return [];
460     return llList2List(to_chop, start, end);
461 }
462
463 // takes any redundant space characters out of the string.
464 string compress_spaces(string s)
465 {
466     string to_return;
467     integer in_space = FALSE;
468     integer i;
469     for (i = 0; i < llStringLength(s); i++) {
470         string chunk = llGetSubString(s, i, i);
471         if (chunk == " ") {
472             if (in_space) {
473                 // we're have already seen a space.  don't keep this too.
474                 //continue;  no such keyword in lsl.
475             } else {
476                 in_space = TRUE;
477                 to_return += chunk;
478             }
479         } else {
480             // the current character was not a space, so just add it.
481             in_space = FALSE;
482             to_return += chunk;
483         }
484     }
485     return to_return;
486 }
487
488 //////////////
489 // huffware script: auto-retire, by fred huffhines, version 2.5.
490 // distributed under BSD-like license.
491 //   !!  keep in mind that this code must be *copied* into another
492 //   !!  script that you wish to add auto-retirement capability to.
493 // when a script has auto_retire in it, it can be dropped into an
494 // object and the most recent version of the script will destroy
495 // all older versions.
496 //
497 // the version numbers are embedded into the script names themselves.
498 // the notation for versions uses a letter 'v', followed by two numbers
499 // in the form "major.minor".
500 // major and minor versions are implicitly considered as a floating point
501 // number that increases with each newer version of the script.  thus,
502 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
503 // and "hazmap v3.2" is a more recent version.
504 //
505 // example usage of the auto-retirement script:
506 //     default {
507 //         state_entry() {
508 //            auto_retire();  // make sure newest addition is only version of script.
509 //        }
510 //     }
511 // this script is partly based on the self-upgrading scripts from markov brodsky
512 // and jippen faddoul.
513 //////////////
514 auto_retire() {
515     string self = llGetScriptName();  // the name of this script.
516     list split = compute_basename_and_version(self);
517     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
518     string basename = llList2String(split, 0);  // script name with no version attached.
519     string version_string = llList2String(split, 1);  // the version found.
520     integer posn;
521     // find any scripts that match the basename.  they are variants of this script.
522     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
523 //log_it("invpo=" + (string)posn);
524         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
525         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
526             // found a basic match at least.
527             list inv_split = compute_basename_and_version(curr_script);
528             if (llGetListLength(inv_split) == 2) {
529                 // see if this script is more ancient.
530                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
531                 // must make sure that the retiring script is completely the identical basename;
532                 // just matching in the front doesn't make it a relative.
533                 if ( (llList2String(inv_split, 0) == basename)
534                     && ((float)inv_version_string < (float)version_string) ) {
535                     // remove script with same name from inventory that has inferior version.
536                     llRemoveInventory(curr_script);
537                 }
538             }
539         }
540     }
541 }
542 //
543 // separates the base script name and version number.  used by auto_retire.
544 list compute_basename_and_version(string to_chop_up)
545 {
546     // minimum script name is 2 characters plus a version.
547     integer space_v_posn;
548     // find the last useful space and 'v' combo.
549     for (space_v_posn = llStringLength(to_chop_up) - 3;
550         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
551         space_v_posn--) {
552         // look for space and v but do nothing else.
553 //log_it("pos=" + (string)space_v_posn);
554     }
555     if (space_v_posn < 2) return [];  // no space found.
556 //log_it("space v@" + (string)space_v_posn);
557     // now we zoom through the stuff after our beloved v character and find any evil
558     // space characters, which are most likely from SL having found a duplicate item
559     // name and not so helpfully renamed it for us.
560     integer indy;
561     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
562 //log_it("indy=" + (string)space_v_posn);
563         if (llGetSubString(to_chop_up, indy, indy) == " ") {
564             // found one; zap it.  since we're going backwards we don't need to
565             // adjust the loop at all.
566             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
567 //log_it("saw case of previously redundant item, aieee.  flattened: " + to_chop_up);
568         }
569     }
570     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
571     // ditch the space character for our numerical check.
572     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
573     // strip out a 'v' if there is one.
574     if (llGetSubString(chop_suffix, 0, 0) == "v")
575         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
576     // if valid floating point number and greater than zero, that works for our version.
577     string basename = to_chop_up;  // script name with no version attached.
578     if ((float)chop_suffix > 0.0) {
579         // this is a big success right here.
580         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
581         return [ basename, chop_suffix ];
582     }
583     // seems like we found nothing useful.
584     return [];
585 }
586 //
587 //////////////
588
589 // end from hufflets.
590 //////////////
591
592 default {
593     state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
594     on_rez(integer parm) { state rerun; }
595 }
596 state rerun { state_entry() { state default; } }
597
598 state real_default
599 {
600     state_entry() { 
601         auto_retire();
602         NOISY_OY = FALSE;
603         // reset our relevant variables.
604         global_notecard_name = "";
605         global_config_list = [];
606         global_config_index = 0;
607         // request that the noteworthy library start looking for our notecard.
608         request_configuration();
609         // listen for commands from people.
610         llListen(0, "", NULL_KEY, "");
611         NOISY_OY = FALSE;
612     }
613     
614     state_exit() { llSetTimerEvent(0.0); }
615
616     touch_start(integer total_number) { show_instructions(); }
617
618     listen(integer chan, string name, key id, string msg)
619     { hearing_some_voices(chan, name, id, msg); }
620
621     link_message(integer sender, integer num, string msg, key id) {
622         if ( (num != SET_COMPARATOR_HUFFWARE_ID + REPLY_DISTANCE)
623             && (num != NOTEWORTHY_HUFFWARE_ID + REPLY_DISTANCE) )
624             return;  // not for us.
625         handle_link_message(sender, num, msg, id);
626     }
627     
628     timer() {
629         NOISY_OY = TRUE;  // assume we can now chat with the user.  config is done hopefully.
630         llSetTimerEvent(0.0);  // turn off timer now.
631     }
632
633     on_rez(integer parm) { show_instructions(); state rerun; }
634 }