annotate Mac/Python/macgetpath.c @ 23029:8291473fde3e legacy-trunk

Mass checkin of universal newline support. Highlights: import and friends will understand any of \r, \n and \r\n as end of line. Python file input will do the same if you use mode 'U'. Everything can be disabled by configuring with --without-universal-newlines. See PEP278 for details.
author Jack Jansen <jack.jansen@cwi.nl>
date Sun, 14 Apr 2002 20:12:41 +0000
parents 5f2dcdd09329
children 1598a1e473e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5079
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
1 /***********************************************************
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
3 The Netherlands.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
4
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
5 All Rights Reserved
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
6
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
8 documentation for any purpose and without fee is hereby granted,
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
9 provided that the above copyright notice appear in all copies and that
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
10 both that copyright notice and this permission notice appear in
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
14 distribution of the software without specific, written prior
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
15 permission.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
16
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
17 While CWI is the initial source for this software, a modified version
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
18 is made available by the Corporation for National Research Initiatives
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
20
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
29
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
30 ******************************************************************/
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
31
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 #include "Python.h"
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 #include "osdefs.h"
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
34 #include "macglue.h"
13605
dc17ef1a7613 include macdefs.h for declaration of getwd, if non-gusi python.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13547
diff changeset
35 #include "macdefs.h"
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 #include "pythonresources.h"
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
37 #ifdef HAVE_UNISTD_H
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
38 #include <unistd.h>
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
39 #endif
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
41 #ifdef TARGET_API_MAC_OSX
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
42 #define PATHNAMELEN 1024
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
43 #else
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
44 #define PATHNAMELEN 256
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
45 #endif
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 /* Return the initial python search path. This is called once from
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 ** initsys() to initialize sys.path.
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 **
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 ** If USE_BUILTIN_PATH is defined the path defined here is used
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 ** (after prepending the python home dir to each item).
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 ** If it is not defined the path is gotten from a resource in the
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 ** Preferences file.
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 **
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 ** XXXX This code needs cleaning up. The routines here have moved
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 ** around quite a bit, and they're pretty messy for that reason.
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 */
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 #include <Files.h>
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 #include <Aliases.h>
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 #include <Folders.h>
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 #include <Resources.h>
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 #include <TextUtils.h>
3057
24af8eab7b76 Fixed to work on 68K (could be yet another optimizer bug or something)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
64 #include <Dialogs.h>
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
66 #ifndef USE_BUILTIN_PATH
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
67 staticforward char *PyMac_GetPythonPath();
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
68 #endif
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
69
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 #define PYTHONPATH "\
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 :\n\
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 :Lib\n\
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 :Lib:stdwin\n\
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 :Lib:test\n\
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 :Lib:mac"
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76
8666
6245b819bdd8 If the preference filename resource is empty don't try to open or
Jack Jansen <jack.jansen@cwi.nl>
parents: 8247
diff changeset
77 static int
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
78 getpreffilefss(FSSpec *fssp)
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
79 {
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
80 static int diditbefore=0;
8666
6245b819bdd8 If the preference filename resource is empty don't try to open or
Jack Jansen <jack.jansen@cwi.nl>
parents: 8247
diff changeset
81 static int rv = 1;
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
82 static FSSpec fss;
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
83 short prefdirRefNum;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
84 long prefdirDirID;
10072
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
85 long pyprefdirDirID;
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
86 Handle namehandle;
10072
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
87 OSErr err;
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
88
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
89 if ( !diditbefore ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
90 if ( (namehandle=GetNamedResource('STR ', PREFFILENAME_NAME)) == NULL ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
91 (void)StopAlert(NOPREFNAME_ID, NULL);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
92 exit(1);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
93 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
94
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
95 if ( **namehandle == '\0' ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
96 /* Empty string means don't use preferences file */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
97 rv = 0;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
98 } else {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
99 /* There is a filename, construct the fsspec */
10072
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
100 if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum,
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
101 &prefdirDirID) != noErr ) {
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
102 /* Something wrong with preferences folder */
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
103 (void)StopAlert(NOPREFDIR_ID, NULL);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
104 exit(1);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
105 }
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
106 /* make fsspec for the "Python" folder inside the prefs folder */
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
107 err = FSMakeFSSpec(prefdirRefNum, prefdirDirID, "\pPython", &fss);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
108 if (err == fnfErr) {
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
109 /* it doesn't exist: create it */
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
110 err = FSpDirCreate(&fss, smSystemScript, &pyprefdirDirID);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
111 } else {
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
112 /* it does exist, now find out the dirID of the Python prefs folder, brrr. */
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
113 CInfoPBRec info;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
114 info.dirInfo.ioVRefNum = fss.vRefNum;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
115 info.dirInfo.ioDrDirID = fss.parID;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
116 info.dirInfo.ioNamePtr = fss.name;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
117 info.dirInfo.ioFDirIndex = 0;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
118 info.dirInfo.ioACUser = 0;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
119 err = PBGetCatInfo(&info, 0);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
120 if (err == noErr) {
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
121 pyprefdirDirID = info.dirInfo.ioDrDirID;
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
122 }
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
123 }
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
124 if (err != noErr) {
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
125 (void)StopAlert(NOPREFDIR_ID, NULL);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
126 exit(1);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
127 }
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
128 HLock(namehandle);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
129 err = FSMakeFSSpec(fss.vRefNum, pyprefdirDirID, (unsigned char *)*namehandle, &fss);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
130 HUnlock(namehandle);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
131 if (err != noErr && err != fnfErr) {
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
132 (void)StopAlert(NOPREFDIR_ID, NULL);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
133 exit(1);
ecebcd84df37 put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
Just van Rossum <just@lettererror.com>
parents: 8788
diff changeset
134 }
8666
6245b819bdd8 If the preference filename resource is empty don't try to open or
Jack Jansen <jack.jansen@cwi.nl>
parents: 8247
diff changeset
135 }
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
136 ReleaseResource(namehandle);
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
137 diditbefore = 1;
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
138 }
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
139 *fssp = fss;
8666
6245b819bdd8 If the preference filename resource is empty don't try to open or
Jack Jansen <jack.jansen@cwi.nl>
parents: 8247
diff changeset
140 return rv;
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
141 }
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 char *
3750
a22438e94fe9 Old names changed to Py_GetCopyright, etc.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3485
diff changeset
144 Py_GetPath()
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 /* Modified by Jack to do something a bit more sensible:
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 ** - Prepend the python home-directory (which is obtained from a Preferences
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 ** resource)
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 ** - Add :
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 */
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 static char *pythonpath;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 char *p, *endp;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 int newlen;
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
154 char *curwd;
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 if ( pythonpath ) return pythonpath;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 #ifndef USE_BUILTIN_PATH
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
158 if ( pythonpath = PyMac_GetPythonPath() )
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 return pythonpath;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 printf("Warning: No pythonpath resource found, using builtin default\n");
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 #endif
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
162 curwd = PyMac_GetPythonDir();
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 p = PYTHONPATH;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 endp = p;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 pythonpath = malloc(2);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166 if ( pythonpath == NULL ) return PYTHONPATH;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 strcpy(pythonpath, ":");
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 while (*endp) {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 endp = strchr(p, '\n');
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 if ( endp == NULL )
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 endp = p + strlen(p);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 pythonpath = realloc(pythonpath, newlen+1);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 if ( pythonpath == NULL ) return PYTHONPATH;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 strcat(pythonpath, "\n");
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 if ( *p == ':' ) {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 p++;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178 strcat(pythonpath, curwd);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 strncat(pythonpath, p, (endp-p));
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 newlen--; /* Ok, ok, we've allocated one byte too much */
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 } else {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 /* We've allocated too much in this case */
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 newlen -= strlen(curwd);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184 pythonpath = realloc(pythonpath, newlen+1);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 if ( pythonpath == NULL ) return PYTHONPATH;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 strncat(pythonpath, p, (endp-p));
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 pythonpath[newlen] = '\0';
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 p = endp + 1;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 return pythonpath;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
194
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
195 /*
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
196 ** Open/create the Python Preferences file, return the handle
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
197 */
12446
e367ad3ea59a Made the GUSI options work again with GUSI 2.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
198 short
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
199 PyMac_OpenPrefFile()
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
200 {
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
201 AliasHandle handle;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
202 FSSpec dirspec;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
203 short prefrh;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
204 OSErr err;
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
205
8666
6245b819bdd8 If the preference filename resource is empty don't try to open or
Jack Jansen <jack.jansen@cwi.nl>
parents: 8247
diff changeset
206 if ( !getpreffilefss(&dirspec))
6245b819bdd8 If the preference filename resource is empty don't try to open or
Jack Jansen <jack.jansen@cwi.nl>
parents: 8247
diff changeset
207 return -1;
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
208 prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm);
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
209 if ( prefrh < 0 ) {
3410
022474ac2451 Changed MacOS creator code from PYTH to Pyth
Jack Jansen <jack.jansen@cwi.nl>
parents: 3057
diff changeset
210 FSpCreateResFile(&dirspec, 'Pyth', 'pref', 0);
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
211 prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm);
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
212 if ( prefrh == -1 ) {
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
213 /* This "cannot happen":-) */
3057
24af8eab7b76 Fixed to work on 68K (could be yet another optimizer bug or something)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
214 printf("Cannot create preferences file, error %d\n", ResError());
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
215 exit(1);
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
216 }
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4442
diff changeset
217 if ( (err=PyMac_init_process_location()) != 0 ) {
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4442
diff changeset
218 printf("Cannot get application location, error %d\n", err);
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
219 exit(1);
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
220 }
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4442
diff changeset
221 dirspec = PyMac_ApplicationFSSpec;
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
222 dirspec.name[0] = 0;
3057
24af8eab7b76 Fixed to work on 68K (could be yet another optimizer bug or something)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
223 if ((err=NewAlias(NULL, &dirspec, &handle)) != 0 ) {
24af8eab7b76 Fixed to work on 68K (could be yet another optimizer bug or something)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
224 printf("Cannot make alias to application directory, error %d\n", err);
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
225 exit(1);
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
226 }
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
227 AddResource((Handle)handle, 'alis', PYTHONHOME_ID, "\p");
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
228 UpdateResFile(prefrh);
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
229
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
230 } else {
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
231 UseResFile(prefrh);
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
232 }
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
233 return prefrh;
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
234 }
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 /*
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237 ** Return the name of the Python directory
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
238 */
6278
2984416a1b2b The preference resource now has a version number
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
239 char *
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
240 PyMac_GetPythonDir()
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 {
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
242 static int diditbefore = 0;
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
243 static char name[PATHNAMELEN] = {':', '\0'};
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
244 AliasHandle handle;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
245 FSSpec dirspec;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
246 Boolean modified = 0;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
247 short oldrh, prefrh = -1, homerh;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
248
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
249 if ( diditbefore )
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
250 return name;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
251
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
252 oldrh = CurResFile();
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
253
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
254 /* First look for an override in the application file */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
255 UseResFile(PyMac_AppRefNum);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
256 handle = (AliasHandle)Get1Resource('alis', PYTHONHOMEOVERRIDE_ID);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
257 UseResFile(oldrh);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
258 if ( handle != NULL ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
259 homerh = PyMac_AppRefNum;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
260 } else {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
261 /* Try to open preferences file in the preferences folder. */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
262 prefrh = PyMac_OpenPrefFile();
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
263 handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
264 if ( handle == NULL ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
265 /* (void)StopAlert(BADPREFFILE_ID, NULL); */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
266 diditbefore=1;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
267 return ":";
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
268 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
269 homerh = prefrh;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
270 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
271 /* It exists. Resolve it (possibly updating it) */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
272 if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
273 (void)StopAlert(BADPREFFILE_ID, NULL);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
274 diditbefore=1;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
275 return ":";
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
276 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
277 if ( modified ) {
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
278 ChangedResource((Handle)handle);
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
279 UpdateResFile(homerh);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
280 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
281 if ( prefrh != -1 ) CloseResFile(prefrh);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
282 UseResFile(oldrh);
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
283
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 13605
diff changeset
284 if ( PyMac_GetFullPathname(&dirspec, name, PATHNAMELEN) == 0 ) {
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
285 strcat(name, ":");
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
286 } else {
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
287 /* If all fails, we return the current directory */
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2984
diff changeset
288 printf("Python home dir exists but I cannot find the pathname!!\n");
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 name[0] = 0;
21423
274aa91b417c Use getcwd(), not silly old getwd().
Jack Jansen <jack.jansen@cwi.nl>
parents: 19841
diff changeset
290 (void)getcwd(name, sizeof(name));
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 }
4442
0549e3428d57 - Get preference filename from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
292 diditbefore = 1;
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 return name;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 #ifndef USE_BUILTIN_PATH
6278
2984416a1b2b The preference resource now has a version number
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
297 char *
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12446
diff changeset
298 PyMac_GetPythonPath(void)
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 {
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
300 short oldrh, prefrh = -1;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
301 char *rv;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
302 int i, newlen;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
303 Str255 pathitem;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
304 int resource_id;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
305 OSErr err;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
306 Handle h;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
307
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
308 oldrh = CurResFile();
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
309 /*
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
310 ** This is a bit tricky. We check here whether the application file
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
311 ** contains an override. This is to forestall us finding another STR# resource
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
312 ** with "our" id and using that for path initialization
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
313 */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
314 UseResFile(PyMac_AppRefNum);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
315 SetResLoad(0);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
316 if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
317 ReleaseResource(h);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
318 resource_id = PYTHONPATHOVERRIDE_ID;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
319 } else {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
320 resource_id = PYTHONPATH_ID;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
321 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
322 SetResLoad(1);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
323 UseResFile(oldrh);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
324
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
325 /* Open the preferences file only if there is no override */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
326 if ( resource_id != PYTHONPATHOVERRIDE_ID )
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
327 prefrh = PyMac_OpenPrefFile();
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
328 /* At this point, we may or may not have the preferences file open, and it
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
329 ** may or may not contain a sys.path STR# resource. We don't care, if it doesn't
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
330 ** exist we use the one from the application (the default).
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
331 ** We put an initial '\n' in front of the path that we don't return to the caller
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
332 */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
333 if( (rv = malloc(2)) == NULL )
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
334 goto out;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
335 strcpy(rv, "\n");
4205
c7994008378d Check that our override pythonpath is actually coming from the
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
336
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
337 for(i=1; ; i++) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
338 GetIndString(pathitem, resource_id, i);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
339 if( pathitem[0] == 0 )
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
340 break;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
341 if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
342 /* We have to put the directory in place */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
343 char *dir = PyMac_GetPythonDir();
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
344
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
345 newlen = strlen(rv) + strlen(dir) + (pathitem[0]-9) + 2;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
346 if( (rv=realloc(rv, newlen)) == NULL)
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
347 goto out;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
348 strcat(rv, dir);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
349 /* Skip a colon at the beginning of the item */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
350 if ( pathitem[0] > 9 && pathitem[1+9] == ':' ) {
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
351 memcpy(rv+strlen(rv), pathitem+1+10, pathitem[0]-10);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
352 newlen--;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
353 } else {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
354 memcpy(rv+strlen(rv), pathitem+1+9, pathitem[0]-9);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
355 }
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
356 rv[newlen-2] = '\n';
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
357 rv[newlen-1] = 0;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
358 } else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
359 /* This is the application itself */
3485
61f19a7b1ff1 Added support for override preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
360
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
361 if ( (err=PyMac_init_process_location()) != 0 ) {
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4442
diff changeset
362 printf("Cannot get application location, error %d\n", err);
3485
61f19a7b1ff1 Added support for override preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
363 exit(1);
61f19a7b1ff1 Added support for override preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
364 }
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4442
diff changeset
365
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4442
diff changeset
366 newlen = strlen(rv) + strlen(PyMac_ApplicationPath) + 2;
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
367 if( (rv=realloc(rv, newlen)) == NULL)
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
368 goto out;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
369 strcpy(rv+strlen(rv), PyMac_ApplicationPath);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
370 rv[newlen-2] = '\n';
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
371 rv[newlen-1] = 0;
3485
61f19a7b1ff1 Added support for override preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
372
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
373 } else {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
374 /* Use as-is */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
375 newlen = strlen(rv) + (pathitem[0]) + 2;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
376 if( (rv=realloc(rv, newlen)) == NULL)
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
377 goto out;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
378 memcpy(rv+strlen(rv), pathitem+1, pathitem[0]);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
379 rv[newlen-2] = '\n';
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
380 rv[newlen-1] = 0;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
381 }
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
383 if( strlen(rv) == 1) {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
384 free(rv);
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
385 rv = NULL;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
386 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
387 if ( rv ) {
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
388 rv[strlen(rv)-1] = 0;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
389 rv++;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
391 out:
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
392 if ( prefrh != -1) CloseResFile(prefrh);
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
393 UseResFile(oldrh);
2984
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 return rv;
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
395 }
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 #endif /* !USE_BUILTIN_PATH */
4c1d80953950 macgetpath - sys.path setting code factored out of config.c and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
398 void
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
399 PyMac_PreferenceOptions(PyMac_PrefRecord *pr)
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
400 {
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
401 short oldrh, prefrh = -1;
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
402 Handle handle;
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
403 int size;
6278
2984416a1b2b The preference resource now has a version number
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
404 PyMac_PrefRecord *p;
2984416a1b2b The preference resource now has a version number
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
405 int action;
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
406
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
407
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
408 oldrh = CurResFile();
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
409
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
410 /* Attempt to load overrides from application */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
411 UseResFile(PyMac_AppRefNum);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
412 handle = Get1Resource('Popt', PYTHONOPTIONSOVERRIDE_ID);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
413 UseResFile(oldrh);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
414
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
415 /* Otherwise get options from prefs file or any other open resource file */
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
416 if ( handle == NULL ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
417 prefrh = PyMac_OpenPrefFile();
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
418 handle = GetResource('Popt', PYTHONOPTIONS_ID);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
419 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
420 if ( handle == NULL ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
421 return;
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
422 }
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
423 HLock(handle);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
424 size = GetHandleSize(handle);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
425 p = (PyMac_PrefRecord *)*handle;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
426 if ( p->version == POPT_VERSION_CURRENT && size == sizeof(PyMac_PrefRecord) ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
427 *pr = *p;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
428 } else {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
429 action = CautionAlert(BADPREFERENCES_ID, NULL);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
430 if ( action == BADPREF_DELETE ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
431 OSErr err;
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
432
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
433 RemoveResource(handle);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
434 if ( (err=ResError()) ) printf("RemoveResource: %d\n", err);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
435 if ( prefrh != -1 ) {
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
436 UpdateResFile(prefrh);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
437 if ( (err=ResError()) ) printf("UpdateResFile: %d\n", err);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
438 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
439 } else if ( action == BADPREF_QUIT )
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
440 exit(1);
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
441 }
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
442 HUnlock(handle);
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
443
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4205
diff changeset
444 if ( prefrh != -1) CloseResFile(prefrh);
8788
d642e6748d12 Re-indented properly (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8666
diff changeset
445 UseResFile(oldrh);
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3410
diff changeset
446 }