26 |
#include <errno.h> |
#include <errno.h> |
27 |
#include <utime.h> |
#include <utime.h> |
28 |
#include <dirent.h> |
#include <dirent.h> |
29 |
|
#include <sys/types.h> |
30 |
#include <sys/stat.h> |
#include <sys/stat.h> |
31 |
#include <string.h> |
#include <string.h> |
32 |
#include <pwd.h> |
#include <pwd.h> |
33 |
#include <sys/param.h> |
#include <sys/param.h> |
34 |
|
#include <stdlib.h> |
35 |
#if __MWERKS__ |
#if __MWERKS__ |
36 |
#include <unistd.h> |
#include <unistd.h> |
37 |
#endif |
#endif |
2770 |
else |
else |
2771 |
return select (n, rfds, wfds, efds, timeout); |
return select (n, rfds, wfds, efds, timeout); |
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. */ |
2785 |
|
void |
2786 |
|
init_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 |
|
} |
2907 |
#endif /* MAC_OSX */ |
#endif /* MAC_OSX */ |
2908 |
|
|
2909 |
void |
void |