annotate Modules/getpath.c @ 10072:ecebcd84df37 legacy-trunk

put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
author Just van Rossum <just@lettererror.com>
date Tue, 02 Feb 1999 15:49:03 +0000
parents 8efa37a770c6
children 1c7c2dd1beb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
1 /***********************************************************
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
3 The Netherlands.
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
4
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
5 All Rights Reserved
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
8 documentation for any purpose and without fee is hereby granted,
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
10 both that copyright notice and this permission notice appear in
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
15 permission.
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3878
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
29
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
30 ******************************************************************/
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
31
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
32 /* Return the initial module search path. */
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
33
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include "Python.h"
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include "osdefs.h"
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
37 #include <sys/types.h>
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
38 #include <sys/stat.h>
5698
ba860dc0a585 Use string.h, not strings.h
Guido van Rossum <guido@python.org>
parents: 5568
diff changeset
39 #include <string.h>
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
41 #if HAVE_UNISTD_H
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
42 #include <unistd.h>
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
43 #endif /* HAVE_UNISTD_H */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
44
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
45 #ifdef WITH_NEXT_FRAMEWORK
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
46 #include <mach-o/dyld.h>
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
47 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
48
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
49 /* Search in some common locations for the associated Python libraries.
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
50 *
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
51 * Two directories must be found, the platform independent directory
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
52 * (prefix), containing the common .py and .pyc files, and the platform
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
53 * dependent directory (exec_prefix), containing the shared library
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
54 * modules. Note that prefix and exec_prefix can be the same directory,
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
55 * but for some installations, they are different.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
56 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
57 * Py_GetPath() carries out separate searches for prefix and exec_prefix.
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
58 * Each search tries a number of different locations until a ``landmark''
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
59 * file or directory is found. If no prefix or exec_prefix is found, a
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
60 * warning message is issued and the preprocessor defined PREFIX and
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
61 * EXEC_PREFIX are used (even though they will not work); python carries on
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
62 * as best as is possible, but most imports will fail.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
63 *
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
64 * Before any searches are done, the location of the executable is
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
65 * determined. If argv[0] has one or more slashs in it, it is used
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
66 * unchanged. Otherwise, it must have been invoked from the shell's path,
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
67 * so we search $PATH for the named executable and use that. If the
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
68 * executable was not found on $PATH (or there was no $PATH environment
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
69 * variable), the original argv[0] string is used.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
70 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
71 * Next, the executable location is examined to see if it is a symbolic
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
72 * link. If so, the link is chased (correctly interpreting a relative
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
73 * pathname if one is found) and the directory of the link target is used.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
74 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
75 * Finally, argv0_path is set to the directory containing the executable
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
76 * (i.e. the last component is stripped).
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
77 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
78 * With argv0_path in hand, we perform a number of steps. The same steps
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
79 * are performed for prefix and for exec_prefix, but with a different
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
80 * landmark.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
81 *
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
82 * Step 1. Are we running python out of the build directory? This is
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
83 * checked by looking for a different kind of landmark relative to
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
84 * argv0_path. For prefix, the landmark's path is derived from the VPATH
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
85 * preprocessor variable (taking into account that its value is almost, but
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
86 * not quite, what we need). For exec_prefix, the landmark is
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
87 * Modules/Setup. If the landmark is found, we're done.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
88 *
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
89 * For the remaining steps, the prefix landmark will always be
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
90 * lib/python$VERSION/string.py and the exec_prefix will always be
6498
4981fd2b3211 Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents: 6121
diff changeset
91 * lib/python$VERSION/lib-dynload, where $VERSION is Python's version
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
92 * number as supplied by the Makefile. Note that this means that no more
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
93 * build directory checking is performed; if the first step did not find
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
94 * the landmarks, the assumption is that python is running from an
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
95 * installed setup.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
96 *
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
97 * Step 2. See if the $PYTHONHOME environment variable points to the
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
98 * installed location of the Python libraries. If $PYTHONHOME is set, then
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
99 * it points to prefix and exec_prefix. $PYTHONHOME can be a single
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
100 * directory, which is used for both, or the prefix and exec_prefix
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
101 * directories separated by a colon.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
102 *
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
103 * Step 3. Try to find prefix and exec_prefix relative to argv0_path,
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
104 * backtracking up the path until it is exhausted. This is the most common
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
105 * step to succeed. Note that if prefix and exec_prefix are different,
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
106 * exec_prefix is more likely to be found; however if exec_prefix is a
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
107 * subdirectory of prefix, both will be found.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
108 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
109 * Step 4. Search the directories pointed to by the preprocessor variables
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
110 * PREFIX and EXEC_PREFIX. These are supplied by the Makefile but can be
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
111 * passed in as options to the configure script.
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
112 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
113 * That's it!
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
114 *
5316
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
115 * Well, almost. Once we have determined prefix and exec_prefix, the
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
116 * preprocesor variable PYTHONPATH is used to construct a path. Each
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
117 * relative path on PYTHONPATH is prefixed with prefix. Then the directory
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
118 * containing the shared library modules is appended. The environment
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
119 * variable $PYTHONPATH is inserted in front of it all. Finally, the
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
120 * prefix and exec_prefix globals are tweaked so they reflect the values
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
121 * expected by other code, by stripping the "lib/python$VERSION/..." stuff
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
122 * off. If either points to the build directory, the globals are reset to
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
123 * the corresponding preprocessor variables (so sys.prefix will reflect the
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
124 * installation location, even though sys.path points into the build
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
125 * directory). This seems to make more sense given that currently the only
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
126 * known use of sys.prefix and sys.exec_prefix is for the ILU installation
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
127 * process to find the installed Python tree.
c8e24c4b8bfb Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents: 5300
diff changeset
128 */
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
129
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
130 #ifndef VERSION
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
131 #define VERSION "1.5"
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
132 #endif
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
133
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
134 #ifndef VPATH
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
135 #define VPATH "."
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 #endif
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
3674
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
138 #ifndef PREFIX
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
139 #define PREFIX "/usr/local"
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
140 #endif
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
141
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
142 #ifndef EXEC_PREFIX
3878
4286910080a9 Don't have "." in the default path.
Guido van Rossum <guido@python.org>
parents: 3674
diff changeset
143 #define EXEC_PREFIX PREFIX
3674
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
144 #endif
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
145
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
146 #ifndef PYTHONPATH
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
147 /* I know this isn't K&R C, but the Makefile specifies it anyway */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
148 #define PYTHONPATH PREFIX "/lib/python" VERSION ":" \
6498
4981fd2b3211 Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents: 6121
diff changeset
149 EXEC_PREFIX "/lib/python" VERSION "/lib-dynload"
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
150 #endif
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
152 #ifndef LANDMARK
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
153 #define LANDMARK "string.py"
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
154 #endif
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
155
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
156 static char prefix[MAXPATHLEN+1];
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
157 static char exec_prefix[MAXPATHLEN+1];
5568
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
158 static char progpath[MAXPATHLEN+1];
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
159 static char *module_search_path = NULL;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
160 static char lib_python[20]; /* Dynamically set to "lib/python" VERSION */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
161
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
162 static void
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
163 reduce(dir)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
164 char *dir;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
165 {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
166 int i = strlen(dir);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
167 while (i > 0 && dir[i] != SEP)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
168 --i;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
169 dir[i] = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
170 }
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
171
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
172
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
173 #ifndef S_ISREG
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
174 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
175 #endif
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
176
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
177 #ifndef S_ISDIR
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
178 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
179 #endif
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
180
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
181 static int
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
182 isfile(filename) /* Is file, not directory */
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
183 char *filename;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
184 {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
185 struct stat buf;
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
186 if (stat(filename, &buf) != 0)
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
187 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
188 if (!S_ISREG(buf.st_mode))
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
189 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
190 return 1;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
191 }
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
192
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
193
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
194 static int
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
195 ismodule(filename) /* Is module -- check for .pyc/.pyo too */
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
196 char *filename;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
197 {
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
198 if (isfile(filename))
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
199 return 1;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
200
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
201 /* Check for the compiled version of prefix. */
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
202 if (strlen(filename) < MAXPATHLEN) {
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
203 strcat(filename, Py_OptimizeFlag ? "o" : "c");
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
204 if (isfile(filename))
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
205 return 1;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
206 }
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
207 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
208 }
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
209
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
210
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
211 static int
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
212 isxfile(filename) /* Is executable file */
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
213 char *filename;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
214 {
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
215 struct stat buf;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
216 if (stat(filename, &buf) != 0)
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
217 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
218 if (!S_ISREG(buf.st_mode))
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
219 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
220 if ((buf.st_mode & 0111) == 0)
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
221 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
222 return 1;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
223 }
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
224
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
225
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
226 static int
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
227 isdir(filename) /* Is directory */
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
228 char *filename;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
229 {
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
230 struct stat buf;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
231 if (stat(filename, &buf) != 0)
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
232 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
233 if (!S_ISDIR(buf.st_mode))
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
234 return 0;
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
235 return 1;
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
236 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
237
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
238
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
239 static void
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
240 joinpath(buffer, stuff)
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
241 char *buffer;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
242 char *stuff;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
243 {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
244 int n, k;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
245 if (stuff[0] == SEP)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
246 n = 0;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
247 else {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
248 n = strlen(buffer);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
249 if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
250 buffer[n++] = SEP;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
251 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
252 k = strlen(stuff);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
253 if (n + k > MAXPATHLEN)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
254 k = MAXPATHLEN - n;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
255 strncpy(buffer+n, stuff, k);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
256 buffer[n+k] = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
257 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
258
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
259
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
260 static int
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
261 search_for_prefix(argv0_path, home)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
262 char *argv0_path;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
263 char *home;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
264 {
5500
821912fd965a Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 5483
diff changeset
265 int n;
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
266 char *vpath;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
267
5482
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
268 /* Check to see if argv[0] is in the build directory */
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
269 strcpy(prefix, argv0_path);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
270 joinpath(prefix, "Modules/Setup");
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
271 if (isfile(prefix)) {
5482
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
272 /* Check VPATH to see if argv0_path is in the build directory.
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
273 * Complication: the VPATH passed in is relative to the
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
274 * Modules build directory and points to the Modules source
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
275 * directory; we need it relative to the build tree and
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
276 * pointing to the source tree. Solution: chop off a leading
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
277 * ".." (but only if it's there -- it could be an absolute
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
278 * path) and chop off the final component (assuming it's
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
279 * "Modules").
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
280 */
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
281 vpath = VPATH;
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
282 if (vpath[0] == '.' && vpath[1] == '.' && vpath[2] == '/')
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
283 vpath += 3;
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
284 strcpy(prefix, argv0_path);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
285 joinpath(prefix, vpath);
5482
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
286 reduce(prefix);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
287 joinpath(prefix, "Lib");
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
288 joinpath(prefix, LANDMARK);
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
289 if (ismodule(prefix))
5482
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
290 return -1;
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
291 }
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
292
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
293 if (home) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
294 /* Check $PYTHONHOME */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
295 char *delim;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
296 strcpy(prefix, home);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
297 delim = strchr(prefix, DELIM);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
298 if (delim)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
299 *delim = '\0';
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
300 joinpath(prefix, lib_python);
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
301 joinpath(prefix, LANDMARK);
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
302 if (ismodule(prefix))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
303 return 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
304 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
305
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
306 /* Search from argv0_path, until root is found */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
307 strcpy(prefix, argv0_path);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
308 do {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
309 n = strlen(prefix);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
310 joinpath(prefix, lib_python);
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
311 joinpath(prefix, LANDMARK);
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
312 if (ismodule(prefix))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
313 return 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
314 prefix[n] = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
315 reduce(prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
316 } while (prefix[0]);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
317
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
318 /* Look at configure's PREFIX */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
319 strcpy(prefix, PREFIX);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
320 joinpath(prefix, lib_python);
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
321 joinpath(prefix, LANDMARK);
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
322 if (ismodule(prefix))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
323 return 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
324
5483
73509efa724b Another change suggested by Donn Cave -- forget "step 5", which
Guido van Rossum <guido@python.org>
parents: 5482
diff changeset
325 /* Fail */
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
326 return 0;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
327 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
328
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
329
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
330 static int
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
331 search_for_exec_prefix(argv0_path, home)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
332 char *argv0_path;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
333 char *home;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
334 {
5500
821912fd965a Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 5483
diff changeset
335 int n;
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
336
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
337 /* Check to see if argv[0] is in the build directory */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
338 strcpy(exec_prefix, argv0_path);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
339 joinpath(exec_prefix, "Modules/Setup");
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
340 if (isfile(exec_prefix)) {
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
341 reduce(exec_prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
342 return -1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
343 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
344
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
345 if (home) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
346 /* Check $PYTHONHOME */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
347 char *delim;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
348 delim = strchr(home, DELIM);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
349 if (delim)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
350 strcpy(exec_prefix, delim+1);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
351 else
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
352 strcpy(exec_prefix, home);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
353 joinpath(exec_prefix, lib_python);
6498
4981fd2b3211 Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents: 6121
diff changeset
354 joinpath(exec_prefix, "lib-dynload");
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
355 if (isdir(exec_prefix))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
356 return 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
357 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
358
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
359 /* Search from argv0_path, until root is found */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
360 strcpy(exec_prefix, argv0_path);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
361 do {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
362 n = strlen(exec_prefix);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
363 joinpath(exec_prefix, lib_python);
6498
4981fd2b3211 Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents: 6121
diff changeset
364 joinpath(exec_prefix, "lib-dynload");
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
365 if (isdir(exec_prefix))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
366 return 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
367 exec_prefix[n] = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
368 reduce(exec_prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
369 } while (exec_prefix[0]);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
370
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
371 /* Look at configure's EXEC_PREFIX */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
372 strcpy(exec_prefix, EXEC_PREFIX);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
373 joinpath(exec_prefix, lib_python);
6498
4981fd2b3211 Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents: 6121
diff changeset
374 joinpath(exec_prefix, "lib-dynload");
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
375 if (isdir(exec_prefix))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
376 return 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
377
5483
73509efa724b Another change suggested by Donn Cave -- forget "step 5", which
Guido van Rossum <guido@python.org>
parents: 5482
diff changeset
378 /* Fail */
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
379 return 0;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
380 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
381
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
382
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
383 static void
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
384 calculate_path()
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
385 {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
386 extern char *Py_GetProgramName();
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
387
5568
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
388 static char delimiter[2] = {DELIM, '\0'};
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
389 static char separator[2] = {SEP, '\0'};
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
390 char *pythonpath = PYTHONPATH;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
391 char *rtpypath = getenv("PYTHONPATH");
7209
c9fe35a8298a - Use Py_GetPythonHome() instead of getenv("PYTHONHOME").
Guido van Rossum <guido@python.org>
parents: 7117
diff changeset
392 char *home = Py_GetPythonHome();
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
393 char *path = getenv("PATH");
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
394 char *prog = Py_GetProgramName();
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
395 char argv0_path[MAXPATHLEN+1];
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
396 int pfound, efound; /* 1 if found; -1 if found build directory */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
397 char *buf;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
398 int bufsz;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
399 int prefixsz;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
400 char *defpath = pythonpath;
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
401 #ifdef WITH_NEXT_FRAMEWORK
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
402 NSModule pythonModule;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
403 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
404
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
405 #ifdef WITH_NEXT_FRAMEWORK
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
406 pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
407 /* Use dylib functions to find out where the framework was loaded from */
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
408 buf = NSLibraryNameForModule(pythonModule);
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
409 if (buf != NULL) {
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
410 /* We're in a framework. */
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
411 strcpy(progpath, buf);
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
412
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
413 /* Frameworks have support for versioning */
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
414 strcpy(lib_python, "lib");
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
415 } else {
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
416 /* If we're not in a framework, fall back to the old way (even though NSNameOfModule() probably does the same thing.) */
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
417 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
418
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
419 /* Initialize this dynamically for K&R C */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
420 sprintf(lib_python, "lib/python%s", VERSION);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
421
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
422 /* If there is no slash in the argv0 path, then we have to
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
423 * assume python is on the user's $PATH, since there's no
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
424 * other way to find a directory to start the search from. If
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
425 * $PATH isn't exported, you lose.
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
426 */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
427 if (strchr(prog, SEP))
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
428 strcpy(progpath, prog);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
429 else if (path) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
430 while (1) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
431 char *delim = strchr(path, DELIM);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
432
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
433 if (delim) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
434 int len = delim - path;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
435 strncpy(progpath, path, len);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
436 *(progpath + len) = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
437 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
438 else
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
439 strcpy(progpath, path);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
440
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
441 joinpath(progpath, prog);
7117
419dca2b3a61 Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents: 6823
diff changeset
442 if (isxfile(progpath))
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
443 break;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
444
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
445 if (!delim) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
446 progpath[0] = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
447 break;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
448 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
449 path = delim + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
450 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
451 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
452 else
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
453 progpath[0] = '\0';
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
454 #ifdef WITH_NEXT_FRAMEWORK
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
455 }
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 8203
diff changeset
456 #endif
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
457
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
458 strcpy(argv0_path, progpath);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
459
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
460 #if HAVE_READLINK
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
461 {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
462 char tmpbuffer[MAXPATHLEN+1];
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
463 int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN);
8203
c28b0538a446 When following symlinks to the real executable, use a loop so a
Guido van Rossum <guido@python.org>
parents: 7209
diff changeset
464 while (linklen != -1) {
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
465 /* It's not null terminated! */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
466 tmpbuffer[linklen] = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
467 if (tmpbuffer[0] == SEP)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
468 strcpy(argv0_path, tmpbuffer);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
469 else {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
470 /* Interpret relative to progpath */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
471 reduce(argv0_path);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
472 joinpath(argv0_path, tmpbuffer);
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
473 }
8203
c28b0538a446 When following symlinks to the real executable, use a loop so a
Guido van Rossum <guido@python.org>
parents: 7209
diff changeset
474 linklen = readlink(argv0_path, tmpbuffer, MAXPATHLEN);
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
475 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
476 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
477 #endif /* HAVE_READLINK */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
478
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
479 reduce(argv0_path);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
480
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
481 if (!(pfound = search_for_prefix(argv0_path, home))) {
7209
c9fe35a8298a - Use Py_GetPythonHome() instead of getenv("PYTHONHOME").
Guido van Rossum <guido@python.org>
parents: 7117
diff changeset
482 if (!Py_FrozenFlag)
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
483 fprintf(stderr,
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
484 "Could not find platform independent libraries <prefix>\n");
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
485 strcpy(prefix, PREFIX);
6121
df028bc54e6f Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents: 5698
diff changeset
486 joinpath(prefix, lib_python);
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
487 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
488 else
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
489 reduce(prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
490
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
491 if (!(efound = search_for_exec_prefix(argv0_path, home))) {
7209
c9fe35a8298a - Use Py_GetPythonHome() instead of getenv("PYTHONHOME").
Guido van Rossum <guido@python.org>
parents: 7117
diff changeset
492 if (!Py_FrozenFlag)
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
493 fprintf(stderr,
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
494 "Could not find platform dependent libraries <exec_prefix>\n");
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
495 strcpy(exec_prefix, EXEC_PREFIX);
6498
4981fd2b3211 Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents: 6121
diff changeset
496 joinpath(exec_prefix, "lib/lib-dynload");
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
497 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
498 /* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
499
7209
c9fe35a8298a - Use Py_GetPythonHome() instead of getenv("PYTHONHOME").
Guido van Rossum <guido@python.org>
parents: 7117
diff changeset
500 if ((!pfound || !efound) && !Py_FrozenFlag)
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
501 fprintf(stderr,
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
502 "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n");
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
503
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
504 /* Calculate size of return buffer.
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
505 */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
506 bufsz = 0;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
507
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
508 if (rtpypath)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
509 bufsz += strlen(rtpypath) + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
510
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
511 prefixsz = strlen(prefix) + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
512
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
513 while (1) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
514 char *delim = strchr(defpath, DELIM);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
515
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
516 if (defpath[0] != SEP)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
517 /* Paths are relative to prefix */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
518 bufsz += prefixsz;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
519
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
520 if (delim)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
521 bufsz += delim - defpath + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
522 else {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
523 bufsz += strlen(defpath) + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
524 break;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
525 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
526 defpath = delim + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
527 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
528
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
529 bufsz += strlen(exec_prefix) + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
530
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
531 /* This is the only malloc call in this file */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
532 buf = malloc(bufsz);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
533
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
534 if (buf == NULL) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
535 /* We can't exit, so print a warning and limp along */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
536 fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n");
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
537 fprintf(stderr, "Using default static PYTHONPATH.\n");
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
538 module_search_path = PYTHONPATH;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
539 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
540 else {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
541 /* Run-time value of $PYTHONPATH goes first */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
542 if (rtpypath) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
543 strcpy(buf, rtpypath);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
544 strcat(buf, delimiter);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
545 }
5482
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
546 else
6fa29756ec6a Fix problem reported by Donn Cave: if VPATH is an absolute path, it
Guido van Rossum <guido@python.org>
parents: 5316
diff changeset
547 buf[0] = '\0';
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
548
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
549 /* Next goes merge of compile-time $PYTHONPATH with
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
550 * dynamically located prefix.
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
551 */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
552 defpath = pythonpath;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
553 while (1) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
554 char *delim = strchr(defpath, DELIM);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
555
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
556 if (defpath[0] != SEP) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
557 strcat(buf, prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
558 strcat(buf, separator);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
559 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
560
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
561 if (delim) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
562 int len = delim - defpath + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
563 int end = strlen(buf) + len;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
564 strncat(buf, defpath, len);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
565 *(buf + end) = '\0';
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
566 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
567 else {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
568 strcat(buf, defpath);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
569 break;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
570 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
571 defpath = delim + 1;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
572 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
573 strcat(buf, delimiter);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
574
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
575 /* Finally, on goes the directory for dynamic-load modules */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
576 strcat(buf, exec_prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
577
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
578 /* And publish the results */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
579 module_search_path = buf;
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
580 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
581
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
582 /* Reduce prefix and exec_prefix to their essence,
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
583 * e.g. /usr/local/lib/python1.5 is reduced to /usr/local.
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
584 * If we're loading relative to the build directory,
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
585 * return the compiled-in defaults instead.
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
586 */
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
587 if (pfound > 0) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
588 reduce(prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
589 reduce(prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
590 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
591 else
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
592 strcpy(prefix, PREFIX);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
593
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
594 if (efound > 0) {
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
595 reduce(exec_prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
596 reduce(exec_prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
597 reduce(exec_prefix);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
598 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
599 else
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
600 strcpy(exec_prefix, EXEC_PREFIX);
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
601 }
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
602
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
603
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
604 /* External interface */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
605
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
606 char *
3621
f158edccc72c grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents: 3416
diff changeset
607 Py_GetPath()
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
608 {
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
609 if (!module_search_path)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
610 calculate_path();
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
611 return module_search_path;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 }
3674
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
613
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
614 char *
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
615 Py_GetPrefix()
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
616 {
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
617 if (!module_search_path)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
618 calculate_path();
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
619 return prefix;
3674
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
620 }
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
621
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
622 char *
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
623 Py_GetExecPrefix()
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
624 {
5300
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
625 if (!module_search_path)
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
626 calculate_path();
e77942562dd3 Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
627 return exec_prefix;
3674
3eaf2c673a11 provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents: 3621
diff changeset
628 }
5568
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
629
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
630 char *
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
631 Py_GetProgramFullPath()
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
632 {
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
633 if (!module_search_path)
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
634 calculate_path();
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
635 return progpath;
139ab21d2629 Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents: 5500
diff changeset
636 }