Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
41fa7ea7
Commit
41fa7ea7
authored
Aug 31, 1995
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python will now attempt (again) to create at least a minimal
preferences file if it is missing.
parent
9119ccfa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
101 deletions
+93
-101
Mac/Include/pythonresources.h
Mac/Include/pythonresources.h
+20
-9
Mac/Python/macgetargv.c
Mac/Python/macgetargv.c
+3
-3
Mac/Python/macgetpath.c
Mac/Python/macgetpath.c
+70
-89
No files found.
Mac/Include/pythonresources.h
View file @
41fa7ea7
...
...
@@ -16,7 +16,7 @@
** shared ppc python, in the core dynamic library)
*/
/* The alert for "No Python directory, where is it?" */
/* The alert for "No Python directory, where is it?"
(OBSOLETE)
*/
#define NOPYTHON_ALERT 128
#define YES_ITEM 1
#define NO_ITEM 2
...
...
@@ -42,6 +42,17 @@
#define OPT_UNBUFFERED 6
#define OPT_DEBUGGING 7
/* Dialog for 'No preferences directory' */
#define NOPREFDIR_ID 133
/* Dialog for 'Create preferences file?' */
#define NOPREFFILE_ID 134
#define NOPREFFILE_YES 1
#define NOPREFFILE_NO 2
/* Dialog for 'Bad preference file' */
#define BADPREFFILE_ID 135
/*
** The following are valid both in the binary (or shared library)
** and in the Preferences file
...
...
Mac/Python/macgetargv.c
View file @
41fa7ea7
...
...
@@ -75,8 +75,8 @@ strdup(char *src)
/* Return FSSpec of current application */
static
OSErr
current
_process_location
(
FSSpec
*
applicationSpec
)
OSErr
PyMac
_process_location
(
FSSpec
*
applicationSpec
)
{
ProcessSerialNumber
currentPSN
;
ProcessInfoRec
info
;
...
...
@@ -155,7 +155,7 @@ get_application_name()
static
char
appname
[
256
];
FSSpec
appspec
;
if
(
current
_process_location
(
&
appspec
))
if
(
PyMac
_process_location
(
&
appspec
))
return
NULL
;
if
(
get_full_path
(
&
appspec
,
appname
))
return
NULL
;
...
...
Mac/Python/macgetpath.c
View file @
41fa7ea7
...
...
@@ -85,118 +85,99 @@ getpythonpath()
return
pythonpath
;
}
/*
**
Return the name of the Python directory
**
Open/create the Python Preferences file, return the handle
*/
char
*
PyMac_
GetPythonDir
()
short
PyMac_
OpenPrefFile
()
{
int
item
;
static
char
name
[
256
];
AliasHandle
handle
;
FSSpec
dirspec
;
int
ok
=
0
;
Boolean
modified
=
0
,
cannotmodify
=
0
;
short
oldrh
,
prefrh
;
short
prefrh
;
short
prefdirRefNum
;
long
prefdirDirID
;
short
action
;
/*
** Remember old resource file and try to open preferences file
** in the preferences folder. If it doesn't exist we try to create
** it. If anything fails here we limp on, but set cannotmodify so
** we don't try to store things later on.
*/
oldrh
=
CurResFile
();
if
(
FindFolder
(
kOnSystemDisk
,
'
pref
'
,
kDontCreateFolder
,
&
prefdirRefNum
,
&
prefdirDirID
)
!=
noErr
)
{
/* Something wrong with preferences folder */
cannotmodify
=
1
;
}
else
{
(
void
)
StopAlert
(
NOPREFDIR_ID
,
NULL
);
exit
(
1
);
}
(
void
)
FSMakeFSSpec
(
prefdirRefNum
,
prefdirDirID
,
"\pPython Preferences"
,
&
dirspec
);
prefrh
=
FSpOpenResFile
(
&
dirspec
,
fsRdWrShPerm
);
if
(
prefrh
==
-
1
)
{
#ifdef USE_MAC_MODPREFS
/* It doesn't exist. Try to create it */
if
(
prefrh
<
0
)
{
action
=
CautionAlert
(
NOPREFFILE_ID
,
NULL
);
if
(
action
==
NOPREFFILE_NO
)
exit
(
1
);
FSpCreateResFile
(
&
dirspec
,
'
PYTH
'
,
'
pref
'
,
0
);
prefrh
=
FSpOpenResFile
(
&
dirspec
,
fsRdWrShPerm
);
if
(
prefrh
==
-
1
)
{
/* This is strange, what should we do now? */
cannotmodify
=
1
;
}
else
{
UseResFile
(
prefrh
);
/* This "cannot happen":-) */
printf
(
"Cannot create preferences file!!
\n
"
);
exit
(
1
);
}
#else
printf
(
"Error: no Preferences file. Attempting to limp on...
\n
"
);
name
[
0
]
=
0
;
getwd
(
name
);
return
name
;
#endif
if
(
PyMac_process_location
(
&
dirspec
)
!=
0
)
{
printf
(
"Cannot get FSSpec for application!!
\n
"
);
exit
(
1
);
}
dirspec
.
name
[
0
]
=
0
;
if
(
NewAlias
(
NULL
,
&
dirspec
,
&
handle
)
!=
0
)
{
printf
(
"Cannot make alias to application directory!!
\n
"
);
exit
(
1
);
}
AddResource
((
Handle
)
handle
,
'
alis
'
,
PYTHONHOME_ID
,
"\p"
);
UpdateResFile
(
prefrh
);
}
else
{
UseResFile
(
prefrh
);
}
return
prefrh
;
}
/*
** Return the name of the Python directory
*/
char
*
PyMac_GetPythonDir
()
{
static
char
name
[
256
];
AliasHandle
handle
;
FSSpec
dirspec
;
Boolean
modified
=
0
;
short
oldrh
,
prefrh
;
/*
** Remember old resource file and try to open preferences file
** in the preferences folder.
*/
oldrh
=
CurResFile
();
prefrh
=
PyMac_OpenPrefFile
();
/* So, we've opened our preferences file, we hope. Look for the alias */
handle
=
(
AliasHandle
)
Get1Resource
(
'
alis
'
,
PYTHONHOME_ID
);
if
(
handle
)
{
/* It exists. Resolve it (possibly updating it) */
if
(
ResolveAlias
(
NULL
,
handle
,
&
dirspec
,
&
modified
)
==
noErr
)
{
ok
=
1
;
}
}
if
(
!
ok
)
{
#ifdef USE_MAC_MODPREFS
/* No luck, so far. ask the user for help */
item
=
Alert
(
NOPYTHON_ALERT
,
NULL
);
if
(
item
==
YES_ITEM
)
{
/* The user wants to point us to a directory. Let her do so */
ok
=
PyMac_GetDirectory
(
&
dirspec
);
if
(
ok
)
modified
=
1
;
}
else
if
(
item
==
CURWD_ITEM
)
{
/* The user told us the current directory is fine. Build an FSSpec for it */
if
(
getwd
(
name
)
)
{
if
(
FSMakeFSSpec
(
0
,
0
,
Pstring
(
name
),
&
dirspec
)
==
0
)
{
ok
=
1
;
modified
=
1
;
if
(
handle
==
NULL
)
{
(
void
)
StopAlert
(
BADPREFFILE_ID
,
NULL
);
exit
(
1
);
}
/* It exists. Resolve it (possibly updating it) */
if
(
ResolveAlias
(
NULL
,
handle
,
&
dirspec
,
&
modified
)
!=
noErr
)
{
(
void
)
StopAlert
(
BADPREFFILE_ID
,
NULL
);
exit
(
1
);
}
}
if
(
handle
)
{
/* Set the (old, invalid) alias record to the new data */
UpdateAlias
(
NULL
,
&
dirspec
,
handle
,
&
modified
);
}
#else
printf
(
"Error: corrupted Preferences file. Attempting to limp on...
\n
"
);
name
[
0
]
=
0
;
getwd
(
name
);
return
name
;
#endif
}
#ifdef USE_MAC_MODPREFS
if
(
ok
&&
modified
&&
!
cannotmodify
)
{
/* We have a new, valid fsspec and we can update the preferences file. Do so. */
if
(
!
handle
)
{
if
(
NewAlias
(
NULL
,
&
dirspec
,
&
handle
)
==
0
)
AddResource
((
Handle
)
handle
,
'
alis
'
,
PYTHONHOME_ID
,
"\p"
);
}
else
{
if
(
modified
)
{
ChangedResource
((
Handle
)
handle
);
}
UpdateResFile
(
prefrh
);
}
#endif
if
(
!
cannotmodify
)
{
/* This means we have the resfile open. Close it. */
CloseResFile
(
prefrh
);
}
/* Back to the old resource file */
UseResFile
(
oldrh
);
/* Now turn the fsspec into a path to give back to our caller */
if
(
ok
)
{
ok
=
(
nfullpath
(
&
dirspec
,
name
)
==
0
);
if
(
ok
)
strcat
(
name
,
":"
);
}
if
(
!
ok
)
{
if
(
nfullpath
(
&
dirspec
,
name
)
==
0
)
{
strcat
(
name
,
":"
);
}
else
{
/* If all fails, we return the current directory */
printf
(
"Python home dir exists but I cannot find the pathname!!
\n
"
);
name
[
0
]
=
0
;
(
void
)
getwd
(
name
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment