Commit 69395696 authored by Diederik van Arkel's avatar Diederik van Arkel
Browse files

add some missing mac specific support files;

parent dd50e46d
CarbonLib
IsWindowModified
SetWindowModified
NewControlKeyFilterUPP
CFBundleGetFunctionPointerForName
CFRelease
CFBundleCreate
CFURLCreateFromFSRef
PBMakeFSRefSync
FindFolder
CFStringGetCString
CFURLCopyFileSystemPath
CFURLCreateWithFileSystemPath
CFStringCreateWithCString
kCFAllocatorDefault
\ No newline at end of file
/*
#include <stdlib.h>
#include <string.h>
#include <QuickDraw.h>
*/
#include <Files.h>
#include <Folders.h>
#include <CFBundle.h>
#include <CFNumber.h>
#include <CFURL.h>
/*
enum {
kFrameworksFolderType = 'fram'
};
enum {
kSystemDomain = -32766
};
*/
enum
{
kAlertID = 128
};
CFBundleRef systemBundle=NULL;
#ifndef __MACH__
typedef int pid_t;
pid_t (*fork_p)(void) = NULL;
int (*execv_p)(const char *path,char *const argv[])=NULL;
pid_t (*waitpid_p)(pid_t wpid,int *status,int options)=NULL;
#endif
/*
extern void w_print_int (int i);
extern void w_print_string (char *);
*/
#ifndef __MACH__
static int initSystemBundle (void)
{
FSRefParam fileRefParam;
FSRef fileRef;
OSErr error;
CFURLRef url;
{
int i;
char *p;
p=(char*)&fileRefParam;
for (i=0; i<sizeof (fileRefParam); ++i)
p[i]=0;
p=(char*)&fileRef;
for (i=0; i<sizeof (fileRef); ++i)
p[i]=0;
}
fileRefParam.ioNamePtr = "\pSystem.framework";;
fileRefParam.newRef = &fileRef;
error = FindFolder (kSystemDomain,kFrameworksFolderType,false,&fileRefParam.ioVRefNum,&fileRefParam.ioDirID);
if (error!=noErr)
return 0;
error = PBMakeFSRefSync (&fileRefParam);
if (error!=noErr)
return 0;
url = CFURLCreateFromFSRef (NULL/*kCFAllocatorDefault*/,&fileRef);
if (url==NULL)
return 0;
systemBundle = CFBundleCreate(NULL/*kCFAllocatorDefault*/, url);
if (systemBundle==NULL)
return 0;
CFRelease (url);
return 1;
}
#endif
#ifdef __MWERKS__
int get_toc (void)
{
asm {
mr r3,RTOC
}
}
int set_toc (int toc)
{
asm {
mr RTOC,r3
}
}
void __ptr_glue (void)
{
asm {
lwz r0,0(r12)
stw RTOC,20(SP)
mtctr r0
lwz RTOC,4(r12)
bctr
}
}
#else
#define get_toc() 0;
#define set_toc(a) ;
#endif
#ifndef __MACH__
pid_t fork (void)
{
int r,t;
if (fork_p==NULL){
if (systemBundle==NULL)
initSystemBundle ();
fork_p = (int(*)(void)) CFBundleGetFunctionPointerForName (systemBundle,CFSTR ("fork"));
if (fork_p==NULL)
return -1;
}
/*
w_print_int ((int)fork_p);
w_print_string ("\r");
w_print_int (((int*)fork_p)[0]);
w_print_string ("\r");
w_print_int (((int*)fork_p)[1]);
w_print_string ("\r");
*/
t=get_toc();
r= (*fork_p)();
set_toc (t);
return r;
}
int execv (const char *path,char *const argv[])
{
int r,t;
if (execv_p==NULL){
if (systemBundle==NULL)
initSystemBundle ();
execv_p = (int (*)(const char *path,char *const argv[])) CFBundleGetFunctionPointerForName (systemBundle,CFSTR ("execv"));
if (execv_p==NULL)
return -1;
}
t=get_toc();
r=(*execv_p) (path,argv);
set_toc (t);
return r;
}
pid_t waitpid (pid_t wpid,int *status,int options)
{
int r,t;
if (waitpid_p==NULL){
if (systemBundle==NULL)
initSystemBundle ();
waitpid_p = (pid_t (*)(pid_t wpid,int *status,int options)) CFBundleGetFunctionPointerForName (systemBundle,CFSTR ("waitpid"));
if (waitpid_p==NULL)
return -1;
}
t=get_toc();
r=(*waitpid_p) (wpid,status,options);
set_toc (t);
return r;
}
#endif
int fork_execv_waitpid (char *command)
{
char *p,*(argv[2049]);
int argc,result;
#ifndef __MACH__
if (!initSystemBundle())
return -1;
#endif
result=0;
argc=0;
p=command;
while (*p==' ' || *p=='\t')
++p;
while (*p!='\0' && argc<2048){
if (*p=='\''){
char c,*d_p;
++p;
argv[argc]=p;
d_p=p;
c=*p;
while (!(c=='\'' && p[1]!='\'') && c!='\0'){
*d_p++=c;
if (c=='\'')
++p;
c=*++p;
}
if (*p=='\0'){
*d_p='\0';
break;
}
++argc;
*d_p='\0';
++p;
} else {
argv[argc++]=p;
while (*p!=' ' && *p!='\t' && *p!='\0')
++p;
if (*p!='\0')
*p++='\0';
}
while (*p==' ' || *p=='\t')
++p;
}
argv[argc]=NULL;
/*
{
int n;
for (n=0; n<argc; ++n)
printf ("%d %s\n",n,argv[n]);
}
*/
/*
{
int n;
for (n=0; n<argc; ++n){
w_print_string (argv[n]);
w_print_string ("\r");
}
}
*/
if (argc>0){
int pid,status;
pid=fork();
if (pid==0)
result=execv (argv[0],argv);
else if (pid!=-1)
waitpid (pid,&status,0);
}
return result;
}
int fork_execv (char *p_command)
{
char *p;
char *(argv[2049]);
int argc,result;
char *command;
#ifndef __MACH__
if (!initSystemBundle())
return -1;
#endif
#if 0
command=p_command;
#else
{
char *p,*d_p;
for (p=p_command; *p!='\0'; ++p)
;
command=NewPtr (p+1-p_command);
d_p=command;
for (p=p_command; *p!='\0'; ++p)
*d_p++=*p;
*d_p='\0';
}
#endif
result=0;
argc=0;
p=command;
while (*p==' ' || *p=='\t')
++p;
while (*p!='\0' && argc<2048){
if (*p=='\''){
char c,*d_p;
++p;
argv[argc]=p;
d_p=p;
c=*p;
while (!(c=='\'' && p[1]!='\'') && c!='\0'){
*d_p++=c;
if (c=='\'')
++p;
c=*++p;
}
if (*p=='\0'){
*d_p='\0';
break;
}
++argc;
*d_p='\0';
++p;
} else {
argv[argc++]=p;
while (*p!=' ' && *p!='\t' && *p!='\0')
++p;
if (*p!='\0')
*p++='\0';
}
while (*p==' ' || *p=='\t')
++p;
}
argv[argc]=NULL;
if (argc>0){
int pid;
pid=fork();
if (pid==0)
result=execv (argv[0],argv);
else if (pid!=-1)
result=0;
else
result=1;
}
DisposePtr (command);
return result;
}
#include <CFURL.h>
Boolean hfs2posix(char *hfsPath,char *buffer,int size)
{
CFURLRef hfs_url;
CFStringRef hfs_string, posix_string;
Boolean ok;
hfs_string = CFStringCreateWithCString(NULL/*kCFAllocatorDefault*/, hfsPath, kCFStringEncodingMacRoman);
hfs_url = CFURLCreateWithFileSystemPath(NULL/*kCFAllocatorDefault*/,hfs_string,kCFURLHFSPathStyle,/*isDirectory*/false);
posix_string = CFURLCopyFileSystemPath(hfs_url, kCFURLPOSIXPathStyle);
ok = CFStringGetCString(posix_string, buffer, size, kCFStringEncodingMacRoman);
CFRelease(posix_string);
CFRelease(hfs_url);
CFRelease(hfs_string);
return ok;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment