aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Choi2002-08-16 02:30:21 +0000
committerAndrew Choi2002-08-16 02:30:21 +0000
commit1000788b7b3bafc8f1b818f013afc8d06e6c0240 (patch)
treeab456a18dfe88e9b4b5c1ef139129c144ac798fb /src
parent56bd69df597bec2f7144be9f2ee1c0a56ef9a8e0 (diff)
downloademacs-1000788b7b3bafc8f1b818f013afc8d06e6c0240.tar.gz
emacs-1000788b7b3bafc8f1b818f013afc8d06e6c0240.zip
2002-08-15 Andrew Choi <akochoi@shaw.ca>
* mac.c (init_mac_osx_environment): New function. * emacs.c (main) [MAC_OSX]: Call init_mac_osx_environment.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/emacs.c5
-rw-r--r--src/mac.c136
3 files changed, 147 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f90dfff2ae4..6d04d220393 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12002-08-15 Andrew Choi <akochoi@shaw.ca>
2
3 * mac.c (init_mac_osx_environment): New function.
4
5 * emacs.c (main) [MAC_OSX]: Call init_mac_osx_environment.
6
12002-08-14 Kim F. Storm <storm@cua.dk> 72002-08-14 Kim F. Storm <storm@cua.dk>
2 8
3 * macros.c (Fstart_kbd_macro): Added NO-EXEC argument to inhibit 9 * macros.c (Fstart_kbd_macro): Added NO-EXEC argument to inhibit
diff --git a/src/emacs.c b/src/emacs.c
index 4d03eab89b8..5d4f24d314b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1363,6 +1363,11 @@ main (argc, argv, envp)
1363 init_ntproc (); /* must precede init_editfns. */ 1363 init_ntproc (); /* must precede init_editfns. */
1364#endif 1364#endif
1365 1365
1366#ifdef MAC_OSX
1367 if (initialized)
1368 init_mac_osx_environment ();
1369#endif
1370
1366 /* egetenv is a pretty low-level facility, which may get called in 1371 /* egetenv is a pretty low-level facility, which may get called in
1367 many circumstances; it seems flimsy to put off initializing it 1372 many circumstances; it seems flimsy to put off initializing it
1368 until calling init_callproc. */ 1373 until calling init_callproc. */
diff --git a/src/mac.c b/src/mac.c
index a9c97849d55..a28f513a707 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -26,10 +26,12 @@ Boston, MA 02111-1307, USA. */
26#include <errno.h> 26#include <errno.h>
27#include <utime.h> 27#include <utime.h>
28#include <dirent.h> 28#include <dirent.h>
29#include <sys/types.h>
29#include <sys/stat.h> 30#include <sys/stat.h>
30#include <string.h> 31#include <string.h>
31#include <pwd.h> 32#include <pwd.h>
32#include <sys/param.h> 33#include <sys/param.h>
34#include <stdlib.h>
33#if __MWERKS__ 35#if __MWERKS__
34#include <unistd.h> 36#include <unistd.h>
35#endif 37#endif
@@ -2768,6 +2770,140 @@ sys_select (n, rfds, wfds, efds, timeout)
2768 else 2770 else
2769 return select (n, rfds, wfds, efds, timeout); 2771 return select (n, rfds, wfds, efds, timeout);
2770} 2772}
2773
2774
2775/* Set up environment variables so that Emacs can correctly find its
2776 support files when packaged as an application bundle. Directories
2777 placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin,
2778 and /usr/local/libexec/emacs/<emacs-version>/<system-configuration>
2779 by `make install' by default can instead be placed in
2780 .../Emacs.app/Contents/Resources/ and
2781 .../Emacs.app/Contents/MacOS/. Each of these environment variables
2782 is changed only if it is not already set. Presumably if the user
2783 sets an environment variable, he will want to use files in his path
2784 instead of ones in the application bundle. */
2785void
2786init_mac_osx_environment ()
2787{
2788 CFBundleRef bundle;
2789 CFURLRef bundleURL;
2790 CFStringRef cf_app_bundle_pathname;
2791 int app_bundle_pathname_len;
2792 char *app_bundle_pathname;
2793 char *p, *q;
2794 struct stat st;
2795
2796 /* Fetch the pathname of the application bundle as a C string into
2797 app_bundle_pathname. */
2798
2799 bundle = CFBundleGetMainBundle ();
2800 if (!bundle)
2801 return;
2802
2803 bundleURL = CFBundleCopyBundleURL (bundle);
2804 if (!bundleURL)
2805 return;
2806
2807 cf_app_bundle_pathname = CFURLCopyFileSystemPath (bundleURL,
2808 kCFURLPOSIXPathStyle);
2809 app_bundle_pathname_len = CFStringGetLength (cf_app_bundle_pathname);
2810 app_bundle_pathname = (char *) alloca (app_bundle_pathname_len + 1);
2811
2812 if (!CFStringGetCString (cf_app_bundle_pathname,
2813 app_bundle_pathname,
2814 app_bundle_pathname_len + 1,
2815 kCFStringEncodingISOLatin1))
2816 {
2817 CFRelease (cf_app_bundle_pathname);
2818 return;
2819 }
2820
2821 CFRelease (cf_app_bundle_pathname);
2822
2823 /* P should have sufficient room for the pathname of the bundle plus
2824 the subpath in it leading to the respective directories. Q
2825 should have three times that much room because EMACSLOADPATH can
2826 have the value "<path to lisp dir>:<path to leim dir>:<path to
2827 site-lisp dir>". */
2828 p = (char *) alloca (app_bundle_pathname_len + 50);
2829 q = (char *) alloca (3 * app_bundle_pathname_len + 150);
2830 if (!getenv ("EMACSLOADPATH"))
2831 {
2832 q[0] = '\0';
2833
2834 strcpy (p, app_bundle_pathname);
2835 strcat (p, "/Contents/Resources/lisp");
2836 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2837 strcat (q, p);
2838
2839 strcpy (p, app_bundle_pathname);
2840 strcat (p, "/Contents/Resources/leim");
2841 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2842 {
2843 if (q[0] != '\0')
2844 strcat (q, ":");
2845 strcat (q, p);
2846 }
2847
2848 strcpy (p, app_bundle_pathname);
2849 strcat (p, "/Contents/Resources/site-lisp");
2850 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2851 {
2852 if (q[0] != '\0')
2853 strcat (q, ":");
2854 strcat (q, p);
2855 }
2856
2857 if (q[0] != '\0')
2858 setenv ("EMACSLOADPATH", q, 1);
2859 }
2860
2861 if (!getenv ("EMACSPATH"))
2862 {
2863 q[0] = '\0';
2864
2865 strcpy (p, app_bundle_pathname);
2866 strcat (p, "/Contents/MacOS/bin");
2867 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2868 strcat (q, p);
2869
2870 strcpy (p, app_bundle_pathname);
2871 strcat (p, "/Contents/MacOS/libexec");
2872 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2873 {
2874 if (q[0] != '\0')
2875 strcat (q, ":");
2876 strcat (q, p);
2877 }
2878
2879 if (q[0] != '\0')
2880 setenv ("EMACSPATH", q, 1);
2881 }
2882
2883 if (!getenv ("EMACSDATA"))
2884 {
2885 strcpy (p, app_bundle_pathname);
2886 strcat (p, "/Contents/Resources/etc");
2887 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2888 setenv ("EMACSDATA", p, 1);
2889 }
2890
2891 if (!getenv ("EMACSDOC"))
2892 {
2893 strcpy (p, app_bundle_pathname);
2894 strcat (p, "/Contents/Resources/etc");
2895 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2896 setenv ("EMACSDOC", p, 1);
2897 }
2898
2899 if (!getenv ("INFOPATH"))
2900 {
2901 strcpy (p, app_bundle_pathname);
2902 strcat (p, "/Contents/Resources/info");
2903 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
2904 setenv ("INFOPATH", p, 1);
2905 }
2906}
2771#endif /* MAC_OSX */ 2907#endif /* MAC_OSX */
2772 2908
2773void 2909void