/* filename: nombre de un fichero. * file_info: structura donde se guardara la informacion. * retorna: 1 si todo ha ido bien en otro caso 0. */ int file_get_file_info(const char *filename, struct file_info *inf) { int ret; long filesize; if(!filename || !inf) return 0; filesize = file_getsize(filename); if(0 >= filesize || MAX_32BIT < filesize) return 0; memset(inf, 0, sizeof(*inf)); inf->size = filesize; ret = file_extension(filename, inf->ext, FILE_MAX_EXTENSION_NAME); if(0 >= ret) return 0; return 1; }
AmAudioFileFormat* AmAudioFile::fileName2Fmt(const string& name, const string& subtype) { string ext = file_extension(name); if(ext == ""){ ERROR("fileName2Fmt: file name has no extension (%s)\n",name.c_str()); return NULL; } iofmt = AmPlugIn::instance()->fileFormat("",ext); if(!iofmt){ ERROR("fileName2Fmt: could not find a format with that extension: '%s'\n",ext.c_str()); return NULL; } if (!subtype.empty()) { amci_subtype_t* st = AmPlugIn::instance()->subtype(iofmt, subtype); if (st!=NULL) { return new AmAudioFileFormat(iofmt->name, st->type, st); } WARN("subtype '%s' for file '%s' not found. Using default subtype\n", subtype.c_str(), name.c_str()); } return new AmAudioFileFormat(iofmt->name, -1); }
static int get_drop_command(const char *filename, int flags) { const char *e; e = file_extension(filename); if (*e && stristr(".bmp.gif.png.jpg.jpeg", e)) { unsigned modkey = get_modkeys() & (MK_ALT|MK_SHIFT|MK_CONTROL); const char *mode; if (0 == modkey) mode = "full"; else if (MK_SHIFT == modkey) mode = "center"; else if (MK_CONTROL == modkey) mode = "tile"; else return 0; if (0 == (flags & 1)) post_command_fmt("@BBCore.rootCommand bsetroot -%s \"%s\"", mode, filename); return 1; } // whether its a style is checked only once by looking at // the file's contents on DragEnter if (flags & 2) { if (0 == (flags & 1)) post_command_fmt(MM_STYLE_BROAM, filename); return 1; } return 0; }
std::wstring Episode::file_name_with_extension() const { auto filename = GetElementAsString(anitomy::kElementFileName); auto extension = file_extension(); if (!extension.empty()) filename += L"." + extension; return filename; }
void Preprocessor::applyHelpFile() { std::string help_file = file_directory(file_name) + file_extension(file_name) + ".help"; std::ifstream hfs(help_file); if(!hfs.is_open()) return; hfs.close(); std::cout << "Using HELP file: " << help_file << '.' << std::endl; readFile(help_file); analyseSource(); lines.clear(); source.clear(); }
AmAudioFileFormat* AmAudioFile::fileName2Fmt(const string& name) { string ext = file_extension(name); if(ext == ""){ ERROR("fileName2Fmt: file name has no extension (%s)\n",name.c_str()); return NULL; } iofmt = AmPlugIn::instance()->fileFormat("",ext); if(!iofmt){ ERROR("fileName2Fmt: could not find a format with that extension: '%s'\n",ext.c_str()); return NULL; } return new AmAudioFileFormat(iofmt->name); }
// -------------------- // volume_file_info::read // -------------------- // Purpose: // Refers to the handler map to choose an appropriate IO object for reading // the requested volume file. Use this function to initialize the volume_file_info // object with info from a volume file. // ---- Change History ---- // ??/??/2007 -- Joe R. -- Initially implemented. // 11/13/2009 -- Joe R. -- Re-implemented using VolumeFile_IO handler map // 12/28/2009 -- Joe R. -- Collecting exception error strings // 09/08/2011 -- Joe R. -- Using splitRawFilename to extract real filename // if the provided filename is a file|obj tuple. void volume_file_info::read(const std::string& filename) { std::string errors; boost::regex file_extension("^(.*)(\\.\\S*)$"); boost::smatch what; std::string actualFileName; std::string objectName; boost::tie(actualFileName, objectName) = volume_file_io::splitRawFilename(filename); if(boost::regex_match(actualFileName, what, file_extension)) { if(volume_file_io::handlerMap()[what[2]].empty()) throw unsupported_volume_file_type(std::string(BOOST_CURRENT_FUNCTION) + std::string(": Cannot read ") + filename); volume_file_io::handlers& h = volume_file_io::handlerMap()[what[2]]; //use the first handler that succeds for(volume_file_io::handlers::iterator i = h.begin(); i != h.end(); i++) try { if(*i) { (*i)->getVolumeFileInfo(_data,filename); return; } } catch(exception& e) { errors += std::string(" :: ") + e.what(); } } throw unsupported_volume_file_type( boost::str( boost::format("%1% : Cannot read '%2%'%3%") % BOOST_CURRENT_FUNCTION % filename % errors ) ); }
bool is_gzip_compressed_file( std::string const& file_name ) { // Check if the file extension hints at gzip. auto const ext = file_extension( file_name ); bool const ext_gz = ( ext == "gz" || ext == "gzip" ); // Open the file in binary mode. std::ifstream infile; infile.open( file_name, std::ifstream::in | std::ifstream::binary ); if( !infile.good() ) { return false; // throw std::runtime_error( "Cannot read from file '" + file_name + "'." ); } // Get the first two characters. If this fails, the file is too short, so it is not a gzip file. unsigned char buffer[2]; infile.read( reinterpret_cast<char*>( &buffer ), 2 ); if( !infile.good() ) { return false; } infile.close(); // Check if the file starts with the magic number of gz files. bool const magic = ( buffer[0] == 0x1f ) && ( buffer[1] == 0x8b ); // If extension and magic number agree, we have a clear result. // Otherwise, issue a warning, and return the magic bit, because this is what we trust more. if( ext_gz && magic ) { return true; } else if( ! ext_gz && ! magic ) { return false; } else if( ext_gz && ! magic ) { LOG_WARN << "File name '" << file_name << "' ends in '.gz', but the file does not seem " << "to contain gzip content."; } else if( ! ext_gz && magic ) { LOG_WARN << "File name '" << file_name << "' does not end in '.gz', but the file seems " << "to contain gzip content."; } return magic; }
int db_share_files( const struct pub_file *files, size_t count, const struct client *owner ) { /* todo: do it in transaction */ while ( count-- > 0 ) { sqlite3_stmt *stmt; const char *ext; int ext_len; int i; uint64_t fid; if ( !files->name_len ) { files++; continue; } fid = MAKE_FID(files->hash); // find extension ext = file_extension(files->name, files->name_len); if ( ext ) ext_len = files->name + files->name_len - ext; else ext_len = 0; i=1; stmt = s_stmt[SHARE_UPD]; DB_CHECK( SQLITE_OK == sqlite3_reset(stmt) ); DB_CHECK( SQLITE_OK == sqlite3_bind_text(stmt, i++, files->name, files->name_len, SQLITE_STATIC) ); DB_CHECK( SQLITE_OK == sqlite3_bind_text(stmt, i++, ext, ext_len, SQLITE_STATIC) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int64(stmt, i++, files->size) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->type) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->media_length) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->media_bitrate) ); DB_CHECK( SQLITE_OK == sqlite3_bind_text(stmt, i++, files->media_codec, files->media_codec_len, SQLITE_STATIC) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int64(stmt, i++, fid) ); DB_CHECK( SQLITE_DONE == sqlite3_step(stmt) ); if ( !sqlite3_changes(s_db) ) { i=1; stmt = s_stmt[SHARE_INS]; DB_CHECK( SQLITE_OK == sqlite3_reset(stmt) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int64(stmt, i++, fid) ); DB_CHECK( SQLITE_OK == sqlite3_bind_blob(stmt, i++, files->hash, sizeof(files->hash), SQLITE_STATIC) ); DB_CHECK( SQLITE_OK == sqlite3_bind_text(stmt, i++, files->name, files->name_len, SQLITE_STATIC) ); DB_CHECK( SQLITE_OK == sqlite3_bind_text(stmt, i++, ext, ext_len, SQLITE_STATIC) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int64(stmt, i++, files->size) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->type) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->media_length) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->media_bitrate) ); DB_CHECK( SQLITE_OK == sqlite3_bind_text(stmt, i++, files->media_codec, files->media_codec_len, SQLITE_STATIC) ); DB_CHECK( SQLITE_DONE == sqlite3_step(stmt) ); } i=1; stmt = s_stmt[SHARE_SRC]; DB_CHECK( SQLITE_OK == sqlite3_reset(stmt) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int64(stmt, i++, fid) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int64(stmt, i++, MAKE_SID(owner)) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->complete) ); DB_CHECK( SQLITE_OK == sqlite3_bind_int(stmt, i++, files->rating) ); DB_CHECK( SQLITE_DONE == sqlite3_step(stmt) ); files++; } return 1; failed: ED2KD_LOGERR("failed to add file to db (%s)", sqlite3_errmsg(s_db)); return 0; }
ST bool is_bsetroot_command(const char **cptr) { char token[MAX_PATH]; *(char*)file_extension(NextToken(token, cptr, NULL)) = 0; return 0 == stricmp(token, "bsetroot") || 0 == stricmp(token, "bsetbg"); }
int main (int argc, char **argv) { char const *doctype; char const **ptr; args_data = postqueue_data = message_data; message_construct(argv[0]); args_construct(argc, argv, "?x:l:", 0); hashmap_construct(&symtab); lines_construct(&global.d_toc); lines_construct(&global.d_section); lines_add(&global.d_section, ""); hashmap_constructText(&global.d_symbol, default_symbols); if (!args_ok() || args_nArgs() < 2) /* check arguments */ usage(); if (args_nArgs() == 2) /* file name specified */ { global.d_out = stdout; global.d_noext = 0; } else { global.d_noext = file_rmExtension(args_arg(2)); global.d_ext = file_extension(args_arg(2)); if (!global.d_ext) { global.d_ext = new_str(args_optarg('x')); if (!global.d_ext) global.d_ext = "ypp"; /* Yodl Post Processor */ } } string_construct(&global.d_outName, 0); postqueue_construct(task); if (global.d_noext) { string_format(&global.d_outName, "%s.%s", global.d_noext, global.d_ext); global.d_out = file_open(string_str(&global.d_outName), "w"); } doctypes[sizeofDocType - 1] = doctype = hashmap_textOf(&global.d_symbol, "documenttype"); for ( ptr = doctypes, global.d_doctype = 1; strcmp(doctype, *ptr); ptr++, global.d_doctype <<= 1 ) ; postqueue_process(); fclose(global.d_out); return 0; }
void convert_in_cells_to_xz(const std::vector<std::string>& filenames, int nnx, int nnz) { std::cout << "Converting to xz plane..." << std::endl; double t_begin = get_wall_time(); const int n_files = filenames.size(); for (int f = 0; f < n_files; ++f) { const std::string filename = filenames[f]; std::ifstream in(filename.c_str(), std::ios::binary); require(in, "File '" + filename + "' can't be opened"); in.seekg(0, in.end); // jump to the end of the file int length = in.tellg(); // total length of the file in bytes int size_value = length / (nnx*nnz); // size (in bytes) of one value require(length % (nnx*nnz) == 0, "The number of bytes in the file " + filename + " is not divisible by the number of elements"); in.seekg(0, in.beg); // jump to the beginning of the file double *values = new double[nnx*nnz]; if (size_value == sizeof(double)) { in.read((char*)values, nnx*nnz*size_value); // read all at once require(nnx*nnz == (int)in.gcount(), "The number of successfully read " "elements is different from the expected one"); } else if (size_value == sizeof(float)) { float val = 0; for (int i = 0; i < nnx*nnz; ++i) // read element-by-element { in.read((char*)&val, size_value); // read a 'float' value values[i] = val; // convert it to a 'double' value } } else require(false, "Unknown size of an element in bytes"); in.close(); const std::string fname_out = file_stem(filename) + "_xz" + file_extension(filename); std::ofstream out(fname_out.c_str(), std::ios::binary); require(out, "File '" + fname_out + "' can't be opened"); for (int i = nnz-1; i >= 0; --i) { for (int j = 0; j < nnx; ++j) if (size_value == sizeof(double)) out.write((char*)&values[i*nnx+j], size_value); else { float val = values[i*nnx+j]; out.write((char*)&val, size_value); } } out.close(); delete[] values; } std::cout << "Converting to xz plane is done. Time = " << get_wall_time() - t_begin << std::endl; }