1996-11-25 07:53:57 -08:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Damien Doligez, projet Para, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1998-10-02 06:02:32 -07:00
|
|
|
/* en Automatique. Distributed only by permission. */
|
1996-11-25 07:53:57 -08:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/* Macintosh-specific stuff */
|
|
|
|
|
|
|
|
#include <CursorCtl.h>
|
|
|
|
#include <Files.h>
|
1998-10-02 06:02:32 -07:00
|
|
|
#include <IntEnv.h>
|
1996-11-25 07:53:57 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <Strings.h>
|
|
|
|
#include <TextUtils.h>
|
|
|
|
#include <Timer.h>
|
|
|
|
#include <Types.h>
|
|
|
|
|
|
|
|
/* The user interface defaults to MPW tool. The standalone application
|
1998-10-02 06:02:32 -07:00
|
|
|
overrides the ui_* functions, as well as [main], [InitCursorCtl],
|
|
|
|
[RotateCursor], [atexit], [getenv], and the terminfo functions.
|
1996-11-25 07:53:57 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
void ui_exit (int return_code)
|
|
|
|
{
|
|
|
|
exit (return_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_read (int file_desc, char *buf, unsigned int length)
|
|
|
|
{
|
|
|
|
return read (file_desc, buf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_write (int file_desc, char *buf, unsigned int length)
|
|
|
|
{
|
|
|
|
return write (file_desc, buf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_print_stderr (char *format, void *arg)
|
|
|
|
{
|
|
|
|
fprintf (stderr, format, arg);
|
1998-10-07 12:01:42 -07:00
|
|
|
fflush (stderr);
|
1996-11-25 07:53:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unix emulation stuff */
|
|
|
|
|
|
|
|
static short prevdir = 0;
|
|
|
|
|
|
|
|
int chdir (char *dir)
|
|
|
|
{
|
|
|
|
WDPBRec pb;
|
|
|
|
int result;
|
1998-10-02 06:02:32 -07:00
|
|
|
short curdir;
|
1996-11-25 07:53:57 -08:00
|
|
|
|
|
|
|
pb.ioCompletion = NULL;
|
|
|
|
pb.ioNamePtr = c2pstr (dir);
|
|
|
|
pb.ioVRefNum = 0;
|
|
|
|
pb.ioWDProcID = 'Caml';
|
|
|
|
pb.ioWDDirID = 0;
|
|
|
|
result = PBOpenWDSync (&pb);
|
|
|
|
p2cstr ((unsigned char *) dir);
|
|
|
|
if (result != noErr) return -1;
|
1998-10-02 06:02:32 -07:00
|
|
|
curdir = pb.ioVRefNum;
|
|
|
|
result = SetVol (NULL, curdir);
|
1996-11-25 07:53:57 -08:00
|
|
|
if (result != noErr) return -1;
|
|
|
|
if (prevdir != 0){
|
1997-05-19 08:42:21 -07:00
|
|
|
pb.ioVRefNum = prevdir;
|
|
|
|
PBCloseWDSync (&pb);
|
1996-11-25 07:53:57 -08:00
|
|
|
}
|
1998-10-02 06:02:32 -07:00
|
|
|
prevdir = curdir;
|
1996-11-25 07:53:57 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-10-02 06:02:32 -07:00
|
|
|
Handle macos_getfullpathname (short vrefnum, long dirid)
|
1996-11-25 07:53:57 -08:00
|
|
|
{
|
1998-10-02 06:02:32 -07:00
|
|
|
Handle result = NewHandle (0);
|
|
|
|
CInfoPBRec mypb;
|
|
|
|
Str255 dirname;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (result == NULL) goto failed;
|
|
|
|
|
|
|
|
mypb.dirInfo.ioNamePtr = dirname;
|
|
|
|
mypb.dirInfo.ioVRefNum = vrefnum;
|
|
|
|
mypb.dirInfo.ioDrParID = dirid;
|
|
|
|
mypb.dirInfo.ioFDirIndex = -1;
|
|
|
|
|
|
|
|
do{
|
|
|
|
mypb.dirInfo.ioDrDirID = mypb.dirInfo.ioDrParID;
|
|
|
|
err = PBGetCatInfo (&mypb, false);
|
|
|
|
if (err) goto failed;
|
|
|
|
Munger (result, 0, NULL, 0, ":", 1);
|
|
|
|
Munger (result, 0, NULL, 0, dirname+1, dirname[0]);
|
|
|
|
/* XXX out of memory ?! */
|
|
|
|
}while (mypb.dirInfo.ioDrDirID != fsRtDirID);
|
1996-11-25 07:53:57 -08:00
|
|
|
return result;
|
|
|
|
|
1998-10-02 06:02:32 -07:00
|
|
|
failed:
|
|
|
|
if (result != NULL) DisposeHandle (result);
|
|
|
|
return NULL;
|
1996-11-25 07:53:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
char *getcwd (char *buf, long size)
|
|
|
|
{
|
1998-10-02 06:02:32 -07:00
|
|
|
size_t len;
|
1996-11-25 07:53:57 -08:00
|
|
|
|
1998-10-02 06:02:32 -07:00
|
|
|
Handle path = macos_getfullpathname (0, 0);
|
1996-11-25 07:53:57 -08:00
|
|
|
if (path == NULL) return NULL;
|
1998-10-02 06:02:32 -07:00
|
|
|
|
|
|
|
len = GetHandleSize (path);
|
|
|
|
|
|
|
|
if (len+1 >= size){
|
|
|
|
DisposeHandle (path);
|
1996-11-25 07:53:57 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (buf == NULL){
|
1998-10-02 06:02:32 -07:00
|
|
|
buf = malloc (len+1);
|
|
|
|
if (buf == NULL) return NULL;
|
1996-11-25 07:53:57 -08:00
|
|
|
}
|
1998-10-02 06:02:32 -07:00
|
|
|
memcpy (buf, *path, len);
|
|
|
|
buf [len] = '\000';
|
|
|
|
DisposeHandle (path);
|
1996-11-25 07:53:57 -08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
int system (char const *cmd)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
FILE *f;
|
1998-10-02 06:02:32 -07:00
|
|
|
|
|
|
|
if (StandAlone) return -1;
|
|
|
|
|
1996-11-25 07:53:57 -08:00
|
|
|
filename = getenv ("ocamlcommands");
|
|
|
|
if (filename == NULL) return 1;
|
|
|
|
f = fopen (filename, "a");
|
|
|
|
if (f == NULL) return 1;
|
|
|
|
fprintf (f, "%s\n", cmd);
|
|
|
|
fclose (f);
|
|
|
|
return 0;
|
|
|
|
}
|