// hdll, pluginmain and audiomaster are set here // must be NULL beforehand! bool VSTPlugin::NewPlugin(const char *plugname) { FLEXT_ASSERT(!pluginmain && !audiomaster); dllname = plugname; #if FLEXT_OS == FLEXT_OS_WIN hdll = LoadLibraryEx(dllname.c_str(),NULL,0 /*DONT_RESOLVE_DLL_REFERENCES*/); /* char buf[255],*c; strcpy(buf,dllname.c_str()); for(c = buf; *c; ++c) if(*c == '/') *c = '\\'; char *sl = strrchr(buf,'\\'); if(sl) *sl = 0; SetCurrentDirectory(buf); hdll = LoadLibrary(dllname.c_str()); */ if(hdll) pluginmain = (PVSTMAIN)GetProcAddress(hdll,"main"); audiomaster = Master; #elif FLEXT_OS == FLEXT_OS_MAC #if 1 CFStringRef fileNameString = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8); if(fileNameString == 0) goto bail; CFURLRef url = CFURLCreateWithFileSystemPath(NULL, fileNameString, kCFURLPOSIXPathStyle, false); CFRelease(fileNameString); if(url == 0) goto bail; hdll = CFBundleCreate(NULL, url); CFRelease (url); if(hdll && !CFBundleLoadExecutable(hdll)) goto bail; PVSTMAIN mainaddr = PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("VSTPluginMain")); if(!mainaddr) mainaddr = (PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("main_macho")); #ifdef __CFM__ pluginmain = (PVSTMAIN)NewMachOFromCFM(mainaddr); audiomaster = NewCFMFromMachO(Master); #else pluginmain = (PVSTMAIN)mainaddr; audiomaster = Master; #endif #else short resFileID; FSSpec spec; OSErr err; err = FSPathMakeFSSpec(dllname.c_str(),&spec,NULL); resFileID = FSpOpenResFile(&spec, fsRdPerm); short cResCB = Count1Resources('aEff'); for(int i = 0; i < cResCB; i++) { Handle codeH; CFragConnectionID connID; Ptr mainAddr; Str255 errName; Str255 fragName; char fragNameCStr[256]; short resID; OSType resType; codeH = Get1IndResource('aEff', short(i+1)); if(!codeH) continue; GetResInfo(codeH, &resID, &resType, fragName); DetachResource(codeH); HLock(codeH); err = GetMemFragment(*codeH, GetHandleSize(codeH), fragName, kPrivateCFragCopy, &connID, (Ptr *) & mainAddr, errName); if(!err) { #ifdef __CFM__ pluginmain = (PVSTMAIN)NewMachOFromCFM(mainAddr); #else pluginmain = (PVSTMAIN)mainAddr; #endif } } CloseResFile(resFileID); audiomaster = #ifdef __CFM__ NewCFMFromMachO(Master); #else Master; #endif #endif #else #error Platform not supported #endif bail: if(pluginmain && audiomaster) return true; else { FreePlugin(); return false; } }
static pdc_bool pdc_init_stream( pdc_core *pdc, pdc_output *out, const char *filename, FILE *fp, size_t (*writeproc)(pdc_output *out, void *data, size_t size)) { static const char fn[] = "pdc_init_stream"; #if (defined(MAC) || defined(MACOSX)) && defined(PDF_FILETYPE_SUPPORTED) #if !defined(TARGET_API_MAC_CARBON) || defined(__MWERKS__) FCBPBRec fcbInfo; Str32 name; #endif /* TARGET_API_MAC_CARBON */ FInfo fInfo; FSSpec fSpec; #endif /* (MAC || MACOSX) && PDF_FILETYPE_SUPPORTED */ /* * This may be left over from the previous run. We deliberately * don't reuse the previous buffer in order to avoid potentially * unwanted growth of the allocated buffer due to a single large * document in a longer series of documents. */ if (out->basepos) pdc_free(pdc, (void *) out->basepos); out->basepos = (pdc_byte *) pdc_malloc(pdc, STREAM_BUFSIZE, fn); out->curpos = out->basepos; out->maxpos = out->basepos + STREAM_BUFSIZE; out->buf_incr = STREAM_BUFSIZE; out->base_offset = 0; out->compressing = pdc_false; #ifdef HAVE_LIBZ /* zlib sometimes reads uninitialized memory where it shouldn't... */ memset(&out->z, 0, sizeof out->z); out->z.zalloc = (alloc_func) pdc_zlib_alloc; out->z.zfree = (free_func) pdc_free; out->z.opaque = (voidpf) pdc; if (deflateInit(&out->z, pdc_get_compresslevel(out)) != Z_OK) pdc_error(pdc, PDC_E_IO_COMPRESS, "deflateInit", 0, 0, 0); out->compr_changed = pdc_false; #endif /* Defaults */ out->fp = (FILE *) NULL; out->writeproc = pdc_writeproc_file; if (fp) { out->fp = fp; } else if (writeproc) { out->writeproc = writeproc; /* PDF_open_mem */ } else if (filename == NULL || *filename == '\0') { /* PDF_open_file with in-core output */ out->writeproc = NULL; } else { /* PDF_open_file with file output */ #if !((defined(MAC) || defined (MACOSX)) && defined(__MWERKS__)) if (filename && !strcmp(filename, "-")) { out->fp = stdout; #if !defined(__MWERKS__) && (defined(WIN32) || defined(OS2)) #if !defined(__BORLANDC__) && !defined(OS2) _setmode(_fileno(stdout), _O_BINARY); #else setmode(fileno(stdout), O_BINARY); #endif /* !__BORLANDC__ && !OS2 */ #endif } else { #endif /* !MAC */ char fopenparams[200]; /* sufficient */ #if defined(MVS) || defined(MVS_TEST) if (out->fopenparams != (char *) 0) { strcpy(fopenparams, WRITEMODE); strcat(fopenparams, ","); strcat(fopenparams, out->fopenparams); } else if (out->recordsize <= 1) { strcpy(fopenparams, WRITEMODE_V); } else { strcpy(fopenparams, WRITEMODE); } #else strcpy(fopenparams, WRITEMODE); #endif out->fp = pdc_fopen_logg(out->pdc, filename, fopenparams); if (out->fp == NULL) return pdc_false; #if (defined(MAC) || defined(MACOSX)) && defined(PDF_FILETYPE_SUPPORTED) if (!pdc->ptfrun) { /* set the proper type and creator for the output file */ #if TARGET_API_MAC_CARBON && !defined(__MWERKS__) if (FSPathMakeFSSpec((const UInt8 *) filename, &fSpec) == noErr) { FSpGetFInfo(&fSpec, &fInfo); fInfo.fdType = 'PDF '; fInfo.fdCreator = 'CARO'; FSpSetFInfo(&fSpec, &fInfo); } #else memset(&fcbInfo, 0, sizeof(FCBPBRec)); fcbInfo.ioRefNum = (short) out->fp->handle; fcbInfo.ioNamePtr = name; if (!PBGetFCBInfoSync(&fcbInfo) && FSMakeFSSpec(fcbInfo.ioFCBVRefNum, fcbInfo.ioFCBParID, name, &fSpec) == noErr) { FSpGetFInfo(&fSpec, &fInfo); fInfo.fdType = 'PDF '; fInfo.fdCreator = 'CARO'; FSpSetFInfo(&fSpec, &fInfo); } #endif /* !defined(TARGET_API_MAC_CARBON) || defined(__MWERKS__) */ } #endif /* (MAC || MACOSX) && PDF_FILETYPE_SUPPORTED */ #if !((defined(MAC) || defined (MACOSX)) && defined(__MWERKS__)) } #endif /* !MAC */ } return pdc_true; }