Re: Include File Relative Paths
- Posted by c.k.lester <euphoric at cklester.com> Mar 07, 2007
- 534 views
Matt Lewis wrote: > > I believe the relevant code is path_open() in scanner.e. CK, I nominate > you to take a swing at it :) Once you get it working, send it to me, and > I'll commit it for you. okay, here's the required changes: add this function:
function get_file_path(sequence s) -- return a directory path from a file path for t=length(s) to 1 by -1 do if find(s[t],SLASH_CHARS) then return s[1..t] end if end for -- if no slashes were found then can't assume it's a directory return ".\"" end function
Then, in path_open(), make this change: ...
if absolute then -- open new_include_name exactly as it is try = open(new_include_name, "r") if try = -1 then errbuff = sprintf("can't open %s", new_include_name) CompileErr(errbuff) end if return try end if ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- THIS IS THE NEW AND REVISED CODE FOR USING RELATIVE INCLUDE FILE PATHS... -- first try path from current file path currdir = get_file_path( file_name[current_file_no] ) full_path = currdir & new_include_name try = open(full_path, "r") if try = -1 then -- relative path name - first try main_path full_path = main_path & new_include_name try = open(full_path, "r") end if -- END OF NEW AND REVISED CODE FOR USING RELATIVE INCLUDE FILE PATHS ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- if try = -1 then -- Search directories listed on EUINC environment var inc_path = getenv("EUINC")
... Hopefully it's clear where to insert new code and modify old code. Now relative includes work. Now to get open() to work relatively... Where's that?