/* Make a reusable file stream. */ static int make_rfs(i_ctx_t *i_ctx_p, os_ptr op, stream *fs, long offset, long length) { uint save_space = icurrent_space; uint stream_space = imemory_space((const gs_ref_memory_t *)fs->memory); gs_const_string fname; gs_parsed_file_name_t pname; stream *s; int code; if (sfilename(fs, &fname) < 0) return_error(e_ioerror); code = gs_parse_file_name(&pname, (const char *)fname.data, fname.size, imemory); if (code < 0) return code; if (pname.len == 0) /* %stdin% etc. won't have a filename */ return_error(e_invalidfileaccess); /* can't reopen */ if (pname.iodev == NULL) pname.iodev = iodev_default(imemory); /* Open the file again, to be independent of the source. */ ialloc_set_space(idmemory, stream_space); code = zopen_file(i_ctx_p, &pname, "r", &s, imemory); ialloc_set_space(idmemory, save_space); if (code < 0) return code; if (sread_subfile(s, offset, length) < 0) { sclose(s); return_error(e_ioerror); } s->close_at_eod = false; make_stream_file(op, s, "r"); return 0; }
/* <file> .filename false */ static int zfilename(i_ctx_t *i_ctx_p) { os_ptr op = osp; stream *s; gs_const_string fname; byte *str; check_file(s, op); if (sfilename(s, &fname) < 0) { make_false(op); return 0; } check_ostack(1); str = ialloc_string(fname.size, "filename"); if (str == 0) return_error(e_VMerror); memcpy(str, fname.data, fname.size); push(1); /* can't fail */ make_const_string( op - 1 , a_all | imemory_space((const struct gs_ref_memory_s*) imemory), fname.size, str); make_true(op); return 0; }
std::string ProxyViz::replaceEnvVar(const MString & filename) const { EnvVar var; std::string sfilename(filename.asChar()); if(var.replace(sfilename)) MGlobal::displayInfo(MString("substitute file path "+filename+" to ")+sfilename.c_str()); return sfilename; }
//--------------------------------------- bool Mesh::InitMaterials( const aiScene* scene, const char* filename ) { // Extract the directory part from the file name std::string sfilename( filename ); std::string::size_type SlashIndex = sfilename.find_last_of("/"); std::string Dir; if (SlashIndex == std::string::npos) { Dir = "."; } else if (SlashIndex == 0) { Dir = "/"; } else { Dir = sfilename.substr(0, SlashIndex); } bool result = false; for ( unsigned i = 0; i < scene->mNumMaterials; ++i ) { const aiMaterial* mat = scene->mMaterials[i]; mTextures[i] = 0; if ( mat->GetTextureCount( aiTextureType_DIFFUSE ) > 0 ) { aiString path; if ( mat->GetTexture( aiTextureType_DIFFUSE, 0 , &path, 0, 0, 0, 0, 0 ) == aiReturn_SUCCESS ) { // Just gonna assume the textures are next to the mesh files std::string txFilename = StringUtil::ExtractFilenameFromPath( path.data ); std::string fullPath = Dir + "/" + txFilename; mTextures[i] = Texture2D::CreateTexture( fullPath.c_str(), false ); if ( !mTextures[i]->Load() ) { Texture2D::DestroyTexture( mTextures[i] ); result = false; } } } if ( !mTextures[i] ) { mTextures[i] = Texture2D::CreateTexture( "../data/textures/white.png" ); result = mTextures[i]->Load(); } } return result; }
/*! Gets the format of the file(s) which has/have to be read. \return Returns the format. */ vpVideoReader::vpVideoFormatType vpVideoReader::getFormat(const char *filename) { std::string sfilename(filename); std::string ext = vpVideoReader::getExtension(sfilename); if (ext.compare(".PGM") == 0) return FORMAT_PGM; else if (ext.compare(".pgm") == 0) return FORMAT_PGM; else if (ext.compare(".PPM") == 0) return FORMAT_PPM; else if (ext.compare(".ppm") == 0) return FORMAT_PPM; else if (ext.compare(".JPG") == 0) return FORMAT_JPEG; else if (ext.compare(".jpg") == 0) return FORMAT_JPEG; else if (ext.compare(".JPEG") == 0) return FORMAT_JPEG; else if (ext.compare(".jpeg") == 0) return FORMAT_JPEG; else if (ext.compare(".PNG") == 0) return FORMAT_PNG; else if (ext.compare(".png") == 0) return FORMAT_PNG; else if (ext.compare(".AVI") == 0) return FORMAT_AVI; else if (ext.compare(".avi") == 0) return FORMAT_AVI; else if (ext.compare(".MPEG") == 0) return FORMAT_MPEG; else if (ext.compare(".mpeg") == 0) return FORMAT_MPEG; else if (ext.compare(".MPG") == 0) return FORMAT_MPEG; else if (ext.compare(".mpg") == 0) return FORMAT_MPEG; else if (ext.compare(".MOV") == 0) return FORMAT_MOV; else if (ext.compare(".mov") == 0) return FORMAT_MOV; else if (ext.compare(".OGV") == 0) return FORMAT_OGV; else if (ext.compare(".ogv") == 0) return FORMAT_OGV; else return FORMAT_UNKNOWN; }