On 11/04/2013 08:20 AM, Adrien Destugues wrote:
The Locale kit uses liblocalestub.a for similar purposes, avoiding exposition of this implementation detail in the API. I'd do something similar to keep the API simpler and clearer, possibly with a way to get either the "main" (application) dirs or the ones for the caller add-on or lib, but not more.It wouldn't exactly simplify the API. One would either still need a parameter to discriminate between the cases or a second function. Furthermore, doing that would require any API on top of find_path() (including the proposed BPathFinder) to live in a static library. Not very elegant IMO.I think using B_MAIN_IMAGE or B_CURRENT_IMAGE instead of &main, NULL, or &someRandomSymbol makes the API simpler, or at least, clearer.
Those couldn't be enums or constants since that leaves the same problem with APIs implemented on top of find_path(). But macros resolving to a code pointer (respectively NULL) should be feasible.
If we go for something like BResources, I think we need the complete set of SetTo* methodes there are in BResources. You may want to access the package-directory even when you have no image at hand (let's say you parckage is made only of data or script files, or the entry point is a script and you want to use the API to locate an executable in the package). The findpaths shell command sounds like a good candidate for this use case.
Yes, the command could be used from within scripts. I'm not sure about the extension of the C API. A second function taking a path instead of the code pointer would be trivial to add -- the naming wouldn't be so nice, though: find_path_for_path()? Alternatively -- if somewhat ugly IMO -- the path could be passed as codePointer of find_path() and a new flag B_FIND_PATH_CODE_POINTER_IS_PATH would signal that case.
The BPathFinder class would gain a respective constructor with a path parameter and, for convenience, maybe another one with an entry_ref parameter. But other than that I don't think any other constructor needs to be added. BFile wouldn't work and I don't think image_id would have any practical use.
CU, Ingo