int LocalPackage::CreateFlistNode(string fname, string tmp_xml) { if (getExtension(filename)=="spkg") return 0; //mDebug("local_package.cpp: CreateFlistNode(): begin"); string tar_cmd; //mDebug("flist tmpfile: "+fname); if (getExtension(filename)=="tgz" || getExtension(filename) == "txz" ||getExtension(filename) == "tlz" ||getExtension(filename) == "tbz" ) tar_cmd="tar tf "+filename+" --exclude install " +" > "+fname + " 2>/dev/null"; if (system(tar_cmd)!=0) { mError("Unable to get file list"); return -1; } #ifdef USE_INTERNAL_SED WriteFile(tmp_xml, files2xml(ReadFile(fname))); #else string sed_cmd; sed_cmd="echo '<?xml version=\"1.0\" encoding=\"utf-8\"?><package><filelist><file>file_list_header' > "+tmp_xml+" && cat "+ fname +" | sed -e i'</file>\\n<file>' >> "+tmp_xml+" && echo '</file></filelist></package>' >> "+tmp_xml; if (system(sed_cmd)!=0) { mError("Parsing using sed failed"); return -1; } #endif //mDebug("local_package.cpp: CreateFlistNode(): end"); return 0; }
void FunctionsTest::testGetExtension() { QCOMPARE(getExtension(""), QString("")); QCOMPARE(getExtension("http://test.com/file"), QString("")); QCOMPARE(getExtension("http://test.com/file.jpg"), QString("jpg")); QCOMPARE(getExtension("http://test.com/file.jpg?toto=1"), QString("jpg")); }
int LocalPackage::injectFile() { if (!dialogMode && verbose) say(string(_("Injecting file") + filename + "\n").c_str()); internal=true; // Injecting data from file! // If any of functions fails (e.g. return!=0) - break process and return failure code (!=0); //int ret=0; //mDebug("local_package.cpp: injectFile(): start"); //mDebug("get_xml"); if (get_xml()!=0) { //mDebug("local_package.cpp: injectFile(): get_xml FAILED"); return -3; } if (getExtension(filename)=="spkg") { //printf("Source package detected, adding to XML\n"); xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"type", (const xmlChar *)"source"); data.set_type(PKGTYPE_SOURCE); } if (getExtension(filename)=="tgz" || getExtension(filename) == "txz" || getExtension(filename) == "tlz" ||getExtension(filename) == "tbz" ) { xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"type", (const xmlChar *)"binary"); data.set_type(PKGTYPE_BINARY); } //mDebug("get_size()\n"); if (get_size()!=0) { mDebug("local_package.cpp: injectFile(): get_size() FAILED"); return -1; } //mDebug("create_md5\n"); if (create_md5()!=0) { mDebug("local_package.cpp: injectFile(): create_md5 FAILED"); return -2; } //mDebug("set_additional_data\n"); //mDebug("local_packaige.cpp: injectFile(): filename is "+ filename); data.set_filename(filename); if (set_additional_data()!=0) { mDebug("local_package.cpp: injectFile(): set_additional_data FAILED"); return -6; } delete_tmp_files(); //mDebug("local_package.cpp: injectFile(): end"); return 0; }
// Remove files of the given type from Locator's list of found files and from the View. // Returns how many rows are removed from the View. //-(5)--------------------------------------------------------------------------------- int CNewFilesLocator::RemoveFilesOfType( const CString& sExtension ) { // Remove files of this type from Locator's list of found files while( true ) { bool bRemoved = false; for( auto curFileIt = m_foundFiles.m_files.begin(); curFileIt != m_foundFiles.m_files.end(); curFileIt++ ) { ASSERT( *curFileIt ); auto curFile = *curFileIt; CString curExt = curFile->getExtension(); curExt.MakeUpper(); if( curExt == sExtension ) { m_foundFiles.m_files.erase( curFileIt ); delete curFile; // Now it is not in use anywhere, delete it bRemoved = true; break; // Actually, start from the beginning of the list } } if( ! bRemoved ) break; // Now there isn't any appropriate file, stop // else start again } // Remove files of this type from the View int nRemoved = m_pView->RemoveFilesOfType( sExtension ); return nRemoved; }
unsigned int CheckFileType(string fname) { // Checking file existanse struct stat st; if (lstat(fname.c_str(), &st) != 0) { if ( errno == ENOENT ) { //mError("file "+fname+" not found"); // FIXME return PKGTYPE_UNKNOWN; } } if ( !S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) ) { //mError("Not a regular file"); // FIXME return PKGTYPE_UNKNOWN; } // Checking extensions and (partially) contents string ext = getExtension(fname); if (ext=="tgz" || ext == "txz" || ext == "tlz" || ext == "tbz") return PKGTYPE_BINARY; if (ext=="spkg") { //mDebug("Source MPKG package detected"); return PKGTYPE_SOURCE; } // mDebug("Unknown package type "+ext); return PKGTYPE_UNKNOWN; }
static bool parseImageIOArgs(PyObject *args, char **path, MMImageType *type) { int pathLen; char *format = NULL; assert(path != NULL); assert(type != NULL); if (!PyArg_ParseTuple(args, "s#|s", path, &pathLen, &format)) return false; /* Attempt to derive type from path */ if (format == NULL) { const char *ext = getExtension(*path, pathLen); if (ext == NULL) { PyErr_SetString(PyExc_ValueError, "Could not find file extension"); return false; } *type = imageTypeFromExtension(ext); } else { *type = imageTypeFromExtension(format); } if (*type == kInvalidImageType) { PyErr_SetString(PyExc_TypeError, "Unsupported image format"); return false; } return true; }
bool ParticleParser::put(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { if(xmlHasProp(cur, (const xmlChar *) "file")) { const char* fname =(const char*)(xmlGetProp(cur, (const xmlChar *) "file")); string pformat = getExtension(fname); if(pformat == "xml") { XMLParticleParser aHandle(ref_); return aHandle.put(fname); } else { WARNMSG("Using old formats") ifstream fin(fname); if(fin) { ParticleInputFactory::createParticle(ref_,fin); } else { ERRORMSG("File " << fname << "is not found."); } return true; } } XMLParticleParser aHandle(ref_); aHandle.put(doc,ns,cur); return false; }
// In future, this function should replace all instances of code that attempts to split slackware filename to parts. This code was got from convert_package function, as it seems to be the most correct one. bool splitSlackwareFilename(string filename, string *name, string *version, string *arch, string *build) { mDebug("Preparing to convert " + filename); string tmp; string ptrstr; // Guessing type string pkgType = getExtension(filename); if (pkgType!="tgz" && pkgType!="txz" && pkgType!="tlz" && pkgType!="tbz") { mError(_("Unknown package type ") + pkgType); return false; } // Name-ver-arch-build parsing string name_tmp=filename.substr(0,filename.find("." + pkgType)); name_tmp = name_tmp.substr(name_tmp.find_last_of("/")+1); ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1); *build=ptrstr; name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-")); ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1); *arch = ptrstr; name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-")); ptrstr=name_tmp.substr(name_tmp.find_last_of("-")+1); *version = ptrstr; name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-")); *name = name_tmp; return true; }
LRESULT AVIPreview::onChangeMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { if (ctrlCommands.GetSelectedCount() == 1) { int sel = ctrlCommands.GetSelectedIndex(); const auto pa = FavoriteManager::getInstance()->getPreviewApp(sel); if (pa) { PreviewDlg dlg; dlg.name = Text::toT(pa->getName()); dlg.application = Text::toT(pa->getApplication()); dlg.argument = Text::toT(pa->getArguments()); dlg.extensions = Text::toT(pa->getExtension()); if (dlg.DoModal() == IDOK) { pa->setName(Text::fromT(dlg.name)); pa->setApplication(Text::fromT(dlg.application)); pa->setArguments(Text::fromT(dlg.argument)); pa->setExtension(Text::fromT(dlg.extensions)); ctrlCommands.SetItemText(sel, 0, dlg.name.c_str()); ctrlCommands.SetItemText(sel, 1, dlg.application.c_str()); ctrlCommands.SetItemText(sel, 2, dlg.argument.c_str()); ctrlCommands.SetItemText(sel, 3, dlg.extensions.c_str()); } } } return 0; }
/* * Manage requests to directories. This will either do an external redirect back to the browser or do an internal * (transparent) redirection and serve different content back to the browser. This routine may modify the requested * URI and/or the request handler. */ static void processDirectory(MaConn *conn, bool *rescan) { MaRequest *req; MaResponse *resp; MprFileInfo *info; char path[MPR_MAX_FNAME], urlBuf[MPR_MAX_FNAME], *index; int len; req = conn->request; resp = conn->response; info = &resp->fileInfo; mprAssert(info->isDir); index = req->dir->indexName; if (req->url[strlen(req->url) - 1] == '/') { /* * Internal directory redirections */ len = (int) strlen(resp->filename); if (resp->filename[len - 1] == '/') { resp->filename[len - 1] = '\0'; } path[0] = '\0'; mprAssert(resp->filename && *resp->filename); mprAssert(index && *index); mprStrcat(path, sizeof(path), NULL, resp->filename, "/", index, NULL); if (mprAccess(resp, path, R_OK)) { /* * Index file exists, so do an internal redirect to it. Client will not be aware of this happening. * Must rematch the handler on return. */ maSetRequestUri(conn, addIndex(conn, urlBuf, sizeof(urlBuf), index)); resp->filename = mprStrdup(resp, path); mprGetFileInfo(conn, resp->filename, &resp->fileInfo); resp->extension = getExtension(conn); if ((resp->mimeType = (char*) maLookupMimeType(conn->host, resp->extension)) == 0) { resp->mimeType = (char*) "text/html"; } *rescan = 1; } return; } /* * External redirect. Ask the client to re-issue a request for a new location. See if an index exists and if so, * construct a new location for the index. If the index can't be accessed, just append a "/" to the URI and redirect. */ if (req->parsedUri->query && req->parsedUri->query[0]) { mprSprintf(path, sizeof(path), "%s/%s?%s", req->url, index, req->parsedUri->query); } else { mprSprintf(path, sizeof(path), "%s/%s", req->url, index); } if (!mprAccess(resp, path, R_OK)) { mprSprintf(path, sizeof(path), "%s/", req->url); } maRedirect(conn, MPR_HTTP_CODE_MOVED_PERMANENTLY, path); resp->handler = conn->http->passHandler; }
Texture *IO::loadTexture(const String &file) { U8 *bitmap; Point2I dims; String extension = getExtension(file); bool (*readFn)(String file, U8 **bitmap, Point2I *dims); //Try to read the image based on format if (extension == "png" || extension == "jng") readFn = mngReadImage; else if (extension == "jpg") readFn = jpegReadImage; else { // ?! readFn = mngReadImage; } if (readFn(file, &bitmap, &dims)) { Texture *tex = new Texture(bitmap, dims); delete [] bitmap; return tex; } return nullptr; }
void ManGenerator::startDoxyAnchor(const char *,const char *manName, const char *, const char *name, const char *) { // something to be done? if( !Config_getBool("MAN_LINKS") ) { return; // no } // the name of the link file is derived from the name of the anchor: // - truncate after an (optional) :: QCString baseName = name; int i=baseName.findRev(':'); if (i!=-1) baseName=baseName.right(baseName.length()-i-1); // - remove dangerous characters and append suffix, then add dir prefix QCString fileName=dir+"/"+buildFileName( baseName ); QFile linkfile( fileName ); // - only create file if it doesn't exist already if ( !linkfile.open( IO_ReadOnly ) ) { if ( linkfile.open( IO_WriteOnly ) ) { QTextStream linkstream; linkstream.setDevice(&linkfile); #if QT_VERSION >= 200 linkstream.setEncoding(QTextStream::Latin1); #endif linkstream << ".so man" << getExtension() << "/" << buildFileName( manName ) << endl; } } linkfile.close(); }
void Shader::compileShader(const char *fileName) { if (fileName == nullptr) return; int numExts = sizeof(ShaderInfo::extensions) / sizeof(ShaderInfo::shader_file_extension); std::string ext = getExtension(fileName); GLSLShader::ShaderType type = GLSLShader::VERTEX; bool matchFound = false; for (int i = 0; i < numExts; ++i) { if (ext == ShaderInfo::extensions[i].ext) { matchFound = true; type = ShaderInfo::extensions[i].type; break; } } if (!matchFound) { std::string msg = "Unrecognized extension: " + ext; throw ShaderException(msg); } compileShader(fileName, type); }
/* * Constructor. */ CAnimation::CAnimation(const STRING file): m_users(1) { extern STRING g_projectPath; renderFrame = &CAnimation::renderAnmFrame; if (!file.empty()) { const STRING ext = getExtension(file); if (_ftcsicmp(ext.c_str(), _T("anm")) == 0) { m_data.open(g_projectPath + MISC_PATH + file); } else if (_ftcsicmp(ext.c_str(), _T("gif")) == 0) { m_data.loadFromGif(resolve(g_projectPath + MISC_PATH + file)); renderFrame = &CAnimation::renderFileFrame; m_data.filename = file; } } freeCanvases(); m_canvases.resize(m_data.frameCount, NULL); }
void MoreInjector::inject(const Icon* icon, const std::map<std::string, std::string>& params) { string size = verifyParameter(params, "size"); string dst = verifyParameter(params, "dst"); const IconInstance* iconInst = icon->findBestInstance(size); if(!iconInst) errorExit("Couldn't find any icon instance."); if(!convertInstanceToImageFormat(iconInst, dst.c_str(), size, getExtension(dst))) errorExit("MoRE icon conversion failed."); }
void DepthExporter::exportMesh(string filename, int width, int height, const bool* mask, const float* depth, const unsigned char* color) { string extension = getExtension(filename); if (extension == "obj") { exportObjMesh(filename, width, height, mask, depth, color); } else if (extension == "ply") { exportPlyMesh(filename, width, height, mask, depth, color); } }
bool hasCaseExtension(const char* fileName,const char* extension) { /* Get the extension: */ const char* extPtr=getExtension(fileName); /* Compare the extension against the given pattern: */ return strcasecmp(extPtr,extension)==0; }
int mpkgSys::_conv_dir(const char *filename, const struct stat *, int filetype) { if (filetype!=FTW_F) return 0; string ext=getExtension(filename); if (ext!="tgz" && ext!="tbz" && ext!="txz" && ext!="tlz") return 0; convert_package(string(filename), output_dir); return 0; }
HDFWalkerInput_0_0::HDFWalkerInput_0_0(MCWalkerConfiguration& W, const string &aroot): targetW(W), version(0,0) { FileName = aroot; string ext=getExtension(aroot); if(ext != "h5") { //if the filename does not h5 extension, add the extension FileName.append(".config.h5"); } }
static QCString getSubdir() { QCString dir = Config_getString("MAN_SUBDIR"); if (dir.isEmpty()) { dir = "man" + getExtension(); } return dir; }
string getExtractedSize(const string& filename) { string ext = getExtension(filename); if (ext == "txz" || ext == "xz") return getXZExtractedSize(filename); else if (ext == "tgz" || ext == "gz") return getGZExtractedSize(filename); else if (ext == "tbz" || ext == "bz2") return getBZExtractedSize(filename); else if (ext == "tlz" || ext == "lzma") return getLZExtractedSize(filename); else return "0"; // Dunno how to determine it }
ManGenerator::ManGenerator() : OutputGenerator() { dir=Config_getString("MAN_OUTPUT")+"/man" + getExtension(); firstCol=TRUE; paragraph=FALSE; col=0; upperCase=FALSE; insideTabbing=FALSE; inHeader=FALSE; }
//------------------------------------------ void ofx3DModelLoader::loadModel(string modelName, float scale){ if( model != NULL)delete model; string ext = getExtension( modelName ); if( ext == "3ds" || ext == "3DS" ){ model = new model3DS(); model->loadModel( modelName.c_str(), scale); } }
void Path::setBaseName(const std::string& name) { std::string ext = getExtension(); _name = name; if (!ext.empty()) { _name.append("."); _name.append(ext); } }
int mpkgSys::_nativize_dir(const char *filename, const struct stat *, int filetype) { if (filetype!=FTW_F) return 0; string ext=getExtension(filename); if (ext!="tgz" && ext!="tbz" && ext!="txz" && ext!="tlz") return 0; LocalPackage lp(filename); if (lp.isNative()) return 0; convert_package(string(filename), output_dir); system("mv -v " + output_dir + "/" + string(filename) + " " + string(filename)); return 0; }
static void metadata_add_file (struct ushare_t *ut, struct upnp_entry_t *entry, const char *file, const char *name, struct stat *st_ptr) { if (!entry || !file || !name) return; #ifdef HAVE_DLNA if (ut->dlna_enabled || is_valid_extension (getExtension (file))) #else if (is_valid_extension (getExtension (file))) #endif { struct upnp_entry_t *child = NULL; child = upnp_entry_new (ut, name, file, entry, st_ptr->st_size, false); if (child) upnp_entry_add_child (ut, entry, child); } }
bool hasCaseExtension(const char* fileName,const char* extension) { /* Get the extension: */ const char* extPtr=getExtension(fileName); /* Compare the extension against the given pattern: */ if(extPtr!=0) return strcasecmp(extPtr,extension)==0; else return extension[0]=='\0'; }
void sendResponseFile(const GServerEvent& event, const std::string& responseFilePath, const std::string& contentType) { if (!isRunning()) { error("HttpServer::sendResponse: server is not running"); } std::string contentTypeActual = contentType; if (contentTypeActual.empty()) { contentTypeActual = getContentType(getExtension(responseFilePath)); } getPlatform()->httpserver_sendResponseFile(event.getRequestID(), contentType, responseFilePath); }
void OSInterface::openFile(std::string &path){ std::shared_ptr<Data> data_instance = Data::getInstance(); std::string ext(getExtension(path)); std::string app(data_instance->extern_programmes.at(ext)); QString program(app.c_str()); QStringList arguments; arguments << QString::fromStdString(path); QProcess *myProcess = new QProcess(); myProcess->start(program, arguments); }
void UnprocessedStatement::process(Ruleset &r) { Extension extension; Mixin mixin; Declaration* declaration; #ifdef WITH_LIBGLOG VLOG(2) << "Statement: " << getTokens()->toString(); #endif // process extends statement if (getExtension(extension.getTarget())) { extension.setExtension(r.getSelector()); getLessRuleset()->getContext()->addExtension(extension); return; } mixin.setStylesheet(getLessRuleset()->getLessStylesheet()); // process mixin if (mixin.parse(*getTokens()) && mixin.insert(*r.getStylesheet(), *getLessRuleset()->getContext(), &r, getLessRuleset())) { } else { declaration = r.createDeclaration(); if (processDeclaration(declaration)) { #ifdef WITH_LIBGLOG VLOG(2) << "Declaration: " << declaration->getProperty() << ": " << declaration->getValue().toString(); #endif getLessRuleset()->getContext()->processValue(declaration->getValue()); #ifdef WITH_LIBGLOG VLOG(2) << "Processed declaration: " << declaration->getProperty() << ": " << declaration->getValue().toString(); #endif } else { r.deleteDeclaration(*declaration); throw new ParseException(getTokens()->toString(), "variable, mixin or declaration.", getTokens()->front().line, getTokens()->front().column, getTokens()->front().source); } } #ifdef WITH_LIBGLOG VLOG(3) << "Statement done"; #endif }