int Application::main(int argc, char **argv) { app = new App(argc, argv); #if !defined(_WIN32) //Windows port uses 256x256 icon from resource file app->setWindowIcon(QIcon(":/bsnes.png")); #endif initargs(argc, argv); //ensure argv[]s are in UTF-8 format initPaths(argv[0]); locateFile(configFilename = "bsnes.cfg", true); locateFile(styleSheetFilename = "style.qss", false); string customStylesheet; if(customStylesheet.readfile(styleSheetFilename) == true) { app->setStyleSheet((const char*)customStylesheet); } else { app->setStyleSheet(defaultStylesheet); } config.load(configFilename); init(); snes.init(); if(argc == 2) { //if valid file was specified on the command-line, attempt to load it now utility.loadCartridge(argv[1]); } while(terminate == false) { processEvents(); utility.updateSystemState(); inputManager.refresh(); if(config.input.focusPolicy == Configuration::Input::FocusPolicyPauseEmulation) { bool inactive = (winMain->window->isActiveWindow() == false); if(!autopause && inactive) { autopause = true; audio.clear(); } else if(autopause && !inactive) { autopause = false; } } else { autopause = false; } if(cartridge.loaded() && !pause && !autopause) { snes.runtoframe(); } else { usleep(20 * 1000); } supressScreenSaver(); } config.save(configFilename); return 0; }
int Application::main(int &argc, char **argv) { app = new App(argc, argv); #if !defined(PLATFORM_WIN) app->setWindowIcon(QIcon(":/bsnes.png")); #else //Windows port uses 256x256 icon from resource file CoInitialize(0); utf8_args(argc, argv); #endif initPaths(argv[0]); locateFile(configFilename = "bsnes-qt.cfg", true); locateFile(styleSheetFilename = "style.qss", false); string customStylesheet; if(customStylesheet.readfile(styleSheetFilename) == true) { app->setStyleSheet((const char*)customStylesheet); } else { app->setStyleSheet(defaultStylesheet); } config().load(configFilename); mapper().bind(); init(); //initialize libsnes snes_set_video_refresh(bsnes_video_refresh); snes_set_audio_sample(bsnes_audio_sample); snes_set_input_poll(bsnes_input_poll); snes_set_input_state(bsnes_input_state); snes_init(); //this used to disable the option if libsupergame was not installed; //after porting bsnes-qt to a standalone application, that's not possible through libsnes mainWindow->system_loadSpecial_superGameBoy->setVisible(true); if(argc == 2) { //if valid file was specified on the command-line, attempt to load it now cartridge.loadNormal(argv[1]); } timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(run())); timer->start(0); app->exec(); //QbWindow::close() saves window geometry for next run for(unsigned i = 0; i < windowList.size(); i++) { windowList[i]->close(); } cartridge.unload(); config().save(configFilename); return 0; }
/////////////////////////////////////////////////////////////////////// // Class : CRenderer // Method : locateFileEx // Description : Locate a file on disk // Return Value : TRUE if found // Comments : int CRenderer::locateFileEx(char *result,const char *name,const char *extension,TSearchpath *searchpath) { const char *dotpos = strchr(name,'.'); const char *seppos = strchr(name,OS_DIR_SEPERATOR); if (dotpos < seppos || dotpos == NULL) { char tmp[OS_MAX_PATH_LENGTH]; sprintf(tmp,"%s.%s",name,extension); error(CODE_SYSTEM, "\n tmp %s \n", tmp); return locateFile(result,tmp,searchpath); } else { return locateFile(result,name,searchpath); } }
static string locateModule(DottedNamePtr name) { string path, relativePath; relativePath = toRelativePath1(name); if (locateFile(relativePath, path)) return path; relativePath = toRelativePath2(name); if (locateFile(relativePath, path)) return path; error(name, "module not found: " + toKey(name)); return ""; }
int Application::main(int &argc, char **argv) { app = new App(argc, argv); #if !defined(PLATFORM_WIN) #if defined(PLATFORM_OSX) app->setWindowIcon(QIcon(":/bsnes_512.png")); #else app->setWindowIcon(QIcon(":/bsnes.png")); #endif #else //Windows port uses 256x256 icon from resource file CoInitialize(0); utf8_args(argc, argv); #endif initPaths(argv[0]); locateFile(configFilename = "bsnes-qt.cfg", true); locateFile(styleSheetFilename = "style.qss", false); string customStylesheet; if(customStylesheet.readfile(styleSheetFilename) == true) { app->setStyleSheet((const char*)customStylesheet); } else { app->setStyleSheet(defaultStylesheet); } config().load(configFilename); mapper().bind(); init(); SNES::system.init(&interface); mainWindow->system_loadSpecial_superGameBoy->setVisible(SNES::supergameboy.opened()); if(argc == 2) { //if valid file was specified on the command-line, attempt to load it now cartridge.loadNormal(argv[1]); } timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(run())); timer->start(0); app->exec(); //QbWindow::close() saves window geometry for next run for(unsigned i = 0; i < windowList.size(); i++) { windowList[i]->close(); } cartridge.unload(); config().save(configFilename); return 0; }
int main() { //read a file, save a file, delete a file, whatever. Testing goes here. //uint8_t mychar = 0x02; //printBinUint8(mychar); //make sure the binary printing function works //create a blank filesystem formatFileSystem("newFile.1kfs", 1024); //write an example file //writeFile("newFile.1kfs", "test", "myData", 6); //write a test file in filesystem writeByte("newFile.1kfs", 0, FILE_START_MARK); writeByte("newFile.1kfs", 1, 'x'); writeByte("newFile.1kfs", 2, 'x'); writeByte("newFile.1kfs", 3, 'x'); writeByte("newFile.1kfs", 4, 'x'); writeByte("newFile.1kfs", 5, 1); writeByte("newFile.1kfs", 6, 'A'); printf("File \"xxxx\" is at %d\n", locateFile("newFile.1kfs", "xxxx")); //test code for (uint32_t i = 0; i < 24; i++) { printBinUint8(readByte("newFile.1kfs", i)); } return 0; }
/* Create and return a list that is ready for use with the sentence forms. For each node in the settings.wordFiles list, create a node whose left is the settings left (for example, %m) and whose right is the associated word list. */ list_t *loadWords(settings_t settings) { /* Variables used to create the list */ list_t *wordList = createList(); assignment_t *wordAssignment; list_t *wordFile; FILE *f; /* Variables from settings */ node_t *settingNode = settings.wordFiles->head; assignment_t *settingAssignment; char *settingFile; /* Load every node in settings.wordFiles */ while (settingNode != NULL) { settingAssignment = settingNode->datum; settingFile = settingAssignment->right; f = locateFile(settings, settingFile); wordFile = loadWordFile(f); fclose(f); wordAssignment = makeAssign(settingAssignment->left, wordFile); addDatum(wordList, wordAssignment); settingNode = settingNode->next; printf("Loaded %s\n", settingFile); } printf("Loaded the word files.\n\n"); return wordList; }
/////////////////////////////////////////////////////////////////////// // Class : CRenderer // Method : getPhotonMap // Description : Load a photon map // Return Value : // Comments : CPhotonMap *CRenderer::getPhotonMap(const char *name) { CFileResource *map; char fileName[OS_MAX_PATH_LENGTH]; FILE *in; assert(name != NULL); assert(frameFiles != NULL); // Check the cache to see if the file is in the memory if (frameFiles->find(name,map) == FALSE) { // Locate the file if (locateFile(fileName,name,texturePath)) { // Try to open the file in = ropen(fileName,"rb",filePhotonMap,TRUE); } else { in = NULL; } // Read it map = new CPhotonMap(name,in); frameFiles->insert(map->name,map); } return (CPhotonMap *) map; }
int CWS_Get_FileType(const char *file, char* typestring, size_t tslen) { int n; if (file && (n=locateFile(file))>=0) { strncpy(typestring,files[n].type,tslen); return 0; } return 1; }
int CWS_Update_FileSize(CWS_FILE* cwsf, const char *fn) { int n; /* only change filesize */ if (cwsf && (n=locateFile(fn))>=0) { files[n].size=(long)cwsf->cws_size; return 1; } return 0; }
static PathString locateModule(DottedNamePtr name) { PathString path; PathString relativePath1 = toRelativePath1(name); if (locateFile(relativePath1, path)) return path; PathString relativePath2 = toRelativePath2(name); if (locateFile(relativePath2, path)) return path; string s; llvm::raw_string_ostream ss(s); ss << "module not found: " + toKey(name) << "\n"; ss << "tried relative paths:\n"; ss << " " << relativePath1 << "\n"; ss << " " << relativePath2 << "\n"; ss << "with suffixes:\n"; for (vector<llvm::SmallString<32> >::const_iterator entry = moduleSuffixes.begin(); entry != moduleSuffixes.end(); ++entry) { ss << " " << *entry << "\n"; } ss << "in search path:\n"; for (vector<PathString>::const_iterator entry = searchPath.begin(); entry != searchPath.end(); ++entry) { ss << " " << *entry << "\n"; } ss.flush(); error(name, s); llvm_unreachable("module not found"); }
int CWS_Update_File(CWS_FILE* cwsf) { int mode; int n; /* only change mode */ if (cwsf && (n=locateFile(cwsf->cws_name))>=0) { mode=(files[n].mode & 07077) | (cwsf->cws_mode & 0700); files[n].mode=mode; return 1; } return 0; }
int CWS_Get_File(const char *file, CWS_FILE* cwsf) { int n; if (file && cwsf && (n=locateFile(file))>=0) { strcpy(cwsf->cws_name,files[n].name); cwsf->cws_size=files[n].size; cwsf->cws_ctime=files[n].cTime; cwsf->cws_mtime=files[n].mTime; cwsf->cws_atime=files[n].aTime; cwsf->cws_mode=files[n].mode; return 1; } return 0; }
QString ProjectImpl::locateSourceFile(const QString& fileNameFragment) const { QFileInfo fi(fileNameFragment); if (fi.isAbsolute()) { return fileNameFragment; } QStringList exts; exts << QLatin1String("pas") << QLatin1String("pp"); QStringList searchPaths; searchPaths << mInputPath << mUnitPaths; return locateFile(searchPaths, exts, fileNameFragment, false); }
inline void loadArchive(ScenarioRunner* sr,std::string type) { sr->getResourceManager()->loadArchive(type,locateFile("data/"+sr->getString())); }
/////////////////////////////////////////////////////////////////////// // Class : CRenderer // Method : getCache // Description : Load a cache // Return Value : // Comments : CTexture3d *CRenderer::getCache(const char *name,const char *mode,const float *from,const float *to) { CFileResource *cache; assert(name != NULL); assert(frameFiles != NULL); // Check the memory first if (frameFiles->find(name,cache) == FALSE) { char fileName[OS_MAX_PATH_LENGTH]; int flags; char type[128]; int createChannel = FALSE; // Process the file mode if (strcmp(mode,"r") == 0) { flags = CACHE_READ| CACHE_SAMPLE; } else if (strcmp(mode,"w") == 0) { flags = CACHE_WRITE | CACHE_SAMPLE; } else if (strcmp(mode,"R") == 0) { flags = CACHE_READ | CACHE_RDONLY; } else if (strcmp(mode,"rw") == 0) { flags = CACHE_READ | CACHE_WRITE | CACHE_SAMPLE; } else { flags = CACHE_SAMPLE; } // Try to read the file cache = NULL; if (flags & CACHE_READ) { // Locate the file if (locateFile(fileName,name,texturePath)) { FILE *in = ropen(fileName,type); if (in != NULL) { // If we're netrendering and writing, treat specially if ((netClient != INVALID_SOCKET) && (flags & CACHE_WRITE)) { flags &= ~CACHE_WRITE; // don't flush cache to disk createChannel = TRUE; if (strncmp(fileName,temporaryPath,strlen(temporaryPath)) == 0) { // it's a temp file, delete it after we're done registerFrameTemporary(fileName,TRUE); } // always remove the file mapping when writing registerFrameTemporary(name,FALSE); } // Create the cache if (strcmp(type,fileIrradianceCache) == 0) { cache = new CIrradianceCache(name,flags,in,from,to,NULL); } else { error(CODE_BUG,"Unable to recognize the file format of \"%s\"\n",name); fclose(in); } } } } // If there is no cache, create it if (cache == NULL) { // If we're netrendering and writing, treat specially if ((netClient != INVALID_SOCKET) && (flags & CACHE_WRITE)) { flags &= ~CACHE_WRITE; // don't flush cache to createChannel = TRUE; // always remove the file mapping when writing registerFrameTemporary(name,FALSE); } // go ahead and create the cache cache = new CIrradianceCache(name,flags,NULL,from,to,CRenderer::toNDC); } // Create channels if possible if (createChannel == TRUE) { if (cache != NULL) { requestRemoteChannel(new CRemoteICacheChannel((CIrradianceCache *) cache)); } } frameFiles->insert(cache->name,cache); } return (CTexture3d *) cache; }
int main(int argc, char **argv) { QCoreApplication app(argc, argv); app.setApplicationVersion("1.0"); #ifdef Q_OS_WIN const QLatin1Char pathsep(';'); #else const QLatin1Char pathsep(':'); #endif QCommandLineParser parser; parser.setApplicationDescription(QCoreApplication::translate("qtpaths", "Command line client to QStandardPaths")); parser.addPositionalArgument(QCoreApplication::translate("qtpaths", "[name]"), QCoreApplication::tr("Name of file or directory")); parser.addHelpOption(); parser.addVersionOption(); //setting up options QCommandLineOption types(QStringLiteral("types"), QCoreApplication::translate("qtpaths", "Available location types.")); parser.addOption(types); QCommandLineOption paths(QStringLiteral("paths"), QCoreApplication::translate("qtpaths", "Find paths for <type>."), QStringLiteral("type")); parser.addOption(paths); QCommandLineOption writablePath(QStringLiteral("writable-path"), QCoreApplication::translate("qtpaths", "Find writable path for <type>."), QStringLiteral("type")); parser.addOption(writablePath); QCommandLineOption locateDir(QStringList() << QStringLiteral("locate-dir") << QStringLiteral("locate-directory"), QCoreApplication::translate("qtpaths", "Locate directory [name] in <type>."), QStringLiteral("type")); parser.addOption(locateDir); QCommandLineOption locateDirs(QStringList() << QStringLiteral("locate-dirs") << QStringLiteral("locate-directories"), QCoreApplication::translate("qtpaths", "Locate directories [name] in all paths for <type>."), QStringLiteral("type")); parser.addOption(locateDirs); QCommandLineOption locateFile(QStringLiteral("locate-file"), QCoreApplication::translate("qtpaths", "Locate file [name] for <type>."), QStringLiteral("type")); parser.addOption(locateFile); QCommandLineOption locateFiles(QStringLiteral("locate-files"), QCoreApplication::translate("qtpaths", "Locate files [name] in all paths for <type>."), QStringLiteral("type")); parser.addOption(locateFiles); QCommandLineOption findExe(QStringList() << QStringLiteral("find-exe") << QStringLiteral("find-executable"), QCoreApplication::translate("qtpaths", "Find executable with [name].")); parser.addOption(findExe); QCommandLineOption display(QStringList() << QStringLiteral("display"), QCoreApplication::translate("qtpaths", "Prints user readable name for <type>."), QStringLiteral("type")); parser.addOption(display); QCommandLineOption testmode(QStringList() << QStringLiteral("testmode") << QStringLiteral("test-mode"), QCoreApplication::translate("qtpaths", "Use paths specific for unit testing.")); parser.addOption(testmode); QCommandLineOption qtversion(QStringLiteral("qt-version"), QCoreApplication::translate("qtpaths", "Qt version.")); parser.addOption(qtversion); QCommandLineOption installprefix(QStringLiteral("install-prefix"), QCoreApplication::translate("qtpaths", "Installation prefix for Qt.")); parser.addOption(installprefix); QCommandLineOption bindir(QStringList() << QStringLiteral("binaries-dir") << QStringLiteral("binaries-directory"), QCoreApplication::translate("qtpaths", "Location of Qt executables.")); parser.addOption(bindir); QCommandLineOption plugindir(QStringList() << QStringLiteral("plugin-dir") << QStringLiteral("plugin-directory"), QCoreApplication::translate("qtpaths", "Location of Qt plugins.")); parser.addOption(plugindir); parser.process(app); QStandardPaths::enableTestMode(parser.isSet(testmode)); QStringList results; if (parser.isSet(qtversion)) { QString qtversionstring = QString::fromLatin1(qVersion()); results << qtversionstring; } if (parser.isSet(installprefix)) { QString path = QLibraryInfo::location(QLibraryInfo::PrefixPath); results << path; } if (parser.isSet(bindir)) { QString path = QLibraryInfo::location(QLibraryInfo::BinariesPath); results << path; } if (parser.isSet(plugindir)) { QString path = QLibraryInfo::location(QLibraryInfo::PluginsPath); results << path; } if (parser.isSet(types)) { QStringList typesList = ::types(); results << typesList.join('\n'); } if (parser.isSet(display)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(display)); QString text = QStandardPaths::displayName(location); results << text; } if (parser.isSet(paths)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(paths)); QStringList paths = QStandardPaths::standardLocations(location); results << paths.join(pathsep); } if (parser.isSet(writablePath)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(writablePath)); QString path = QStandardPaths::writableLocation(location); results << path; } if (parser.isSet(findExe)) { QString searchitem = searchStringOrError(&parser); QString path = QStandardPaths::findExecutable(searchitem); results << path; } if (parser.isSet(locateDir)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(locateDir)); QString searchitem = searchStringOrError(&parser); QString path = QStandardPaths::locate(location, searchitem, QStandardPaths::LocateDirectory); results << path; } if (parser.isSet(locateFile)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(locateFile)); QString searchitem = searchStringOrError(&parser); QString path = QStandardPaths::locate(location, searchitem, QStandardPaths::LocateFile); results << path; } if (parser.isSet(locateDirs)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(locateDirs)); QString searchitem = searchStringOrError(&parser); QStringList paths = QStandardPaths::locateAll(location, searchitem, QStandardPaths::LocateDirectory); results << paths.join(pathsep); } if (parser.isSet(locateFiles)) { QStandardPaths::StandardLocation location = parseLocationOrError(parser.value(locateFiles)); QString searchitem = searchStringOrError(&parser); QStringList paths = QStandardPaths::locateAll(location, searchitem, QStandardPaths::LocateFile); results << paths.join(pathsep); } if (results.isEmpty()) { parser.showHelp(); } else if (results.size() == 1) { const QString &item = results.first(); message(item); if (item.isEmpty()) return EXIT_FAILURE; } else { QString errorMessage = QCoreApplication::translate("qtpaths", "Several options given, only one is supported at a time."); error(errorMessage); } return EXIT_SUCCESS; }
/////////////////////////////////////////////////////////////////////// // Class : CRenderer // Method : getTexture3d // Description : Get a point cloud or brickmap // Return Value : // Comments : CTexture3d *CRenderer::getTexture3d(const char *name,int write,const char* channels,const float *from,const float *to,int hierarchy) { CFileResource *texture3d; char fileName[OS_MAX_PATH_LENGTH]; FILE *in; assert(name != NULL); assert(frameFiles != NULL); if (frameFiles->find(name,texture3d) == FALSE) { if (from == NULL) { from = world->from; to = world->to; } // If we are writing, it must be a point cloud if (write == TRUE) { if (netClient != INVALID_SOCKET) { CPointCloud *cloud = new CPointCloud(name,world->from,world->to,CRenderer::toNDC,channels,FALSE); texture3d = cloud; // Ensure we unmap the file when done. Do not delete it // as we mark the file to never be written in the server registerFrameTemporary(name,FALSE); requestRemoteChannel(new CRemotePtCloudChannel(cloud)); } else { // alloate a point cloud which will be written to disk texture3d = new CPointCloud(name,from,to,CRenderer::toNDC,channels,TRUE); } } else { // Locate the file if (locateFile(fileName,name,texturePath)) { // Try to open the file if ((in = ropen(fileName,"rb",filePointCloud,TRUE)) != NULL) { if (hierarchy == TRUE) { texture3d = new CPointHierarchy(name,from,to,in); } else { texture3d = new CPointCloud(name,from,to,in); } } else { if ((in = ropen(fileName,"rb",fileBrickMap,TRUE)) != NULL) { texture3d = new CBrickMap(in,name,from,to); } } } else { in = NULL; } if (in == NULL) { // allocate a dummy blank-channel point cloud error(CODE_BADTOKEN,"Cannot find or open Texture3D file \"%s\"\n",name); texture3d = new CPointCloud(name,world->from,world->to,NULL,NULL,FALSE); // remove the dummy mapping once the frame ends registerFrameTemporary(name,FALSE); } } frameFiles->insert(texture3d->name,texture3d); } return (CPointCloud *) texture3d; }
// loadClassInfo bool imageNet::loadClassInfo( const char* filename ) { if( !filename ) return false; // locate the file const std::string path = locateFile(filename); if( path.length() == 0 ) { printf("imageNet -- failed to find %s\n", filename); return false; } // open the file FILE* f = fopen(path.c_str(), "r"); if( !f ) { printf("imageNet -- failed to open %s\n", path.c_str()); return false; } // read class descriptions char str[512]; while( fgets(str, 512, f) != NULL ) { const int syn = 9; // length of synset prefix (in characters) const int len = strlen(str); if( len > syn && str[0] == 'n' && str[syn] == ' ' ) { str[syn] = 0; str[len-1] = 0; const std::string a = str; const std::string b = (str + syn + 1); //printf("a=%s b=%s\n", a.c_str(), b.c_str()); mClassSynset.push_back(a); mClassDesc.push_back(b); } else if( len > 0 ) // no 9-character synset prefix (i.e. from DIGITS snapshot) { char a[10]; sprintf(a, "n%08u", mCustomClasses); //printf("a=%s b=%s (custom non-synset)\n", a, str); mCustomClasses++; if( str[len-1] == '\n' ) str[len-1] = 0; mClassSynset.push_back(a); mClassDesc.push_back(str); } } fclose(f); printf("imageNet -- loaded %zu class info entries\n", mClassSynset.size()); if( mClassSynset.size() == 0 ) return false; mClassPath = path; return true; }
bool create(const QString &dir, CFontEngine &fe) { bool root(Misc::root()), added = false; QString fmapDir(Misc::dirSyntax(root ? KFI_ROOT_CFG_DIR : dir)); CFile old(fmapDir); QStringList entries; int i; FcPattern *pat = FcPatternCreate(); FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SCALABLE, (void *)0); FcFontSet *fs = FcFontList(0, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); for(i = 0; i < fs->nfont; i++) { QString fName(Misc::fileSyntax(CFcEngine::getFcString(fs->fonts[i], FC_FILE))); FcBool scalable = FcFalse; if(!fName.isEmpty() && (root || dir.isEmpty() || 0 == fName.find(dir)) && FcResultMatch == FcPatternGetBool(fs->fonts[i], FC_SCALABLE, 0, &scalable) && scalable) { const QStringList *existing = old.getEntries(fName); if(existing && existing->count()) entries += (*existing); else { int face = 0, numFaces = 0; do { if(fe.openFont(fName, face)) { if(fe.hasPsInfo()) { if(0 == numFaces) numFaces = fe.getNumFaces(); // Only really for TTC files... // // Add real addEntry(entries, fe.getPsName(), fName, fmapDir); added = true; // // Add fake entries for X11 generated names switch(fe.getWeight()) { case CFontEngine::WEIGHT_MEDIUM: case CFontEngine::WEIGHT_REGULAR: { QString x11Ps(createX11PsName(fe.getFamilyName())); if(CFontEngine::ITALIC_ITALIC != fe.getItalic() && CFontEngine::ITALIC_OBLIQUE != fe.getItalic()) addAliasEntry(entries, createName(x11Ps, "Roman", getItalicStr(fe.getItalic())), fe.getPsName()); addAliasEntry(entries, createName(x11Ps, NULL, getItalicStr(fe.getItalic())), fe.getPsName()); break; } case CFontEngine::WEIGHT_UNKNOWN: break; default: addAliasEntry(entries, createName(createX11PsName(fe.getFamilyName()), CFontEngine::weightStr(fe.getWeight()), getItalicStr(fe.getItalic())), fe.getPsName()); } } fe.closeFont(); } } while(++face < numFaces); } } } bool status = true; if(added || entries.count() != old.getLineCount()) { KSaveFile out(fmapDir + FONTMAP); QTextStream *stream = out.textStream(); if(stream) { QStringList::Iterator it; for(it = entries.begin(); it != entries.end(); ++it) *stream << *it << endl; } else status = false; } // // Ensure GS's main Fontmap references our file... if(root && status) { static const char *constGhostscriptDirs[] = {"/usr/share/ghostscript/", "/usr/local/share/ghostscript/", "/usr/share/gs-esp/", NULL}; QString gsFile = locateFile(FONTMAP, constGhostscriptDirs); if(!gsFile.isEmpty()) { const int constMaxLineLen = 1024; const char *constRLF = ".runlibfile"; char line[constMaxLineLen]; ifstream in(QFile::encodeName(gsFile)); if(in) { QCString fmap(QFile::encodeName(fmapDir + FONTMAP)); int lineNum = 0, kfiLine = -1, gsLine = -1, ncLine = -1; do { in.getline(line, constMaxLineLen); if(in.good()) { line[constMaxLineLen - 1] = '\0'; if(strstr(line, fmap.data()) != NULL && strstr(line, constRLF) != NULL) kfiLine = lineNum; else if(strstr(line, FONTMAP ".GS") != NULL && strstr(line, constRLF) != NULL) gsLine = lineNum; if(-1 == ncLine && '%' != line[0]) ncLine = lineNum; lineNum++; } } while(!in.eof() && (-1 == kfiLine || -1 == gsLine)); // // If the file doesn't already say to use our Fontmap file, then tell it to! // Also, ensure ours is .runlibfile'd before the main GS one - else problems can occur if(-1 == kfiLine || kfiLine > gsLine) { in.clear(); in.seekg(0, ios::end); int size = (streamoff)in.tellg(); in.seekg(0, ios::beg); char *buffer = new char[size + strlen(fmap) + strlen(constRLF) + 5]; if(buffer) { bool added = false; buffer[0] = '\0'; lineNum = 0; do { in.getline(line, constMaxLineLen); if(in.good()) { line[constMaxLineLen - 1] = '\0'; if(lineNum >= ncLine && !added) { strcat(buffer, "("); strcat(buffer, fmap); strcat(buffer, ") "); strcat(buffer, constRLF); strcat(buffer, "\n"); added = true; } if(lineNum != kfiLine) { strcat(buffer, line); strcat(buffer, "\n"); } lineNum++; } } while(!in.eof()); in.close(); if(added) // Don't re-write GS's Fontmap unless we've actually added something... { KSaveFile out(gsFile); QTextStream *stream = out.textStream(); if(stream) *stream << buffer; } delete[] buffer; } } } } } return status; }