// // FileXOpen.vdm Christian Ziemski 11.02.2004 // // // Extends the File_Open() command with a search path. // // The search path is given in T-Reg 103 and the filename in T-Reg 104. // If the file is found in one of the given directories that one is opened. // Otherwise the standard File_Open() is used, which looks in the current // directory, opens the file if existing or creates a new one there. // // (Macro created due to a feature wish of Pauli Lindgren) // //-------------------------------------------------------------- // // Example input for testing: // Search path: // Format 1: every directory in one line Reg_Set(103,'"C:\" C:\xxx\vedit "C:\xxx\test with space\" C:\xxx\test tdir\ C:\temp') // or format 2: One line with doublequoted directories Reg_Set(103,'"C:\", "C:\xxx\vedit", "C:\xxx\test with space\", "C:\xxx\test tdir\", "C:\temp"') // Filename: Reg_Set(104,"TestFile.txt") //========================================================================= if (Reg_Size(104) == 0) { // No filename => nothing to do return } Reg_Empty(105) if (Reg_Size(103) > 0) { // special handling only if search path filled #103=Buf_Num #104=Buf_Switch(Buf_Free) Reg_Ins(103) // search path // // The search path is expected to be one directory per line for further handling. // // If it's in the alternate format of one line with every directory // limited by double quotes it is reformatted below. // // If there is another input format needed, it has to be // reformated accordingly here! // ... // ... // ... BoF Replace("|<|W","", BEGIN+ALL+NOERR) // remove leading spaces #105=0 Search('"', NOERR) // any double quotes there? if (! EM) { // yes: so check whether they are all paired while (! EM) { #105++ Char(1) Search('"', NOERR+ERRBREAK) } if ((#105 & 1) == 1) { // odd number of double quotes Alert Statline_Message("Syntax error in search path!") Buf_Quit(OK) Buf_Switch(#103) return } } BoF while (Cur_Char == 34) { // if " at beginning Del_Char Search('"') // search closing double quote Del_Char if (At_EOL) { Line(1, NOERR+ERRBREAK) } else { Ins_Newline(1) } Replace("|<|W","", BEGIN+ALL+NOERR) // remove leading spaces Replace('^[^"]*', REGEXP+NOERR) // remove chars between directories (e.g. comma) } Replace("|W|>","", BEGIN+ALL+NOERR) // remove trailing spaces Replace("|<|N","", BEGIN+ALL+NOERR) // remove empty lines Replace('"','', BEGIN+ALL+NOERR) // remove double quotes (if still any from format 1) BoF while (! At_EoF) { // loop through the search path EoL Reg_Copy_Block(105, BoL_Pos, Cur_Pos) // get directory if (Cur_Char(-1) != 92) { // if no trailing backslash: append it Reg_Set(105, "\", APPEND) } if (File_Exist("|@(105)|@(104)", NOERR)) { // file found? break } Reg_Empty(105) Line(1, NOERR) } Buf_Quit(OK) Buf_Switch(#103) } File_Open("|@(105)|@(104)") // open file with or without path