Lsl Read Access Notecard in Other Prim
This page contains code from a script that enables a scripter to read and dispense notecards that incorporate data in the INI File format. Some other version of these functions that uses OSSL functions is available, and has to power to write data to a notecard. I want to provide a full clarification of the functions available, but if you're in a hurry to simply take hold of them, scroll down to the bottom of this folio for the total code.
Contents
- Notes
- Part Documentation
- Source Code
Notes
These functions have some limited support for INI way comments within the notecard. Comments must start with a semicolon and occupy a notecard line of their own. They cannot be appended to the end a cardinal/value pair. These functions simply ignore comments. They exercise non store them, and comments will non be preserved when the notecard is written.
Within a script, the INI information is stored in a single list. Each list chemical element is composed of a section, fundamental, and value delimited by a null grapheme. This is important because a notecard line is express to 255 characters, so you must keep in mind that any values yous shop share those 255 characters with the name of the section, the central, and two null characters. Unless you go nuts, this should still be sufficient for most uses.
These functions were written and tested with OpenSimulator's XEngine in listen. These may piece of work over in SL, merely have not been tested there. In improver, SL imposes limits on lists that XEngine does not. As written, these functions as well will not part properly on Aurora-Sim. I accept used modified versions there, and so they're usable on Aurora-Sim if you're up to tracking down the different ways scripts function at that place.
Office Documentation
The following functions are provided: GetINIKey, SetINIKey, GetINISectionList, GetINIKeyList, DeleteINISection, DeleteINIKey, and KeyExists. A state for reading the notecard is also provided. A description of this land and each function follows.
state ReadINI
This land simply takes a notecard with INI formatted information, reads it, and returns a list that contains the INI data. You'll probably want this listing to be assigned to a global variable, every bit many of the other functions crave this list to be passed to it, and return it. The notecard must, of class, reside in the contents of the same prim every bit the script using this office.
string GetINIKey(list ini, string inisection, string inikey)
GetINIKey returns the value of a department'due south key. It expects a listing containing INI data, the proper noun of a department, and the name of the key. If no value is found, it but returns an empty string. Whatever leading or trailing spaces are trimmed from the fundamental.
list SetINIKey(list ini, cord inisection, string inikey, string inivalue)
This function is passed a list containing INI data, the name of a section, name of a key, and a value assigned to the cardinal. You tin use SetINIKey in a few dissimilar ways. If the section or central do non yet exist, they will be created. If it does exist, the value volition be updated with the i you provide. This office returns a list that contains the newly updated INI data in its entirety. Any leading or trailing spaces are trimmed from the cardinal.
listing GetINISectionList(list ini)
GetINISectionList simply returns a list which contains all sections inside the INI data passed to it.
list GetINIKeyList(list ini, string inisection)
GetINIKeyList likewise returns a list of all the keys within a specified department from the INI date passed to information technology.
list DeleteINISection(list ini, cord inisection)
This function will remove an entire section from the INI data passed to it, and return a list containing the resulting INI data in its entirety. Information technology removes all central/value pairs associated with the department as well.
list DeleteINIKey(listing ini, string inisection, string inikey)
DeleteINIKey deletes a fundamental from a section. It expects a list containing INI data, the name of the section that contains the key, and the name of the key to be removed. A listing containing the updated INI data is returned in its entirety.
integer KeyExists(list ini, string inisection, string inikey)
This part can be used simply to check whether or not a primal from a given section exists. It returns the LSL constant TRUE if information technology does, or FALSE if it does not.
Source Code
// Copyright 2012 Michael Bailey (Marcus Llewellyn). All rights reserved. // Redistribution and utilize in source and binary forms, with or without modification, are // permitted provided that the following weather are met: // 1. Redistributions of source code must retain the to a higher place copyright notice, this list of // conditions and the post-obit disclaimer. // 2. Redistributions in binary form must reproduce the in a higher place copyright detect, this listing // of weather condition and the following disclaimer in the documentation and/or other materials // provided with the distribution. // THIS SOFTWARE IS PROVIDED BY MICHAEL BAILEY ``AS IS'' AND Whatsoever EXPRESS OR IMPLIED WARRANTIES, INCLUDING, But NOT Express TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO Effect SHALL MICHAEL BAILEY OR CONTRIBUTORS BE LIABLE FOR ANY Directly, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL Amercement (INCLUDING, Merely NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE Appurtenances OR SERVICES; LOSS OF Employ, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) However CAUSED AND ON Whatever THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN Whatever Mode OUT OF THE Utilize OF THIS SOFTWARE, Fifty-fifty IF Brash OF THE POSSIBILITY OF SUCH Damage. // The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Michael Bailey. string inicardname = "TestCard.ini"; string tempsection = ""; cardinal iniquery = NULL_KEY; integer inilinenum = 0; list inidata = []; string GetINIKey(list ini, string inisection, cord inikey) { // Recall the value for a given department and key. Spaces are trimmed from // the result. integer inilen = llGetListLength(ini); integer i = 0; for (i; i<inilen; i++) { list temp = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); if (llList2String(temp, 0) == inisection) { // Section institute, now await for key. integer j = 0; for (j; j<2; j++) { if (llList2String(temp, ane) == inikey) { // Key plant, and then render value. render llStringTrim(llList2String(temp, ii), STRING_TRIM); } } } } // No results plant. render ""; } list SetINIKey(listing ini, string inisection, string inikey, cord inivalue) { // Store a value for a given section and fundamental. Create new INI entries // if they don't already exist. Spaces are trimmed from parameters. inisection = llStringTrim(inisection, STRING_TRIM); inikey = llStringTrim(inikey, STRING_TRIM); inivalue = llStringTrim(inivalue, STRING_TRIM); integer inilen = llGetListLength(ini); integer sectionpos = -one; integer i = 0; for (i; i<inilen; i++) { list iniline = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); // If the section was found, keep track of it's last known position // in the list in case the key isn't constitute. if (llList2String(iniline, 0) == inisection) { sectionpos = i; } if ((llList2String(iniline, 0) == inisection) && (llList2String(iniline, 1) == inikey)) { // Found the section and key, and then replace value. string newline = inisection + llUnescapeURL("%00") + inikey + llUnescapeURL("%00") + inivalue; return llListReplaceList(ini, [newline], i, i); } } // We didn't find it, so we'll accept to create and add together a new line to the INI. if (sectionpos == -1) { // No matching department was found. So create and add it with the new // key-value pair. ini += [inisection + llUnescapeURL("%00") + inikey + llUnescapeURL("%00") + inivalue]; return ini; } else { // There was a matching section, simply no matching fundamental. So insert a new // INI line at the end of the requested department. ini = llListInsertList(ini, [inisection + llUnescapeURL("%00") + inikey + llUnescapeURL("%00") + inivalue], sectionpos + 1); render ini; } return ini; } list GetINISectionList(listing ini) { list sectionlist = []; string department = ""; integer i = 0; integer inilength = llGetListLength(ini); for (i; i<inilength; i++) { list iniline = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); string temp = llList2String(iniline,0); if (temp != department) { sectionlist += [temp]; section = temp; } } render sectionlist; } list GetINIKeyList(list ini, string inisection) { list keylist = []; integer i = 0; integer inilength = llGetListLength(ini); for (i; i<inilength; i++) { list iniline = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); if (llList2String(iniline,0) == inisection) { keylist += [llList2String(iniline,ane)]; } } return keylist; } list DeleteINISection(list ini, string inisection) { integer i = 0; integer inilength = llGetListLength(ini); for (i; i<inilength; i++) { list iniline = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); if (llList2String(iniline,0) == inisection) { ini = llDeleteSubList(ini, i, i); i--; inilength--; } } return ini; } listing DeleteINIKey(listing ini, string inisection, cord inikey) { integer i = 0; integer inilength = llGetListLength(ini); for (i; i<inilength; i++) { list iniline = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); if (llList2String(iniline,0) == inisection && llList2String(iniline,i) == inikey) { ini = llDeleteSubList(ini, i, i); i--; inilength--; } } render ini; } integer KeyExists(listing ini, string inisection, string inikey) { integer i = 0; integer inilength = llGetListLength(ini); for (i; i<inilength; i++) { list iniline = llParseString2List(llList2String(ini, i), [llUnescapeURL("%00")], []); if (llList2String(iniline,0) == inisection && llList2String(iniline,i) == inikey) return TRUE; } return Faux; } default { state_entry() { country ReadINI; } } state ReadINI { // Read INI file in equally a list, each element of which is a null delimited line // containing the section name, key proper noun, and value. state_entry() { // Initialize variables and get-go reading. iniquery = NULL_KEY; inilinenum = 0; inidata = []; tempsection = ""; iniquery = llGetNotecardLine(inicardname, inilinenum); } dataserver(key query_id, cord data) { if (query_id == iniquery) { if (data == EOF) { // Finished reading notecard. country contest_init; } else if ((llStringTrim(data, STRING_TRIM) == "") || (llGetSubString(data, 0, 0) == ";")) { // Skip blank likes and comments. inilinenum++; iniquery = llGetNotecardLine(inicardname, inilinenum); } else { // The existent work begins. cord firstchar = llGetSubString(data, 0, 0); string lastchar = llGetSubString(data, llStringLength(information) -ane, llStringLength(data) -1); if ((firstchar == "[") && (lastchar == "]")) { // This is a new section. tempsection = llGetSubString(data, 1, llStringLength(data) - 2); } else if (~(llSubStringIndex(information, "="))) { // This is a central=value line. string newkey = llStringTrim(llDeleteSubString(information, llSubStringIndex(information, "="), -ane), STRING_TRIM); string newval = llStringTrim(llDeleteSubString(data, 0, llSubStringIndex(data, "=")), STRING_TRIM); if (KeyExists(inidata, tempsection, newkey)) { inidata = SetINIKey(inidata, tempsection, newkey, newval); } else { inidata += [tempsection + llUnescapeURL("%00") + newkey + llUnescapeURL("%00") + newval]; } } inilinenum++; iniquery = llGetNotecardLine(inicardname, inilinenum); } } } }
Source: https://bearlywritten.wordpress.com/lsl-and-ossl-scripts/ini-notecards-with-vanilla-lsl/
0 Response to "Lsl Read Access Notecard in Other Prim"
Post a Comment