annotate src/mac.c @ 88287:c4875198e277

(rmail-summary-edit-map): Rewrite.
author Alex Schroeder <alex@gnu.org>
date Mon, 23 Jan 2006 23:17:58 +0000
parents d7ddb3e565de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1 /* Unix emulation routines for GNU Emacs on the Mac OS.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3 2005 Free Software Foundation, Inc.
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5 This file is part of GNU Emacs.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
6
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
10 any later version.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
11
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
15 GNU General Public License for more details.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
16
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
20 Boston, MA 02110-1301, USA. */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
21
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
22 /* Contributed by Andrew Choi (akochoi@mac.com). */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
23
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
24 #include <config.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
25
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
26 #include <stdio.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
27 #include <errno.h>
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
28
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
29 #include "lisp.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
30 #include "process.h"
45848
39cdf9669519 In src/:
Andrew Choi <akochoi@shaw.ca>
parents: 45141
diff changeset
31 #undef init_process
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
32 #include "systime.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
33 #include "sysselect.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
34 #include "blockinput.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
35
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
36 #include "macterm.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
37
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
38 #include "charset.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
39 #include "coding.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
40 #if !TARGET_API_MAC_CARBON
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
41 #include <Files.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
42 #include <MacTypes.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
43 #include <TextUtils.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
44 #include <Folders.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
45 #include <Resources.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
46 #include <Aliases.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
47 #include <FixMath.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
48 #include <Timer.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
49 #include <OSA.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
50 #include <AppleScript.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
51 #include <Scrap.h>
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
52 #include <Events.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
53 #include <Processes.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
54 #include <EPPC.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
55 #include <MacLocales.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
56 #include <Endian.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
57 #endif /* not TARGET_API_MAC_CARBON */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
58
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
59 #include <utime.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
60 #include <dirent.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
61 #include <sys/types.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
62 #include <sys/stat.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
63 #include <pwd.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
64 #include <grp.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
65 #include <sys/param.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
66 #include <fcntl.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
67 #if __MWERKS__
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
68 #include <unistd.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
69 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
70
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
71 /* The system script code. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
72 static int mac_system_script_code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
73
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
74 /* The system locale identifier string. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
75 static Lisp_Object Vmac_system_locale;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
76
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
77 /* An instance of the AppleScript component. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
78 static ComponentInstance as_scripting_component;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
79 /* The single script context used for all script executions. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
80 static OSAID as_script_context;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
81
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
82 static OSErr posix_pathname_to_fsspec P_ ((const char *, FSSpec *));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
83 static OSErr fsspec_to_posix_pathname P_ ((const FSSpec *, char *, int));
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
84
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
85 /* When converting from Mac to Unix pathnames, /'s in folder names are
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
86 converted to :'s. This function, used in copying folder names,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
87 performs a strncat and converts all character a to b in the copy of
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
88 the string s2 appended to the end of s1. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
89
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
90 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
91 string_cat_and_replace (char *s1, const char *s2, int n, char a, char b)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
92 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
93 int l1 = strlen (s1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
94 int l2 = strlen (s2);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
95 char *p = s1 + l1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
96 int i;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
97
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
98 strncat (s1, s2, n);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
99 for (i = 0; i < l2; i++)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
100 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
101 if (*p == a)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
102 *p = b;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
103 p++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
104 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
105 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
106
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
107
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
108 /* Convert a Mac pathname to Posix form. A Mac full pathname is one
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
109 that does not begin with a ':' and contains at least one ':'. A Mac
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
110 full pathname causes a '/' to be prepended to the Posix pathname.
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
111 The algorithm for the rest of the pathname is as follows:
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
112 For each segment between two ':',
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
113 if it is non-null, copy as is and then add a '/' at the end,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
114 otherwise, insert a "../" into the Posix pathname.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
115 Returns 1 if successful; 0 if fails. */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
116
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
117 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
118 mac_to_posix_pathname (const char *mfn, char *ufn, int ufnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
119 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
120 const char *p, *q, *pe;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
121
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
122 strcpy (ufn, "");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
123
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
124 if (*mfn == '\0')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
125 return 1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
126
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
127 p = strchr (mfn, ':');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
128 if (p != 0 && p != mfn) /* full pathname */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
129 strcat (ufn, "/");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
130
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
131 p = mfn;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
132 if (*p == ':')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
133 p++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
134
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
135 pe = mfn + strlen (mfn);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
136 while (p < pe)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
137 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
138 q = strchr (p, ':');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
139 if (q)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
140 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
141 if (q == p)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
142 { /* two consecutive ':' */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
143 if (strlen (ufn) + 3 >= ufnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
144 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
145 strcat (ufn, "../");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
146 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
147 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
148 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
149 if (strlen (ufn) + (q - p) + 1 >= ufnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
150 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
151 string_cat_and_replace (ufn, p, q - p, '/', ':');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
152 strcat (ufn, "/");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
153 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
154 p = q + 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
155 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
156 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
157 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
158 if (strlen (ufn) + (pe - p) >= ufnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
159 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
160 string_cat_and_replace (ufn, p, pe - p, '/', ':');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
161 /* no separator for last one */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
162 p = pe;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
163 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
164 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
165
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
166 return 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
167 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
168
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
169
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
170 extern char *get_temp_dir_name ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
171
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
172
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
173 /* Convert a Posix pathname to Mac form. Approximately reverse of the
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
174 above in algorithm. */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
175
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
176 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
177 posix_to_mac_pathname (const char *ufn, char *mfn, int mfnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
178 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
179 const char *p, *q, *pe;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
180 char expanded_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
181
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
182 strcpy (mfn, "");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
183
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
184 if (*ufn == '\0')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
185 return 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
186
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
187 p = ufn;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
188
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
189 /* Check for and handle volume names. Last comparison: strangely
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
190 somewhere "/.emacs" is passed. A temporary fix for now. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
191 if (*p == '/' && strchr (p+1, '/') == NULL && strcmp (p, "/.emacs") != 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
192 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
193 if (strlen (p) + 1 > mfnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
194 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
195 strcpy (mfn, p+1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
196 strcat (mfn, ":");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
197 return 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
198 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
199
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
200 /* expand to emacs dir found by init_emacs_passwd_dir */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
201 if (strncmp (p, "~emacs/", 7) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
202 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
203 struct passwd *pw = getpwnam ("emacs");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
204 p += 7;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
205 if (strlen (pw->pw_dir) + strlen (p) > MAXPATHLEN)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
206 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
207 strcpy (expanded_pathname, pw->pw_dir);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
208 strcat (expanded_pathname, p);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
209 p = expanded_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
210 /* now p points to the pathname with emacs dir prefix */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
211 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
212 else if (strncmp (p, "/tmp/", 5) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
213 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
214 char *t = get_temp_dir_name ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
215 p += 5;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
216 if (strlen (t) + strlen (p) > MAXPATHLEN)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
217 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
218 strcpy (expanded_pathname, t);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
219 strcat (expanded_pathname, p);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
220 p = expanded_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
221 /* now p points to the pathname with emacs dir prefix */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
222 }
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
223 else if (*p != '/') /* relative pathname */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
224 strcat (mfn, ":");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
225
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
226 if (*p == '/')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
227 p++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
228
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
229 pe = p + strlen (p);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
230 while (p < pe)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
231 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
232 q = strchr (p, '/');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
233 if (q)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
234 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
235 if (q - p == 2 && *p == '.' && *(p+1) == '.')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
236 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
237 if (strlen (mfn) + 1 >= mfnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
238 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
239 strcat (mfn, ":");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
240 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
241 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
242 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
243 if (strlen (mfn) + (q - p) + 1 >= mfnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
244 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
245 string_cat_and_replace (mfn, p, q - p, ':', '/');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
246 strcat (mfn, ":");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
247 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
248 p = q + 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
249 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
250 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
251 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
252 if (strlen (mfn) + (pe - p) >= mfnbuflen)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
253 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
254 string_cat_and_replace (mfn, p, pe - p, ':', '/');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
255 p = pe;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
256 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
257 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
258
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
259 return 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
260 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
261
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
262
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
263 /***********************************************************************
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
264 Conversions on Apple event objects
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
265 ***********************************************************************/
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
266
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
267 static Lisp_Object Qundecoded_file_name;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
268
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
269 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
270 mac_aelist_to_lisp (desc_list)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
271 AEDescList *desc_list;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
272 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
273 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
274 long count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
275 Lisp_Object result, elem;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
276 DescType desc_type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
277 Size size;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
278 AEKeyword keyword;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
279 AEDesc desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
280
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
281 err = AECountItems (desc_list, &count);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
282 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
283 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
284 result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
285 while (count > 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
286 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
287 err = AESizeOfNthItem (desc_list, count, &desc_type, &size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
288 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
289 switch (desc_type)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
290 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
291 case typeAEList:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
292 case typeAERecord:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
293 case typeAppleEvent:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
294 err = AEGetNthDesc (desc_list, count, typeWildCard,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
295 &keyword, &desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
296 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
297 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
298 elem = mac_aelist_to_lisp (&desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
299 AEDisposeDesc (&desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
300 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
301
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
302 default:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
303 if (desc_type == typeNull)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
304 elem = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
305 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
306 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
307 elem = make_uninit_string (size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
308 err = AEGetNthPtr (desc_list, count, typeWildCard, &keyword,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
309 &desc_type, SDATA (elem), size, &size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
310 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
311 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
312 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
313 desc_type = EndianU32_NtoB (desc_type);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
314 elem = Fcons (make_unibyte_string ((char *) &desc_type, 4), elem);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
315 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
316 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
317
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
318 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
319 elem = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
320 else if (desc_list->descriptorType != typeAEList)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
321 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
322 keyword = EndianU32_NtoB (keyword);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
323 elem = Fcons (make_unibyte_string ((char *) &keyword, 4), elem);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
324 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
325
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
326 result = Fcons (elem, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
327 count--;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
328 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
329
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
330 desc_type = EndianU32_NtoB (desc_list->descriptorType);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
331 return Fcons (make_unibyte_string ((char *) &desc_type, 4), result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
332 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
333
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
334 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
335 mac_aedesc_to_lisp (desc)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
336 AEDesc *desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
337 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
338 OSErr err = noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
339 DescType desc_type = desc->descriptorType;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
340 Lisp_Object result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
341
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
342 switch (desc_type)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
343 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
344 case typeNull:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
345 result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
346 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
347
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
348 case typeAEList:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
349 case typeAERecord:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
350 case typeAppleEvent:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
351 return mac_aelist_to_lisp (desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
352 #if 0
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
353 /* The following one is much simpler, but creates and disposes
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
354 of Apple event descriptors many times. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
355 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
356 long count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
357 Lisp_Object elem;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
358 AEKeyword keyword;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
359 AEDesc desc1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
360
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
361 err = AECountItems (desc, &count);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
362 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
363 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
364 result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
365 while (count > 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
366 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
367 err = AEGetNthDesc (desc, count, typeWildCard, &keyword, &desc1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
368 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
369 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
370 elem = mac_aedesc_to_lisp (&desc1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
371 AEDisposeDesc (&desc1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
372 if (desc_type != typeAEList)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
373 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
374 keyword = EndianU32_NtoB (keyword);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
375 elem = Fcons (make_unibyte_string ((char *) &keyword, 4), elem);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
376 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
377 result = Fcons (elem, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
378 count--;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
379 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
380 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
381 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
382 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
383
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
384 default:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
385 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
386 result = make_uninit_string (AEGetDescDataSize (desc));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
387 err = AEGetDescData (desc, SDATA (result), SBYTES (result));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
388 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
389 result = make_uninit_string (GetHandleSize (desc->dataHandle));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
390 memcpy (SDATA (result), *(desc->dataHandle), SBYTES (result));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
391 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
392 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
393 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
394
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
395 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
396 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
397
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
398 desc_type = EndianU32_NtoB (desc_type);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
399 return Fcons (make_unibyte_string ((char *) &desc_type, 4), result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
400 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
401
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
402 static pascal OSErr
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
403 mac_coerce_file_name_ptr (type_code, data_ptr, data_size,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
404 to_type, handler_refcon, result)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
405 DescType type_code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
406 const void *data_ptr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
407 Size data_size;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
408 DescType to_type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
409 long handler_refcon;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
410 AEDesc *result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
411 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
412 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
413
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
414 if (type_code == typeNull)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
415 err = errAECoercionFail;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
416 else if (type_code == to_type || to_type == typeWildCard)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
417 err = AECreateDesc (TYPE_FILE_NAME, data_ptr, data_size, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
418 else if (type_code == TYPE_FILE_NAME)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
419 /* Coercion from undecoded file name. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
420 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
421 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
422 CFStringRef str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
423 CFURLRef url = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
424 CFDataRef data = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
425
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
426 str = CFStringCreateWithBytes (NULL, data_ptr, data_size,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
427 kCFStringEncodingUTF8, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
428 if (str)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
429 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
430 url = CFURLCreateWithFileSystemPath (NULL, str,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
431 kCFURLPOSIXPathStyle, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
432 CFRelease (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
433 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
434 if (url)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
435 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
436 data = CFURLCreateData (NULL, url, kCFStringEncodingUTF8, true);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
437 CFRelease (url);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
438 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
439 if (data)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
440 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
441 err = AECoercePtr (typeFileURL, CFDataGetBytePtr (data),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
442 CFDataGetLength (data), to_type, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
443 CFRelease (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
444 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
445 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
446 err = memFullErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
447 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
448 FSSpec fs;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
449 char *buf;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
450
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
451 buf = xmalloc (data_size + 1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
452 if (buf)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
453 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
454 memcpy (buf, data_ptr, data_size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
455 buf[data_size] = '\0';
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
456 err = posix_pathname_to_fsspec (buf, &fs);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
457 xfree (buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
458 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
459 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
460 err = memFullErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
461 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
462 err = AECoercePtr (typeFSS, &fs, sizeof (FSSpec), to_type, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
463 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
464 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
465 else if (to_type == TYPE_FILE_NAME)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
466 /* Coercion to undecoded file name. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
467 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
468 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
469 CFURLRef url = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
470 CFStringRef str = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
471 CFDataRef data = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
472
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
473 if (type_code == typeFileURL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
474 url = CFURLCreateWithBytes (NULL, data_ptr, data_size,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
475 kCFStringEncodingUTF8, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
476 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
477 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
478 AEDesc desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
479 Size size;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
480 char *buf;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
481
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
482 err = AECoercePtr (type_code, data_ptr, data_size,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
483 typeFileURL, &desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
484 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
485 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
486 size = AEGetDescDataSize (&desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
487 buf = xmalloc (size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
488 if (buf)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
489 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
490 err = AEGetDescData (&desc, buf, size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
491 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
492 url = CFURLCreateWithBytes (NULL, buf, size,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
493 kCFStringEncodingUTF8, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
494 xfree (buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
495 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
496 AEDisposeDesc (&desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
497 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
498 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
499 if (url)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
500 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
501 str = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
502 CFRelease (url);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
503 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
504 if (str)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
505 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
506 data = CFStringCreateExternalRepresentation (NULL, str,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
507 kCFStringEncodingUTF8,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
508 '\0');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
509 CFRelease (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
510 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
511 if (data)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
512 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
513 err = AECreateDesc (TYPE_FILE_NAME, CFDataGetBytePtr (data),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
514 CFDataGetLength (data), result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
515 CFRelease (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
516 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
517 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
518 char file_name[MAXPATHLEN];
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
519
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
520 if (type_code == typeFSS && data_size == sizeof (FSSpec))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
521 err = fsspec_to_posix_pathname (data_ptr, file_name,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
522 sizeof (file_name) - 1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
523 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
524 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
525 AEDesc desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
526 FSSpec fs;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
527
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
528 err = AECoercePtr (type_code, data_ptr, data_size, typeFSS, &desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
529 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
530 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
531 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
532 err = AEGetDescData (&desc, &fs, sizeof (FSSpec));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
533 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
534 fs = *(FSSpec *)(*(desc.dataHandle));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
535 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
536 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
537 err = fsspec_to_posix_pathname (&fs, file_name,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
538 sizeof (file_name) - 1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
539 AEDisposeDesc (&desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
540 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
541 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
542 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
543 err = AECreateDesc (TYPE_FILE_NAME, file_name,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
544 strlen (file_name), result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
545 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
546 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
547 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
548 abort ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
549
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
550 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
551 return errAECoercionFail;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
552 return noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
553 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
554
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
555 static pascal OSErr
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
556 mac_coerce_file_name_desc (from_desc, to_type, handler_refcon, result)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
557 const AEDesc *from_desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
558 DescType to_type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
559 long handler_refcon;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
560 AEDesc *result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
561 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
562 OSErr err = noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
563 DescType from_type = from_desc->descriptorType;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
564
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
565 if (from_type == typeNull)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
566 err = errAECoercionFail;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
567 else if (from_type == to_type || to_type == typeWildCard)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
568 err = AEDuplicateDesc (from_desc, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
569 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
570 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
571 char *data_ptr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
572 Size data_size;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
573
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
574 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
575 data_size = AEGetDescDataSize (from_desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
576 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
577 data_size = GetHandleSize (from_desc->dataHandle);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
578 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
579 data_ptr = xmalloc (data_size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
580 if (data_ptr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
581 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
582 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
583 err = AEGetDescData (from_desc, data_ptr, data_size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
584 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
585 memcpy (data_ptr, *(from_desc->dataHandle), data_size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
586 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
587 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
588 err = mac_coerce_file_name_ptr (from_type, data_ptr,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
589 data_size, to_type,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
590 handler_refcon, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
591 xfree (data_ptr);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
592 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
593 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
594 err = memFullErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
595 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
596
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
597 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
598 return errAECoercionFail;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
599 return noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
600 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
601
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
602 OSErr
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
603 init_coercion_handler ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
604 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
605 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
606
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
607 static AECoercePtrUPP coerce_file_name_ptrUPP = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
608 static AECoerceDescUPP coerce_file_name_descUPP = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
609
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
610 if (coerce_file_name_ptrUPP == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
611 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
612 coerce_file_name_ptrUPP = NewAECoercePtrUPP (mac_coerce_file_name_ptr);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
613 coerce_file_name_descUPP = NewAECoerceDescUPP (mac_coerce_file_name_desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
614 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
615
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
616 err = AEInstallCoercionHandler (TYPE_FILE_NAME, typeWildCard,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
617 (AECoercionHandlerUPP)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
618 coerce_file_name_ptrUPP, 0, false, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
619 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
620 err = AEInstallCoercionHandler (typeWildCard, TYPE_FILE_NAME,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
621 (AECoercionHandlerUPP)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
622 coerce_file_name_ptrUPP, 0, false, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
623 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
624 err = AEInstallCoercionHandler (TYPE_FILE_NAME, typeWildCard,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
625 coerce_file_name_descUPP, 0, true, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
626 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
627 err = AEInstallCoercionHandler (typeWildCard, TYPE_FILE_NAME,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
628 coerce_file_name_descUPP, 0, true, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
629 return err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
630 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
631
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
632 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
633 OSErr
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
634 create_apple_event_from_event_ref (event, num_params, names, types, result)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
635 EventRef event;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
636 UInt32 num_params;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
637 EventParamName *names;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
638 EventParamType *types;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
639 AppleEvent *result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
640 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
641 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
642 static const ProcessSerialNumber psn = {0, kCurrentProcess};
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
643 AEAddressDesc address_desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
644 UInt32 i, size;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
645 CFStringRef string;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
646 CFDataRef data;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
647 char *buf;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
648
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
649 err = AECreateDesc (typeProcessSerialNumber, &psn,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
650 sizeof (ProcessSerialNumber), &address_desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
651 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
652 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
653 err = AECreateAppleEvent (0, 0, /* Dummy class and ID. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
654 &address_desc, /* NULL is not allowed
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
655 on Mac OS Classic. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
656 kAutoGenerateReturnID,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
657 kAnyTransactionID, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
658 AEDisposeDesc (&address_desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
659 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
660 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
661 return err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
662
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
663 for (i = 0; i < num_params; i++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
664 switch (types[i])
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
665 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
666 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
667 case typeCFStringRef:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
668 err = GetEventParameter (event, names[i], typeCFStringRef, NULL,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
669 sizeof (CFStringRef), NULL, &string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
670 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
671 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
672 data = CFStringCreateExternalRepresentation (NULL, string,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
673 kCFStringEncodingUTF8,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
674 '?');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
675 if (data == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
676 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
677 /* typeUTF8Text is not available on Mac OS X 10.1. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
678 AEPutParamPtr (result, names[i], 'utf8',
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
679 CFDataGetBytePtr (data), CFDataGetLength (data));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
680 CFRelease (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
681 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
682 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
683
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
684 default:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
685 err = GetEventParameter (event, names[i], types[i], NULL,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
686 0, &size, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
687 if (err != noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
688 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
689 buf = xmalloc (size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
690 if (buf == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
691 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
692 err = GetEventParameter (event, names[i], types[i], NULL,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
693 size, NULL, buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
694 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
695 AEPutParamPtr (result, names[i], types[i], buf, size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
696 xfree (buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
697 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
698 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
699
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
700 return noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
701 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
702 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
703
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
704
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
705 /***********************************************************************
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
706 Conversion between Lisp and Core Foundation objects
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
707 ***********************************************************************/
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
708
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
709 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
710 static Lisp_Object Qstring, Qnumber, Qboolean, Qdate, Qdata;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
711 static Lisp_Object Qarray, Qdictionary;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
712
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
713 struct cfdict_context
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
714 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
715 Lisp_Object *result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
716 int with_tag, hash_bound;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
717 };
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
718
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
719 /* C string to CFString. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
720
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
721 CFStringRef
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
722 cfstring_create_with_utf8_cstring (c_str)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
723 const char *c_str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
724 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
725 CFStringRef str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
726
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
727 str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingUTF8);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
728 if (str == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
729 /* Failed to interpret as UTF 8. Fall back on Mac Roman. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
730 str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingMacRoman);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
731
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
732 return str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
733 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
734
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
735
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
736 /* Lisp string to CFString. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
737
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
738 CFStringRef
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
739 cfstring_create_with_string (s)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
740 Lisp_Object s;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
741 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
742 CFStringRef string = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
743
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
744 if (STRING_MULTIBYTE (s))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
745 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
746 char *p, *end = SDATA (s) + SBYTES (s);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
747
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
748 for (p = SDATA (s); p < end; p++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
749 if (!isascii (*p))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
750 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
751 s = ENCODE_UTF_8 (s);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
752 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
753 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
754 string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
755 kCFStringEncodingUTF8, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
756 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
757
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
758 if (string == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
759 /* Failed to interpret as UTF 8. Fall back on Mac Roman. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
760 string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
761 kCFStringEncodingMacRoman, false);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
762
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
763 return string;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
764 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
765
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
766
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
767 /* From CFData to a lisp string. Always returns a unibyte string. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
768
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
769 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
770 cfdata_to_lisp (data)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
771 CFDataRef data;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
772 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
773 CFIndex len = CFDataGetLength (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
774 Lisp_Object result = make_uninit_string (len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
775
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
776 CFDataGetBytes (data, CFRangeMake (0, len), SDATA (result));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
777
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
778 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
779 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
780
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
781
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
782 /* From CFString to a lisp string. Returns a unibyte string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
783 containing a UTF-8 byte sequence. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
784
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
785 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
786 cfstring_to_lisp_nodecode (string)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
787 CFStringRef string;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
788 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
789 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
790 const char *s = CFStringGetCStringPtr (string, kCFStringEncodingUTF8);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
791
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
792 if (s)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
793 result = make_unibyte_string (s, strlen (s));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
794 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
795 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
796 CFDataRef data =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
797 CFStringCreateExternalRepresentation (NULL, string,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
798 kCFStringEncodingUTF8, '?');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
799
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
800 if (data)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
801 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
802 result = cfdata_to_lisp (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
803 CFRelease (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
804 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
805 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
806
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
807 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
808 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
809
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
810
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
811 /* From CFString to a lisp string. Never returns a unibyte string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
812 (even if it only contains ASCII characters).
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
813 This may cause GC during code conversion. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
814
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
815 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
816 cfstring_to_lisp (string)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
817 CFStringRef string;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
818 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
819 Lisp_Object result = cfstring_to_lisp_nodecode (string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
820
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
821 if (!NILP (result))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
822 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
823 result = code_convert_string_norecord (result, Qutf_8, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
824 /* This may be superfluous. Just to make sure that the result
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
825 is a multibyte string. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
826 result = string_to_multibyte (result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
827 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
828
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
829 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
830 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
831
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
832
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
833 /* CFNumber to a lisp integer or a lisp float. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
834
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
835 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
836 cfnumber_to_lisp (number)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
837 CFNumberRef number;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
838 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
839 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
840 #if BITS_PER_EMACS_INT > 32
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
841 SInt64 int_val;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
842 CFNumberType emacs_int_type = kCFNumberSInt64Type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
843 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
844 SInt32 int_val;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
845 CFNumberType emacs_int_type = kCFNumberSInt32Type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
846 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
847 double float_val;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
848
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
849 if (CFNumberGetValue (number, emacs_int_type, &int_val)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
850 && !FIXNUM_OVERFLOW_P (int_val))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
851 result = make_number (int_val);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
852 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
853 if (CFNumberGetValue (number, kCFNumberDoubleType, &float_val))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
854 result = make_float (float_val);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
855 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
856 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
857
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
858
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
859 /* CFDate to a list of three integers as in a return value of
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
860 `current-time'. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
861
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
862 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
863 cfdate_to_lisp (date)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
864 CFDateRef date;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
865 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
866 static const CFGregorianDate epoch_gdate = {1970, 1, 1, 0, 0, 0.0};
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
867 static CFAbsoluteTime epoch = 0.0, sec;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
868 int high, low;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
869
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
870 if (epoch == 0.0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
871 epoch = CFGregorianDateGetAbsoluteTime (epoch_gdate, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
872
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
873 sec = CFDateGetAbsoluteTime (date) - epoch;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
874 high = sec / 65536.0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
875 low = sec - high * 65536.0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
876
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
877 return list3 (make_number (high), make_number (low), make_number (0));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
878 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
879
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
880
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
881 /* CFBoolean to a lisp symbol, `t' or `nil'. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
882
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
883 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
884 cfboolean_to_lisp (boolean)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
885 CFBooleanRef boolean;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
886 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
887 return CFBooleanGetValue (boolean) ? Qt : Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
888 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
889
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
890
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
891 /* Any Core Foundation object to a (lengthy) lisp string. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
892
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
893 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
894 cfobject_desc_to_lisp (object)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
895 CFTypeRef object;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
896 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
897 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
898 CFStringRef desc = CFCopyDescription (object);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
899
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
900 if (desc)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
901 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
902 result = cfstring_to_lisp (desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
903 CFRelease (desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
904 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
905
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
906 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
907 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
908
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
909
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
910 /* Callback functions for cfproperty_list_to_lisp. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
911
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
912 static void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
913 cfdictionary_add_to_list (key, value, context)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
914 const void *key;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
915 const void *value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
916 void *context;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
917 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
918 struct cfdict_context *cxt = (struct cfdict_context *)context;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
919
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
920 *cxt->result =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
921 Fcons (Fcons (cfstring_to_lisp (key),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
922 cfproperty_list_to_lisp (value, cxt->with_tag,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
923 cxt->hash_bound)),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
924 *cxt->result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
925 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
926
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
927 static void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
928 cfdictionary_puthash (key, value, context)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
929 const void *key;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
930 const void *value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
931 void *context;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
932 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
933 Lisp_Object lisp_key = cfstring_to_lisp (key);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
934 struct cfdict_context *cxt = (struct cfdict_context *)context;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
935 struct Lisp_Hash_Table *h = XHASH_TABLE (*(cxt->result));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
936 unsigned hash_code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
937
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
938 hash_lookup (h, lisp_key, &hash_code);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
939 hash_put (h, lisp_key,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
940 cfproperty_list_to_lisp (value, cxt->with_tag, cxt->hash_bound),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
941 hash_code);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
942 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
943
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
944
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
945 /* Convert CFPropertyList PLIST to a lisp object. If WITH_TAG is
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
946 non-zero, a symbol that represents the type of the original Core
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
947 Foundation object is prepended. HASH_BOUND specifies which kinds
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
948 of the lisp objects, alists or hash tables, are used as the targets
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
949 of the conversion from CFDictionary. If HASH_BOUND is negative,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
950 always generate alists. If HASH_BOUND >= 0, generate an alist if
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
951 the number of keys in the dictionary is smaller than HASH_BOUND,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
952 and a hash table otherwise. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
953
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
954 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
955 cfproperty_list_to_lisp (plist, with_tag, hash_bound)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
956 CFPropertyListRef plist;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
957 int with_tag, hash_bound;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
958 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
959 CFTypeID type_id = CFGetTypeID (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
960 Lisp_Object tag = Qnil, result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
961 struct gcpro gcpro1, gcpro2;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
962
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
963 GCPRO2 (tag, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
964
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
965 if (type_id == CFStringGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
966 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
967 tag = Qstring;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
968 result = cfstring_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
969 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
970 else if (type_id == CFNumberGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
971 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
972 tag = Qnumber;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
973 result = cfnumber_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
974 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
975 else if (type_id == CFBooleanGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
976 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
977 tag = Qboolean;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
978 result = cfboolean_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
979 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
980 else if (type_id == CFDateGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
981 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
982 tag = Qdate;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
983 result = cfdate_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
984 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
985 else if (type_id == CFDataGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
986 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
987 tag = Qdata;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
988 result = cfdata_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
989 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
990 else if (type_id == CFArrayGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
991 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
992 CFIndex index, count = CFArrayGetCount (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
993
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
994 tag = Qarray;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
995 result = Fmake_vector (make_number (count), Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
996 for (index = 0; index < count; index++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
997 XVECTOR (result)->contents[index] =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
998 cfproperty_list_to_lisp (CFArrayGetValueAtIndex (plist, index),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
999 with_tag, hash_bound);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1000 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1001 else if (type_id == CFDictionaryGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1002 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1003 struct cfdict_context context;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1004 CFIndex count = CFDictionaryGetCount (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1005
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1006 tag = Qdictionary;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1007 context.result = &result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1008 context.with_tag = with_tag;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1009 context.hash_bound = hash_bound;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1010 if (hash_bound < 0 || count < hash_bound)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1011 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1012 result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1013 CFDictionaryApplyFunction (plist, cfdictionary_add_to_list,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1014 &context);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1015 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1016 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1017 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1018 result = make_hash_table (Qequal,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1019 make_number (count),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1020 make_float (DEFAULT_REHASH_SIZE),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1021 make_float (DEFAULT_REHASH_THRESHOLD),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1022 Qnil, Qnil, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1023 CFDictionaryApplyFunction (plist, cfdictionary_puthash,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1024 &context);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1025 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1026 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1027 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1028 abort ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1029
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1030 UNGCPRO;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1031
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1032 if (with_tag)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1033 result = Fcons (tag, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1034
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1035 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1036 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1037 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1038
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1039
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1040 /***********************************************************************
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1041 Emulation of the X Resource Manager
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1042 ***********************************************************************/
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1043
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1044 /* Parser functions for resource lines. Each function takes an
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1045 address of a variable whose value points to the head of a string.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1046 The value will be advanced so that it points to the next character
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1047 of the parsed part when the function returns.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1048
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1049 A resource name such as "Emacs*font" is parsed into a non-empty
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1050 list called `quarks'. Each element is either a Lisp string that
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1051 represents a concrete component, a Lisp symbol LOOSE_BINDING
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1052 (actually Qlambda) that represents any number (>=0) of intervening
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1053 components, or a Lisp symbol SINGLE_COMPONENT (actually Qquote)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1054 that represents as any single component. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1055
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1056 #define P (*p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1057
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1058 #define LOOSE_BINDING Qlambda /* '*' ("L"oose) */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1059 #define SINGLE_COMPONENT Qquote /* '?' ("Q"uestion) */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1060
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1061 static void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1062 skip_white_space (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1063 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1064 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1065 /* WhiteSpace = {<space> | <horizontal tab>} */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1066 while (*P == ' ' || *P == '\t')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1067 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1068 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1069
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1070 static int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1071 parse_comment (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1072 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1073 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1074 /* Comment = "!" {<any character except null or newline>} */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1075 if (*P == '!')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1076 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1077 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1078 while (*P)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1079 if (*P++ == '\n')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1080 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1081 return 1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1082 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1083 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1084 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1085 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1086
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1087 /* Don't interpret filename. Just skip until the newline. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1088 static int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1089 parse_include_file (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1090 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1091 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1092 /* IncludeFile = "#" WhiteSpace "include" WhiteSpace FileName WhiteSpace */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1093 if (*P == '#')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1094 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1095 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1096 while (*P)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1097 if (*P++ == '\n')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1098 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1099 return 1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1100 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1101 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1102 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1103 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1104
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1105 static char
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1106 parse_binding (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1107 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1108 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1109 /* Binding = "." | "*" */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1110 if (*P == '.' || *P == '*')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1111 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1112 char binding = *P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1113
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1114 while (*P == '.' || *P == '*')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1115 if (*P++ == '*')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1116 binding = '*';
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1117 return binding;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1118 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1119 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1120 return '\0';
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1121 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1122
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1123 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1124 parse_component (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1125 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1126 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1127 /* Component = "?" | ComponentName
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1128 ComponentName = NameChar {NameChar}
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1129 NameChar = "a"-"z" | "A"-"Z" | "0"-"9" | "_" | "-" */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1130 if (*P == '?')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1131 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1132 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1133 return SINGLE_COMPONENT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1134 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1135 else if (isalnum (*P) || *P == '_' || *P == '-')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1136 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1137 char *start = P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1138
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1139 while (isalnum (*P) || *P == '_' || *P == '-')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1140 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1141
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1142 return make_unibyte_string (start, P - start);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1143 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1144 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1145 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1146 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1147
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1148 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1149 parse_resource_name (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1150 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1151 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1152 Lisp_Object result = Qnil, component;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1153 char binding;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1154
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1155 /* ResourceName = [Binding] {Component Binding} ComponentName */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1156 if (parse_binding (p) == '*')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1157 result = Fcons (LOOSE_BINDING, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1158
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1159 component = parse_component (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1160 if (NILP (component))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1161 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1162
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1163 result = Fcons (component, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1164 while ((binding = parse_binding (p)) != '\0')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1165 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1166 if (binding == '*')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1167 result = Fcons (LOOSE_BINDING, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1168 component = parse_component (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1169 if (NILP (component))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1170 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1171 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1172 result = Fcons (component, result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1173 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1174
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1175 /* The final component should not be '?'. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1176 if (EQ (component, SINGLE_COMPONENT))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1177 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1178
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1179 return Fnreverse (result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1180 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1181
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1182 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1183 parse_value (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1184 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1185 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1186 char *q, *buf;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1187 Lisp_Object seq = Qnil, result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1188 int buf_len, total_len = 0, len, continue_p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1189
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1190 q = strchr (P, '\n');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1191 buf_len = q ? q - P : strlen (P);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1192 buf = xmalloc (buf_len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1193
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1194 while (1)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1195 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1196 q = buf;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1197 continue_p = 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1198 while (*P)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1199 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1200 if (*P == '\n')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1201 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1202 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1203 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1204 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1205 else if (*P == '\\')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1206 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1207 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1208 if (*P == '\0')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1209 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1210 else if (*P == '\n')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1211 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1212 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1213 continue_p = 1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1214 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1215 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1216 else if (*P == 'n')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1217 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1218 *q++ = '\n';
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1219 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1220 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1221 else if ('0' <= P[0] && P[0] <= '7'
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1222 && '0' <= P[1] && P[1] <= '7'
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1223 && '0' <= P[2] && P[2] <= '7')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1224 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1225 *q++ = (P[0] - '0' << 6) + (P[1] - '0' << 3) + (P[2] - '0');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1226 P += 3;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1227 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1228 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1229 *q++ = *P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1230 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1231 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1232 *q++ = *P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1233 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1234 len = q - buf;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1235 seq = Fcons (make_unibyte_string (buf, len), seq);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1236 total_len += len;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1237
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1238 if (continue_p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1239 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1240 q = strchr (P, '\n');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1241 len = q ? q - P : strlen (P);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1242 if (len > buf_len)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1243 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1244 xfree (buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1245 buf_len = len;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1246 buf = xmalloc (buf_len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1247 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1248 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1249 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1250 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1251 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1252 xfree (buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1253
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1254 if (SBYTES (XCAR (seq)) == total_len)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1255 return make_string (SDATA (XCAR (seq)), total_len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1256 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1257 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1258 buf = xmalloc (total_len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1259 q = buf + total_len;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1260 for (; CONSP (seq); seq = XCDR (seq))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1261 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1262 len = SBYTES (XCAR (seq));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1263 q -= len;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1264 memcpy (q, SDATA (XCAR (seq)), len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1265 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1266 result = make_string (buf, total_len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1267 xfree (buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1268 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1269 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1270 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1271
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1272 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1273 parse_resource_line (p)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1274 char **p;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1275 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1276 Lisp_Object quarks, value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1277
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1278 /* ResourceLine = Comment | IncludeFile | ResourceSpec | <empty line> */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1279 if (parse_comment (p) || parse_include_file (p))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1280 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1281
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1282 /* ResourceSpec = WhiteSpace ResourceName WhiteSpace ":" WhiteSpace Value */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1283 skip_white_space (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1284 quarks = parse_resource_name (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1285 if (NILP (quarks))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1286 goto cleanup;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1287 skip_white_space (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1288 if (*P != ':')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1289 goto cleanup;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1290 P++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1291 skip_white_space (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1292 value = parse_value (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1293 return Fcons (quarks, value);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1294
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1295 cleanup:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1296 /* Skip the remaining data as a dummy value. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1297 parse_value (p);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1298 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1299 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1300
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1301 #undef P
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1302
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1303 /* Equivalents of X Resource Manager functions.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1304
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1305 An X Resource Database acts as a collection of resource names and
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1306 associated values. It is implemented as a trie on quarks. Namely,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1307 each edge is labeled by either a string, LOOSE_BINDING, or
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1308 SINGLE_COMPONENT. Each node has a node id, which is a unique
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1309 nonnegative integer, and the root node id is 0. A database is
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1310 implemented as a hash table that maps a pair (SRC-NODE-ID .
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1311 EDGE-LABEL) to DEST-NODE-ID. It also holds a maximum node id used
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1312 in the table as a value for HASHKEY_MAX_NID. A value associated to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1313 a node is recorded as a value for the node id.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1314
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1315 A database also has a cache for past queries as a value for
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1316 HASHKEY_QUERY_CACHE. It is another hash table that maps
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1317 "NAME-STRING\0CLASS-STRING" to the result of the query. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1318
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1319 #define HASHKEY_MAX_NID (make_number (0))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1320 #define HASHKEY_QUERY_CACHE (make_number (-1))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1321
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1322 static XrmDatabase
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1323 xrm_create_database ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1324 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1325 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1326
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1327 database = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1328 make_float (DEFAULT_REHASH_SIZE),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1329 make_float (DEFAULT_REHASH_THRESHOLD),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1330 Qnil, Qnil, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1331 Fputhash (HASHKEY_MAX_NID, make_number (0), database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1332 Fputhash (HASHKEY_QUERY_CACHE, Qnil, database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1333
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1334 return database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1335 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1336
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1337 static void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1338 xrm_q_put_resource (database, quarks, value)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1339 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1340 Lisp_Object quarks, value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1341 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1342 struct Lisp_Hash_Table *h = XHASH_TABLE (database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1343 unsigned hash_code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1344 int max_nid, i;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1345 Lisp_Object node_id, key;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1346
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1347 max_nid = XINT (Fgethash (HASHKEY_MAX_NID, database, Qnil));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1348
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1349 XSETINT (node_id, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1350 for (; CONSP (quarks); quarks = XCDR (quarks))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1351 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1352 key = Fcons (node_id, XCAR (quarks));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1353 i = hash_lookup (h, key, &hash_code);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1354 if (i < 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1355 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1356 max_nid++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1357 XSETINT (node_id, max_nid);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1358 hash_put (h, key, node_id, hash_code);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1359 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1360 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1361 node_id = HASH_VALUE (h, i);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1362 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1363 Fputhash (node_id, value, database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1364
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1365 Fputhash (HASHKEY_MAX_NID, make_number (max_nid), database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1366 Fputhash (HASHKEY_QUERY_CACHE, Qnil, database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1367 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1368
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1369 /* Merge multiple resource entries specified by DATA into a resource
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1370 database DATABASE. DATA points to the head of a null-terminated
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1371 string consisting of multiple resource lines. It's like a
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1372 combination of XrmGetStringDatabase and XrmMergeDatabases. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1373
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1374 void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1375 xrm_merge_string_database (database, data)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1376 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1377 char *data;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1378 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1379 Lisp_Object quarks_value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1380
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1381 while (*data)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1382 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1383 quarks_value = parse_resource_line (&data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1384 if (!NILP (quarks_value))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1385 xrm_q_put_resource (database,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1386 XCAR (quarks_value), XCDR (quarks_value));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1387 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1388 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1389
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1390 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1391 xrm_q_get_resource_1 (database, node_id, quark_name, quark_class)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1392 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1393 Lisp_Object node_id, quark_name, quark_class;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1394 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1395 struct Lisp_Hash_Table *h = XHASH_TABLE (database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1396 Lisp_Object key, labels[3], value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1397 int i, k;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1398
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1399 if (!CONSP (quark_name))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1400 return Fgethash (node_id, database, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1401
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1402 /* First, try tight bindings */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1403 labels[0] = XCAR (quark_name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1404 labels[1] = XCAR (quark_class);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1405 labels[2] = SINGLE_COMPONENT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1406
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1407 key = Fcons (node_id, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1408 for (k = 0; k < sizeof (labels) / sizeof (*labels); k++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1409 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1410 XSETCDR (key, labels[k]);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1411 i = hash_lookup (h, key, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1412 if (i >= 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1413 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1414 value = xrm_q_get_resource_1 (database, HASH_VALUE (h, i),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1415 XCDR (quark_name), XCDR (quark_class));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1416 if (!NILP (value))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1417 return value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1418 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1419 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1420
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1421 /* Then, try loose bindings */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1422 XSETCDR (key, LOOSE_BINDING);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1423 i = hash_lookup (h, key, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1424 if (i >= 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1425 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1426 value = xrm_q_get_resource_1 (database, HASH_VALUE (h, i),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1427 quark_name, quark_class);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1428 if (!NILP (value))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1429 return value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1430 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1431 return xrm_q_get_resource_1 (database, node_id,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1432 XCDR (quark_name), XCDR (quark_class));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1433 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1434 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1435 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1436 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1437
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1438 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1439 xrm_q_get_resource (database, quark_name, quark_class)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1440 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1441 Lisp_Object quark_name, quark_class;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1442 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1443 return xrm_q_get_resource_1 (database, make_number (0),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1444 quark_name, quark_class);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1445 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1446
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1447 /* Retrieve a resource value for the specified NAME and CLASS from the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1448 resource database DATABASE. It corresponds to XrmGetResource. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1449
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1450 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1451 xrm_get_resource (database, name, class)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1452 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1453 char *name, *class;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1454 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1455 Lisp_Object key, query_cache, quark_name, quark_class, tmp;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1456 int i, nn, nc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1457 struct Lisp_Hash_Table *h;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1458 unsigned hash_code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1459
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1460 nn = strlen (name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1461 nc = strlen (class);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1462 key = make_uninit_string (nn + nc + 1);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1463 strcpy (SDATA (key), name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1464 strncpy (SDATA (key) + nn + 1, class, nc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1465
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1466 query_cache = Fgethash (HASHKEY_QUERY_CACHE, database, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1467 if (NILP (query_cache))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1468 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1469 query_cache = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1470 make_float (DEFAULT_REHASH_SIZE),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1471 make_float (DEFAULT_REHASH_THRESHOLD),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1472 Qnil, Qnil, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1473 Fputhash (HASHKEY_QUERY_CACHE, query_cache, database);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1474 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1475 h = XHASH_TABLE (query_cache);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1476 i = hash_lookup (h, key, &hash_code);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1477 if (i >= 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1478 return HASH_VALUE (h, i);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1479
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1480 quark_name = parse_resource_name (&name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1481 if (*name != '\0')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1482 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1483 for (tmp = quark_name, nn = 0; CONSP (tmp); tmp = XCDR (tmp), nn++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1484 if (!STRINGP (XCAR (tmp)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1485 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1486
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1487 quark_class = parse_resource_name (&class);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1488 if (*class != '\0')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1489 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1490 for (tmp = quark_class, nc = 0; CONSP (tmp); tmp = XCDR (tmp), nc++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1491 if (!STRINGP (XCAR (tmp)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1492 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1493
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1494 if (nn != nc)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1495 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1496 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1497 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1498 tmp = xrm_q_get_resource (database, quark_name, quark_class);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1499 hash_put (h, key, tmp, hash_code);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1500 return tmp;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1501 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1502 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1503
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1504 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1505 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1506 xrm_cfproperty_list_to_value (plist)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1507 CFPropertyListRef plist;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1508 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1509 CFTypeID type_id = CFGetTypeID (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1510
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1511 if (type_id == CFStringGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1512 return cfstring_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1513 else if (type_id == CFNumberGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1514 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1515 CFStringRef string;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1516 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1517
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1518 string = CFStringCreateWithFormat (NULL, NULL, CFSTR ("%@"), plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1519 if (string)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1520 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1521 result = cfstring_to_lisp (string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1522 CFRelease (string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1523 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1524 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1525 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1526 else if (type_id == CFBooleanGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1527 return build_string (CFBooleanGetValue (plist) ? "true" : "false");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1528 else if (type_id == CFDataGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1529 return cfdata_to_lisp (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1530 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1531 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1532 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1533 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1534
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1535 /* Create a new resource database from the preferences for the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1536 application APPLICATION. APPLICATION is either a string that
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1537 specifies an application ID, or NULL that represents the current
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1538 application. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1539
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1540 XrmDatabase
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1541 xrm_get_preference_database (application)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1542 char *application;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1543 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1544 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1545 CFStringRef app_id, *keys, user_doms[2], host_doms[2];
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1546 CFMutableSetRef key_set = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1547 CFArrayRef key_array;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1548 CFIndex index, count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1549 char *res_name;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1550 XrmDatabase database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1551 Lisp_Object quarks = Qnil, value = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1552 CFPropertyListRef plist;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1553 int iu, ih;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1554 struct gcpro gcpro1, gcpro2, gcpro3;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1555
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1556 user_doms[0] = kCFPreferencesCurrentUser;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1557 user_doms[1] = kCFPreferencesAnyUser;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1558 host_doms[0] = kCFPreferencesCurrentHost;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1559 host_doms[1] = kCFPreferencesAnyHost;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1560
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1561 database = xrm_create_database ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1562
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1563 GCPRO3 (database, quarks, value);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1564
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1565 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1566
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1567 app_id = kCFPreferencesCurrentApplication;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1568 if (application)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1569 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1570 app_id = cfstring_create_with_utf8_cstring (application);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1571 if (app_id == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1572 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1573 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1574
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1575 key_set = CFSetCreateMutable (NULL, 0, &kCFCopyStringSetCallBacks);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1576 if (key_set == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1577 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1578 for (iu = 0; iu < sizeof (user_doms) / sizeof (*user_doms) ; iu++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1579 for (ih = 0; ih < sizeof (host_doms) / sizeof (*host_doms); ih++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1580 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1581 key_array = CFPreferencesCopyKeyList (app_id, user_doms[iu],
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1582 host_doms[ih]);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1583 if (key_array)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1584 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1585 count = CFArrayGetCount (key_array);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1586 for (index = 0; index < count; index++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1587 CFSetAddValue (key_set,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1588 CFArrayGetValueAtIndex (key_array, index));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1589 CFRelease (key_array);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1590 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1591 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1592
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1593 count = CFSetGetCount (key_set);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1594 keys = xmalloc (sizeof (CFStringRef) * count);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1595 if (keys == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1596 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1597 CFSetGetValues (key_set, (const void **)keys);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1598 for (index = 0; index < count; index++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1599 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1600 res_name = SDATA (cfstring_to_lisp_nodecode (keys[index]));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1601 quarks = parse_resource_name (&res_name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1602 if (!(NILP (quarks) || *res_name))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1603 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1604 plist = CFPreferencesCopyAppValue (keys[index], app_id);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1605 value = xrm_cfproperty_list_to_value (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1606 CFRelease (plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1607 if (!NILP (value))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1608 xrm_q_put_resource (database, quarks, value);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1609 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1610 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1611
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1612 xfree (keys);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1613 out:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1614 if (key_set)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1615 CFRelease (key_set);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1616 CFRelease (app_id);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1617
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1618 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1619
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1620 UNGCPRO;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1621
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1622 return database;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1623 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1624 return xrm_create_database ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1625 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1626 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1627
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
1628
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1629 #ifndef MAC_OSX
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1630
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1631 /* The following functions with "sys_" prefix are stubs to Unix
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1632 functions that have already been implemented by CW or MPW. The
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1633 calls to them in Emacs source course are #define'd to call the sys_
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1634 versions by the header files s-mac.h. In these stubs pathnames are
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1635 converted between their Unix and Mac forms. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1636
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1637
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1638 /* Unix epoch is Jan 1, 1970 while Mac epoch is Jan 1, 1904: 66 years
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1639 + 17 leap days. These are for adjusting time values returned by
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1640 MacOS Toolbox functions. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1641
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1642 #define MAC_UNIX_EPOCH_DIFF ((365L * 66 + 17) * 24 * 60 * 60)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1643
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1644 #ifdef __MWERKS__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1645 #if __MSL__ < 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1646 /* CW Pro 5 epoch is Jan 1, 1900 (aaarghhhhh!); remember, 1900 is not
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1647 a leap year! This is for adjusting time_t values returned by MSL
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1648 functions. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1649 #define CW_OR_MPW_UNIX_EPOCH_DIFF ((365L * 70 + 17) * 24 * 60 * 60)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1650 #else /* __MSL__ >= 0x6000 */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1651 /* CW changes Pro 6 to follow Unix! */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1652 #define CW_OR_MPW_UNIX_EPOCH_DIFF ((365L * 66 + 17) * 24 * 60 * 60)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1653 #endif /* __MSL__ >= 0x6000 */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1654 #elif __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1655 /* MPW library functions follow Unix (confused?). */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1656 #define CW_OR_MPW_UNIX_EPOCH_DIFF ((365L * 66 + 17) * 24 * 60 * 60)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1657 #else /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1658 You lose!!!
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1659 #endif /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1660
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1661
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1662 /* Define our own stat function for both MrC and CW. The reason for
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1663 doing this: "stat" is both the name of a struct and function name:
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1664 can't use the same trick like that for sys_open, sys_close, etc. to
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1665 redirect Emacs's calls to our own version that converts Unix style
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1666 filenames to Mac style filename because all sorts of compilation
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1667 errors will be generated if stat is #define'd to be sys_stat. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1668
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1669 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1670 stat_noalias (const char *path, struct stat *buf)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1671 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1672 char mac_pathname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1673 CInfoPBRec cipb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1674
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1675 if (posix_to_mac_pathname (path, mac_pathname, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1676 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1677
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1678 c2pstr (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1679 cipb.hFileInfo.ioNamePtr = mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1680 cipb.hFileInfo.ioVRefNum = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1681 cipb.hFileInfo.ioDirID = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1682 cipb.hFileInfo.ioFDirIndex = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1683 /* set to 0 to get information about specific dir or file */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1684
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1685 errno = PBGetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1686 if (errno == -43) /* -43: fnfErr defined in Errors.h */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1687 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1688 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1689 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1690
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1691 if (cipb.hFileInfo.ioFlAttrib & 0x10) /* bit 4 = 1 for directories */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1692 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1693 buf->st_mode = S_IFDIR | S_IREAD | S_IEXEC;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1694
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1695 if (!(cipb.hFileInfo.ioFlAttrib & 0x1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1696 buf->st_mode |= S_IWRITE; /* bit 1 = 1 for locked files/directories */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1697 buf->st_ino = cipb.dirInfo.ioDrDirID;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1698 buf->st_dev = cipb.dirInfo.ioVRefNum;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1699 buf->st_size = cipb.dirInfo.ioDrNmFls;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1700 /* size of dir = number of files and dirs */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1701 buf->st_atime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1702 = buf->st_mtime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1703 = cipb.dirInfo.ioDrMdDat - MAC_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1704 buf->st_ctime = cipb.dirInfo.ioDrCrDat - MAC_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1705 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1706 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1707 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1708 buf->st_mode = S_IFREG | S_IREAD;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1709 if (!(cipb.hFileInfo.ioFlAttrib & 0x1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1710 buf->st_mode |= S_IWRITE; /* bit 1 = 1 for locked files/directories */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1711 if (cipb.hFileInfo.ioFlFndrInfo.fdType == 'APPL')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1712 buf->st_mode |= S_IEXEC;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1713 buf->st_ino = cipb.hFileInfo.ioDirID;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1714 buf->st_dev = cipb.hFileInfo.ioVRefNum;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1715 buf->st_size = cipb.hFileInfo.ioFlLgLen;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1716 buf->st_atime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1717 = buf->st_mtime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1718 = cipb.hFileInfo.ioFlMdDat - MAC_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1719 buf->st_ctime = cipb.hFileInfo.ioFlCrDat - MAC_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1720 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1721
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1722 if (cipb.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1723 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1724 /* identify alias files as symlinks */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1725 buf->st_mode &= ~S_IFREG;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1726 buf->st_mode |= S_IFLNK;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1727 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1728
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1729 buf->st_nlink = 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1730 buf->st_uid = getuid ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1731 buf->st_gid = getgid ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1732 buf->st_rdev = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1733
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1734 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1735 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1736
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1737
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1738 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1739 lstat (const char *path, struct stat *buf)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1740 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1741 int result;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1742 char true_pathname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1743
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1744 /* Try looking for the file without resolving aliases first. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1745 if ((result = stat_noalias (path, buf)) >= 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1746 return result;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1747
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1748 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1749 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1750
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1751 return stat_noalias (true_pathname, buf);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1752 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1753
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1754
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1755 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1756 stat (const char *path, struct stat *sb)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1757 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1758 int result;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1759 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1760 int len;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1761
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1762 if ((result = stat_noalias (path, sb)) >= 0 &&
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1763 ! (sb->st_mode & S_IFLNK))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1764 return result;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1765
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1766 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1767 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1768
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1769 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1770 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1771 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1772 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1773 /* in fact our readlink terminates strings */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1774 return lstat (fully_resolved_name, sb);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1775 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1776 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1777 return lstat (true_pathname, sb);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1778 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1779
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1780
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1781 #if __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1782 /* CW defines fstat in stat.mac.c while MPW does not provide this
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1783 function. Without the information of how to get from a file
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1784 descriptor in MPW StdCLib to a Mac OS file spec, it should be hard
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1785 to implement this function. Fortunately, there is only one place
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1786 where this function is called in our configuration: in fileio.c,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1787 where only the st_dev and st_ino fields are used to determine
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1788 whether two fildes point to different i-nodes to prevent copying
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1789 a file onto itself equal. What we have here probably needs
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1790 improvement. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1791
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1792 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1793 fstat (int fildes, struct stat *buf)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1794 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1795 buf->st_dev = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1796 buf->st_ino = fildes;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1797 buf->st_mode = S_IFREG; /* added by T.I. for the copy-file */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1798 return 0; /* success */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1799 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1800 #endif /* __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1801
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1802
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1803 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1804 mkdir (const char *dirname, int mode)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1805 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1806 #pragma unused(mode)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1807
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1808 HFileParam hfpb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1809 char true_pathname[MAXPATHLEN+1], mac_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1810
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1811 if (find_true_pathname (dirname, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1812 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1813
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1814 if (posix_to_mac_pathname (true_pathname, mac_pathname, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1815 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1816
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1817 c2pstr (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1818 hfpb.ioNamePtr = mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1819 hfpb.ioVRefNum = 0; /* ignored unless name is invalid */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1820 hfpb.ioDirID = 0; /* parent is the root */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1821
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1822 errno = PBDirCreate ((HParmBlkPtr) &hfpb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1823 /* just return the Mac OSErr code for now */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1824 return errno == noErr ? 0 : -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1825 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1826
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1827
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1828 #undef rmdir
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1829 sys_rmdir (const char *dirname)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1830 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1831 HFileParam hfpb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1832 char mac_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1833
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1834 if (posix_to_mac_pathname (dirname, mac_pathname, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1835 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1836
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1837 c2pstr (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1838 hfpb.ioNamePtr = mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1839 hfpb.ioVRefNum = 0; /* ignored unless name is invalid */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1840 hfpb.ioDirID = 0; /* parent is the root */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1841
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1842 errno = PBHDelete ((HParmBlkPtr) &hfpb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1843 return errno == noErr ? 0 : -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1844 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1845
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1846
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1847 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1848 /* No implementation yet. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1849 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1850 execvp (const char *path, ...)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1851 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1852 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1853 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1854 #endif /* __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1855
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1856
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1857 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1858 utime (const char *path, const struct utimbuf *times)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1859 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1860 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1861 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1862 char mac_pathname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1863 CInfoPBRec cipb;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1864
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1865 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1866 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1867
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1868 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1869 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1870 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1871 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1872 strcpy (fully_resolved_name, true_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1873
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1874 if (!posix_to_mac_pathname (fully_resolved_name, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1875 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1876
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1877 c2pstr (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1878 cipb.hFileInfo.ioNamePtr = mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1879 cipb.hFileInfo.ioVRefNum = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1880 cipb.hFileInfo.ioDirID = 0;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1881 cipb.hFileInfo.ioFDirIndex = 0;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1882 /* set to 0 to get information about specific dir or file */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1883
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1884 errno = PBGetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1885 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1886 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1887
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1888 if (cipb.hFileInfo.ioFlAttrib & 0x10) /* bit 4 = 1 for directories */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1889 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1890 if (times)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1891 cipb.dirInfo.ioDrMdDat = times->modtime + MAC_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1892 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1893 GetDateTime (&cipb.dirInfo.ioDrMdDat);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1894 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1895 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1896 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1897 if (times)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1898 cipb.hFileInfo.ioFlMdDat = times->modtime + MAC_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1899 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1900 GetDateTime (&cipb.hFileInfo.ioFlMdDat);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1901 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1902
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1903 errno = PBSetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1904 return errno == noErr ? 0 : -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1905 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1906
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1907
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1908 #ifndef F_OK
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1909 #define F_OK 0
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1910 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1911 #ifndef X_OK
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1912 #define X_OK 1
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1913 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1914 #ifndef W_OK
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1915 #define W_OK 2
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1916 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1917
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1918 /* Like stat, but test for access mode in hfpb.ioFlAttrib */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1919 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1920 access (const char *path, int mode)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1921 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1922 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1923 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1924 char mac_pathname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1925 CInfoPBRec cipb;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1926
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1927 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1928 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1929
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1930 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1931 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1932 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1933 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1934 strcpy (fully_resolved_name, true_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1935
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1936 if (!posix_to_mac_pathname (fully_resolved_name, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1937 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1938
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1939 c2pstr (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1940 cipb.hFileInfo.ioNamePtr = mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1941 cipb.hFileInfo.ioVRefNum = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1942 cipb.hFileInfo.ioDirID = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1943 cipb.hFileInfo.ioFDirIndex = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1944 /* set to 0 to get information about specific dir or file */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1945
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1946 errno = PBGetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1947 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1948 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1949
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1950 if (mode == F_OK) /* got this far, file exists */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1951 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1952
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1953 if (mode & X_OK)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1954 if (cipb.hFileInfo.ioFlAttrib & 0x10) /* path refers to a directory */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1955 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1956 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1957 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1958 if (cipb.hFileInfo.ioFlFndrInfo.fdType == 'APPL')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1959 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1960 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1961 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1962 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1963
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1964 if (mode & W_OK)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1965 return (cipb.hFileInfo.ioFlAttrib & 0x1) ? -1 : 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1966 /* don't allow if lock bit is on */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1967
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1968 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1969 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1970
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1971
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1972 #define DEV_NULL_FD 0x10000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1973
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1974 #undef open
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1975 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1976 sys_open (const char *path, int oflag)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1977 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1978 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1979 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1980 char mac_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1981
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1982 if (strcmp (path, "/dev/null") == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1983 return DEV_NULL_FD; /* some bogus fd to be ignored in write */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1984
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1985 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1986 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
1987
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1988 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1989 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1990 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1991 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1992 strcpy (fully_resolved_name, true_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1993
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1994 if (!posix_to_mac_pathname (fully_resolved_name, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1995 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1996 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1997 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1998 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
1999 int res = open (mac_pathname, oflag);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2000 /* if (oflag == O_WRONLY || oflag == O_RDWR) */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2001 if (oflag & O_CREAT)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2002 fsetfileinfo (mac_pathname, 'EMAx', 'TEXT');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2003 return res;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2004 #else /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2005 return open (mac_pathname, oflag);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2006 #endif /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2007 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2008 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2009
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2010
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2011 #undef creat
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2012 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2013 sys_creat (const char *path, mode_t mode)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2014 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2015 char true_pathname[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2016 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2017 char mac_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2018
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2019 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2020 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2021
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2022 if (!posix_to_mac_pathname (true_pathname, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2023 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2024 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2025 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2026 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2027 int result = creat (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2028 fsetfileinfo (mac_pathname, 'EMAx', 'TEXT');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2029 return result;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2030 #else /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2031 return creat (mac_pathname, mode);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2032 #endif /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2033 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2034 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2035
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2036
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2037 #undef unlink
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2038 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2039 sys_unlink (const char *path)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2040 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2041 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2042 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2043 char mac_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2044
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2045 if (find_true_pathname (path, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2046 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2047
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2048 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2049 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2050 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2051 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2052 strcpy (fully_resolved_name, true_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2053
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2054 if (!posix_to_mac_pathname (fully_resolved_name, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2055 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2056 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2057 return unlink (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2058 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2059
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2060
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2061 #undef read
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2062 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2063 sys_read (int fildes, char *buf, int count)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2064 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2065 if (fildes == 0) /* this should not be used for console input */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2066 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2067 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2068 #if __MSL__ >= 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2069 return _read (fildes, buf, count);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2070 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2071 return read (fildes, buf, count);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2072 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2073 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2074
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2075
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2076 #undef write
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2077 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2078 sys_write (int fildes, const char *buf, int count)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2079 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2080 if (fildes == DEV_NULL_FD)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2081 return count;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2082 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2083 #if __MSL__ >= 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2084 return _write (fildes, buf, count);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2085 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2086 return write (fildes, buf, count);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2087 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2088 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2089
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2090
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2091 #undef rename
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2092 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2093 sys_rename (const char * old_name, const char * new_name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2094 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2095 char true_old_pathname[MAXPATHLEN+1], true_new_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2096 char fully_resolved_old_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2097 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2098 char mac_old_name[MAXPATHLEN+1], mac_new_name[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2099
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2100 if (find_true_pathname (old_name, true_old_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2101 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2102
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2103 len = readlink (true_old_pathname, fully_resolved_old_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2104 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2105 fully_resolved_old_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2106 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2107 strcpy (fully_resolved_old_name, true_old_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2108
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2109 if (find_true_pathname (new_name, true_new_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2110 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2111
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2112 if (strcmp (fully_resolved_old_name, true_new_pathname) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2113 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2114
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2115 if (!posix_to_mac_pathname (fully_resolved_old_name,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2116 mac_old_name,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2117 MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2118 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2119
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2120 if (!posix_to_mac_pathname(true_new_pathname, mac_new_name, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2121 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2122
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2123 /* If a file with new_name already exists, rename deletes the old
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2124 file in Unix. CW version fails in these situation. So we add a
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2125 call to unlink here. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2126 (void) unlink (mac_new_name);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2127
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2128 return rename (mac_old_name, mac_new_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2129 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2130
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2131
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2132 #undef fopen
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2133 extern FILE *fopen (const char *name, const char *mode);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2134 FILE *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2135 sys_fopen (const char *name, const char *mode)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2136 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2137 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2138 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2139 char mac_pathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2140
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2141 if (find_true_pathname (name, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2142 return 0;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2143
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2144 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2145 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2146 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2147 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2148 strcpy (fully_resolved_name, true_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2149
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2150 if (!posix_to_mac_pathname (fully_resolved_name, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2151 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2152 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2153 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2154 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2155 if (mode[0] == 'w' || mode[0] == 'a')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2156 fsetfileinfo (mac_pathname, 'EMAx', 'TEXT');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2157 #endif /* not __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2158 return fopen (mac_pathname, mode);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2159 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2160 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2161
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2162
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2163 #include "keyboard.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2164 extern Boolean mac_wait_next_event (EventRecord *, UInt32, Boolean);
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2165
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2166 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2167 select (n, rfds, wfds, efds, timeout)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2168 int n;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2169 SELECT_TYPE *rfds;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2170 SELECT_TYPE *wfds;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2171 SELECT_TYPE *efds;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2172 struct timeval *timeout;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2173 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2174 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2175 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2176 EventTimeout timeout_sec =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2177 (timeout
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2178 ? (EMACS_SECS (*timeout) * kEventDurationSecond
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2179 + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2180 : kEventDurationForever);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2181
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2182 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2183 err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2184 UNBLOCK_INPUT;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2185 #else /* not TARGET_API_MAC_CARBON */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2186 EventRecord e;
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2187 UInt32 sleep_time = EMACS_SECS (*timeout) * 60 +
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2188 ((EMACS_USECS (*timeout) * 60) / 1000000);
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2189
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2190 /* Can only handle wait for keyboard input. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2191 if (n > 1 || wfds || efds)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2192 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2193
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2194 /* Also return true if an event other than a keyDown has occurred.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2195 This causes kbd_buffer_get_event in keyboard.c to call
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2196 read_avail_input which in turn calls XTread_socket to poll for
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2197 these events. Otherwise these never get processed except but a
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2198 very slow poll timer. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2199 if (mac_wait_next_event (&e, sleep_time, false))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2200 err = noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2201 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2202 err = -9875; /* eventLoopTimedOutErr */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2203 #endif /* not TARGET_API_MAC_CARBON */
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2204
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2205 if (FD_ISSET (0, rfds))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2206 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2207 return 1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2208 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2209 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2210 FD_ZERO (rfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2211 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2212 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2213 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2214 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2215 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2216 if (input_polling_used ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2217 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2218 /* It could be confusing if a real alarm arrives while
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2219 processing the fake one. Turn it off and let the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2220 handler reset it. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2221 extern void poll_for_input_1 P_ ((void));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2222 int old_poll_suppress_count = poll_suppress_count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2223 poll_suppress_count = 1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2224 poll_for_input_1 ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2225 poll_suppress_count = old_poll_suppress_count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2226 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2227 errno = EINTR;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2228 return -1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2229 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2230 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2231 return 0;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2232 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2233
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2234
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2235 /* Simulation of SIGALRM. The stub for function signal stores the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2236 signal handler function in alarm_signal_func if a SIGALRM is
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2237 encountered. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2238
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2239 #include <signal.h>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2240 #include "syssignal.h"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2241
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2242 static TMTask mac_atimer_task;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2243
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2244 static QElemPtr mac_atimer_qlink = (QElemPtr) &mac_atimer_task;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2245
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2246 static int signal_mask = 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2247
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2248 #ifdef __MRC__
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2249 __sigfun alarm_signal_func = (__sigfun) 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2250 #elif __MWERKS__
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2251 __signal_func_ptr alarm_signal_func = (__signal_func_ptr) 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2252 #else /* not __MRC__ and not __MWERKS__ */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2253 You lose!!!
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2254 #endif /* not __MRC__ and not __MWERKS__ */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2255
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2256 #undef signal
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2257 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2258 extern __sigfun signal (int signal, __sigfun signal_func);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2259 __sigfun
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2260 sys_signal (int signal_num, __sigfun signal_func)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2261 #elif __MWERKS__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2262 extern __signal_func_ptr signal (int signal, __signal_func_ptr signal_func);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2263 __signal_func_ptr
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2264 sys_signal (int signal_num, __signal_func_ptr signal_func)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2265 #else /* not __MRC__ and not __MWERKS__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2266 You lose!!!
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2267 #endif /* not __MRC__ and not __MWERKS__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2268 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2269 if (signal_num != SIGALRM)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2270 return signal (signal_num, signal_func);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2271 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2272 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2273 #ifdef __MRC__
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2274 __sigfun old_signal_func;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2275 #elif __MWERKS__
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2276 __signal_func_ptr old_signal_func;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2277 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2278 You lose!!!
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2279 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2280 old_signal_func = alarm_signal_func;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2281 alarm_signal_func = signal_func;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2282 return old_signal_func;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2283 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2284 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2285
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2286
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2287 static pascal void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2288 mac_atimer_handler (qlink)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2289 TMTaskPtr qlink;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2290 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2291 if (alarm_signal_func)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2292 (alarm_signal_func) (SIGALRM);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2293 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2294
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2295
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2296 static void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2297 set_mac_atimer (count)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2298 long count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2299 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2300 static TimerUPP mac_atimer_handlerUPP = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2301
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2302 if (mac_atimer_handlerUPP == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2303 mac_atimer_handlerUPP = NewTimerUPP (mac_atimer_handler);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2304 mac_atimer_task.tmCount = 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2305 mac_atimer_task.tmAddr = mac_atimer_handlerUPP;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2306 mac_atimer_qlink = (QElemPtr) &mac_atimer_task;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2307 InsTime (mac_atimer_qlink);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2308 if (count)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2309 PrimeTime (mac_atimer_qlink, count);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2310 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2311
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2312
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2313 int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2314 remove_mac_atimer (remaining_count)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2315 long *remaining_count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2316 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2317 if (mac_atimer_qlink)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2318 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2319 RmvTime (mac_atimer_qlink);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2320 if (remaining_count)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2321 *remaining_count = mac_atimer_task.tmCount;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2322 mac_atimer_qlink = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2323
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2324 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2325 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2326 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2327 return -1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2328 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2329
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2330
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2331 int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2332 sigblock (int mask)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2333 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2334 int old_mask = signal_mask;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2335
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2336 signal_mask |= mask;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2337
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2338 if ((old_mask ^ signal_mask) & sigmask (SIGALRM))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2339 remove_mac_atimer (NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2340
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2341 return old_mask;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2342 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2343
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2344
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2345 int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2346 sigsetmask (int mask)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2347 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2348 int old_mask = signal_mask;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2349
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2350 signal_mask = mask;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2351
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2352 if ((old_mask ^ signal_mask) & sigmask (SIGALRM))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2353 if (signal_mask & sigmask (SIGALRM))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2354 remove_mac_atimer (NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2355 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2356 set_mac_atimer (mac_atimer_task.tmCount);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2357
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2358 return old_mask;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2359 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2360
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2361
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2362 int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2363 alarm (int seconds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2364 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2365 long remaining_count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2366
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2367 if (remove_mac_atimer (&remaining_count) == 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2368 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2369 set_mac_atimer (seconds * 1000);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2370
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2371 return remaining_count / 1000;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2372 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2373 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2374 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2375 mac_atimer_task.tmCount = seconds * 1000;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2376
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2377 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2378 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2379 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2380
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2381
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2382 int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2383 setitimer (which, value, ovalue)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2384 int which;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2385 const struct itimerval *value;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2386 struct itimerval *ovalue;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2387 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2388 long remaining_count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2389 long count = (EMACS_SECS (value->it_value) * 1000
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2390 + (EMACS_USECS (value->it_value) + 999) / 1000);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2391
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2392 if (remove_mac_atimer (&remaining_count) == 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2393 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2394 if (ovalue)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2395 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2396 bzero (ovalue, sizeof (*ovalue));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2397 EMACS_SET_SECS_USECS (ovalue->it_value, remaining_count / 1000,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2398 (remaining_count % 1000) * 1000);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2399 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2400 set_mac_atimer (count);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2401 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2402 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2403 mac_atimer_task.tmCount = count;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2404
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2405 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2406 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2407
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2408
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2409 /* gettimeofday should return the amount of time (in a timeval
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2410 structure) since midnight today. The toolbox function Microseconds
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2411 returns the number of microseconds (in a UnsignedWide value) since
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2412 the machine was booted. Also making this complicated is WideAdd,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2413 WideSubtract, etc. take wide values. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2414
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2415 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2416 gettimeofday (tp)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2417 struct timeval *tp;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2418 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2419 static inited = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2420 static wide wall_clock_at_epoch, clicks_at_epoch;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2421 UnsignedWide uw_microseconds;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2422 wide w_microseconds;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2423 time_t sys_time (time_t *);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2424
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2425 /* If this function is called for the first time, record the number
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2426 of seconds since midnight and the number of microseconds since
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2427 boot at the time of this first call. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2428 if (!inited)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2429 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2430 time_t systime;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2431 inited = 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2432 systime = sys_time (NULL);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2433 /* Store microseconds since midnight in wall_clock_at_epoch. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2434 WideMultiply (systime, 1000000L, &wall_clock_at_epoch);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2435 Microseconds (&uw_microseconds);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2436 /* Store microseconds since boot in clicks_at_epoch. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2437 clicks_at_epoch.hi = uw_microseconds.hi;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2438 clicks_at_epoch.lo = uw_microseconds.lo;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2439 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2440
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2441 /* Get time since boot */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2442 Microseconds (&uw_microseconds);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2443
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2444 /* Convert to time since midnight*/
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2445 w_microseconds.hi = uw_microseconds.hi;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2446 w_microseconds.lo = uw_microseconds.lo;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2447 WideSubtract (&w_microseconds, &clicks_at_epoch);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2448 WideAdd (&w_microseconds, &wall_clock_at_epoch);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2449 tp->tv_sec = WideDivide (&w_microseconds, 1000000L, &tp->tv_usec);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2450
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2451 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2452 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2453
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2454
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2455 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2456 unsigned int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2457 sleep (unsigned int seconds)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2458 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2459 unsigned long time_up;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2460 EventRecord e;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2461
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2462 time_up = TickCount () + seconds * 60;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2463 while (TickCount () < time_up)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2464 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2465 /* Accept no event; just wait. by T.I. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2466 WaitNextEvent (0, &e, 30, NULL);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2467 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2468
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2469 return (0);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2470 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2471 #endif /* __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2472
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2473
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2474 /* The time functions adjust time values according to the difference
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2475 between the Unix and CW epoches. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2476
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2477 #undef gmtime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2478 extern struct tm *gmtime (const time_t *);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2479 struct tm *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2480 sys_gmtime (const time_t *timer)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2481 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2482 time_t unix_time = *timer + CW_OR_MPW_UNIX_EPOCH_DIFF;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2483
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2484 return gmtime (&unix_time);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2485 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2486
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2487
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2488 #undef localtime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2489 extern struct tm *localtime (const time_t *);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2490 struct tm *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2491 sys_localtime (const time_t *timer)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2492 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2493 #if __MSL__ >= 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2494 time_t unix_time = *timer;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2495 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2496 time_t unix_time = *timer + CW_OR_MPW_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2497 #endif
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2498
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2499 return localtime (&unix_time);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2500 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2501
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2502
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2503 #undef ctime
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2504 extern char *ctime (const time_t *);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2505 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2506 sys_ctime (const time_t *timer)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2507 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2508 #if __MSL__ >= 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2509 time_t unix_time = *timer;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2510 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2511 time_t unix_time = *timer + CW_OR_MPW_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2512 #endif
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2513
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2514 return ctime (&unix_time);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2515 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2516
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2517
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2518 #undef time
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2519 extern time_t time (time_t *);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2520 time_t
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2521 sys_time (time_t *timer)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2522 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2523 #if __MSL__ >= 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2524 time_t mac_time = time (NULL);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2525 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2526 time_t mac_time = time (NULL) - CW_OR_MPW_UNIX_EPOCH_DIFF;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2527 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2528
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2529 if (timer)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2530 *timer = mac_time;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2531
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2532 return mac_time;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2533 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2534
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2535
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2536 /* no subprocesses, empty wait */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2537
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2538 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2539 wait (int pid)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2540 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2541 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2542 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2543
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2544
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2545 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2546 croak (char *badfunc)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2547 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2548 printf ("%s not yet implemented\r\n", badfunc);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2549 exit (1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2550 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2551
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2552
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2553 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2554 mktemp (char *template)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2555 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2556 int len, k;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2557 static seqnum = 0;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2558
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2559 len = strlen (template);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2560 k = len - 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2561 while (k >= 0 && template[k] == 'X')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2562 k--;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2563
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2564 k++; /* make k index of first 'X' */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2565
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2566 if (k < len)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2567 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2568 /* Zero filled, number of digits equal to the number of X's. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2569 sprintf (&template[k], "%0*d", len-k, seqnum++);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2570
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2571 return template;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2572 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2573 else
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2574 return 0;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2575 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2576
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2577
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2578 /* Emulate getpwuid, getpwnam and others. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2579
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2580 #define PASSWD_FIELD_SIZE 256
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2581
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2582 static char my_passwd_name[PASSWD_FIELD_SIZE];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2583 static char my_passwd_dir[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2584
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2585 static struct passwd my_passwd =
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2586 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2587 my_passwd_name,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2588 my_passwd_dir,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2589 };
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2590
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2591 static struct group my_group =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2592 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2593 /* There are no groups on the mac, so we just return "root" as the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2594 group name. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2595 "root",
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2596 };
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2597
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2598
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2599 /* Initialized by main () in macterm.c to pathname of emacs directory. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2600
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2601 char emacs_passwd_dir[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2602
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2603 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2604 getwd (char *);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2605
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2606 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2607 init_emacs_passwd_dir ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2608 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2609 int found = false;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2610
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2611 if (getwd (emacs_passwd_dir) && getwd (my_passwd_dir))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2612 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2613 /* Need pathname of first ancestor that begins with "emacs"
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2614 since Mac emacs application is somewhere in the emacs-*
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2615 tree. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2616 int len = strlen (emacs_passwd_dir);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2617 int j = len - 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2618 /* j points to the "/" following the directory name being
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2619 compared. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2620 int i = j - 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2621 while (i >= 0 && !found)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2622 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2623 while (i >= 0 && emacs_passwd_dir[i] != '/')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2624 i--;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2625 if (emacs_passwd_dir[i] == '/' && i+5 < len)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2626 found = (strncmp (&(emacs_passwd_dir[i+1]), "emacs", 5) == 0);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2627 if (found)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2628 emacs_passwd_dir[j+1] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2629 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2630 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2631 j = i;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2632 i = j - 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2633 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2634 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2635 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2636
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2637 if (!found)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2638 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2639 /* Setting to "/" probably won't work but set it to something
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2640 anyway. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2641 strcpy (emacs_passwd_dir, "/");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2642 strcpy (my_passwd_dir, "/");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2643 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2644 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2645
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2646
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2647 static struct passwd emacs_passwd =
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2648 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2649 "emacs",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2650 emacs_passwd_dir,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2651 };
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2652
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2653 static int my_passwd_inited = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2654
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2655
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2656 static void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2657 init_my_passwd ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2658 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2659 char **owner_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2660
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2661 /* Note: my_passwd_dir initialized in int_emacs_passwd_dir to
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2662 directory where Emacs was started. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2663
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2664 owner_name = (char **) GetResource ('STR ',-16096);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2665 if (owner_name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2666 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2667 HLock (owner_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2668 BlockMove ((unsigned char *) *owner_name,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2669 (unsigned char *) my_passwd_name,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2670 *owner_name[0]+1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2671 HUnlock (owner_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2672 p2cstr ((unsigned char *) my_passwd_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2673 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2674 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2675 my_passwd_name[0] = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2676 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2677
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2678
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2679 struct passwd *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2680 getpwuid (uid_t uid)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2681 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2682 if (!my_passwd_inited)
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2683 {
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2684 init_my_passwd ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2685 my_passwd_inited = 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2686 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2687
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2688 return &my_passwd;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2689 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2690
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2691
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2692 struct group *
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2693 getgrgid (gid_t gid)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2694 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2695 return &my_group;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2696 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2697
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2698
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2699 struct passwd *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2700 getpwnam (const char *name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2701 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2702 if (strcmp (name, "emacs") == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2703 return &emacs_passwd;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2704
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2705 if (!my_passwd_inited)
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2706 {
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2707 init_my_passwd ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2708 my_passwd_inited = 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2709 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2710
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2711 return &my_passwd;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2712 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2713
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2714
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2715 /* The functions fork, kill, sigsetmask, sigblock, request_sigio,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2716 setpgrp, setpriority, and unrequest_sigio are defined to be empty
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2717 as in msdos.c. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2718
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2719
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2720 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2721 fork ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2722 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2723 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2724 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2725
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2726
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2727 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2728 kill (int x, int y)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2729 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2730 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2731 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2732
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2733
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2734 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2735 sys_subshell ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2736 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2737 error ("Can't spawn subshell");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2738 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2739
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2740
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2741 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2742 request_sigio (void)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2743 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2744 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2745
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2746
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2747 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2748 unrequest_sigio (void)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2749 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2750 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2751
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2752
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2753 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2754 setpgrp ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2755 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2756 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2757 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2758
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2759
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2760 /* No pipes yet. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2761
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2762 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2763 pipe (int _fildes[2])
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2764 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2765 errno = EACCES;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2766 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2767 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2768
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2769
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2770 /* Hard and symbolic links. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2771
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2772 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2773 symlink (const char *name1, const char *name2)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2774 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2775 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2776 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2777 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2778
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2779
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2780 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2781 link (const char *name1, const char *name2)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2782 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2783 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2784 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2785 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2786
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2787 #endif /* ! MAC_OSX */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2788
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2789 /* Determine the path name of the file specified by VREFNUM, DIRID,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2790 and NAME and place that in the buffer PATH of length
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2791 MAXPATHLEN. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2792 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2793 path_from_vol_dir_name (char *path, int man_path_len, short vol_ref_num,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2794 long dir_id, ConstStr255Param name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2795 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2796 Str255 dir_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2797 CInfoPBRec cipb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2798 OSErr err;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2799
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2800 if (strlen (name) > man_path_len)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2801 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2802
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2803 memcpy (dir_name, name, name[0]+1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2804 memcpy (path, name, name[0]+1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2805 p2cstr (path);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2806
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2807 cipb.dirInfo.ioDrParID = dir_id;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2808 cipb.dirInfo.ioNamePtr = dir_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2809
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2810 do
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2811 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2812 cipb.dirInfo.ioVRefNum = vol_ref_num;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2813 cipb.dirInfo.ioFDirIndex = -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2814 cipb.dirInfo.ioDrDirID = cipb.dirInfo.ioDrParID;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2815 /* go up to parent each time */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2816
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2817 err = PBGetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2818 if (err != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2819 return 0;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2820
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2821 p2cstr (dir_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2822 if (strlen (dir_name) + strlen (path) + 1 >= man_path_len)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2823 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2824
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2825 strcat (dir_name, ":");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2826 strcat (dir_name, path);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2827 /* attach to front since we're going up directory tree */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2828 strcpy (path, dir_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2829 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2830 while (cipb.dirInfo.ioDrDirID != fsRtDirID);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2831 /* stop when we see the volume's root directory */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2832
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2833 return 1; /* success */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2834 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2835
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2836
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2837 static OSErr
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2838 posix_pathname_to_fsspec (ufn, fs)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2839 const char *ufn;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2840 FSSpec *fs;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2841 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2842 Str255 mac_pathname;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2843
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2844 if (posix_to_mac_pathname (ufn, mac_pathname, sizeof (mac_pathname)) == 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2845 return fnfErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2846 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2847 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2848 c2pstr (mac_pathname);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2849 return FSMakeFSSpec (0, 0, mac_pathname, fs);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2850 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2851 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2852
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2853 static OSErr
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2854 fsspec_to_posix_pathname (fs, ufn, ufnbuflen)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2855 const FSSpec *fs;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2856 char *ufn;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2857 int ufnbuflen;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2858 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2859 char mac_pathname[MAXPATHLEN];
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2860
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2861 if (path_from_vol_dir_name (mac_pathname, sizeof (mac_pathname) - 1,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2862 fs->vRefNum, fs->parID, fs->name)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2863 && mac_to_posix_pathname (mac_pathname, ufn, ufnbuflen))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2864 return noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2865 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2866 return fnfErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2867 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2868
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2869 #ifndef MAC_OSX
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2870
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2871 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2872 readlink (const char *path, char *buf, int bufsiz)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2873 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2874 char mac_sym_link_name[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2875 OSErr err;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2876 FSSpec fsspec;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2877 Boolean target_is_folder, was_aliased;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2878 Str255 directory_name, mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2879 CInfoPBRec cipb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2880
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2881 if (posix_to_mac_pathname (path, mac_sym_link_name, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2882 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2883
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2884 c2pstr (mac_sym_link_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2885 err = FSMakeFSSpec (0, 0, mac_sym_link_name, &fsspec);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2886 if (err != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2887 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2888 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2889 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2890 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2891
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2892 err = ResolveAliasFile (&fsspec, true, &target_is_folder, &was_aliased);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2893 if (err != noErr || !was_aliased)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2894 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2895 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2896 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2897 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2898
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2899 if (path_from_vol_dir_name (mac_pathname, 255, fsspec.vRefNum, fsspec.parID,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2900 fsspec.name) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2901 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2902 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2903 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2904 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2905
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2906 if (mac_to_posix_pathname (mac_pathname, buf, bufsiz) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2907 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2908 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2909 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2910 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2911
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2912 return strlen (buf);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2913 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2914
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2915
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2916 /* Convert a path to one with aliases fully expanded. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2917
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2918 static int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2919 find_true_pathname (const char *path, char *buf, int bufsiz)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2920 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2921 char *q, temp[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2922 const char *p;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2923 int len;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2924
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2925 if (bufsiz <= 0 || path == 0 || path[0] == '\0')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2926 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2927
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2928 buf[0] = '\0';
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2929
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2930 p = path;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2931 if (*p == '/')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2932 q = strchr (p + 1, '/');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2933 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2934 q = strchr (p, '/');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2935 len = 0; /* loop may not be entered, e.g., for "/" */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2936
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2937 while (q)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2938 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2939 strcpy (temp, buf);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2940 strncat (temp, p, q - p);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2941 len = readlink (temp, buf, bufsiz);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2942 if (len <= -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2943 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2944 if (strlen (temp) + 1 > bufsiz)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2945 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2946 strcpy (buf, temp);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2947 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2948 strcat (buf, "/");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2949 len++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2950 p = q + 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2951 q = strchr(p, '/');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2952 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2953
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2954 if (len + strlen (p) + 1 >= bufsiz)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2955 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
2956
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2957 strcat (buf, p);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2958 return len + strlen (p);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2959 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2960
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2961
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2962 mode_t
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2963 umask (mode_t numask)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2964 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2965 static mode_t mask = 022;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2966 mode_t oldmask = mask;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2967 mask = numask;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2968 return oldmask;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2969 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2970
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2971
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2972 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2973 chmod (const char *path, mode_t mode)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2974 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2975 /* say it always succeed for now */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2976 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2977 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2978
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2979
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2980 int
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2981 fchmod (int fd, mode_t mode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2982 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2983 /* say it always succeed for now */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2984 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2985 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2986
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2987
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2988 int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2989 fchown (int fd, uid_t owner, gid_t group)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2990 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2991 /* say it always succeed for now */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2992 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2993 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2994
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2995
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
2996 int
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2997 dup (int oldd)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2998 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
2999 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3000 return fcntl (oldd, F_DUPFD, 0);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3001 #elif __MWERKS__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3002 /* current implementation of fcntl in fcntl.mac.c simply returns old
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3003 descriptor */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3004 return fcntl (oldd, F_DUPFD);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3005 #else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3006 You lose!!!
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3007 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3008 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3009
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3010
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3011 /* This is from the original sysdep.c. Emulate BSD dup2. First close
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3012 newd if it already exists. Then, attempt to dup oldd. If not
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3013 successful, call dup2 recursively until we are, then close the
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3014 unsuccessful ones. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3015
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3016 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3017 dup2 (int oldd, int newd)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3018 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3019 int fd, ret;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3020
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3021 close (newd);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3022
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3023 fd = dup (oldd);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3024 if (fd == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3025 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3026 if (fd == newd)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3027 return newd;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3028 ret = dup2 (oldd, newd);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3029 close (fd);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3030 return ret;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3031 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3032
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3033
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3034 /* let it fail for now */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3035
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3036 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3037 sbrk (int incr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3038 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3039 return (char *) -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3040 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3041
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3042
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3043 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3044 fsync (int fd)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3045 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3046 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3047 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3048
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3049
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3050 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3051 ioctl (int d, int request, void *argp)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3052 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3053 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3054 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3055
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3056
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3057 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3058 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3059 isatty (int fildes)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3060 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3061 if (fildes >=0 && fildes <= 2)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3062 return 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3063 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3064 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3065 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3066
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3067
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3068 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3069 getgid ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3070 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3071 return 100;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3072 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3073
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3074
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3075 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3076 getegid ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3077 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3078 return 100;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3079 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3080
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3081
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3082 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3083 getuid ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3084 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3085 return 200;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3086 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3087
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3088
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3089 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3090 geteuid ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3091 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3092 return 200;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3093 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3094 #endif /* __MRC__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3095
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3096
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3097 #ifdef __MWERKS__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3098 #if __MSL__ < 0x6000
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3099 #undef getpid
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3100 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3101 getpid ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3102 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3103 return 9999;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3104 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3105 #endif
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3106 #endif /* __MWERKS__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3107
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3108 #endif /* ! MAC_OSX */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3109
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3110
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3111 /* Return the path to the directory in which Emacs can create
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3112 temporary files. The MacOS "temporary items" directory cannot be
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3113 used because it removes the file written by a process when it
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3114 exits. In that sense it's more like "/dev/null" than "/tmp" (but
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3115 again not exactly). And of course Emacs needs to read back the
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3116 files written by its subprocesses. So here we write the files to a
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3117 directory "Emacs" in the Preferences Folder. This directory is
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3118 created if it does not exist. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3119
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3120 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3121 get_temp_dir_name ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3122 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3123 static char *temp_dir_name = NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3124 short vol_ref_num;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3125 long dir_id;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3126 OSErr err;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3127 Str255 dir_name, full_path;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3128 CInfoPBRec cpb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3129 char unix_dir_name[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3130 DIR *dir;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3131
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3132 /* Cache directory name with pointer temp_dir_name.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3133 Look for it only the first time. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3134 if (!temp_dir_name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3135 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3136 err = FindFolder (kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3137 &vol_ref_num, &dir_id);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3138 if (err != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3139 return NULL;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3140
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3141 if (!path_from_vol_dir_name (full_path, 255, vol_ref_num, dir_id, "\p"))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3142 return NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3143
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3144 if (strlen (full_path) + 6 <= MAXPATHLEN)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3145 strcat (full_path, "Emacs:");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3146 else
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3147 return NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3148
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3149 if (!mac_to_posix_pathname (full_path, unix_dir_name, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3150 return NULL;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3151
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3152 dir = opendir (unix_dir_name); /* check whether temp directory exists */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3153 if (dir)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3154 closedir (dir);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3155 else if (mkdir (unix_dir_name, 0700) != 0) /* create it if not */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3156 return NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3157
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3158 temp_dir_name = (char *) malloc (strlen (unix_dir_name) + 1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3159 strcpy (temp_dir_name, unix_dir_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3160 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3161
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3162 return temp_dir_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3163 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3164
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3165 #ifndef MAC_OSX
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3166
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3167 /* Allocate and construct an array of pointers to strings from a list
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3168 of strings stored in a 'STR#' resource. The returned pointer array
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3169 is stored in the style of argv and environ: if the 'STR#' resource
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3170 contains numString strings, a pointer array with numString+1
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3171 elements is returned in which the last entry contains a null
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3172 pointer. The pointer to the pointer array is passed by pointer in
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3173 parameter t. The resource ID of the 'STR#' resource is passed in
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3174 parameter StringListID.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3175 */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3176
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3177 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3178 get_string_list (char ***t, short string_list_id)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3179 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3180 Handle h;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3181 Ptr p;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3182 int i, num_strings;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3183
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3184 h = GetResource ('STR#', string_list_id);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3185 if (h)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3186 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3187 HLock (h);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3188 p = *h;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3189 num_strings = * (short *) p;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3190 p += sizeof(short);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3191 *t = (char **) malloc (sizeof (char *) * (num_strings + 1));
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3192 for (i = 0; i < num_strings; i++)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3193 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3194 short length = *p++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3195 (*t)[i] = (char *) malloc (length + 1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3196 strncpy ((*t)[i], p, length);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3197 (*t)[i][length] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3198 p += length;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3199 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3200 (*t)[num_strings] = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3201 HUnlock (h);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3202 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3203 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3204 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3205 /* Return no string in case GetResource fails. Bug fixed by
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3206 Ikegami Tsutomu. Caused MPW build to crash without sym -on
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3207 option (no sym -on implies -opt local). */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3208 *t = (char **) malloc (sizeof (char *));
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3209 (*t)[0] = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3210 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3211 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3212
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3213
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3214 static char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3215 get_path_to_system_folder ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3216 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3217 short vol_ref_num;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3218 long dir_id;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3219 OSErr err;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3220 Str255 dir_name, full_path;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3221 CInfoPBRec cpb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3222 static char system_folder_unix_name[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3223 DIR *dir;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3224
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3225 err = FindFolder (kOnSystemDisk, kSystemFolderType, kDontCreateFolder,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3226 &vol_ref_num, &dir_id);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3227 if (err != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3228 return NULL;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3229
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3230 if (!path_from_vol_dir_name (full_path, 255, vol_ref_num, dir_id, "\p"))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3231 return NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3232
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3233 if (!mac_to_posix_pathname (full_path, system_folder_unix_name,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3234 MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3235 return NULL;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3236
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3237 return system_folder_unix_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3238 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3239
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3240
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3241 char **environ;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3242
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3243 #define ENVIRON_STRING_LIST_ID 128
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3244
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3245 /* Get environment variable definitions from STR# resource. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3246
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3247 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3248 init_environ ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3249 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3250 int i;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3251
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3252 get_string_list (&environ, ENVIRON_STRING_LIST_ID);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3253
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3254 i = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3255 while (environ[i])
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3256 i++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3257
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3258 /* Make HOME directory the one Emacs starts up in if not specified
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3259 by resource. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3260 if (getenv ("HOME") == NULL)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3261 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3262 environ = (char **) realloc (environ, sizeof (char *) * (i + 2));
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3263 if (environ)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3264 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3265 environ[i] = (char *) malloc (strlen (my_passwd_dir) + 6);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3266 if (environ[i])
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3267 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3268 strcpy (environ[i], "HOME=");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3269 strcat (environ[i], my_passwd_dir);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3270 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3271 environ[i+1] = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3272 i++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3273 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3274 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3275
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3276 /* Make HOME directory the one Emacs starts up in if not specified
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3277 by resource. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3278 if (getenv ("MAIL") == NULL)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3279 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3280 environ = (char **) realloc (environ, sizeof (char *) * (i + 2));
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3281 if (environ)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3282 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3283 char * path_to_system_folder = get_path_to_system_folder ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3284 environ[i] = (char *) malloc (strlen (path_to_system_folder) + 22);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3285 if (environ[i])
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3286 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3287 strcpy (environ[i], "MAIL=");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3288 strcat (environ[i], path_to_system_folder);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3289 strcat (environ[i], "Eudora Folder/In");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3290 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3291 environ[i+1] = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3292 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3293 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3294 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3295
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3296
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3297 /* Return the value of the environment variable NAME. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3298
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3299 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3300 getenv (const char *name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3301 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3302 int length = strlen(name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3303 char **e;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3304
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3305 for (e = environ; *e != 0; e++)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3306 if (strncmp(*e, name, length) == 0 && (*e)[length] == '=')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3307 return &(*e)[length + 1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3308
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3309 if (strcmp (name, "TMPDIR") == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3310 return get_temp_dir_name ();
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3311
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3312 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3313 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3314
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3315
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3316 #ifdef __MRC__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3317 /* see Interfaces&Libraries:Interfaces:CIncludes:signal.h */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3318 char *sys_siglist[] =
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3319 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3320 "Zero is not a signal!!!",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3321 "Abort", /* 1 */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3322 "Interactive user interrupt", /* 2 */ "?",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3323 "Floating point exception", /* 4 */ "?", "?", "?",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3324 "Illegal instruction", /* 8 */ "?", "?", "?", "?", "?", "?", "?",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3325 "Segment violation", /* 16 */ "?", "?", "?", "?", "?", "?", "?",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3326 "?", "?", "?", "?", "?", "?", "?", "?",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3327 "Terminal" /* 32 */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3328 };
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3329 #elif __MWERKS__
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3330 char *sys_siglist[] =
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3331 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3332 "Zero is not a signal!!!",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3333 "Abort",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3334 "Floating point exception",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3335 "Illegal instruction",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3336 "Interactive user interrupt",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3337 "Segment violation",
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3338 "Terminal"
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3339 };
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3340 #else /* not __MRC__ and not __MWERKS__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3341 You lose!!!
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3342 #endif /* not __MRC__ and not __MWERKS__ */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3343
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3344
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3345 #include <utsname.h>
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3346
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3347 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3348 uname (struct utsname *name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3349 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3350 char **system_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3351 system_name = GetString (-16413); /* IM - Resource Manager Reference */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3352 if (system_name)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3353 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3354 BlockMove (*system_name, name->nodename, (*system_name)[0]+1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3355 p2cstr (name->nodename);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3356 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3357 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3358 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3359 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3360 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3361
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3362
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3363 /* Event class of HLE sent to subprocess. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3364 const OSType kEmacsSubprocessSend = 'ESND';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3365
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3366 /* Event class of HLE sent back from subprocess. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3367 const OSType kEmacsSubprocessReply = 'ERPY';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3368
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3369
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3370 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3371 mystrchr (char *s, char c)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3372 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3373 while (*s && *s != c)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3374 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3375 if (*s == '\\')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3376 s++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3377 s++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3378 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3379
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3380 if (*s)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3381 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3382 *s = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3383 return s;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3384 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3385 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3386 return NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3387 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3388
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3389
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3390 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3391 mystrtok (char *s)
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3392 {
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3393 while (*s)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3394 s++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3395
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3396 return s + 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3397 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3398
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3399
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3400 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3401 mystrcpy (char *to, char *from)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3402 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3403 while (*from)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3404 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3405 if (*from == '\\')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3406 from++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3407 *to++ = *from++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3408 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3409 *to = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3410 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3411
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3412
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3413 /* Start a Mac subprocess. Arguments for it is passed in argv (null
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3414 terminated). The process should run with the default directory
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3415 "workdir", read input from "infn", and write output and error to
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3416 "outfn" and "errfn", resp. The Process Manager call
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3417 LaunchApplication is used to start the subprocess. We use high
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3418 level events as the mechanism to pass arguments to the subprocess
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3419 and to make Emacs wait for the subprocess to terminate and pass
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3420 back a result code. The bulk of the code here packs the arguments
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3421 into one message to be passed together with the high level event.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3422 Emacs also sometimes starts a subprocess using a shell to perform
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3423 wildcard filename expansion. Since we don't really have a shell on
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3424 the Mac, this case is detected and the starting of the shell is
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3425 by-passed. We really need to add code here to do filename
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3426 expansion to support such functionality.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3427
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3428 We can't use this strategy in Carbon because the High Level Event
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3429 APIs are not available. */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3430
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3431 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3432 run_mac_command (argv, workdir, infn, outfn, errfn)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3433 unsigned char **argv;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3434 const char *workdir;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3435 const char *infn, *outfn, *errfn;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3436 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3437 #if TARGET_API_MAC_CARBON
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3438 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3439 #else /* not TARGET_API_MAC_CARBON */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3440 char macappname[MAXPATHLEN+1], macworkdir[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3441 char macinfn[MAXPATHLEN+1], macoutfn[MAXPATHLEN+1], macerrfn[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3442 int paramlen, argc, newargc, j, retries;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3443 char **newargv, *param, *p;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3444 OSErr iErr;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3445 FSSpec spec;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3446 LaunchParamBlockRec lpbr;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3447 EventRecord send_event, reply_event;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3448 RgnHandle cursor_region_handle;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3449 TargetID targ;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3450 unsigned long ref_con, len;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3451
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3452 if (posix_to_mac_pathname (workdir, macworkdir, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3453 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3454 if (posix_to_mac_pathname (infn, macinfn, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3455 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3456 if (posix_to_mac_pathname (outfn, macoutfn, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3457 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3458 if (posix_to_mac_pathname (errfn, macerrfn, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3459 return -1;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3460
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3461 paramlen = strlen (macworkdir) + strlen (macinfn) + strlen (macoutfn)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3462 + strlen (macerrfn) + 4; /* count nulls at end of strings */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3463
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3464 argc = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3465 while (argv[argc])
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3466 argc++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3467
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3468 if (argc == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3469 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3470
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3471 /* If a subprocess is invoked with a shell, we receive 3 arguments
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3472 of the form: "<path to emacs bins>/sh" "-c" "<path to emacs
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3473 bins>/<command> <command args>" */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3474 j = strlen (argv[0]);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3475 if (j >= 3 && strcmp (argv[0]+j-3, "/sh") == 0
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3476 && argc == 3 && strcmp (argv[1], "-c") == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3477 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3478 char *command, *t, tempmacpathname[MAXPATHLEN+1];
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3479
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3480 /* The arguments for the command in argv[2] are separated by
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3481 spaces. Count them and put the count in newargc. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3482 command = (char *) alloca (strlen (argv[2])+2);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3483 strcpy (command, argv[2]);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3484 if (command[strlen (command) - 1] != ' ')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3485 strcat (command, " ");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3486
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3487 t = command;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3488 newargc = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3489 t = mystrchr (t, ' ');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3490 while (t)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3491 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3492 newargc++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3493 t = mystrchr (t+1, ' ');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3494 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3495
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3496 newargv = (char **) alloca (sizeof (char *) * newargc);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3497
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3498 t = command;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3499 for (j = 0; j < newargc; j++)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3500 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3501 newargv[j] = (char *) alloca (strlen (t) + 1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3502 mystrcpy (newargv[j], t);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3503
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3504 t = mystrtok (t);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3505 paramlen += strlen (newargv[j]) + 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3506 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3507
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3508 if (strncmp (newargv[0], "~emacs/", 7) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3509 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3510 if (posix_to_mac_pathname (newargv[0], tempmacpathname, MAXPATHLEN+1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3511 == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3512 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3513 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3514 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3515 { /* sometimes Emacs call "sh" without a path for the command */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3516 #if 0
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3517 char *t = (char *) alloca (strlen (newargv[0]) + 7 + 1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3518 strcpy (t, "~emacs/");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3519 strcat (t, newargv[0]);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3520 #endif /* 0 */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3521 Lisp_Object path;
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3522 openp (Vexec_path, build_string (newargv[0]), Vexec_suffixes, &path,
45004
303384b6edc4 (run_mac_command): Update call to openp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 44890
diff changeset
3523 make_number (X_OK));
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3524
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3525 if (NILP (path))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3526 return -1;
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45851
diff changeset
3527 if (posix_to_mac_pathname (SDATA (path), tempmacpathname,
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3528 MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3529 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3530 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3531 strcpy (macappname, tempmacpathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3532 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3533 else
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3534 {
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3535 if (posix_to_mac_pathname (argv[0], macappname, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3536 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3537
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3538 newargv = (char **) alloca (sizeof (char *) * argc);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3539 newargc = argc;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3540 for (j = 1; j < argc; j++)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3541 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3542 if (strncmp (argv[j], "~emacs/", 7) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3543 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3544 char *t = strchr (argv[j], ' ');
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3545 if (t)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3546 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3547 char tempcmdname[MAXPATHLEN+1], tempmaccmdname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3548 strncpy (tempcmdname, argv[j], t-argv[j]);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3549 tempcmdname[t-argv[j]] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3550 if (posix_to_mac_pathname (tempcmdname, tempmaccmdname,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3551 MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3552 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3553 newargv[j] = (char *) alloca (strlen (tempmaccmdname)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3554 + strlen (t) + 1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3555 strcpy (newargv[j], tempmaccmdname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3556 strcat (newargv[j], t);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3557 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3558 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3559 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3560 char tempmaccmdname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3561 if (posix_to_mac_pathname (argv[j], tempmaccmdname,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3562 MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3563 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3564 newargv[j] = (char *) alloca (strlen (tempmaccmdname)+1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3565 strcpy (newargv[j], tempmaccmdname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3566 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3567 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3568 else
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3569 newargv[j] = argv[j];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3570 paramlen += strlen (newargv[j]) + 1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3571 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3572 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3573
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3574 /* After expanding all the arguments, we now know the length of the
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3575 parameter block to be sent to the subprocess as a message
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3576 attached to the HLE. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3577 param = (char *) malloc (paramlen + 1);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3578 if (!param)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3579 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3580
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3581 p = param;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3582 *p++ = newargc;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3583 /* first byte of message contains number of arguments for command */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3584 strcpy (p, macworkdir);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3585 p += strlen (macworkdir);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3586 *p++ = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3587 /* null terminate strings sent so it's possible to use strcpy over there */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3588 strcpy (p, macinfn);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3589 p += strlen (macinfn);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3590 *p++ = '\0';
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3591 strcpy (p, macoutfn);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3592 p += strlen (macoutfn);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3593 *p++ = '\0';
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3594 strcpy (p, macerrfn);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3595 p += strlen (macerrfn);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3596 *p++ = '\0';
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3597 for (j = 1; j < newargc; j++)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3598 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3599 strcpy (p, newargv[j]);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3600 p += strlen (newargv[j]);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3601 *p++ = '\0';
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3602 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3603
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3604 c2pstr (macappname);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3605
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3606 iErr = FSMakeFSSpec (0, 0, macappname, &spec);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3607
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3608 if (iErr != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3609 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3610 free (param);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3611 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3612 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3613
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3614 lpbr.launchBlockID = extendedBlock;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3615 lpbr.launchEPBLength = extendedBlockLen;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3616 lpbr.launchControlFlags = launchContinue + launchNoFileFlags;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3617 lpbr.launchAppSpec = &spec;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3618 lpbr.launchAppParameters = NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3619
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3620 iErr = LaunchApplication (&lpbr); /* call the subprocess */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3621 if (iErr != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3622 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3623 free (param);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3624 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3625 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3626
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3627 send_event.what = kHighLevelEvent;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3628 send_event.message = kEmacsSubprocessSend;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3629 /* Event ID stored in "where" unused */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3630
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3631 retries = 3;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3632 /* OS may think current subprocess has terminated if previous one
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3633 terminated recently. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3634 do
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3635 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3636 iErr = PostHighLevelEvent (&send_event, &lpbr.launchProcessSN, 0, param,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3637 paramlen + 1, receiverIDisPSN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3638 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3639 while (iErr == sessClosedErr && retries-- > 0);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3640
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3641 if (iErr != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3642 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3643 free (param);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3644 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3645 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3646
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3647 cursor_region_handle = NewRgn ();
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3648
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3649 /* Wait for the subprocess to finish, when it will send us a ERPY
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3650 high level event. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3651 while (1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3652 if (WaitNextEvent (highLevelEventMask, &reply_event, 180,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3653 cursor_region_handle)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3654 && reply_event.message == kEmacsSubprocessReply)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3655 break;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3656
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3657 /* The return code is sent through the refCon */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3658 iErr = AcceptHighLevelEvent (&targ, &ref_con, NULL, &len);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3659 if (iErr != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3660 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3661 DisposeHandle ((Handle) cursor_region_handle);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3662 free (param);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3663 return -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3664 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3665
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3666 DisposeHandle ((Handle) cursor_region_handle);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3667 free (param);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3668
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3669 return ref_con;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3670 #endif /* not TARGET_API_MAC_CARBON */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3671 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3672
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3673
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3674 DIR *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3675 opendir (const char *dirname)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3676 {
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3677 char true_pathname[MAXPATHLEN+1], fully_resolved_name[MAXPATHLEN+1];
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3678 char mac_pathname[MAXPATHLEN+1], vol_name[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3679 DIR *dirp;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3680 CInfoPBRec cipb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3681 HVolumeParam vpb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3682 int len, vol_name_len;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3683
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3684 if (find_true_pathname (dirname, true_pathname, MAXPATHLEN+1) == -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3685 return 0;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3686
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3687 len = readlink (true_pathname, fully_resolved_name, MAXPATHLEN);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3688 if (len > -1)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3689 fully_resolved_name[len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3690 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3691 strcpy (fully_resolved_name, true_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3692
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3693 dirp = (DIR *) malloc (sizeof(DIR));
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3694 if (!dirp)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3695 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3696
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3697 /* Handle special case when dirname is "/": sets up for readir to
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3698 get all mount volumes. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3699 if (strcmp (fully_resolved_name, "/") == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3700 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3701 dirp->getting_volumes = 1; /* special all mounted volumes DIR struct */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3702 dirp->current_index = 1; /* index for first volume */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3703 return dirp;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3704 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3705
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3706 /* Handle typical cases: not accessing all mounted volumes. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3707 if (!posix_to_mac_pathname (fully_resolved_name, mac_pathname, MAXPATHLEN+1))
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3708 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3709
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3710 /* Emacs calls opendir without the trailing '/', Mac needs trailing ':' */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3711 len = strlen (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3712 if (mac_pathname[len - 1] != ':' && len < MAXPATHLEN)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3713 strcat (mac_pathname, ":");
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3714
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3715 /* Extract volume name */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3716 vol_name_len = strchr (mac_pathname, ':') - mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3717 strncpy (vol_name, mac_pathname, vol_name_len);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3718 vol_name[vol_name_len] = '\0';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3719 strcat (vol_name, ":");
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3720
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3721 c2pstr (mac_pathname);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3722 cipb.hFileInfo.ioNamePtr = mac_pathname;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3723 /* using full pathname so vRefNum and DirID ignored */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3724 cipb.hFileInfo.ioVRefNum = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3725 cipb.hFileInfo.ioDirID = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3726 cipb.hFileInfo.ioFDirIndex = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3727 /* set to 0 to get information about specific dir or file */
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3728
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3729 errno = PBGetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3730 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3731 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3732 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3733 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3734 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3735
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3736 if (!(cipb.hFileInfo.ioFlAttrib & 0x10)) /* bit 4 = 1 for directories */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3737 return 0; /* not a directory */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3738
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3739 dirp->dir_id = cipb.dirInfo.ioDrDirID; /* used later in readdir */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3740 dirp->getting_volumes = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3741 dirp->current_index = 1; /* index for first file/directory */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3742
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3743 c2pstr (vol_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3744 vpb.ioNamePtr = vol_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3745 /* using full pathname so vRefNum and DirID ignored */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3746 vpb.ioVRefNum = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3747 vpb.ioVolIndex = -1;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3748 errno = PBHGetVInfo ((union HParamBlockRec *) &vpb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3749 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3750 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3751 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3752 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3753 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3754
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3755 dirp->vol_ref_num = vpb.ioVRefNum;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3756
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3757 return dirp;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3758 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3759
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3760 int
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3761 closedir (DIR *dp)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3762 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3763 free (dp);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3764
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3765 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3766 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3767
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3768
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3769 struct dirent *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3770 readdir (DIR *dp)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3771 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3772 HParamBlockRec hpblock;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3773 CInfoPBRec cipb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3774 static struct dirent s_dirent;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3775 static Str255 s_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3776 int done;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3777 char *p;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3778
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3779 /* Handle the root directory containing the mounted volumes. Call
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3780 PBHGetVInfo specifying an index to obtain the info for a volume.
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3781 PBHGetVInfo returns an error when it receives an index beyond the
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3782 last volume, at which time we should return a nil dirent struct
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3783 pointer. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3784 if (dp->getting_volumes)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3785 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3786 hpblock.volumeParam.ioNamePtr = s_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3787 hpblock.volumeParam.ioVRefNum = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3788 hpblock.volumeParam.ioVolIndex = dp->current_index;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3789
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3790 errno = PBHGetVInfo (&hpblock, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3791 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3792 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3793 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3794 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3795 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3796
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3797 p2cstr (s_name);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3798 strcat (s_name, "/"); /* need "/" for stat to work correctly */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3799
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3800 dp->current_index++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3801
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3802 s_dirent.d_ino = hpblock.volumeParam.ioVRefNum;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3803 s_dirent.d_name = s_name;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3804
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3805 return &s_dirent;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3806 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3807 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3808 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3809 cipb.hFileInfo.ioVRefNum = dp->vol_ref_num;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3810 cipb.hFileInfo.ioNamePtr = s_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3811 /* location to receive filename returned */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3812
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3813 /* return only visible files */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3814 done = false;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3815 while (!done)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3816 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3817 cipb.hFileInfo.ioDirID = dp->dir_id;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3818 /* directory ID found by opendir */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3819 cipb.hFileInfo.ioFDirIndex = dp->current_index;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3820
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3821 errno = PBGetCatInfo (&cipb, false);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3822 if (errno != noErr)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3823 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3824 errno = ENOENT;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3825 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3826 }
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3827
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3828 /* insist on a visible entry */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3829 if (cipb.hFileInfo.ioFlAttrib & 0x10) /* directory? */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3830 done = !(cipb.dirInfo.ioDrUsrWds.frFlags & fInvisible);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3831 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3832 done = !(cipb.hFileInfo.ioFlFndrInfo.fdFlags & fInvisible);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3833
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3834 dp->current_index++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3835 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3836
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3837 p2cstr (s_name);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3838
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3839 p = s_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3840 while (*p)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3841 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3842 if (*p == '/')
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3843 *p = ':';
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3844 p++;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3845 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3846
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3847 s_dirent.d_ino = cipb.dirInfo.ioDrDirID;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3848 /* value unimportant: non-zero for valid file */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3849 s_dirent.d_name = s_name;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3850
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3851 return &s_dirent;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3852 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3853 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3854
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3855
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3856 char *
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3857 getwd (char *path)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3858 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3859 char mac_pathname[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3860 Str255 directory_name;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3861 OSErr errno;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3862 CInfoPBRec cipb;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3863
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3864 if (path_from_vol_dir_name (mac_pathname, 255, 0, 0, "\p") == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3865 return NULL;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3866
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3867 if (mac_to_posix_pathname (mac_pathname, path, MAXPATHLEN+1) == 0)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3868 return 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3869 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3870 return path;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3871 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3872
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3873 #endif /* ! MAC_OSX */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3874
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3875
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3876 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3877 initialize_applescript ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3878 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3879 AEDesc null_desc;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3880 OSAError osaerror;
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
3881
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3882 /* if open fails, as_scripting_component is set to NULL. Its
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3883 subsequent use in OSA calls will fail with badComponentInstance
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3884 error. */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3885 as_scripting_component = OpenDefaultComponent (kOSAComponentType,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3886 kAppleScriptSubtype);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3887
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3888 null_desc.descriptorType = typeNull;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3889 null_desc.dataHandle = 0;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3890 osaerror = OSAMakeContext (as_scripting_component, &null_desc,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3891 kOSANullScript, &as_script_context);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3892 if (osaerror)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3893 as_script_context = kOSANullScript;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3894 /* use default context if create fails */
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3895 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3896
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3897
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3898 void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3899 terminate_applescript()
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3900 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3901 OSADispose (as_scripting_component, as_script_context);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3902 CloseComponent (as_scripting_component);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3903 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
3904
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3905 /* Convert a lisp string to the 4 byte character code. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3906
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3907 OSType
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3908 mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3909 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3910 OSType result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3911 if (NILP(arg))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3912 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3913 result = defCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3914 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3915 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3916 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3917 /* check type string */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3918 CHECK_STRING(arg);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3919 if (SBYTES (arg) != 4)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3920 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3921 error ("Wrong argument: need string of length 4 for code");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3922 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3923 result = EndianU32_BtoN (*((UInt32 *) SDATA (arg)));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3924 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3925 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3926 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3927
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3928 /* Convert the 4 byte character code into a 4 byte string. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3929
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3930 Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3931 mac_get_object_from_code(OSType defCode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3932 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3933 UInt32 code = EndianU32_NtoB (defCode);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3934
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3935 return make_unibyte_string ((char *)&code, 4);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3936 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3937
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3938
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3939 DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1, 1, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3940 doc: /* Get the creator code of FILENAME as a four character string. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3941 (filename)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3942 Lisp_Object filename;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3943 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3944 OSErr status;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3945 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3946 FSRef fref;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3947 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3948 FSSpec fss;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3949 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3950 OSType cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3951 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3952 CHECK_STRING (filename);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3953
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3954 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3955 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3956 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3957 filename = Fexpand_file_name (filename, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3958
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3959 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3960 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3961 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3962 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3963 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3964 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3965
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3966 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3967 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3968 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3969 FSCatalogInfo catalogInfo;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3970
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3971 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3972 &catalogInfo, NULL, NULL, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3973 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3974 FInfo finder_info;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3975
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3976 status = FSpGetFInfo (&fss, &finder_info);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3977 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3978 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3979 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3980 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3981 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3982 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3983 result = mac_get_object_from_code (finder_info.fdCreator);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3984 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3985 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3986 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3987 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3988 if (status != noErr) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3989 error ("Error while getting file information.");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3990 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3991 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3992 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3993
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3994 DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3995 doc: /* Get the type code of FILENAME as a four character string. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3996 (filename)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3997 Lisp_Object filename;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3998 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
3999 OSErr status;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4000 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4001 FSRef fref;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4002 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4003 FSSpec fss;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4004 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4005 OSType cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4006 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4007 CHECK_STRING (filename);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4008
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4009 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4010 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4011 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4012 filename = Fexpand_file_name (filename, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4013
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4014 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4015 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4016 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4017 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4018 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4019 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4020
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4021 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4022 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4023 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4024 FSCatalogInfo catalogInfo;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4025
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4026 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4027 &catalogInfo, NULL, NULL, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4028 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4029 FInfo finder_info;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4030
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4031 status = FSpGetFInfo (&fss, &finder_info);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4032 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4033 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4034 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4035 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4036 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4037 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4038 result = mac_get_object_from_code (finder_info.fdType);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4039 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4040 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4041 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4042 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4043 if (status != noErr) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4044 error ("Error while getting file information.");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4045 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4046 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4047 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4048
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4049 DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 1, 2, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4050 doc: /* Set creator code of file FILENAME to CODE.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4051 If non-nil, CODE must be a 4-character string. Otherwise, 'EMAx' is
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4052 assumed. Return non-nil if successful. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4053 (filename, code)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4054 Lisp_Object filename, code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4055 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4056 OSErr status;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4057 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4058 FSRef fref;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4059 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4060 FSSpec fss;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4061 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4062 OSType cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4063 CHECK_STRING (filename);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4064
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4065 cCode = mac_get_code_from_arg(code, 'EMAx');
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4066
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4067 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4068 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4069 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4070 filename = Fexpand_file_name (filename, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4071
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4072 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4073 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4074 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4075 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4076 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4077 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4078
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4079 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4080 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4081 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4082 FSCatalogInfo catalogInfo;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4083 FSRef parentDir;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4084 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4085 &catalogInfo, NULL, NULL, &parentDir);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4086 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4087 FInfo finder_info;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4088
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4089 status = FSpGetFInfo (&fss, &finder_info);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4090 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4091 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4092 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4093 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4094 ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4095 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4096 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4097 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4098 finder_info.fdCreator = cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4099 status = FSpSetFInfo (&fss, &finder_info);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4100 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4101 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4102 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4103 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4104 if (status != noErr) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4105 error ("Error while setting creator information.");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4106 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4107 return Qt;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4108 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4109
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4110 DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4111 doc: /* Set file code of file FILENAME to CODE.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4112 CODE must be a 4-character string. Return non-nil if successful. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4113 (filename, code)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4114 Lisp_Object filename, code;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4115 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4116 OSErr status;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4117 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4118 FSRef fref;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4119 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4120 FSSpec fss;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4121 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4122 OSType cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4123 CHECK_STRING (filename);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4124
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4125 cCode = mac_get_code_from_arg(code, 0); /* Default to empty code*/
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4126
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4127 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4128 return Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4129 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4130 filename = Fexpand_file_name (filename, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4131
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4132 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4133 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4134 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4135 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4136 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4137 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4138
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4139 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4140 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4141 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4142 FSCatalogInfo catalogInfo;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4143 FSRef parentDir;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4144 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4145 &catalogInfo, NULL, NULL, &parentDir);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4146 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4147 FInfo finder_info;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4148
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4149 status = FSpGetFInfo (&fss, &finder_info);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4150 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4151 if (status == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4152 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4153 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4154 ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4155 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4156 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4157 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4158 finder_info.fdType = cCode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4159 status = FSpSetFInfo (&fss, &finder_info);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4160 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4161 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4162 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4163 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4164 if (status != noErr) {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4165 error ("Error while setting creator information.");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4166 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4167 return Qt;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4168 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4169
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4170
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4171 /* Compile and execute the AppleScript SCRIPT and return the error
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4172 status as function value. A zero is returned if compilation and
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4173 execution is successful, in which case *RESULT is set to a Lisp
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4174 string containing the resulting script value. Otherwise, the Mac
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4175 error code is returned and *RESULT is set to an error Lisp string.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4176 For documentation on the MacOS scripting architecture, see Inside
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4177 Macintosh - Interapplication Communications: Scripting
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4178 Components. */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4179
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4180 static long
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4181 do_applescript (script, result)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4182 Lisp_Object script, *result;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4183 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4184 AEDesc script_desc, result_desc, error_desc, *desc = NULL;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4185 OSErr error;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4186 OSAError osaerror;
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4187
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4188 *result = Qnil;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4189
45851
7b1f766314f6 2002-06-17 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 45848
diff changeset
4190 if (!as_scripting_component)
7b1f766314f6 2002-06-17 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 45848
diff changeset
4191 initialize_applescript();
7b1f766314f6 2002-06-17 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 45848
diff changeset
4192
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4193 error = AECreateDesc (typeChar, SDATA (script), SBYTES (script),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4194 &script_desc);
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4195 if (error)
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4196 return error;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4197
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4198 osaerror = OSADoScript (as_scripting_component, &script_desc, kOSANullScript,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4199 typeChar, kOSAModeNull, &result_desc);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4200
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4201 if (osaerror == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4202 /* success: retrieve resulting script value */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4203 desc = &result_desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4204 else if (osaerror == errOSAScriptError)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4205 /* error executing AppleScript: retrieve error message */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4206 if (!OSAScriptError (as_scripting_component, kOSAErrorMessage, typeChar,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4207 &error_desc))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4208 desc = &error_desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4209
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4210 if (desc)
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4211 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4212 #if TARGET_API_MAC_CARBON
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4213 *result = make_uninit_string (AEGetDescDataSize (desc));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4214 AEGetDescData (desc, SDATA (*result), SBYTES (*result));
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4215 #else /* not TARGET_API_MAC_CARBON */
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4216 *result = make_uninit_string (GetHandleSize (desc->dataHandle));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4217 memcpy (SDATA (*result), *(desc->dataHandle), SBYTES (*result));
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4218 #endif /* not TARGET_API_MAC_CARBON */
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4219 AEDisposeDesc (desc);
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4220 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4221
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4222 AEDisposeDesc (&script_desc);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4223
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4224 return osaerror;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4225 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4226
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4227
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4228 DEFUN ("do-applescript", Fdo_applescript, Sdo_applescript, 1, 1, 0,
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4229 doc: /* Compile and execute AppleScript SCRIPT and return the result.
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4230 If compilation and execution are successful, the resulting script
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4231 value is returned as a string. Otherwise the function aborts and
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4232 displays the error message returned by the AppleScript scripting
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4233 component. */)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4234 (script)
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4235 Lisp_Object script;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4236 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4237 Lisp_Object result;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4238 long status;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4239
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4240 CHECK_STRING (script);
47942
080b4586492b Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 46916
diff changeset
4241
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4242 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4243 status = do_applescript (script, &result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4244 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4245 if (status == 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4246 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4247 else if (!STRINGP (result))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4248 error ("AppleScript error %d", status);
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4249 else
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4250 error ("%s", SDATA (result));
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4251 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4252
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4253
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4254 DEFUN ("mac-file-name-to-posix", Fmac_file_name_to_posix,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4255 Smac_file_name_to_posix, 1, 1, 0,
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4256 doc: /* Convert Macintosh FILENAME to Posix form. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4257 (filename)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4258 Lisp_Object filename;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4259 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4260 char posix_filename[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4261
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4262 CHECK_STRING (filename);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4263
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4264 if (mac_to_posix_pathname (SDATA (filename), posix_filename, MAXPATHLEN))
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4265 return build_string (posix_filename);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4266 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4267 return Qnil;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4268 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4269
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4270
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4271 DEFUN ("posix-file-name-to-mac", Fposix_file_name_to_mac,
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4272 Sposix_file_name_to_mac, 1, 1, 0,
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4273 doc: /* Convert Posix FILENAME to Mac form. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4274 (filename)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4275 Lisp_Object filename;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4276 {
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4277 char mac_filename[MAXPATHLEN+1];
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4278
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4279 CHECK_STRING (filename);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4280
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4281 if (posix_to_mac_pathname (SDATA (filename), mac_filename, MAXPATHLEN))
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4282 return build_string (mac_filename);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4283 else
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4284 return Qnil;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4285 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4286
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4287
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4288 DEFUN ("mac-coerce-ae-data", Fmac_coerce_ae_data, Smac_coerce_ae_data, 3, 3, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4289 doc: /* Coerce Apple event data SRC-DATA of type SRC-TYPE to DST-TYPE.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4290 Each type should be a string of length 4 or the symbol
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4291 `undecoded-file-name'. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4292 (src_type, src_data, dst_type)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4293 Lisp_Object src_type, src_data, dst_type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4294 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4295 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4296 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4297 DescType src_desc_type, dst_desc_type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4298 AEDesc dst_desc;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4299 #ifdef MAC_OSX
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4300 FSRef fref;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4301 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4302 FSSpec fs;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4303 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4304
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4305 CHECK_STRING (src_data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4306 if (EQ (src_type, Qundecoded_file_name))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4307 src_desc_type = TYPE_FILE_NAME;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4308 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4309 src_desc_type = mac_get_code_from_arg (src_type, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4310
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4311 if (EQ (dst_type, Qundecoded_file_name))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4312 dst_desc_type = TYPE_FILE_NAME;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4313 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4314 dst_desc_type = mac_get_code_from_arg (dst_type, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4315
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4316 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4317 err = AECoercePtr (src_desc_type, SDATA (src_data), SBYTES (src_data),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4318 dst_desc_type, &dst_desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4319 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4320 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4321 result = Fcdr (mac_aedesc_to_lisp (&dst_desc));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4322 AEDisposeDesc (&dst_desc);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4323 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4324 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4325
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4326 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4327 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4328
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4329
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4330 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4331 static Lisp_Object Qxml, Qmime_charset;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4332 static Lisp_Object QNFD, QNFKD, QNFC, QNFKC, QHFS_plus_D, QHFS_plus_C;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4333
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4334 DEFUN ("mac-get-preference", Fmac_get_preference, Smac_get_preference, 1, 4, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4335 doc: /* Return the application preference value for KEY.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4336 KEY is either a string specifying a preference key, or a list of key
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4337 strings. If it is a list, the (i+1)-th element is used as a key for
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4338 the CFDictionary value obtained by the i-th element. Return nil if
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4339 lookup is failed at some stage.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4340
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4341 Optional arg APPLICATION is an application ID string. If omitted or
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4342 nil, that stands for the current application.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4343
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4344 Optional arg FORMAT specifies the data format of the return value. If
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4345 omitted or nil, each Core Foundation object is converted into a
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4346 corresponding Lisp object as follows:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4347
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4348 Core Foundation Lisp Tag
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4349 ------------------------------------------------------------
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4350 CFString Multibyte string string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4351 CFNumber Integer or float number
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4352 CFBoolean Symbol (t or nil) boolean
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4353 CFDate List of three integers date
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4354 (cf. `current-time')
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4355 CFData Unibyte string data
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4356 CFArray Vector array
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4357 CFDictionary Alist or hash table dictionary
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4358 (depending on HASH-BOUND)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4359
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4360 If it is t, a symbol that represents the type of the original Core
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4361 Foundation object is prepended. If it is `xml', the value is returned
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4362 as an XML representation.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4363
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4364 Optional arg HASH-BOUND specifies which kinds of the list objects,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4365 alists or hash tables, are used as the targets of the conversion from
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4366 CFDictionary. If HASH-BOUND is a negative integer or nil, always
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4367 generate alists. If HASH-BOUND >= 0, generate an alist if the number
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4368 of keys in the dictionary is smaller than HASH-BOUND, and a hash table
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4369 otherwise. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4370 (key, application, format, hash_bound)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4371 Lisp_Object key, application, format, hash_bound;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4372 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4373 CFStringRef app_id, key_str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4374 CFPropertyListRef app_plist = NULL, plist;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4375 Lisp_Object result = Qnil, tmp;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4376
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4377 if (STRINGP (key))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4378 key = Fcons (key, Qnil);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4379 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4380 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4381 CHECK_CONS (key);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4382 for (tmp = key; CONSP (tmp); tmp = XCDR (tmp))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4383 CHECK_STRING_CAR (tmp);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4384 if (!NILP (tmp))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4385 wrong_type_argument (Qlistp, key);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4386 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4387 if (!NILP (application))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4388 CHECK_STRING (application);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4389 CHECK_SYMBOL (format);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4390 if (!NILP (hash_bound))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4391 CHECK_NUMBER (hash_bound);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4392
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4393 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4394
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4395 app_id = kCFPreferencesCurrentApplication;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4396 if (!NILP (application))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4397 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4398 app_id = cfstring_create_with_string (application);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4399 if (app_id == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4400 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4401 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4402 key_str = cfstring_create_with_string (XCAR (key));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4403 if (key_str == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4404 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4405 app_plist = CFPreferencesCopyAppValue (key_str, app_id);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4406 CFRelease (key_str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4407 if (app_plist == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4408 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4409
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4410 plist = app_plist;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4411 for (key = XCDR (key); CONSP (key); key = XCDR (key))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4412 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4413 if (CFGetTypeID (plist) != CFDictionaryGetTypeID ())
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4414 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4415 key_str = cfstring_create_with_string (XCAR (key));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4416 if (key_str == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4417 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4418 plist = CFDictionaryGetValue (plist, key_str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4419 CFRelease (key_str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4420 if (plist == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4421 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4422 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4423
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4424 if (NILP (key))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4425 if (EQ (format, Qxml))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4426 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4427 CFDataRef data = CFPropertyListCreateXMLData (NULL, plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4428 if (data == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4429 goto out;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4430 result = cfdata_to_lisp (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4431 CFRelease (data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4432 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4433 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4434 result =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4435 cfproperty_list_to_lisp (plist, EQ (format, Qt),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4436 NILP (hash_bound) ? -1 : XINT (hash_bound));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4437
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4438 out:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4439 if (app_plist)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4440 CFRelease (app_plist);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4441 CFRelease (app_id);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4442
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4443 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4444
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4445 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4446 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4447
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4448
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4449 static CFStringEncoding
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4450 get_cfstring_encoding_from_lisp (obj)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4451 Lisp_Object obj;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4452 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4453 CFStringRef iana_name;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4454 CFStringEncoding encoding = kCFStringEncodingInvalidId;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4455
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4456 if (NILP (obj))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4457 return kCFStringEncodingUnicode;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4458
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4459 if (INTEGERP (obj))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4460 return XINT (obj);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4461
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4462 if (SYMBOLP (obj) && !NILP (Fcoding_system_p (obj)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4463 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4464 Lisp_Object coding_spec, plist;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4465
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4466 coding_spec = Fget (obj, Qcoding_system);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4467 plist = XVECTOR (coding_spec)->contents[3];
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4468 obj = Fplist_get (XVECTOR (coding_spec)->contents[3], Qmime_charset);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4469 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4470
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4471 if (SYMBOLP (obj))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4472 obj = SYMBOL_NAME (obj);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4473
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4474 if (STRINGP (obj))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4475 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4476 iana_name = cfstring_create_with_string (obj);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4477 if (iana_name)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4478 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4479 encoding = CFStringConvertIANACharSetNameToEncoding (iana_name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4480 CFRelease (iana_name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4481 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4482 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4483
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4484 return encoding;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4485 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4486
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4487 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4488 static CFStringRef
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4489 cfstring_create_normalized (str, symbol)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4490 CFStringRef str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4491 Lisp_Object symbol;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4492 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4493 int form = -1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4494 TextEncodingVariant variant;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4495 float initial_mag = 0.0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4496 CFStringRef result = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4497
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4498 if (EQ (symbol, QNFD))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4499 form = kCFStringNormalizationFormD;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4500 else if (EQ (symbol, QNFKD))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4501 form = kCFStringNormalizationFormKD;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4502 else if (EQ (symbol, QNFC))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4503 form = kCFStringNormalizationFormC;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4504 else if (EQ (symbol, QNFKC))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4505 form = kCFStringNormalizationFormKC;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4506 else if (EQ (symbol, QHFS_plus_D))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4507 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4508 variant = kUnicodeHFSPlusDecompVariant;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4509 initial_mag = 1.5;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4510 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4511 else if (EQ (symbol, QHFS_plus_C))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4512 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4513 variant = kUnicodeHFSPlusCompVariant;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4514 initial_mag = 1.0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4515 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4516
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4517 if (form >= 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4518 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4519 CFMutableStringRef mut_str = CFStringCreateMutableCopy (NULL, 0, str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4520
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4521 if (mut_str)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4522 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4523 CFStringNormalize (mut_str, form);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4524 result = mut_str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4525 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4526 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4527 else if (initial_mag > 0.0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4528 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4529 UnicodeToTextInfo uni = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4530 UnicodeMapping map;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4531 CFIndex length;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4532 UniChar *in_text, *buffer = NULL, *out_buf = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4533 OSErr err = noErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4534 ByteCount out_read, out_size, out_len;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4535
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4536 map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4537 kUnicodeNoSubset,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4538 kTextEncodingDefaultFormat);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4539 map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4540 variant,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4541 kTextEncodingDefaultFormat);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4542 map.mappingVersion = kUnicodeUseLatestMapping;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4543
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4544 length = CFStringGetLength (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4545 out_size = (int)((float)length * initial_mag) * sizeof (UniChar);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4546 if (out_size < 32)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4547 out_size = 32;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4548
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4549 in_text = (UniChar *)CFStringGetCharactersPtr (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4550 if (in_text == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4551 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4552 buffer = xmalloc (sizeof (UniChar) * length);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4553 if (buffer)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4554 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4555 CFStringGetCharacters (str, CFRangeMake (0, length), buffer);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4556 in_text = buffer;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4557 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4558 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4559
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4560 if (in_text)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4561 err = CreateUnicodeToTextInfo(&map, &uni);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4562 while (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4563 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4564 out_buf = xmalloc (out_size);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4565 if (out_buf == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4566 err = mFulErr;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4567 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4568 err = ConvertFromUnicodeToText (uni, length * sizeof (UniChar),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4569 in_text,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4570 kUnicodeDefaultDirectionMask,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4571 0, NULL, NULL, NULL,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4572 out_size, &out_read, &out_len,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4573 out_buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4574 if (err == noErr && out_read < length * sizeof (UniChar))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4575 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4576 xfree (out_buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4577 out_size += length;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4578 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4579 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4580 break;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4581 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4582 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4583 result = CFStringCreateWithCharacters (NULL, out_buf,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4584 out_len / sizeof (UniChar));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4585 if (uni)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4586 DisposeUnicodeToTextInfo (&uni);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4587 if (out_buf)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4588 xfree (out_buf);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4589 if (buffer)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4590 xfree (buffer);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4591 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4592 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4593 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4594 result = str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4595 CFRetain (result);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4596 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4597
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4598 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4599 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4600 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4601
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4602 DEFUN ("mac-code-convert-string", Fmac_code_convert_string, Smac_code_convert_string, 3, 4, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4603 doc: /* Convert STRING from SOURCE encoding to TARGET encoding.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4604 The conversion is performed using the converter provided by the system.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4605 Each encoding is specified by either a coding system symbol, a mime
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4606 charset string, or an integer as a CFStringEncoding value. Nil for
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4607 encoding means UTF-16 in native byte order, no byte order mark.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4608 On Mac OS X 10.2 and later, you can do Unicode Normalization by
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4609 specifying the optional argument NORMALIZATION-FORM with a symbol NFD,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4610 NFKD, NFC, NFKC, HFS+D, or HFS+C.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4611 On successful conversion, return the result string, else return nil. */)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4612 (string, source, target, normalization_form)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4613 Lisp_Object string, source, target, normalization_form;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4614 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4615 Lisp_Object result = Qnil;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4616 CFStringEncoding src_encoding, tgt_encoding;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4617 CFStringRef str = NULL;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4618
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4619 CHECK_STRING (string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4620 if (!INTEGERP (source) && !STRINGP (source))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4621 CHECK_SYMBOL (source);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4622 if (!INTEGERP (target) && !STRINGP (target))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4623 CHECK_SYMBOL (target);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4624 CHECK_SYMBOL (normalization_form);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4625
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4626 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4627
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4628 src_encoding = get_cfstring_encoding_from_lisp (source);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4629 tgt_encoding = get_cfstring_encoding_from_lisp (target);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4630
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4631 /* We really want string_to_unibyte, but since it doesn't exist yet, we
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4632 use string_as_unibyte which works as well, except for the fact that
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4633 it's too permissive (it doesn't check that the multibyte string only
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4634 contain single-byte chars). */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4635 string = Fstring_as_unibyte (string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4636 if (src_encoding != kCFStringEncodingInvalidId
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4637 && tgt_encoding != kCFStringEncodingInvalidId)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4638 str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4639 src_encoding, !NILP (source));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4640 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4641 if (str)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4642 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4643 CFStringRef saved_str = str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4644
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4645 str = cfstring_create_normalized (saved_str, normalization_form);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4646 CFRelease (saved_str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4647 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4648 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4649 if (str)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4650 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4651 CFIndex str_len, buf_len;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4652
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4653 str_len = CFStringGetLength (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4654 if (CFStringGetBytes (str, CFRangeMake (0, str_len), tgt_encoding, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4655 !NILP (target), NULL, 0, &buf_len) == str_len)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4656 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4657 result = make_uninit_string (buf_len);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4658 CFStringGetBytes (str, CFRangeMake (0, str_len), tgt_encoding, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4659 !NILP (target), SDATA (result), buf_len, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4660 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4661 CFRelease (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4662 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4663
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4664 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4665
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4666 return result;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4667 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4668 #endif /* TARGET_API_MAC_CARBON */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4669
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4670
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4671 DEFUN ("mac-clear-font-name-table", Fmac_clear_font_name_table, Smac_clear_font_name_table, 0, 0, 0,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4672 doc: /* Clear the font name table. */)
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4673 ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4674 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4675 check_mac ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4676 mac_clear_font_name_table ();
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4677 return Qnil;
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4678 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4679
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4680
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4681 static Lisp_Object
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4682 mac_get_system_locale ()
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4683 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4684 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4685 LangCode lang;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4686 RegionCode region;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4687 LocaleRef locale;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4688 Str255 str;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4689
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4690 lang = GetScriptVariable (smSystemScript, smScriptLang);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4691 region = GetScriptManagerVariable (smRegionCode);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4692 err = LocaleRefFromLangOrRegionCode (lang, region, &locale);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4693 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4694 err = LocaleRefGetPartString (locale, kLocaleAllPartsMask,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4695 sizeof (str), str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4696 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4697 return build_string (str);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4698 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4699 return Qnil;
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4700 }
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
4701
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4702
46856
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4703 #ifdef MAC_OSX
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4704 #undef select
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4705
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4706 extern int inhibit_window_system;
48740
b45c19284d24 sys_select: Call mac_check_for_quit_char every second while blocking
Steven Tamm <steventamm@mac.com>
parents: 47942
diff changeset
4707 extern int noninteractive;
46856
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4708
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4709 /* Unlike in X11, window events in Carbon do not come from sockets.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4710 So we cannot simply use `select' to monitor two kinds of inputs:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4711 window events and process outputs. We emulate such functionality
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4712 by regarding fd 0 as the window event channel and simultaneously
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4713 monitoring both kinds of input channels. It is implemented by
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4714 dividing into some cases:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4715 1. The window event channel is not involved.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4716 -> Use `select'.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4717 2. Sockets are not involved.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4718 -> Use ReceiveNextEvent.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4719 3. [If SELECT_USE_CFSOCKET is defined]
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4720 Only the window event channel and socket read channels are
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4721 involved, and timeout is not too short (greater than
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4722 SELECT_TIMEOUT_THRESHHOLD_RUNLOOP seconds).
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4723 -> Create CFSocket for each socket and add it into the current
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4724 event RunLoop so that a `ready-to-read' event can be posted
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4725 to the event queue that is also used for window events. Then
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4726 ReceiveNextEvent can wait for both kinds of inputs.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4727 4. Otherwise.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4728 -> Periodically poll the window input channel while repeatedly
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4729 executing `select' with a short timeout
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4730 (SELECT_POLLING_PERIOD_USEC microseconds). */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4731
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4732 #define SELECT_POLLING_PERIOD_USEC 20000
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4733 #ifdef SELECT_USE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4734 #define SELECT_TIMEOUT_THRESHOLD_RUNLOOP 0.2
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4735 #define EVENT_CLASS_SOCK 'Sock'
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4736
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4737 static void
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4738 socket_callback (s, type, address, data, info)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4739 CFSocketRef s;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4740 CFSocketCallBackType type;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4741 CFDataRef address;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4742 const void *data;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4743 void *info;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4744 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4745 EventRef event;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4746
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4747 CreateEvent (NULL, EVENT_CLASS_SOCK, 0, 0, kEventAttributeNone, &event);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4748 PostEventToQueue (GetCurrentEventQueue (), event, kEventPriorityStandard);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4749 ReleaseEvent (event);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4750 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4751 #endif /* SELECT_USE_CFSOCKET */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4752
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4753 static int
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4754 select_and_poll_event (n, rfds, wfds, efds, timeout)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4755 int n;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4756 SELECT_TYPE *rfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4757 SELECT_TYPE *wfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4758 SELECT_TYPE *efds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4759 struct timeval *timeout;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4760 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4761 int r;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4762 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4763
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4764 r = select (n, rfds, wfds, efds, timeout);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4765 if (r != -1)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4766 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4767 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4768 err = ReceiveNextEvent (0, NULL, kEventDurationNoWait,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4769 kEventLeaveInQueue, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4770 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4771 if (err == noErr)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4772 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4773 FD_SET (0, rfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4774 r++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4775 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4776 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4777 return r;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4778 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4779
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4780 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1020
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4781 #undef SELECT_INVALIDATE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4782 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4783
46856
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4784 int
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4785 sys_select (n, rfds, wfds, efds, timeout)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4786 int n;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4787 SELECT_TYPE *rfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4788 SELECT_TYPE *wfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4789 SELECT_TYPE *efds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4790 struct timeval *timeout;
46856
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
4791 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4792 OSErr err;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4793 int i, r;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4794 EMACS_TIME select_timeout;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4795
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4796 if (inhibit_window_system || noninteractive
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4797 || rfds == NULL || !FD_ISSET (0, rfds))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4798 return select (n, rfds, wfds, efds, timeout);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4799
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4800 FD_CLR (0, rfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4801
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4802 if (wfds == NULL && efds == NULL)
48740
b45c19284d24 sys_select: Call mac_check_for_quit_char every second while blocking
Steven Tamm <steventamm@mac.com>
parents: 47942
diff changeset
4803 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4804 int nsocks = 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4805 SELECT_TYPE orfds = *rfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4806
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4807 EventTimeout timeout_sec =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4808 (timeout
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4809 ? (EMACS_SECS (*timeout) * kEventDurationSecond
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4810 + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4811 : kEventDurationForever);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4812
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4813 for (i = 1; i < n; i++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4814 if (FD_ISSET (i, rfds))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4815 nsocks++;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4816
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4817 if (nsocks == 0)
48740
b45c19284d24 sys_select: Call mac_check_for_quit_char every second while blocking
Steven Tamm <steventamm@mac.com>
parents: 47942
diff changeset
4818 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4819 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4820 err = ReceiveNextEvent (0, NULL, timeout_sec,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4821 kEventLeaveInQueue, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4822 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4823 if (err == noErr)
48818
5030a4c296d2 * macterm.c (mac_check_for_quit_char): Correctly set the
Steven Tamm <steventamm@mac.com>
parents: 48793
diff changeset
4824 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4825 FD_SET (0, rfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4826 return 1;
48818
5030a4c296d2 * macterm.c (mac_check_for_quit_char): Correctly set the
Steven Tamm <steventamm@mac.com>
parents: 48793
diff changeset
4827 }
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4828 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4829 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4830 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4831
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4832 /* Avoid initial overhead of RunLoop setup for the case that
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4833 some input is already available. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4834 EMACS_SET_SECS_USECS (select_timeout, 0, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4835 r = select_and_poll_event (n, rfds, wfds, efds, &select_timeout);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4836 if (r != 0 || timeout_sec == 0.0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4837 return r;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4838
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4839 *rfds = orfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4840
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4841 #ifdef SELECT_USE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4842 if (timeout_sec > 0 && timeout_sec <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4843 goto poll_periodically;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4844
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4845 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4846 CFRunLoopRef runloop =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4847 (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ());
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4848 EventTypeSpec specs[] = {{EVENT_CLASS_SOCK, 0}};
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4849 #ifdef SELECT_INVALIDATE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4850 CFSocketRef *shead, *s;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4851 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4852 CFRunLoopSourceRef *shead, *s;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4853 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4854
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4855 BLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4856
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4857 #ifdef SELECT_INVALIDATE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4858 shead = xmalloc (sizeof (CFSocketRef) * nsocks);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4859 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4860 shead = xmalloc (sizeof (CFRunLoopSourceRef) * nsocks);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4861 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4862 s = shead;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4863 for (i = 1; i < n; i++)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4864 if (FD_ISSET (i, rfds))
48818
5030a4c296d2 * macterm.c (mac_check_for_quit_char): Correctly set the
Steven Tamm <steventamm@mac.com>
parents: 48793
diff changeset
4865 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4866 CFSocketRef socket =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4867 CFSocketCreateWithNative (NULL, i, kCFSocketReadCallBack,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4868 socket_callback, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4869 CFRunLoopSourceRef source =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4870 CFSocketCreateRunLoopSource (NULL, socket, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4871
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4872 #ifdef SELECT_INVALIDATE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4873 CFSocketSetSocketFlags (socket, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4874 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4875 CFRunLoopAddSource (runloop, source, kCFRunLoopDefaultMode);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4876 #ifdef SELECT_INVALIDATE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4877 CFRelease (source);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4878 *s = socket;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4879 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4880 CFRelease (socket);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4881 *s = source;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4882 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4883 s++;
48818
5030a4c296d2 * macterm.c (mac_check_for_quit_char): Correctly set the
Steven Tamm <steventamm@mac.com>
parents: 48793
diff changeset
4884 }
5030a4c296d2 * macterm.c (mac_check_for_quit_char): Correctly set the
Steven Tamm <steventamm@mac.com>
parents: 48793
diff changeset
4885
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4886 err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4887
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4888 do
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4889 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4890 --s;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4891 #ifdef SELECT_INVALIDATE_CFSOCKET
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4892 CFSocketInvalidate (*s);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4893 #else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4894 CFRunLoopRemoveSource (runloop, *s, kCFRunLoopDefaultMode);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4895 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4896 CFRelease (*s);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4897 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4898 while (s != shead);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4899
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4900 xfree (shead);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4901
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4902 if (err)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4903 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4904 FD_ZERO (rfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4905 r = 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4906 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4907 else
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4908 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4909 FlushEventsMatchingListFromQueue (GetCurrentEventQueue (),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4910 GetEventTypeCount (specs),
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4911 specs);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4912 EMACS_SET_SECS_USECS (select_timeout, 0, 0);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4913 r = select_and_poll_event (n, rfds, wfds, efds, &select_timeout);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4914 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4915
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4916 UNBLOCK_INPUT;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4917
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4918 return r;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4919 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4920 #endif /* SELECT_USE_CFSOCKET */
48740
b45c19284d24 sys_select: Call mac_check_for_quit_char every second while blocking
Steven Tamm <steventamm@mac.com>
parents: 47942
diff changeset
4921 }
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4922
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4923 poll_periodically:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4924 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4925 EMACS_TIME end_time, now, remaining_time;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4926 SELECT_TYPE orfds = *rfds, owfds, oefds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4927
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4928 if (wfds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4929 owfds = *wfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4930 if (efds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4931 oefds = *efds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4932 if (timeout)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4933 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4934 remaining_time = *timeout;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4935 EMACS_GET_TIME (now);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4936 EMACS_ADD_TIME (end_time, now, remaining_time);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4937 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4938
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4939 do
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4940 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4941 EMACS_SET_SECS_USECS (select_timeout, 0, SELECT_POLLING_PERIOD_USEC);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4942 if (timeout && EMACS_TIME_LT (remaining_time, select_timeout))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4943 select_timeout = remaining_time;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4944 r = select_and_poll_event (n, rfds, wfds, efds, &select_timeout);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4945 if (r != 0)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4946 return r;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4947
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4948 *rfds = orfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4949 if (wfds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4950 *wfds = owfds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4951 if (efds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4952 *efds = oefds;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4953
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4954 if (timeout)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4955 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4956 EMACS_GET_TIME (now);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4957 EMACS_SUB_TIME (remaining_time, end_time, now);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4958 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4959 }
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4960 while (!timeout || EMACS_TIME_LT (now, end_time));
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4961
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4962 FD_ZERO (rfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4963 if (wfds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4964 FD_ZERO (wfds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4965 if (efds)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4966 FD_ZERO (efds);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4967 return 0;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4968 }
48740
b45c19284d24 sys_select: Call mac_check_for_quit_char every second while blocking
Steven Tamm <steventamm@mac.com>
parents: 47942
diff changeset
4969 }
b45c19284d24 sys_select: Call mac_check_for_quit_char every second while blocking
Steven Tamm <steventamm@mac.com>
parents: 47942
diff changeset
4970
46916
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4971 /* Set up environment variables so that Emacs can correctly find its
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4972 support files when packaged as an application bundle. Directories
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4973 placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin,
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4974 and /usr/local/libexec/emacs/<emacs-version>/<system-configuration>
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4975 by `make install' by default can instead be placed in
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4976 .../Emacs.app/Contents/Resources/ and
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4977 .../Emacs.app/Contents/MacOS/. Each of these environment variables
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4978 is changed only if it is not already set. Presumably if the user
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4979 sets an environment variable, he will want to use files in his path
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4980 instead of ones in the application bundle. */
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4981 void
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4982 init_mac_osx_environment ()
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4983 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4984 CFBundleRef bundle;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4985 CFURLRef bundleURL;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4986 CFStringRef cf_app_bundle_pathname;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4987 int app_bundle_pathname_len;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4988 char *app_bundle_pathname;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4989 char *p, *q;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4990 struct stat st;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4991
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4992 /* Initialize locale related variables. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4993 mac_system_script_code =
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4994 (ScriptCode) GetScriptManagerVariable (smSysScript);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4995 Vmac_system_locale = mac_get_system_locale ();
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
4996
46916
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4997 /* Fetch the pathname of the application bundle as a C string into
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4998 app_bundle_pathname. */
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
4999
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5000 bundle = CFBundleGetMainBundle ();
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5001 if (!bundle || CFBundleGetIdentifier (bundle) == NULL)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5002 {
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5003 /* We could not find the bundle identifier. For now, prevent
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5004 the fatal error by bringing it up in the terminal. */
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5005 inhibit_window_system = 1;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5006 return;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5007 }
46916
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5008
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5009 bundleURL = CFBundleCopyBundleURL (bundle);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5010 if (!bundleURL)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5011 return;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5012
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5013 cf_app_bundle_pathname = CFURLCopyFileSystemPath (bundleURL,
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5014 kCFURLPOSIXPathStyle);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5015 app_bundle_pathname_len = CFStringGetLength (cf_app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5016 app_bundle_pathname = (char *) alloca (app_bundle_pathname_len + 1);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5017
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5018 if (!CFStringGetCString (cf_app_bundle_pathname,
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5019 app_bundle_pathname,
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5020 app_bundle_pathname_len + 1,
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5021 kCFStringEncodingISOLatin1))
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5022 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5023 CFRelease (cf_app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5024 return;
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5025 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5026
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5027 CFRelease (cf_app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5028
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5029 /* P should have sufficient room for the pathname of the bundle plus
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5030 the subpath in it leading to the respective directories. Q
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5031 should have three times that much room because EMACSLOADPATH can
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5032 have the value "<path to lisp dir>:<path to leim dir>:<path to
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5033 site-lisp dir>". */
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5034 p = (char *) alloca (app_bundle_pathname_len + 50);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5035 q = (char *) alloca (3 * app_bundle_pathname_len + 150);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5036 if (!getenv ("EMACSLOADPATH"))
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5037 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5038 q[0] = '\0';
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5039
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5040 strcpy (p, app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5041 strcat (p, "/Contents/Resources/lisp");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5042 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5043 strcat (q, p);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5044
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5045 strcpy (p, app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5046 strcat (p, "/Contents/Resources/leim");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5047 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5048 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5049 if (q[0] != '\0')
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5050 strcat (q, ":");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5051 strcat (q, p);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5052 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5053
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5054 strcpy (p, app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5055 strcat (p, "/Contents/Resources/site-lisp");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5056 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5057 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5058 if (q[0] != '\0')
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5059 strcat (q, ":");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5060 strcat (q, p);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5061 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5062
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5063 if (q[0] != '\0')
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5064 setenv ("EMACSLOADPATH", q, 1);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5065 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5066
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5067 if (!getenv ("EMACSPATH"))
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5068 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5069 q[0] = '\0';
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5070
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5071 strcpy (p, app_bundle_pathname);
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5072 strcat (p, "/Contents/MacOS/libexec");
46916
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5073 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5074 strcat (q, p);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5075
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5076 strcpy (p, app_bundle_pathname);
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5077 strcat (p, "/Contents/MacOS/bin");
46916
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5078 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5079 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5080 if (q[0] != '\0')
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5081 strcat (q, ":");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5082 strcat (q, p);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5083 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5084
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5085 if (q[0] != '\0')
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5086 setenv ("EMACSPATH", q, 1);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5087 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5088
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5089 if (!getenv ("EMACSDATA"))
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5090 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5091 strcpy (p, app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5092 strcat (p, "/Contents/Resources/etc");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5093 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5094 setenv ("EMACSDATA", p, 1);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5095 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5096
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5097 if (!getenv ("EMACSDOC"))
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5098 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5099 strcpy (p, app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5100 strcat (p, "/Contents/Resources/etc");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5101 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5102 setenv ("EMACSDOC", p, 1);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5103 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5104
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5105 if (!getenv ("INFOPATH"))
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5106 {
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5107 strcpy (p, app_bundle_pathname);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5108 strcat (p, "/Contents/Resources/info");
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5109 if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5110 setenv ("INFOPATH", p, 1);
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5111 }
aff9c7fcedb0 2002-08-15 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46856
diff changeset
5112 }
46856
eba75fedd593 2002-08-10 Andrew Choi <akochoi@shaw.ca>
Andrew Choi <akochoi@shaw.ca>
parents: 46788
diff changeset
5113 #endif /* MAC_OSX */
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5114
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5115
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5116 void
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5117 syms_of_mac ()
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5118 {
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5119 Qundecoded_file_name = intern ("undecoded-file-name");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5120 staticpro (&Qundecoded_file_name);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5121
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5122 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5123 Qstring = intern ("string"); staticpro (&Qstring);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5124 Qnumber = intern ("number"); staticpro (&Qnumber);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5125 Qboolean = intern ("boolean"); staticpro (&Qboolean);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5126 Qdate = intern ("date"); staticpro (&Qdate);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5127 Qdata = intern ("data"); staticpro (&Qdata);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5128 Qarray = intern ("array"); staticpro (&Qarray);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5129 Qdictionary = intern ("dictionary"); staticpro (&Qdictionary);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5130
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5131 Qxml = intern ("xml");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5132 staticpro (&Qxml);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5133
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5134 Qmime_charset = intern ("mime-charset");
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5135 staticpro (&Qmime_charset);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5136
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5137 QNFD = intern ("NFD"); staticpro (&QNFD);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5138 QNFKD = intern ("NFKD"); staticpro (&QNFKD);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5139 QNFC = intern ("NFC"); staticpro (&QNFC);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5140 QNFKC = intern ("NFKC"); staticpro (&QNFKC);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5141 QHFS_plus_D = intern ("HFS+D"); staticpro (&QHFS_plus_D);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5142 QHFS_plus_C = intern ("HFS+C"); staticpro (&QHFS_plus_C);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5143 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5144
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5145 defsubr (&Smac_coerce_ae_data);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5146 #if TARGET_API_MAC_CARBON
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5147 defsubr (&Smac_get_preference);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5148 defsubr (&Smac_code_convert_string);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5149 #endif
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5150 defsubr (&Smac_clear_font_name_table);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5151
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5152 defsubr (&Smac_set_file_creator);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5153 defsubr (&Smac_set_file_type);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5154 defsubr (&Smac_get_file_creator);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5155 defsubr (&Smac_get_file_type);
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5156 defsubr (&Sdo_applescript);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5157 defsubr (&Smac_file_name_to_posix);
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5158 defsubr (&Sposix_file_name_to_mac);
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5159
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5160 DEFVAR_INT ("mac-system-script-code", &mac_system_script_code,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5161 doc: /* The system script code. */);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5162 mac_system_script_code = (ScriptCode) GetScriptManagerVariable (smSysScript);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5163
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5164 DEFVAR_LISP ("mac-system-locale", &Vmac_system_locale,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5165 doc: /* The system locale identifier string.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5166 This is not a POSIX locale ID, but an ICU locale ID. So encoding
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5167 information is not included. */);
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5168 Vmac_system_locale = mac_get_system_locale ();
44890
01b93e5e53a7 Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
diff changeset
5169 }
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5170
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5171 /* arch-tag: 29d30c1f-0c6b-4f88-8a6d-0558d7f9dbff
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49600
diff changeset
5172 (do not change this comment) */