// -*-ASCII:EDT-*- // purpose: Section Reader, that reads the entries of exactly // one specified section (is called by setXMLContribMode.edt). // In case of section = '[execute]', the entries are // considered of being macros that are executed immediately. // The other entries are treated like pairs of keys and values // and are stored in local variables where the variable name // (key) is prefixed with the string value of $(SectionReaderPrefix); . // // It works as well with '=' as seperator: key=value // or with whitespace(s) between key and value: key value // // author: Georges Schmitz // version: 0.8 (2001-10-15) // 0.8.1 (2002-02-15) changed !$(modePrefix); to $(applyPrefix); // 0.8.2 (2002-06-12) - checking of FindInString results revised // - empty keys are explicitly released as Local Variable // 0.8.2a (2002-07-11) changed $(applyPrefix); to $(SectionReaderPrefix); // // this macro explicitly reads only *ONE* *named* section of a configfile SetOK(1); FindInString("%$('cfgFileContent');","<\[%$('cfgSection');\]*>",2,3,1011,0); // Exit if we didn't find such a section something IfOK("Relax;","Exit;"); // Else continue (as long, as we find the next section) Loop(!`> // As the first FindInString (named section) searched until the end of line, > // the first word of the next line will be the variable name or a new section. > // We are searching for words that may contain numerics, points and "underscores"; > // with the two parts in the RegExp, we may find the variable name (left part), > // or any new section (right part) or even nothing (EOF): in the two latter cases we exit! > FindInString("%$('cfgFileContent');","<+{$Alpha+Numeric+[""_\.""]$}|{\[*\]}",2,3,1011,%!3);> // Perhaps we reached EOF, stop in consequence > IfOK("Relax;","Stop;"); > ExtractByIndex(8,"%$('cfgFileContent');",%!2,%!3); > FormatString("%!8", 6, "trimboth");> // Make the test for (perhaps next) section-like string "[abc]" in reg6 > FindInString("%!6","\[*\]",4,5,1); > IfOK("Stop;"); > // No section? then continue> // we probably have a variable name in reg6 > // and it follows though the value for the variable until the end of line > // skipping one character (index: %!3+1) eliminates the separator character ('=' or ' ' or even ':') > FindInString("%$('cfgFileContent');","*>",2,3,1011,%!3+1); > // cut 2 characters (EOL) at the end > ExtractByIndex(8,"%$('cfgFileContent');",%!2,%!3-2);> FormatString("%!8", 5, "trimboth");> // BUT (!!!) in case of Section = "[execute]", consider reg5 being a macro > // execute this with the "do();" macro > IfStr("%$('cfgSection');","execute","=",!" > Do(|%!5|); > ",!" > // everything else is a normal section entry, if the value is not empty > IfStr(|%!5|,||,|>|,| > Assign(*%$('SectionReaderPrefix');%!6*,*%!5*);> |,| > // VERY IMPORTANT!!! > // Check if "%$('SectionReaderPrefix');%!6" is not an empty string, > // else you get a fatal expression like Release(""); > // which means, reset ALL local variables > IfStr(*%$('SectionReaderPrefix');%!6*,**,*>*,* > Release(""%$('SectionReaderPrefix');%!6"");> *);> |);> //Prompt(|%$(*%$('SectionReaderPrefix');%!6*);|); > "); > `); LetReg(2,""); LetReg(3,""); LetReg(4,""); LetReg(5,""); LetReg(6,""); LetReg(8,""); //Release('SectionReaderPrefix'); End;