Commit 2ba1e103 authored by Diederik van Arkel's avatar Diederik van Arkel
Browse files

Merge Mac c-sources into cUtilSystem;

parent 58716e6f
/*
#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
};
#ifndef __MACH__
#include <Carbon.h>
#else
#include <Carbon/Carbon.h>
#endif
CFBundleRef systemBundle=NULL;
......@@ -36,10 +14,6 @@ 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)
{
......@@ -131,14 +105,6 @@ pid_t fork (void)
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)();
......@@ -242,24 +208,6 @@ int fork_execv_waitpid (char *command)
++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;
......@@ -285,9 +233,6 @@ int fork_execv (char *p_command)
return -1;
#endif
#if 0
command=p_command;
#else
{
char *p,*d_p;
......@@ -301,7 +246,6 @@ int fork_execv (char *p_command)
*d_p++=*p;
*d_p='\0';
}
#endif
result=0;
......@@ -366,3 +310,128 @@ int fork_execv (char *p_command)
return result;
}
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;
}
OSErr LaunchTheDocument(FSSpec *document, OSType appCreator, FSSpec *appSpec) {
OSErr err, sresult;
AEAddressDesc appAddr;
AEDescList fileList;
AEDesc fileListElt, paraDesc;
AppleEvent theEvent;
AppleEvent eventReply;
AliasHandle docAlias;
FInfo fndrInfo;
LaunchParamBlockRec launchPB;
Size paraSize;
AppParametersPtr paraData;
/* initialize our records to NULL
descriptors */
AECreateDesc(typeNull, NULL, 0, &appAddr);
AECreateDesc(typeNull, NULL, 0, &fileList);
AECreateDesc(typeNull, NULL, 0, &fileListElt);
AECreateDesc(typeNull, NULL, 0, &theEvent);
AECreateDesc(typeNull, NULL, 0, &eventReply);
AECreateDesc(typeNull, NULL, 0, &paraDesc);
docAlias = NULL;
paraData = NULL;
/* create an open documents Apple Event */
err = AECreateDesc(typeApplSignature,
(Ptr)&appCreator, sizeof(OSType), &appAddr);
if (err != noErr) goto bail;
err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
&appAddr, kAutoGenerateReturnID, kAnyTransactionID,
&theEvent);
if (err != noErr) goto bail;
/* create a one element list of files to send in the
event */
err = AECreateList(NULL, 0, false, &fileList);
if (err != noErr) goto bail;
err = NewAlias(NULL, document, &docAlias);
if (err != noErr) goto bail;
HLock((Handle) docAlias);
err = AECreateDesc(typeAlias, (Ptr) (*docAlias),
GetHandleSize((Handle) docAlias), &fileListElt);
HUnlock((Handle) docAlias);
if (err != noErr) goto bail;
err = AEPutDesc(&fileList, 0, &fileListElt);
if (err != noErr) goto bail;
/* add the file list to the open documents event */
err = AEPutParamDesc(&theEvent, keyDirectObject, &fileList);
if (err != noErr) goto bail;
/* send the Apple Event */
err = AESend(&theEvent, &eventReply, kAENoReply,
kAENormalPriority, kNoTimeOut, NULL, NULL);
/* if the target could not be found...
no such app running? */
if (err == connectionInvalid || err == procNotFound) {
/* ask the Apple Event Manager to coerce the Apple
event into a launch application parameter block
record. */
err = AECoerceDesc(&theEvent, typeAppParameters,
&paraDesc);
if (err != noErr) goto bail;
/* copy the record's data into our own memory
location so it can be incorporated into the
LaunchApplication parameter block. Here, the new
location is referenced using the variable paraData. */
#if TARGET_API_MAC_CARBON
paraSize = AEGetDescDataSize(&paraDesc);
paraData = (AppParametersPtr) NewPtr(paraSize);
if (paraData == NULL) { err = memFullErr; goto bail; }
err = AEGetDescData(&paraDesc, paraData, paraSize );
if (err != noErr) goto bail;
#else
paraSize = GetHandleSize((Handle) paraDesc.dataHandle);
paraData = (AppParametersPtr) NewPtr(paraSize);
if (paraData == NULL) { err = memFullErr; goto bail; }
BlockMoveData(*paraDesc.dataHandle, paraData, paraSize);
#endif
/* launch the application */
launchPB.launchBlockID = extendedBlock;
launchPB.launchEPBLength = extendedBlockLen;
launchPB.launchFileFlags = 0;
launchPB.launchControlFlags =
launchContinue + launchNoFileFlags;
launchPB.launchAppSpec = appSpec;
launchPB.launchAppParameters = paraData;
err = LaunchApplication(&launchPB);
}
bail:
/* clean up, and go.. */
if (docAlias != NULL) DisposeHandle((Handle) docAlias);
if (paraData != NULL) DisposePtr((Ptr) paraData);
AEDisposeDesc(&paraDesc);
AEDisposeDesc(&appAddr);
AEDisposeDesc(&fileListElt);
AEDisposeDesc(&fileList);
AEDisposeDesc(&theEvent);
AEDisposeDesc(&eventReply);
return err;
}
#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;
}
Supports Markdown
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