/** * Reads the layout info stored in the given (XML) file and creates figure templates. * Existing templates remain in where they are but are replaced if a new definition with an existing name is found. * * @param filename The name of the file to load. * @return Returns GC_NO_ERROR if everything was ok, otherwise an error code. */ TGCError CGenericCanvas::addLayoutsFromFile(const char* filename) { TGCError result = GC_NO_ERROR; xmlNodePtr root, current; CFigureParser parser(this); parser.addListener(&FListener); string currentDir = getCurrentDir(); xmlDocPtr document = xmlParseFile(utf8ToANSI(string(filename)).c_str()); if (document == NULL) return GC_XML_PARSE_ERROR; root = xmlDocGetRootElement(document); if (root == NULL) { xmlFreeDoc(document); error(this, "XML Error: Template file is empty."); return GC_XML_EMPTY_DOCUMENT; } if (!XML_IS(root, "gc-layouts")) { xmlFreeDoc(document); error(this, "XML Error: Template file invalid."); return GC_XML_INVALID_DOCUMENT; } // Switch to the directory of the given file. This is necessary to make relative file names working. string path = extractFilePath(filename); setCurrentDir(path); // Parse description elements. glMatrixMode(GL_MODELVIEW); current = root->children; while (current != NULL) { // Be flexible, ignore any unknown layout entries. if (XML_IS(current, "layout-definition")) parser.parseLayoutDefinition(current, FModel); else if (XML_IS(current, "connection-definition")) parser.parseDecorDefinition(current, FModel); current = current->next; } setCurrentDir(currentDir); xmlFreeDoc(document); parser.removeListener(&FListener); return result; }
void MainForm::saveHtml(QFile *file) { QString text = textEdit->document()->toHtml().toUtf8(); QString newDir = extractFilePath(file->fileName()) + extractFileName(file->fileName()) + ".files"; text.replace("<meta name=\"qrichtext\" content=\"1\" />", "<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\" />"); /*text.replace(workingDir + "output_files", newDir); text.replace("[img src=", "<img src="); text.replace(".bmp\"]", ".bmp\">"); text.replace(".bmp]", ".bmp>"); QDir dir(workingDir+"output_files"); dir.rename(workingDir+"output_files", newDir);*/ file->write(text.toAscii()); }
void transformDicom2(char *filename, char *output) { TDCMopts opts; char auxFile[1024], outdir[1024]; extractFilePath(output, outdir); defaultOptions(opts, outdir); changeFileExt(output, "", auxFile); extractFileName(auxFile, opts.filename); // opts.isVerbose = 2; if (0) { strcpy(opts.indir, filename); nii_loadDir(&opts); } else singleDICOM(&opts, filename); }
int vfsGzFileOpen(void *param1, int param2, int type, int mode, VIRTUAL_FILE* f) { const char *stdMode = NULL; if (mode == VF_O_READ) stdMode = "r"; else if (mode == VF_O_WRITE) stdMode = "w"; else // if (mode == VF_O_READWRITE) return 0; f->ioPtr = (void*)gzopen((char*)param1, stdMode); if (mode == VF_O_WRITE && !f->ioPtr) { //Create the path if it doesn't exist char path[1024]; extractFilePath(param1, path, 1); makeDir(path); f->ioPtr = (void*)gzopen((char*)param1, stdMode); } return (int)f->ioPtr; }
//----------------------------------------------------------------------------- // 描述: 取得可执行文件所在的路径 //----------------------------------------------------------------------------- string IseApplication::getExePath() { return extractFilePath(exeName_); }
/** * Reads the style template info stored in the given (XML) file and creates style templates (OpenGL display lists). * Existing templates remain where they are but are replaced if a new definition with an existing name is found. * * @param filename The name of the file to load. * @param variables A set of name/value pairs to be replaced in the xml text. * @return Returns GC_NO_ERROR if everything was ok, otherwise an error code. */ TGCError CGenericCanvas::addStylesFromFile(const char* filename, map<wstring, wstring>& variables) { TGCError result = GC_NO_ERROR; xmlNodePtr root, current; CSVGParser parser; xmlDocPtr document = NULL; string currentDir = getCurrentDir(); if (!variables.empty()) { char *data; size_t length; data= preprocessFile(filename, variables, length); if (data) { document = xmlParseMemory(data, (int) length); free(data); } } else document = xmlParseFile(utf8ToANSI(filename).c_str()); if (document == NULL) return GC_XML_PARSE_ERROR; root = xmlDocGetRootElement(document); if (root == NULL) { xmlFreeDoc(document); error(this, "XML Error: Template file is empty."); return GC_XML_EMPTY_DOCUMENT; } if (!XML_IS(root, "gc-styles")) { xmlFreeDoc(document); error(this, "XML Error: Template file invalid."); return GC_XML_INVALID_DOCUMENT; } // Switch to the directory of the given file. This is necessary to make relative file names working. string path = extractFilePath(filename); setCurrentDir(path); // Parse description elements. glMatrixMode(GL_MODELVIEW); current = root->children; while (current != NULL) { // Be flexible, ignore any unknown layout entries. if (XML_IS(current, "style-definition")) { parser.parseDefinition(current, FModel); } else if (XML_IS(current, "texture")) { // Adds a new texture to the texture list. parseTextureEntry(current, FModel); checkError(); }; current = current->next; } setCurrentDir(currentDir); xmlFreeDoc(document); return result; }