summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXInit.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r--macosx/tkMacOSXInit.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index 946bf30..cc7c23a 100644
--- a/macosx/tkMacOSXInit.c
+++ b/macosx/tkMacOSXInit.c
@@ -28,6 +28,13 @@ static char tkLibPath[PATH_MAX + 1] = "";
static char scriptPath[PATH_MAX + 1] = "";
+/*
+ * Forward declarations...
+ */
+
+static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip,
+ int objc, Tcl_Obj *const objv[]);
+
#pragma mark TKApplication(TKInit)
@implementation TKApplication
@@ -388,7 +395,8 @@ TkpInit(
TkMacOSXRegisterServiceWidgetObjCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "::tk::mac::iconBitmap",
TkMacOSXIconBitmapObjCmd, NULL, NULL);
- Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", TkMacOSXGetAppPath,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+ Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath",
+ TkMacOSXGetAppPathCmd, NULL, NULL);
/*
* Initialize the NSServices object here. Apple's docs say to do this
@@ -437,11 +445,11 @@ TkpGetAppName(
}
Tcl_DStringAppend(namePtr, name, -1);
}
-
+
/*
*----------------------------------------------------------------------
*
- * TkMacOSXGetAppPath --
+ * TkMacOSXGetAppPathCmd --
*
* Returns the path of the Wish application bundle.
*
@@ -453,42 +461,39 @@ TkpGetAppName(
*
*----------------------------------------------------------------------
*/
-int TkMacOSXGetAppPath(
- ClientData cd,
- Tcl_Interp *ip,
- int objc,
- Tcl_Obj *CONST objv[])
-{
-
- CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle());
-
-
- /*
- * Convert the URL reference into a string reference.
- */
-
- CFStringRef appPath = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
- /*
- * Get the system encoding method.
- */
-
- CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
+static int
+TkMacOSXGetAppPathCmd(
+ ClientData ignored,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *const objv[])
+{
+ if (objc != 1) {
+ Tcl_WrongNumArgs(interp, 1, objv, NULL);
+ return TCL_ERROR;
+ }
- /*
- * Convert the string reference into a C string.
- */
+ /*
+ * Get the application path URL and convert it to a string path reference.
+ */
- char *path = (char *) CFStringGetCStringPtr(appPath, encodingMethod);
+ CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle());
+ CFStringRef appPath =
+ CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
- Tcl_SetResult(ip, path, NULL);
+ /*
+ * Convert (and copy) the string reference into a Tcl result.
+ */
- CFRelease(mainBundleURL);
- CFRelease(appPath);
- return TCL_OK;
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ CFStringGetCStringPtr(appPath, CFStringGetSystemEncoding()), -1));
+ CFRelease(mainBundleURL);
+ CFRelease(appPath);
+ return TCL_OK;
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -555,7 +560,7 @@ TkMacOSXDefaultStartupScript(void)
CFURLRef scriptFldrURL;
char startupScript[PATH_MAX + 1];
- if (CFURLGetFileSystemRepresentation (appMainURL, true,
+ if (CFURLGetFileSystemRepresentation(appMainURL, true,
(unsigned char *) startupScript, PATH_MAX)) {
Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL);
scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL,