/* jijun 4/22/97, 4/23/97 */ void setneuronhome(const char* p) { CInfoPBRec myPB; short vRefNum; long dirID; Str255 dirName; char prePath[256]; static char fullPath[256]; OSErr err = HGetVol ((0), &vRefNum, &dirID); if (err==noErr) { myPB.dirInfo.ioNamePtr = dirName; myPB.dirInfo.ioVRefNum = vRefNum; myPB.dirInfo.ioDrParID = dirID; myPB.dirInfo.ioFDirIndex= -1; do { myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID; err = PBGetCatInfoSync(&myPB); if (err==noErr) { dirName[dirName[0]+1]='\0'; strcpy(prePath, (char*)&dirName[1]); strcat(prePath, ":"); strcat(prePath, fullPath); strcpy(fullPath, prePath); } } while (myPB.dirInfo.ioDrDirID > 2); } neuron_home=fullPath; // get rid of last ':' neuron_home[strlen(neuron_home)-1] = '\0'; // debugfile("neuron_home = %s\n", neuron_home); }
//------------------------------------------------------------------------ bool pixel_map::save_as_qt(const char *filename) const { FSSpec fss; OSErr err; // get file specification to application directory err = HGetVol(nil, &fss.vRefNum, &fss.parID); if (err == noErr) { GraphicsExportComponent ge; CopyCStringToPascal(filename, fss.name); // I decided to use PNG as output image file type. // There are a number of other available formats. // Should I check the file suffix to choose the image file format? err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypePNG, &ge); if (err == noErr) { err = GraphicsExportSetInputGWorld(ge, m_pmap); if (err == noErr) { err = GraphicsExportSetOutputFile (ge, &fss); if (err == noErr) { GraphicsExportDoExport(ge, nil); } } CloseComponent(ge); } } return err == noErr; }
void NScanResource( MADLibrary *inMADDriver) { short i; #define BASERES 1000 for( i = 0; i < MAXPLUG; i++) { Boolean ResourceOK; Handle aRes, bRes; ResourceOK = true; aRes = MADGet1Resource( 'CODE', BASERES + i, inMADDriver); if( aRes == NULL) ResourceOK = false; else { DisposeHandle( aRes); aRes = NULL; } bRes = MADGet1Resource( 'STR#', BASERES + i, inMADDriver); if( bRes == NULL) ResourceOK = false; else { DisposeHandle( bRes); bRes = NULL; } if( inMADDriver->TotalPlug < MAXPLUG && ResourceOK == true) { short No = inMADDriver->TotalPlug; Handle theRes; Str255 tStr; // theName = LMGetCurApName(); HGetVol( NULL, &inMADDriver->ThePlug[ No].file.vRefNum, &inMADDriver->ThePlug[ No].file.parID); pStrCpy( inMADDriver->ThePlug[ No].file.name, RSRCNAME); /** CODE du Plug-in **/ GetIndString( tStr, BASERES+i, 1); BlockMoveData( tStr + 1, &inMADDriver->ThePlug[ No].type, 4); inMADDriver->ThePlug[ No].type[ 4] = 0; GetIndString( tStr, BASERES+i, 2); BlockMoveData( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4); GetIndString( inMADDriver->ThePlug[ No].MenuName, BASERES+i, 3); GetIndString( inMADDriver->ThePlug[ No].AuthorString, BASERES+i, 4); inMADDriver->TotalPlug++; } } }
FILE *f_open(Filename fn, char const *mode) { short savevol; long savedir; char tmp[256]; FILE *ret; HGetVol(NULL, &savevol, &savedir); if (HSetVol(NULL, fn.fss.vRefNum, fn.fss.parID) == noErr) { p2cstrcpy(tmp, fn.fss.name); ret = fopen(tmp, mode); } else ret = NULL; HSetVol(NULL, savevol, savedir); return ret; }
int FSpGetDefaultDir( FSSpecPtr dirSpec) /* On return the default directory. */ { OSErr err; short vRefNum = 0; long int dirID = 0; err = HGetVol(NULL, &vRefNum, &dirID); if (err == noErr) { err = FSMakeFSSpecCompat(vRefNum, dirID, (ConstStr255Param) NULL, dirSpec); } return err; }
void MInitImportPlug( MADLibrary *inMADDriver, FSSpec *PlugsFolderName) { short vRefNum; long dirID; HGetVol( NULL, &vRefNum, &dirID); inMADDriver->ThePlug = (PlugInfo*) MADNewPtr( MAXPLUG * sizeof( PlugInfo), inMADDriver); inMADDriver->TotalPlug = 0; if( PlugsFolderName != NULL) { PlugsFolderOK = 0; NScanDirImportPlug( inMADDriver, PlugsFolderName->parID, PlugsFolderName->vRefNum, PlugsFolderName->name); } HSetVol( NULL, vRefNum, dirID); NScanResource( inMADDriver); }
static FILE * OpenScript(StandardFileReply *reply) { FILE * stream; OSType fileType = 'TEXT'; Str255 buff; short vRefNum; long dirID; stream = nil; HGetVol( buff, &vRefNum, &dirID ); HSetVol( nil, reply->sfFile.vRefNum, reply->sfFile.parID ); p2cstr( (StringPtr) &reply->sfFile.name ); stream = fopen( (char *) &reply->sfFile.name, "r" ); fprintf(gLogFile, "\n%s\n",(char *) &reply->sfFile.name); if ( stream == nil ) { DebugStr( "\punable to open script file." ); }
/* Sets itself to current directory. */ HXBOOL CHXDirectory::SetCurrentDir() { OSErr err; long dirID; short vRefNum; FSRef currDir; err = HGetVol(NULL, &vRefNum, &dirID); if (err == noErr) { err = FSMakeFSRef(vRefNum, dirID, NULL, &currDir); if (err == noErr) { CHXDirSpecifier dirSpec(currDir); SetPath(dirSpec.GetPathName()); } } return (err == noErr); }
// I let Quicktime handle image import since it supports most popular // image formats such as: // *.psd, *.bmp, *.tif, *.png, *.jpg, *.gif, *.pct, *.pcx //------------------------------------------------------------------------ bool pixel_map::load_from_qt(const char *filename) { FSSpec fss; OSErr err; // get file specification to application directory err = HGetVol(nil, &fss.vRefNum, &fss.parID); if (err == noErr) { CopyCStringToPascal(filename, fss.name); GraphicsImportComponent gi; err = GetGraphicsImporterForFile (&fss, &gi); if (err == noErr) { ImageDescriptionHandle desc; GraphicsImportGetImageDescription(gi, &desc); // For simplicity, all images are currently converted to 32 bit. // create an empty pixelmap short depth = 32; create ((**desc).width, (**desc).height, (org_e)depth, 0xff); DisposeHandle ((Handle)desc); // let Quicktime draw to pixelmap GraphicsImportSetGWorld(gi, m_pmap, nil); GraphicsImportDraw(gi); // Well, this is a hack. The graphics importer sets the alpha channel of the pixelmap to 0x00 // for imported images without alpha channel but this would cause agg to draw an invisible image. // set alpha channel to 0xff unsigned char * buf = m_buf; for (unsigned int size = 0; size < m_img_size; size += 4) { *buf = 0xff; buf += 4; } } } return err == noErr; }
int osd_environment( void ) { char buffer[257]; OSErr err; short vRefNum; long dirID; /* カレントディレクトリを設定 */ dir_cwd[0] = '\0'; err = HGetVol((UInt8*)buffer, &vRefNum, &dirID); if (noErr != err) { ; }else{ err = GetFullPath(vRefNum, dirID, (UInt8*)buffer); if (noErr == err) { buffer[ buffer[0]+1 ] = '\0'; strcpy( dir_cwd, &buffer[1] ); }else{ ; } } /* ROMディレクトリを設定する */ if( strlen( dir_rom ) + sizeof( ":ROM" ) < 256 ){ dir_rom[0] = '\0'; strcat( dir_rom, dir_cwd ); strcat( dir_rom, ":ROM" ); } /* DISKディレクトリを設定する */ if( strlen( dir_disk ) + sizeof( ":DISK" ) < 256 ){ dir_disk[0] = '\0'; strcat( dir_disk, dir_cwd ); strcat( dir_disk, ":DISK" ); } /* TAPEディレクトリを設定する */ if( strlen( dir_tape ) + sizeof( ":TAPE" ) < 256 ){ dir_tape[0] = '\0'; strcat( dir_tape, dir_cwd ); strcat( dir_tape, ":TAPE" ); } /* SNAPディレクトリを設定する */ if( strlen( dir_snap ) + sizeof( ":SNAP" ) < 256 ){ dir_snap[0] = '\0'; strcat( dir_snap, dir_cwd ); strcat( dir_snap, ":SNAP" ); } /* STATEディレクトリを設定する */ if( strlen( dir_state ) + sizeof( ":STATE" ) < 256 ){ dir_state[0] = '\0'; strcat( dir_state, dir_cwd ); strcat( dir_state, ":STATE" ); } /* 全体設定ディレクトリを設定する */ if( strlen( dir_g_cfg ) + sizeof( ":Prefs" ) < 256 ){ dir_g_cfg[0] = '\0'; strcat( dir_g_cfg, dir_cwd ); /* strcat( dir_g_cfg, ":Prefs" );*/ } /* 個別設定ディレクトリを設定する */ if( strlen( dir_l_cfg ) + sizeof( ":Prefs" ) < 256 ){ dir_l_cfg[0] = '\0'; strcat( dir_l_cfg, dir_cwd ); /* strcat( dir_l_cfg, ":Prefs" );*/ } return TRUE; }
static OSErr MacPathname2FSSpec(const char *inPathname, FSSpec *outFSS) { OSErr err; size_t len; char *p; short vRefNum; long dirID; FSSpec fss; if (inPathname == NULL || outFSS == NULL) { return paramErr; } err = HGetVol(NULL, &vRefNum, &dirID); /* default volume and directory */ if (err != noErr) return err; len = strlen(inPathname); p = strchr(inPathname, ':'); if (p == NULL) { /* Partial pathname -- filename only */ Str31 filename; assert(len <= 31); c2pstrcpy(filename, inPathname); err = FSMakeFSSpec(vRefNum, dirID, filename, outFSS); } else { Str31 name; int nameLen; if (inPathname[0] == ':') { /* Relative pathname including directory path */ } else { /* Absolute pathname */ /* Str31 volName; We would use Str28 if it was defined -- 27, plus 1 for ':'. */ nameLen = p - inPathname; assert(nameLen <= 27); name[0] = nameLen + 1; memcpy(name + 1, inPathname, nameLen + 1); /* Copy the volume name and the colon. */ err = DetermineVRefNum(name, 0, &vRefNum); if (err != noErr) return err; dirID = 2; } /* vRefNum and dirID now specify the directory in which we should descend the path pointed to by p (pointing to the first colon). */ p++; while (p != NULL && *p != '\0') { char *q = strchr(p, ':'); if (q != NULL) { Boolean isDir; nameLen = q - p; assert(nameLen <= 31); name[0] = nameLen; memcpy(name + 1, p, nameLen); err = FSMakeFSSpec(vRefNum, dirID, name, &fss); if (err != noErr) return err; if (q[1] == '\0') { p = NULL; *outFSS = fss; } else { err = FSpGetDirectoryID(&fss, &dirID, &isDir); assert(isDir == true); if (err != noErr) return err; p = q + 1; } } else { q = strchr(p, '\0'); /* go to end of string */ nameLen = q - p; assert(nameLen > 0); assert(nameLen <= 31); c2pstrcpy(name, p); p = NULL; err = FSMakeFSSpec(vRefNum, dirID, name, outFSS); } } } return err; }
char *macFindFile(char *fileName, Str255 message, Str255 defaultname, Integer readWrite, Integer ntypes, OSType * types, Integer * volume) { SFTypeList myTypes; Point p; Integer numTypes; Integer vRefNum = (volume != (Integer *) 0) ? *volume : 0; LongInt dirID; int i; WHERE("macFindFile"); if (fileName[0] == '\0') { /* Use standard file dialog box */ SetPt(&p, 82, 90); DeactivateWindow(); /*unhighlight front window*/ if (readWrite == WRITEIT) { /* write */ DialogEdit = true; NDialogButtons = 2; ButtonChars[0] = 's'; ButtonChars[1] = 'n'; SFPPutFile(p, message, defaultname, NullDialogHookPtr, &Reply, putDlgID, MyDialogFilterPtr); } /*if (readWrite == WRITEIT)*/ else {/* read */ if(ntypes == 0) { numTypes = 0; myTypes[numTypes++] = 'TEXT'; myTypes[numTypes++] = 'ttro'; if(types != (OSType *) 0) { myTypes[numTypes++] = types[0]; } } else { numTypes = (ntypes <= 4) ? ntypes : 4; /*play it safe*/ for(i = 0;i < numTypes; i++) { myTypes[i] = types[i]; } } DialogEdit = false; NDialogButtons = 2; ButtonChars[0] = 'o'; /* Open */ ButtonChars[1] = 'n'; /* Cancel */ SFPGetFile(p, message, NullFileFilterPtr, numTypes, myTypes, NullDialogHookPtr, &Reply, getDlgID, MyDialogFilterPtr); } /*if (readWrite == WRITEIT){}else{}*/ macUpdate((WindowPtr) 0); if (!Reply.good) { /* cancelled */ return (0); } vRefNum = Reply.vRefNum; if (volume != (Integer *) 0) { *volume = vRefNum; } PtoCstr((unsigned char *) Reply.fName); strcpy(FileName, (char *) Reply.fName); CtoPstr((char *) Reply.fName); fileName = FileName; } /*if (fileName[0] == '\0')*/ else if (volume != (Integer *) 0 && vRefNum == 0 && HGetVol((StringPtr) 0, &vRefNum, &dirID) == noErr) { *volume = vRefNum; } if (vRefNum != 0) { SetVol(0L, vRefNum); } return (fileName); } /*macFindFile()*/
globle int GenOpenReadBinary( void *theEnv, char *funcName, char *fileName) { #if MAC Str255 tempName; OSErr resultCode; Str255 volName; short int vRefNum; long vDirNum; FSSpec theFSSpec; resultCode = HGetVol(volName,&vRefNum,&vDirNum); if (resultCode != noErr) { OpenErrorMessage(theEnv,funcName,fileName); return(0); } strcpy((char *) tempName,fileName); CopyCStringToPascal((char *) tempName,tempName); resultCode = FSMakeFSSpec(vRefNum,vDirNum,tempName,&theFSSpec); if (resultCode != noErr) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } resultCode = FSpOpenDF(&theFSSpec,fsCurPerm,&SystemDependentData(theEnv)->BinaryRefNum); if (resultCode != noErr) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif #if IBM_TBC || IBM_MSC || IBM_ICB SystemDependentData(theEnv)->BinaryFileHandle = open(fileName,O_RDONLY | O_BINARY); if (SystemDependentData(theEnv)->BinaryFileHandle == -1) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif #if (! MAC) && (! IBM_TBC) && (! IBM_MSC) && (! IBM_ICB) if ((SystemDependentData(theEnv)->BinaryFP = fopen(fileName,"rb")) == NULL) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif return(TRUE); }