char *getenv(const char *name) { FILE *fp; char *LineStr = NULL; EnviromentPair *Env1; FSSpec spec; OSErr err; if (IgnoreEnvironment) return NULL; /* user wants to ignore the environment vars */ if (name == NULL) return NULL; GetCompletePath(CompletePath,"MacZip.Env",&spec,&err); /* try open the file in the current folder */ fp = FSp_fopen(&spec,"r"); if (fp == NULL) { /* Okey, lets try open the file in the preference folder */ FSpFindFolder_Name( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &spec, "\pMacZip.Env"); fp = FSp_fopen(&spec,"r"); if (fp == NULL) { return NULL; /* there is no enviroment-file */ } }
/** * replaces standard fopen -- opens files for writing in the project's output directory, * and files for reading in the object code directory. */ FILE* std::fopen(const char* filename, const char *mode) { CWFileSpec& fileDir = (mode[0] == 'r' ? gObjectCodeDirectory : gOutputDirectory); FSSpec fileSpec = { fileDir.vRefNum, fileDir.parID }; c2p_strcpy(fileSpec.name, filename); return FSp_fopen(&fileSpec, mode); }
PGPError pgpPlatformOpenFileSpecAsFILE( PFLFileSpecRef spec, const char * openMode, FILE ** fileOut ) { PGPError err = kPGPError_NoErr; FILE * stdioFILE = NULL; FSSpec fsSpec; PGPValidatePtr( fileOut ); *fileOut = NULL; PFLValidateFileSpec( spec ); PGPValidatePtr( openMode ); PGPValidateParam( spec->type == kPFLFileSpecMacType ); err = PFLGetFSSpecFromFileSpec( spec, &fsSpec ); if ( IsntPGPError( err ) ) { stdioFILE = FSp_fopen( &fsSpec, openMode ); if ( NULL==(int)( stdioFILE ) ) err = kPGPError_FileNotFound; } *fileOut = stdioFILE; return( err ); }
static CWResult LinkHeaders(CWPluginContext context, XPIDLSettings& settings) { // find out how many files there are to link. long fileCount = 0; CWResult err = CWGetProjectFileCount(context, &fileCount); if (err != cwNoErr || fileCount == 0) return err; // get the output directory. FSSpec outputDir; err = CWGetOutputFileDirectory(context, &outputDir); if (!CWSUCCESS(err)) return err; // enumerate all of the output header files, and make aliases to them in // the output directory. for (long index = 0; (err == cwNoErr) && (index < fileCount); index++) { // get the name of each output file. CWFileSpec outputFile; err = CWGetStoredObjectFileSpec(context, index, &outputFile); if (err == cwNoErr) { FInfo info; err = FSpGetFInfo(&outputFile, &info); FSSpec aliasFile = { outputDir.vRefNum, outputDir.parID }; BlockMoveData(outputFile.name, aliasFile.name, 1 + outputFile.name[0]); AliasHandle alias = NULL; if (NewAliasMinimal(&outputFile, &alias) == noErr) { // recreate the alias file from scratch. FSpDelete(&aliasFile); FSpCreateResFile(&aliasFile, info.fdCreator, info.fdType, smRoman); short refNum = FSpOpenResFile(&aliasFile, fsRdWrPerm); if (refNum != -1) { UseResFile(refNum); AddResource(Handle(alias), rAliasType, 0, aliasFile.name); ReleaseResource(Handle(alias)); UpdateResFile(refNum); CloseResFile(refNum); } // finally, mark the newly created file as an alias file. FSpGetFInfo(&aliasFile, &info); info.fdFlags |= kIsAlias; FSpSetFInfo(&aliasFile, &info); } } } // create the target file in the output directory. BlockMoveData(settings.output, outputDir.name, 1 + settings.output[0]); FILE* outputFile = FSp_fopen(&outputDir, "w"); if (outputFile != NULL) fclose(outputFile); return err; }
void doSaveCommand(FILE **f) { StandardFileReply fileReply; *f = NULL; StandardPutFile("\pSave file as:","\puntitled",&fileReply); *f = FSp_fopen(&fileReply.sfFile, "wb"); }
void doOpenCommand(FILE **f) { StandardFileReply fileReply; *f = NULL; StandardGetFile(NULL,-1,NULL,&fileReply); if(fileReply.sfGood) { *f = FSp_fopen(&fileReply.sfFile, "rb"); }; }
/** * Substitute for standard fopen, treats certain filenames specially, * and also considers the mode argument. If a file is being opened * for reading, the file is assumed to be locateable using CodeWarrior's * standard access paths. If it's for writing, the file is opened in * the current project's output directory. */ FILE* std::fopen(const char* filename, const char *mode) { FSSpec filespec; CWResult err = noErr; do { if (filename == gSourcePath || strcmp(filename, gSourcePath) == 0) { // opening the main source file. filespec = gSourceFile; } else if (mode[0] == 'w') { // if an output file, open it in the current compilation's output directory. c2p_strcpy(filespec.name, filename); filespec.vRefNum = gOutputFile.vRefNum; filespec.parID = gOutputFile.parID; c2p_strcpy(gOutputFile.name, filename); } else { // an input file, use CodeWarrior's search paths to find the named source file. err = LocateFile(gPluginContext, filename, filespec); } } while (0); // if all went well, we have a file to open. return (err == noErr ? FSp_fopen(&filespec, mode) : NULL); }