Mercurial > cpython-lru_cache-weakref
annotate Modules/getpath.c @ 7278:59d2761ba1cf legacy-trunk
Remove obsolete pagenumbering / pagestyle cruft.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Fri, 13 Feb 1998 07:08:56 +0000 |
| parents | c9fe35a8298a |
| children | c28b0538a446 |
| 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 | 34 #include "Python.h" |
| 35 #include "osdefs.h" | |
| 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 | 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 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
45 /* 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
|
46 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
47 * 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
|
48 * (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
|
49 * 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
|
50 * 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
|
51 * 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
|
52 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
53 * 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
|
54 * 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
|
55 * 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
|
56 * 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
|
57 * 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
|
58 * 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
|
59 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
60 * 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
|
61 * 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
|
62 * 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
|
63 * 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
|
64 * 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
|
65 * 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
|
66 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
67 * 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
|
68 * 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
|
69 * 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
|
70 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
71 * 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
|
72 * (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
|
73 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
74 * 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
|
75 * 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
|
76 * landmark. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
77 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
78 * 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
|
79 * 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
|
80 * 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
|
81 * 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
|
82 * 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
|
83 * 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
|
84 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
85 * 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
|
86 * 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
|
87 * 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
|
88 * 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
|
89 * 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
|
90 * 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
|
91 * installed setup. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
92 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
93 * 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
|
94 * 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
|
95 * 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
|
96 * 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
|
97 * 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
|
98 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
99 * 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
|
100 * 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
|
101 * 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
|
102 * 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
|
103 * 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
|
104 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
105 * 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
|
106 * 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
|
107 * 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
|
108 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
109 * That's it! |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
110 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
111 * 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
|
112 * 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
|
113 * 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
|
114 * 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
|
115 * 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
|
116 * 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
|
117 * 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
|
118 * 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
|
119 * 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
|
120 * 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
|
121 * 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
|
122 * 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
|
123 * 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
|
124 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
125 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
126 #ifndef VERSION |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
127 #define VERSION "1.5" |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
128 #endif |
|
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 VPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
131 #define VPATH "." |
| 2896 | 132 #endif |
| 133 | |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
134 #ifndef PREFIX |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
135 #define PREFIX "/usr/local" |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
136 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
137 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
138 #ifndef EXEC_PREFIX |
|
3878
4286910080a9
Don't have "." in the default path.
Guido van Rossum <guido@python.org>
parents:
3674
diff
changeset
|
139 #define EXEC_PREFIX PREFIX |
|
3674
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 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
142 #ifndef PYTHONPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
143 /* 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
|
144 #define PYTHONPATH PREFIX "/lib/python" VERSION ":" \ |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
145 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
|
146 #endif |
| 2896 | 147 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
148 #ifndef LANDMARK |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
149 #define LANDMARK "string.py" |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
150 #endif |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
151 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
158 static void |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
159 reduce(dir) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
160 char *dir; |
|
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 int i = strlen(dir); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
163 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
|
164 --i; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
165 dir[i] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
166 } |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
167 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
168 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
169 #ifndef S_ISREG |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
170 #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
|
171 #endif |
|
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_ISDIR |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
174 #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
|
175 #endif |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
176 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
177 static int |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
178 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
|
179 char *filename; |
|
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 struct stat buf; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
182 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
|
183 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
184 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
|
185 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
186 return 1; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
187 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
188 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
189 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
190 static int |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
191 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
|
192 char *filename; |
|
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 if (isfile(filename)) |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
195 return 1; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
196 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
197 /* 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
|
198 if (strlen(filename) < MAXPATHLEN) { |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
199 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
|
200 if (isfile(filename)) |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
201 return 1; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
202 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
203 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
204 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
205 |
|
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 static int |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
208 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
|
209 char *filename; |
|
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 struct stat buf; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
212 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
|
213 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
214 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
|
215 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
216 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
|
217 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
218 return 1; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
219 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
220 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
221 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
222 static int |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
223 isdir(filename) /* Is directory */ |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
224 char *filename; |
|
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 struct stat buf; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
227 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
|
228 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
229 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
|
230 return 0; |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
231 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
232 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
233 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
234 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
235 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
|
236 joinpath(buffer, stuff) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
237 char *buffer; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
238 char *stuff; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
239 { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
240 int n, k; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
241 if (stuff[0] == SEP) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
242 n = 0; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
243 else { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
244 n = strlen(buffer); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
245 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
|
246 buffer[n++] = SEP; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
247 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
248 k = strlen(stuff); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
249 if (n + k > MAXPATHLEN) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
250 k = MAXPATHLEN - n; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
251 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
|
252 buffer[n+k] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
253 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
254 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
255 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
256 static int |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
257 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
|
258 char *argv0_path; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
259 char *home; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
260 { |
| 5500 | 261 int n; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
262 char *vpath; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
263 |
|
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
|
264 /* 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
|
265 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
|
266 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
|
267 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
|
268 /* 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
|
269 * 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
|
270 * 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
|
271 * 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
|
272 * 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
|
273 * ".." (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
|
274 * 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
|
275 * "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
|
276 */ |
|
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 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 joinpath(prefix, LANDMARK); |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
285 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
|
286 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
|
287 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
288 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
289 if (home) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
290 /* Check $PYTHONHOME */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
291 char *delim; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
292 strcpy(prefix, home); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
293 delim = strchr(prefix, DELIM); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
294 if (delim) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
295 *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
|
296 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
|
297 joinpath(prefix, LANDMARK); |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
298 if (ismodule(prefix)) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
299 return 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
300 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
301 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
302 /* 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
|
303 strcpy(prefix, argv0_path); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
304 do { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
305 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
|
306 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
|
307 joinpath(prefix, LANDMARK); |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
308 if (ismodule(prefix)) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
309 return 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
310 prefix[n] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
311 reduce(prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
312 } while (prefix[0]); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
313 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
314 /* 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
|
315 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
|
316 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
|
317 joinpath(prefix, LANDMARK); |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
318 if (ismodule(prefix)) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
319 return 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
320 |
|
5483
73509efa724b
Another change suggested by Donn Cave -- forget "step 5", which
Guido van Rossum <guido@python.org>
parents:
5482
diff
changeset
|
321 /* Fail */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
322 return 0; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
323 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
324 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
325 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
326 static int |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
327 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
|
328 char *argv0_path; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
329 char *home; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
330 { |
| 5500 | 331 int n; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
332 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
333 /* 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
|
334 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
|
335 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
|
336 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
|
337 reduce(exec_prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
338 return -1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
339 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
340 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
341 if (home) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
342 /* Check $PYTHONHOME */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
343 char *delim; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
344 delim = strchr(home, DELIM); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
345 if (delim) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
346 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
|
347 else |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
348 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
|
349 joinpath(exec_prefix, lib_python); |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
350 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
|
351 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
|
352 return 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
353 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
354 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
355 /* 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
|
356 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
|
357 do { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
358 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
|
359 joinpath(exec_prefix, lib_python); |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
360 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
|
361 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
|
362 return 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
363 exec_prefix[n] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
364 reduce(exec_prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
365 } while (exec_prefix[0]); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
366 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
367 /* 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
|
368 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
|
369 joinpath(exec_prefix, lib_python); |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
370 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
|
371 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
|
372 return 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
373 |
|
5483
73509efa724b
Another change suggested by Donn Cave -- forget "step 5", which
Guido van Rossum <guido@python.org>
parents:
5482
diff
changeset
|
374 /* Fail */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
375 return 0; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
376 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
377 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
378 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
379 static void |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
380 calculate_path() |
|
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 extern char *Py_GetProgramName(); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
383 |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
384 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
|
385 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
|
386 char *pythonpath = PYTHONPATH; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
387 char *rtpypath = getenv("PYTHONPATH"); |
|
7209
c9fe35a8298a
- Use Py_GetPythonHome() instead of getenv("PYTHONHOME").
Guido van Rossum <guido@python.org>
parents:
7117
diff
changeset
|
388 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
|
389 char *path = getenv("PATH"); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
390 char *prog = Py_GetProgramName(); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
391 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
|
392 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
|
393 char *buf; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
394 int bufsz; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
395 int prefixsz; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
396 char *defpath = pythonpath; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
397 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
398 /* 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
|
399 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
|
400 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
401 /* 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
|
402 * 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
|
403 * 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
|
404 * $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
|
405 */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
406 if (strchr(prog, SEP)) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
407 strcpy(progpath, prog); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
408 else if (path) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
409 while (1) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
410 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
|
411 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
412 if (delim) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
413 int len = delim - path; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
414 strncpy(progpath, path, len); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
415 *(progpath + len) = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
416 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
417 else |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
418 strcpy(progpath, path); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
419 |
|
6121
df028bc54e6f
Globally renamed join() to joinpath() to avoid compilation error on Cray.
Guido van Rossum <guido@python.org>
parents:
5698
diff
changeset
|
420 joinpath(progpath, prog); |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
421 if (isxfile(progpath)) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
422 break; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
423 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
424 if (!delim) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
425 progpath[0] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
426 break; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
427 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
428 path = delim + 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
429 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
430 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
431 else |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
432 progpath[0] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
433 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
434 strcpy(argv0_path, progpath); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
435 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
436 #if HAVE_READLINK |
|
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 char tmpbuffer[MAXPATHLEN+1]; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
439 int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
440 if (linklen != -1) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
441 /* 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
|
442 tmpbuffer[linklen] = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
443 if (tmpbuffer[0] == SEP) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
444 strcpy(argv0_path, tmpbuffer); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
445 else { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
446 /* Interpret relative to progpath */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
447 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
|
448 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
|
449 } |
|
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 #endif /* HAVE_READLINK */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
453 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
454 reduce(argv0_path); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
455 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
456 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
|
457 if (!Py_FrozenFlag) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
458 fprintf(stderr, |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
459 "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
|
460 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
|
461 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
|
462 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
463 else |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
464 reduce(prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
465 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
466 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
|
467 if (!Py_FrozenFlag) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
468 fprintf(stderr, |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
469 "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
|
470 strcpy(exec_prefix, EXEC_PREFIX); |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
471 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
|
472 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
473 /* 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
|
474 |
|
7209
c9fe35a8298a
- Use Py_GetPythonHome() instead of getenv("PYTHONHOME").
Guido van Rossum <guido@python.org>
parents:
7117
diff
changeset
|
475 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
|
476 fprintf(stderr, |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
477 "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
|
478 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
479 /* 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
|
480 */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
481 bufsz = 0; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
482 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
483 if (rtpypath) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
484 bufsz += strlen(rtpypath) + 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
485 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
486 prefixsz = strlen(prefix) + 1; |
|
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 while (1) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
489 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
|
490 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
491 if (defpath[0] != SEP) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
492 /* 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
|
493 bufsz += prefixsz; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
494 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
495 if (delim) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
496 bufsz += delim - defpath + 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
497 else { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
498 bufsz += strlen(defpath) + 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
499 break; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
500 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
501 defpath = delim + 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
502 } |
|
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 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
|
505 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
506 /* 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
|
507 buf = malloc(bufsz); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
508 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
509 if (buf == NULL) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
510 /* 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
|
511 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
|
512 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
|
513 module_search_path = PYTHONPATH; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
514 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
515 else { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
516 /* 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
|
517 if (rtpypath) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
518 strcpy(buf, rtpypath); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
519 strcat(buf, delimiter); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
520 } |
|
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
|
521 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
|
522 buf[0] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
523 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
524 /* 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
|
525 * dynamically located prefix. |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
526 */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
527 defpath = pythonpath; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
528 while (1) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
529 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
|
530 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
531 if (defpath[0] != SEP) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
532 strcat(buf, prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
533 strcat(buf, separator); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
534 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
535 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
536 if (delim) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
537 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
|
538 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
|
539 strncat(buf, defpath, len); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
540 *(buf + end) = '\0'; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
541 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
542 else { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
543 strcat(buf, defpath); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
544 break; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
545 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
546 defpath = delim + 1; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
547 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
548 strcat(buf, delimiter); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
549 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
550 /* 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
|
551 strcat(buf, exec_prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
552 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
553 /* And publish the results */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
554 module_search_path = buf; |
|
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 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
557 /* 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
|
558 * 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
|
559 * 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
|
560 * 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
|
561 */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
562 if (pfound > 0) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
563 reduce(prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
564 reduce(prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
565 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
566 else |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
567 strcpy(prefix, PREFIX); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
568 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
569 if (efound > 0) { |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
570 reduce(exec_prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
571 reduce(exec_prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
572 reduce(exec_prefix); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
573 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
574 else |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
575 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
|
576 } |
|
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 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
579 /* External interface */ |
| 2896 | 580 |
| 581 char * | |
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
3416
diff
changeset
|
582 Py_GetPath() |
| 2896 | 583 { |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
584 if (!module_search_path) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
585 calculate_path(); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
586 return module_search_path; |
| 2896 | 587 } |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
588 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
589 char * |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
590 Py_GetPrefix() |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
591 { |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
592 if (!module_search_path) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
593 calculate_path(); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
594 return prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
595 } |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
596 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
597 char * |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
598 Py_GetExecPrefix() |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
599 { |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
600 if (!module_search_path) |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
601 calculate_path(); |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
602 return exec_prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
603 } |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
604 |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
605 char * |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
606 Py_GetProgramFullPath() |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
607 { |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
608 if (!module_search_path) |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
609 calculate_path(); |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
610 return progpath; |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
611 } |
