Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
On 05 Feb 2009, at 08:54, Ken G. Brown wrote: How can I find the directory path to the executable of the currently executing program from within the program? Or alternately, how can I specify the relative path to a file that is located in the same folder as the application bundle for my currently executing program? Using ./filename does not appear to work for me. Are there file and directory type utilities available? Where can I read up on them? http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/CFBundles.html E.g., http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/Tasks/locating.html#/ /apple_ref/doc/uid/20001123-123785 Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] dynamic arrays: copy-on-write or not?
On 05 Feb 2009, at 05:55, David Emerson wrote: Dynamic arrays are reference counted: assignment of one dynamic array-type variable to another will let both variables point to the same array. Contrary to ansistrings, an assignment to an element of one array will be reflected in the other: there is no copy-on-write. This is fine, but what is strange is that calling setlength DOES perform copy-on-write! var a, b : array of longint; begin setlength (a,2); b := a; setlength (a,5); writeln (length(b)); // I get 2, not 5 end. Why this inconsistency? It's the way Delphi works. In fact, calling setlength is /the/ way to make a dynamic array unique (afaik, the only alternative is calling copy, but that's slower in case the array already was unique. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
Thx for the quick response! I think I'm almost there. I seem to have a bundlePath : CFURLRef; but I don't quite know what to do with it. How do I convert it to something I can use in a Reset() to open a file? Thx, Ken G. Brown At 10:29 AM +0100 2/5/09, Jonas Maebe apparently wrote: On 05 Feb 2009, at 08:54, Ken G. Brown wrote: How can I find the directory path to the executable of the currently executing program from within the program? Or alternately, how can I specify the relative path to a file that is located in the same folder as the application bundle for my currently executing program? Using ./filename does not appear to work for me. Are there file and directory type utilities available? Where can I read up on them? http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/CFBundles.html E.g., http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/Tasks/locating.html#//apple_ref/doc/uid/20001123-123785 Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
On 05 Feb 2009, at 17:03, Ken G. Brown wrote: Thx for the quick response! I think I'm almost there. I seem to have a bundlePath : CFURLRef; but I don't quite know what to do with it. How do I convert it to something I can use in a Reset() to open a file? If you enter CFURLRef in the search box at the top right point of the page, the first link in the search results is http://developer.apple.com/documentation/CoreFoundation/Reference/CFBundleRef/Reference/reference.html The Overview section notes: *** You can also obtain locations of subdirectories in a bundle represented as CFURL objects. The CFBundleCopyExecutableURL function returns the location of the application's executable. The functions CFBundleCopyResourceURL, CFBundleCopySharedFrameworksURL, CFBundleCopyPrivateFrameworksURL,CFBundleCopySharedSupportURL, and CFBundleCopyBuiltInPlugInsURL return the location of a bundle's subdirectory containing resources, shared frameworks, private frameworks, shared support files, and plug-ins *** Clicking on CFURLRef in the declarations of these functions redirects to http://developer.apple.com/documentation/CoreFoundation/Reference/CFURLRef/Reference/reference.html#/ /apple_ref/doc/c_ref/CFURLRef On that page, under Functions by Task and then Accessing the Parts of a URL, there is a function called CFURLCopyFileSystemPath. This function can return a POSIX path (kCFURLPOSIXPathStyle) in a CFStringRef. Clicking on CFStringRef redirects to http://developer.apple.com/documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html#/ /apple_ref/doc/c_ref/CFStringRef There, under Functions by Task and then String File System Representations, there is a function called CFStringGetFileSystemRepresentation, which in combination with CFStringGetMaximumSizeOfFileSystemRepresentation can be used to obtain a null-terminated string containing a path that can be passed to reset etc. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
Whew! Thx! I was part way through all that but wasn't sure what I could pass to reset(); Digging through it now. I haven't dealt with this stuff before. Ken At 6:24 PM +0100 2/5/09, Jonas Maebe apparently wrote: On 05 Feb 2009, at 17:03, Ken G. Brown wrote: Thx for the quick response! I think I'm almost there. I seem to have a bundlePath : CFURLRef; but I don't quite know what to do with it. How do I convert it to something I can use in a Reset() to open a file? If you enter CFURLRef in the search box at the top right point of the page, the first link in the search results is http://developer.apple.com/documentation/CoreFoundation/Reference/CFBundleRef/Reference/reference.html The Overview section notes: *** You can also obtain locations of subdirectories in a bundle represented as CFURL objects. The CFBundleCopyExecutableURL function returns the location of the application's executable. The functions CFBundleCopyResourceURL, CFBundleCopySharedFrameworksURL, CFBundleCopyPrivateFrameworksURL,CFBundleCopySharedSupportURL, and CFBundleCopyBuiltInPlugInsURL return the location of a bundle's subdirectory containing resources, shared frameworks, private frameworks, shared support files, and plug-ins *** Clicking on CFURLRef in the declarations of these functions redirects to http://developer.apple.com/documentation/CoreFoundation/Reference/CFURLRef/Reference/reference.html#//apple_ref/doc/c_ref/CFURLRef On that page, under Functions by Task and then Accessing the Parts of a URL, there is a function called CFURLCopyFileSystemPath. This function can return a POSIX path (kCFURLPOSIXPathStyle) in a CFStringRef. Clicking on CFStringRef redirects to http://developer.apple.com/documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html#//apple_ref/doc/c_ref/CFStringRef There, under Functions by Task and then String File System Representations, there is a function called CFStringGetFileSystemRepresentation, which in combination with CFStringGetMaximumSizeOfFileSystemRepresentation can be used to obtain a null-terminated string containing a path that can be passed to reset etc. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
On 05 Feb 2009, at 21:29, Ken G. Brown wrote: So far I have the following external definitions: All external definitions you need are already in the MacOSAll unit shipped with FPC. Function CFStringGetFileSystemRepresentation(myPathString : CFStringRef; buffer : ppchar; maxBufLen : CFIndex) : Boolean; cdecl; External; Function _CFStringGetFileSystemRepresentation(myPathString : CFStringRef; buffer : ppchar; maxBufLen : CFIndex) : Boolean; C; External; Function CFStringGetMaximumSizeOfFileSystemRepresentation(myPathStr2 : CFStringRef) : CFIndex; cdecl; External; Function _CFStringGetMaximumSizeOfFileSystemRepresentation(myPathStr2 : CFStringRef) : CFIndex; C; External; Function CFBundleGetMainBundle() : CFBundleRef; cdecl; External; Function _CFBundleGetMainBundle() : CFBundleRef; C; External; The ones with the extra underscore don't exist. and the following snippet var success : boolean = false; mainBundle : CFBundleRef; bundlePath : CFURLRef; bundlePathStr : CFStringRef; myBundlePathStr : ppchar; myBundlePathStr has to be a pchar; begin // Get the main bundle for the app mainBundle := CFBundleGetMainBundle(); bundlePath := CFBundleCopyBundleURL(mainBundle); bundlePathStr := CFURLCopyFileSystemPath (bundlePath, kCFURLPOSIXPathStyle); success := CFStringGetFileSystemRepresentation (bundlePathStr, myBundlePathStr, CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); I'm not quite sure if I am doing the 2nd arg correctly, it's supposed to be char *buffer. Does this look alright? If not, what should I be using for the myBundlePathString type? You have to allocate memory for it. Something like myBundlePathStr := getmem(CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); success := CFStringGetFileSystemRepresentation (bundlePathStr, myBundlePathStr, CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); When interfacing with C routines, you have to do the same things as if you were using C. And I notice that CFStringGetFileSystemRepresentation is only available for 10.4 and newer. What do i need to do instead if wanting to deploy to 10.3.9? Call CFStringGetCStringPtr and/or CFStringGetCStringPtr and tell it to convert to utf-8 (kCFStringEncodingUTF8). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
At 9:51 PM +0100 2/5/09, Jonas Maebe apparently wrote: On 05 Feb 2009, at 21:29, Ken G. Brown wrote: So far I have the following external definitions: All external definitions you need are already in the MacOSAll unit shipped with FPC. Function CFStringGetFileSystemRepresentation(myPathString : CFStringRef; buffer : ppchar; maxBufLen : CFIndex) : Boolean; cdecl; External; Function _CFStringGetFileSystemRepresentation(myPathString : CFStringRef; buffer : ppchar; maxBufLen : CFIndex) : Boolean; C; External; Function CFStringGetMaximumSizeOfFileSystemRepresentation(myPathStr2 : CFStringRef) : CFIndex; cdecl; External; Function _CFStringGetMaximumSizeOfFileSystemRepresentation(myPathStr2 : CFStringRef) : CFIndex; C; External; Function CFBundleGetMainBundle() : CFBundleRef; cdecl; External; Function _CFBundleGetMainBundle() : CFBundleRef; C; External; The ones with the extra underscore don't exist. and the following snippet var success : boolean = false; mainBundle : CFBundleRef; bundlePath : CFURLRef; bundlePathStr : CFStringRef; myBundlePathStr : ppchar; myBundlePathStr has to be a pchar; begin // Get the main bundle for the app mainBundle := CFBundleGetMainBundle(); bundlePath := CFBundleCopyBundleURL(mainBundle); bundlePathStr := CFURLCopyFileSystemPath (bundlePath, kCFURLPOSIXPathStyle); success := CFStringGetFileSystemRepresentation (bundlePathStr, myBundlePathStr, CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); I'm not quite sure if I am doing the 2nd arg correctly, it's supposed to be char *buffer. Does this look alright? If not, what should I be using for the myBundlePathString type? You have to allocate memory for it. Something like myBundlePathStr:=getmem(CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); success := CFStringGetFileSystemRepresentation (bundlePathStr, myBundlePathStr, CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); Ah! Sweet! I'm getting the path! Now all that's left is to get the path without the app name and add my filename! :) Thank you Sir! Ken When interfacing with C routines, you have to do the same things as if you were using C. And I notice that CFStringGetFileSystemRepresentation is only available for 10.4 and newer. What do i need to do instead if wanting to deploy to 10.3.9? Call CFStringGetCStringPtr and/or CFStringGetCStringPtr and tell it to convert to utf-8 (kCFStringEncodingUTF8). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: specifying the relative path to a file that is located in the same folder as the application bundle?
Ken G. Brown kbrown-ee4meeah...@public.gmane.org wrote in message news:p06240407c5b049e88...@[10.0.1.199]... MacOS X, 10.5.6, fpc 2.2.2 How can I find the directory path to the executable of the currently executing program from within the program? Or alternately, how can I specify the relative path to a file that is located in the same folder as the application bundle for my currently executing program? Using ./filename does not appear to work for me. Are there file and directory type utilities available? Where can I read up on them? Thx for any tips, Ken G. Brown ___ fpc-pascal maillist - fpc-pascal-pd4fty7x32k2wbthl531ywd2fqjk+...@public.gmane.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal Maybe I haven't understood you completely, but have you tried this? MyProgramFolder := ExtractFilePath(ParamStr(0)); This should hopefully get you the folder of the currently running program from within the program (at least under Win32 and Linux). cheers, Paul ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: specifying the relative path to a file that is located in the same folder as the application bundle?
On 05 Feb 2009, at 23:00, Jonas Maebe wrote: On 05 Feb 2009, at 22:52, Paul Nicholls wrote: Maybe I haven't understood you completely, but have you tried this? MyProgramFolder := ExtractFilePath(ParamStr(0)); This should hopefully get you the folder of the currently running program from within the program (at least under Win32 and Linux). That is completely OS (and sometimes OS-version) dependent, and should not be used if you want portable code (even on Linux it does not work under all circumstances). For background information on this, see http://bugs.freepascal.org/view.php?id=8358 Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] specifying the relative path to a file that is located in the same folder as the application bundle?
Thanks a bunch for all the help! My legacy OS 9 app is now upgraded to OS X and working! It put up a hell of a fight but with all your help, the obstacles have been overcome. Awesome! Ken G. Brown At 9:51 PM +0100 2/5/09, Jonas Maebe apparently wrote: You have to allocate memory for it. Something like myBundlePathStr:=getmem(CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); success := CFStringGetFileSystemRepresentation (bundlePathStr, myBundlePathStr, CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); When interfacing with C routines, you have to do the same things as if you were using C. And I notice that CFStringGetFileSystemRepresentation is only available for 10.4 and newer. What do i need to do instead if wanting to deploy to 10.3.9? Call CFStringGetCStringPtr and/or CFStringGetCStringPtr and tell it to convert to utf-8 (kCFStringEncodingUTF8). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal