extern void main(void) { OSStatus err; FCBPBRec fcbPB; FSSpec fss; // 1. Show our "icon march" icon ShowInitIcon(128, true); // 2. Find our FSSpec fss.name[0] = 0; fcbPB.ioNamePtr = fss.name; fcbPB.ioVRefNum = 0; fcbPB.ioRefNum = (short)CurResFile(); fcbPB.ioFCBIndx = 0; err = PBGetFCBInfoSync(&fcbPB); // 3. Tell CFM that we're a CFM library container file fss.vRefNum = fcbPB.ioFCBVRefNum; fss.parID = fcbPB.ioFCBParID; if (err == noErr) err = FragRegisterFileLibs(&fss, false); // 4. Now that CFM knows we're a library container, tell it to go and get our library if (err == noErr) { CFragConnectionID c; Ptr m; Str255 e; THz oldZone = GetZone(); SetZone(SystemZone()); err = GetSharedLibrary("\pDarwin;mDNS", kPowerPCCFragArch, kLoadCFrag, &c, &m, e); SetZone(oldZone); }
static OSErr FileGetLocation( short iRefNum, short* oVRefNum, long* oParDirID, StringPtr oFileName) { FCBPBRec pb; OSErr errCode = noErr; pb.ioNamePtr = oFileName; pb.ioVRefNum = 0; pb.ioRefNum = iRefNum; pb.ioFCBIndx = 0; errCode = PBGetFCBInfoSync(&pb); if (errCode != noErr) goto punt; *oVRefNum = pb.ioFCBVRefNum; *oParDirID = pb.ioFCBParID; punt: return errCode; }
// -------------------------------------------------------------------------------------- static OSErr getCurrentResourceFSSpec(FSSpec *curResSpec) { OSErr error; FCBPBPtr fileInfo; // file control block parameter block pointer StrFileName fileName; /* In the age of application packages and bundles, it's less likely that the current resource file is the application file itself. It's more likely to be a flattened resource file in a bundle so we need a generic method instead of the traditional Process Manager method of getting the current application's FSSpec of it's executable file */ fileInfo = (FCBPBPtr)NewPtr(sizeof(FCBPBRec)); fileInfo->ioNamePtr = fileName; // to hold the resource file's name fileInfo->ioVRefNum = 0; // 0 to search through all open files on all volumes fileInfo->ioRefNum = CurResFile(); // get info about the main resource file // by using its reference number fileInfo->ioFCBIndx = 0; // 0 to ignore this parameter and use the // ioRefNum parameter instead error = PBGetFCBInfoSync(fileInfo); // synchronous because we don't have // anything else to do while we're waiting on the filesystem if (error == noErr) // if we got the necessary file info, make an FSSpec out of it FSMakeFSSpec(fileInfo->ioFCBVRefNum, fileInfo->ioFCBParID, fileName, curResSpec); DisposePtr((Ptr)fileInfo); return error; }
/* ** GetResRefNumFromFCB ** ** Search open files for this resource file and return the file reference number if found. ** Otherwise return -1. ** */ static ASInt16 GetResRefNumFromFCB(ASInt16 vRefNum, ASInt32 dirID, ConstStr255Param fileName) { StrFileName fcbFileName; FCBPBRec fcbPB; ASInt16 ioFCBIndx; ASInt16 plugResFile = -1; OSErr err = noErr; /* search for open plugin resource file reference number */ /* miMemset( &fcbPB, 0, sizeof(fcbPB) );*/ /* can not use miUtils in pdfviewer */ memset( &fcbPB, 0, sizeof(fcbPB) ); fcbPB.ioNamePtr = fcbFileName; fcbPB.ioVRefNum = vRefNum; for (ioFCBIndx = 1; err == noErr && plugResFile == -1; ioFCBIndx++) { fcbPB.ioFCBIndx = ioFCBIndx; err = PBGetFCBInfoSync(&fcbPB); if (err == noErr && fcbPB.ioFCBParID == dirID && fcbPB.ioFCBFlags & kioFCBResourceMask && EqualString(fcbFileName, fileName, true, true) ) { plugResFile = fcbPB.ioRefNum; } } return plugResFile; } /* GetResRefNumFromFCB */
/****************************************************************************** Utility routine to check that a file opened with read/write permission does in fact have read/write permission. It is possible to get a read-only file reference for a resource file that has been opened with read/write permission. This routine verify that a file open with read/write permission does in fact have write permission. pRefNum input: File reference number for file to be checked. RESULT CODES ____________ true The resource file was really opened with write permission false It wasn't ____________ */ pascal Boolean MoreResIsResFileRefNumWritable(const SInt16 pRefNum) { FCBPBRec fcbPB; Boolean result = false; fcbPB.ioNamePtr = NULL; fcbPB.ioVRefNum = 0; fcbPB.ioRefNum = pRefNum; fcbPB.ioFCBIndx = 0; if ( PBGetFCBInfoSync( &fcbPB ) == noErr ) { result = ( (fcbPB.ioFCBFlags & kioFCBWriteMask) != 0 ); } return result; }//end MoreResIsResFileRefNumWritable
/* close the output file, if opened with PDF_open_file(); * close the output stream if opened */ static void pdf_close_file(PDF *p) { #if defined(MAC) && defined(__MWERKS__) FCBPBRec fcbInfo; Str32 name; FInfo fInfo; FSSpec fSpec; #endif if (p->fp == NULL) return; #if defined(MAC) && defined(__MWERKS__) /* Contributed by Leonard Rosenthol: * On the MacOS, files are not associated with applications by extensions. * Instead, it uses a pair of values called the type & creator. * This block of code sets those values for PDF files. */ memset(&fcbInfo, 0, sizeof(FCBPBRec)); fcbInfo.ioRefNum = (short) p->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 /* * If filename is set, we started with PDF_open_file; therefore * we also close the file ourselves. */ if (p->filename && p->writeproc) { if (strcmp(p->filename, "-")) fclose(p->fp); p->free(p, p->filename); } /* mark fp as dead in case the error handler jumps in later */ p->fp = NULL; }
void SetLocaleFile( UInt8 * langStr, OSType signature ) { FCBPBRec resPb; Str31 fileName; OSErr err; resPb.ioCompletion = nil; // Find the plugin directory using resPb.ioNamePtr = fileName; // the res file ref num as a base. resPb.ioRefNum = GetAcroPluginResourceMap(); resPb.ioFCBIndx = 0; // Look up GetAcroPluginResourceMap() err = PBGetFCBInfoSync( &resPb ); if( err != noErr ) { // Something bad happened. Set locale gLocaleResFile = 0; // to nil and default to English return; } SearchDirectory( resPb.ioFCBVRefNum, resPb.ioFCBParID, langStr, signature, 1 ); }
Boolean QTInfo_IsRefNumOfResourceFork (short theRefNum) { FCBPBRec myFCBPBRec; Boolean myIsResFork = false; OSErr myErr = noErr; myFCBPBRec.ioCompletion = NULL; myFCBPBRec.ioNamePtr = NULL; myFCBPBRec.ioVRefNum = 0; myFCBPBRec.ioRefNum = theRefNum; myFCBPBRec.ioFCBIndx = 0; myErr = PBGetFCBInfoSync(&myFCBPBRec); if (myErr == noErr) if (myFCBPBRec.ioFCBFlags & kioFCBResourceMask) myIsResFork = true; return(myIsResFork); }
/* Given a file reference, answer its location as a vRefNum and a dirID. */ static FT_Error get_file_location( short ref_num, short* v_ref_num, long* dir_id, unsigned char* file_name ) { FCBPBRec pb; OSErr error; pb.ioNamePtr = file_name; pb.ioVRefNum = 0; pb.ioRefNum = ref_num; pb.ioFCBIndx = 0; error = PBGetFCBInfoSync( &pb ); if ( error == noErr ) { *v_ref_num = pb.ioFCBVRefNum; *dir_id = pb.ioFCBParID; } return error; }
FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; /* test for valid `aface' and `library' delayed to */ /* `FT_New_Face_From_XXX' */ GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_THROW( Invalid_File_Format ); HLock( fond ); parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); HUnlock( fond ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; #if HAVE_FSREF { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( !error ) have_lwfn = 1; } #elif HAVE_FSSPEC { UInt8 path_fond[PATH_MAX]; FCBPBRec pb; Str255 fond_file_name; FSSpec spec; FT_MEM_SET( &spec, 0, sizeof ( FSSpec ) ); FT_MEM_SET( &pb, 0, sizeof ( FCBPBRec ) ); pb.ioNamePtr = fond_file_name; pb.ioVRefNum = 0; pb.ioRefNum = res; pb.ioFCBIndx = 0; err = PBGetFCBInfoSync( &pb ); if ( noErr != err ) goto found_no_lwfn_file; err = FSMakeFSSpec( pb.ioFCBVRefNum, pb.ioFCBParID, fond_file_name, &spec ); if ( noErr != err ) goto found_no_lwfn_file; err = FT_FSpMakePath( &spec, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( !error ) have_lwfn = 1; } #endif /* HAVE_FSREF, HAVE_FSSPEC */ } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_ERR( Unknown_File_Format ); found_no_lwfn_file: if ( have_sfnt && error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }
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; }