// -*- ASCII:EDT -*- //---------------------------------------------------------------------- // purpose: Extracts the relative Path to %P // Should one limit moving upwards with "../" to a specific // number of nodes? For the moment the value is 3. // The case of a different drive is checked! //---------------------------------------------------------------------- // author: georges.schmitz@heitec.de //---------------------------------------------------------------------- // version: 1.0 (2001-07-08) // first version // 1.01 (2001-10-22) // take path to tokenizer as local variable // 1.1 (2002-04-15) // changes to work with updated tokenizer macro (V1.12) // => smaller code //---------------------------------------------------------------------- // use the file browser; this is left to your gusto! Browse(0, "All files|*.*|Images|*.gif;*.jpg;*.png;*.eps;*.pdf", "%P"); Assign("filename","%!0"); // Seperate the browsed path into its parts Assign("tkStr","%!0"); // we still have DOS names Assign("tkSep","\"); // check first if tokenizer macro exists IfFileExists("%b\macros\macro\tokenizer.edt",> "Assign('tokenizerMacro','%b\macros\macro\tokenizer.edt'); > ","> IfFileExists('%B\macros\macro\tokenizer.edt',> 'Assign(|tokenizerMacro|,|%B\macros\macro\tokenizer.edt|); > ','> Prompt(|The Tokenizer Macro could not be found! Expected file to be located at: %\ %\>>%$(""tokenizerMacro"");<<|,3);Exit; > ');> "); Assign("tkResultPrefix","browsedPath"); Exe("%$('tokenizerMacro');"); // use current path Assign("tkStr","%P"); Assign("tkSep","\"); Assign("tkResultPrefix","actualPath"); // Divide the actual Path into its components Exe("%$('tokenizerMacro');"); // Prompt("Nodes of current Path: %$('actualPathCnt');"); // compare the two paths // counter for *CORRESPONDING* nodelevels is numReg6 LetRegNum(6,0); Loop(!*> // Ins("actualPath%!6: %$('actualPath%!6'); browsedPath%!6: %$('browsedPath%!6');");NewLine;> IfStr("%$('actualPath%!6');","%$('browsedPath%!6');","=",!" > ",!" > // ELSE > LetRegNum(6,%!6-1); > // exit the loop > Stop; > "); > LetRegNum(6,%!6+1);> // for safety stop after 20 loop > IfNum("%!6",20,">","Stop;","");> *); // Prompt("Point X: %!6"); // NumReg6 holds the nodelevel, from where on the paths // don't correspond anymore, let's call it point X // Build the result in reg0 LetReg(0,""); // How many nodes do we have to move *UP* from point X? // store this in numReg5 LetRegNum(5,"%$('actualPathCnt');-%!6"); Assign("UpwardMovings","%!5"); //Prompt("Nodes up from Point X: %!5"); Repeat("%!5",!*LetReg(0,"%!0..\");*); // and now append the rest of the browsed path // How many nodes do we have to move *DOWN* from point X? // store this again in numReg5 LetRegNum(5,"%$('browsedPathCnt');-%!6"); // Prompt("Nodes down from Point X: %!5"); // use numReg6 as counter, it still holds the // start position from above Repeat("%!5",!*LetReg(0,"%!0%$('browsedPath%!6');\");LetRegNum(6,%!6+1);*); //Cut the last "\" GetLength(9,"%!0"); ExtractByIndex(0,"%!0",0,"%!9-2"); // Now make some checkings (just in case, override reg0 with the // full path stored in %$('filename');) // was it the same drive? (that was the first token) IfStr("%$('actualPath0');","%$('browsedPath0');","=","","LetReg(0,""%$('filename');"");"); // Here you can specify, how much "/.." may occure in a relative file path IfNum("%$('UpwardMovings');",3,">","LetReg(0,""%$('filename');"");"); DosToUnix("%!0",0); // Finally insert the (hopefully relative) filepath Ins("%!0"); // Releasing the the local variables for the browsed filename LetRegNum(7,0); // loop counter Repeat("%$('browsedPathCnt');",!*Release('browsedPath%!7');LetRegNum(7,%!7+1);*); Release("filename"); Release("UpwardMovings"); End;