static int game_by_id_callback(void *data, int argc, char *argv[], char *column[]) { bgg_client::data::game * game = (bgg_client::data::game *) data; for (uint32_t i = 0; i < argc; i++) { if (argv[i] == nullptr) break; std::string col(column[i]); if (col == "id") game->setGameId(atoi(argv[i])); else if (col == "name") game->setGameName(argv[i]); else if (col == "description") game->setDescription(argv[i]); else if (col == "minplayers") game->setMinPlayers(atoi(argv[i])); else if (col == "maxplayers") game->setMaxPlayers(atoi(argv[i])); else if (col == "playingtime") game->setPlayingTime(atoi(argv[i])); else if (col == "yearpublished") game->setYearPublished(atoi(argv[i])); else if (col == "rank") game->setRank(atoi(argv[i])); else if (col == "extension") game->setIsExtension(atoi(argv[i])); else if (col == "thumbnail") game->setThumbnailUrl(argv[i]); else if (col == "expands") game->setExpands(atoi(argv[i])); else if (col == "authors") { std::string authors(argv[i]); ssize_t last_pos(0); ssize_t pos(0); while ((pos = authors.find(", ", last_pos)) != std::string::npos) { game->setAuthor(authors.substr(last_pos, pos - last_pos).c_str()); last_pos = pos + 2; } std::string last_author = authors.substr(last_pos, authors.size()); if (not last_author.empty()) { game->setAuthor(last_author); } } } return 0; }
QString Feed::debugInfo() const { QString info; info += QLatin1String("# Feed begin ######################\n"); QString dtitle = title(); if (!dtitle.isNull()) info += QLatin1String("title: #") + dtitle + QLatin1String("#\n"); QString dlink = link(); if (!dlink.isNull()) info += QLatin1String("link: #") + dlink + QLatin1String("#\n"); QString ddescription = description(); if (!ddescription.isNull()) info += QLatin1String("description: #") + ddescription + QLatin1String("#\n"); QString dcopyright = copyright(); if (!dcopyright.isNull()) info += QLatin1String("copyright: #") + dcopyright + QLatin1String("#\n"); QString dlanguage = language(); if (!dlanguage.isNull()) info += QLatin1String("language: #") + dlanguage + QLatin1String("#\n"); QList<PersonPtr> dauthors = authors(); QList<PersonPtr>::ConstIterator itp = dauthors.constBegin(); QList<PersonPtr>::ConstIterator endp = dauthors.constEnd(); for ( ; itp != endp; ++itp) info += (*itp)->debugInfo(); QList<CategoryPtr> dcategories = categories(); QList<CategoryPtr>::ConstIterator itc = dcategories.constBegin(); QList<CategoryPtr>::ConstIterator endc = dcategories.constEnd(); for ( ; itc != endc; ++itc) info += (*itc)->debugInfo(); ImagePtr dimage = image(); if (!dimage->isNull()) info += dimage->debugInfo(); QList<ItemPtr> ditems = items(); QList<ItemPtr>::ConstIterator it = ditems.constBegin(); QList<ItemPtr>::ConstIterator end = ditems.constEnd(); for ( ; it != end; ++it) info += (*it)->debugInfo(); info += QLatin1String("# Feed end ########################\n"); return info; }
QString Entry::debugInfo() const { QString info; info += QLatin1String("### Entry: ###################\n"); if (!title().isEmpty()) info += QLatin1String("title: #") + title() + QLatin1String("#\n"); if (!summary().isEmpty()) info += QLatin1String("summary: #") + summary() + QLatin1String("#\n"); if (!id().isEmpty()) info += QLatin1String("id: #") + id() + QLatin1String("#\n"); if (!content().isNull()) info += content().debugInfo(); if (!rights().isEmpty()) info += QLatin1String("rights: #") + rights() + QLatin1String("#\n"); QString dupdated = dateTimeToString(updated()); if (!dupdated.isNull()) info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n"); QString dpublished = dateTimeToString(published()); if (!dpublished.isNull()) info += QLatin1String("published: #") + dpublished + QLatin1String("#\n"); QList<Link> dlinks = links(); QList<Link>::ConstIterator endlinks = dlinks.constEnd(); for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it) info += (*it).debugInfo(); QList<Category> dcats = categories(); QList<Category>::ConstIterator endcats = dcats.constEnd(); for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it) info += (*it).debugInfo(); info += QLatin1String("### Authors: ###################\n"); QList<Person> dauthors = authors(); QList<Person>::ConstIterator endauthors = dauthors.constEnd(); for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it) info += (*it).debugInfo(); info += QLatin1String("### Contributors: ###################\n"); QList<Person> dcontri = contributors(); QList<Person>::ConstIterator endcontri = dcontri.constEnd(); for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it) info += (*it).debugInfo(); if (!source().isNull()) info += source().debugInfo(); info += QLatin1String("### Entry end ################\n"); return info; }
QString Source::debugInfo() const { QString info; info += QLatin1String("### Source: ###################\n"); if (!title().isEmpty()) info += QLatin1String("title: #") + title() + QLatin1String("#\n"); if (!subtitle().isEmpty()) info += QLatin1String("subtitle: #") + subtitle() + QLatin1String("#\n"); if (!id().isEmpty()) info += QLatin1String("id: #") + id() + QLatin1String("#\n"); if (!rights().isEmpty()) info += QLatin1String("rights: #") + rights() + QLatin1String("#\n"); if (!icon().isEmpty()) info += QLatin1String("icon: #") + icon() + QLatin1String("#\n"); if (!logo().isEmpty()) info += QLatin1String("logo: #") + logo() + QLatin1String("#\n"); if (!generator().isNull()) info += generator().debugInfo(); QString dupdated = dateTimeToString(updated()); if (!dupdated.isNull()) info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n"); QList<Link> dlinks = links(); QList<Link>::ConstIterator endlinks = dlinks.constEnd(); for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it) info += (*it).debugInfo(); QList<Category> dcats = categories(); QList<Category>::ConstIterator endcats = dcats.constEnd(); for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it) info += (*it).debugInfo(); info += QLatin1String("### Authors: ###################\n"); QList<Person> dauthors = authors(); QList<Person>::ConstIterator endauthors = dauthors.constEnd(); for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it) info += (*it).debugInfo(); info += QLatin1String("### Contributors: ###################\n"); QList<Person> dcontri = contributors(); QList<Person>::ConstIterator endcontri = dcontri.constEnd(); for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it) info += (*it).debugInfo(); info += QLatin1String("### Source end ################\n"); return info; }
AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); ui.quasselLogo->setPixmap(DesktopIcon("quassel", IconLoader::SizeHuge)); ui.versionLabel->setText(QString(tr("<b>Version:</b> %1<br><b>Protocol version:</b> %2<br><b>Built:</b> %3")) .arg(Quassel::buildInfo().fancyVersionString) .arg(Quassel::buildInfo().protocolVersion) .arg(Quassel::buildInfo().buildDate)); ui.aboutTextBrowser->setHtml(about()); ui.authorTextBrowser->setHtml(authors()); ui.contributorTextBrowser->setHtml(contributors()); ui.thanksToTextBrowser->setHtml(thanksTo()); setWindowIcon(Icon("quassel")); }
AboutDialog::AboutDialog( QWidget *parent ) : QDialog( parent ), ui( new Ui::AboutDialog ) { ui->setupUi( this ); QFile authors( ":/CONTRIBUTORS" ); authors.open( QFile::ReadOnly ); ui->authors->setPlainText( authors.readAll() ); QFile license( ":/COPYING" ); license.open( QFile::ReadOnly ); ui->license->setPlainText( license.readAll() ); ItalcCore::enforceBranding( this ); }
//Welcoming window void Gui::Welcome(void) { //Define the texts Texts welcome(0,150,_font,"Multi Armed Bandit",_textColor); Texts authors(0,350,_font2,"Nathan Benabou & Pierre Vuillemin",_textColor); //Define the Button Buttons enter(361, 500, "Images/enter1.png","Images/enter2.png","Images/enter3.png"); //Display them centered welcome.DisplayCentered(_screen); authors.DisplayCentered(_screen); //enter.Show(_screen); //Start getting events SDL_Event event; //Initialization of the loop bool skip = false; while((_quit==false)&&(skip==false)) { //While there's an event to handle while( SDL_PollEvent( &event ) ) { if(enter.HandleEvents(event)==false) { skip=true; } //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program _quit = true; } } enter.Show(_screen); _screen.Display(); } _screen.Clean("Images/background.png"); }
void usage(void) { intro(); fprintf(stderr, "USAGE:\n\tinterpreter <FILE> [OPTIONS]\n"); fprintf(stderr, "\n"); fprintf(stderr, "FILE:\n\tTinyC grammer source code file\n"); fprintf(stderr, "\n"); fprintf(stderr, "OPTIONS:\n"); int i; for(i = 0; i < long_option_length; i++) { if( i > 0 && i % 4 == 0) { fprintf(stderr, "\t\n"); } if( long_option_desc[i][0] != NULL ) { fprintf(stderr, "\t-%c %s\t--%s %s\t %s\n", long_options[i].val, long_option_desc[i][0], long_options[i].name, long_option_desc[i][0], long_option_desc[i][1]); } else { fprintf(stderr, "\t-%c\t\t--%-16s %s\n", long_options[i].val, long_options[i].name, long_option_desc[i][1]); } } fprintf(stderr, "\n"); // tools(); authors(); }
void CCSVWriter::Write ( const CCachedLogInfo& cache , const TFileName& fileName) { std::ofstream authors ((fileName + _T(".authors.csv")).c_str()); WriteStringList (authors, cache.GetLogInfo().GetAuthors()); std::ofstream userRevPropNames ((fileName + _T(".revpropnames.csv")).c_str()); WriteStringList (userRevPropNames, cache.GetLogInfo().GetUserRevProps()); std::ofstream paths ((fileName + _T(".paths.csv")).c_str()); WritePathList (paths, cache.GetLogInfo().GetPaths()); std::ofstream changes ((fileName + _T(".changes.csv")).c_str()); WriteChanges (changes, cache); std::ofstream merges ((fileName + _T(".merges.csv")).c_str()); WriteMerges (merges, cache); std::ofstream userRevProps ((fileName + _T(".userrevprops.csv")).c_str()); WriteRevProps (userRevProps, cache); std::ofstream revisions ((fileName + _T(".revisions.csv")).c_str()); WriteRevisions (revisions, cache); std::ofstream skipranges ((fileName + _T(".skipranges.csv")).c_str()); WriteSkipRanges (skipranges, cache); }
//Do zrobienia(?): przerzuciæ obs³ugê slotów (open, close) do engine'u? MWindow::MWindow(){ #ifdef MYDEBUG qDebug() << "Startuje konstruktor MWindow()"; #endif //Tworzenie silnika engine = new MEngine; //Akcje do menu File openAction = new QAction(tr("&Otworz graf"), this); closeAction = new QAction(tr("&Zamknij graf"), this); saveOneAction = new QAction(tr("&Zapisz rezultat"), this); //saveAllAction = new QAction(tr("Sa&ve all"), this); newWindowAction = new QAction(tr("&Rysuj!"), this); //Tworzy nowe okienko exitAction = new QAction(tr("Wyjscie"), this); //Akcje do menu Algorithm BFSAction = new QAction(tr("BFS"), this); DFSAction = new QAction(tr("DFS"), this); transposeAction = new QAction(tr("Transponuj"), this); toUdirectedAction = new QAction(tr("Symetryzuj"), this); stronglyConnectedAction = new QAction(tr("Silnie spojne skladowe"), this); graphColoringAction = new QAction(tr("Kolorowanie wierzcholkowe"), this); //Akcje do menu About displayHelpAction = new QAction(tr("&Pomoc"), this); displayAuthorsAction = new QAction(tr("Autorzy"), this); displayAboutQtAction = new QAction(tr("Info o Qt"), this); // closeAction->setEnabled(false); saveOneAction->setEnabled(false); //saveAllAction->setEnabled(false); newWindowAction->setEnabled(false); BFSAction->setEnabled(false); DFSAction->setEnabled(false); transposeAction->setEnabled(false); toUdirectedAction->setEnabled(false); displayHelpAction->setEnabled(false); stronglyConnectedAction->setEnabled(false); graphColoringAction->setEnabled(false); // connect(openAction, SIGNAL(triggered()), this, SLOT(open())); connect(closeAction, SIGNAL(triggered()), this , SLOT(closeGraph())); connect(saveOneAction, SIGNAL(triggered()), this, SLOT(save())); connect(newWindowAction, SIGNAL(triggered()), this, SLOT(openNewWindow())); connect(exitAction, SIGNAL(triggered()), this, SLOT(quit())); // connect(BFSAction, SIGNAL(triggered()), this, SLOT(BFS())); connect(DFSAction, SIGNAL(triggered()), this, SLOT(DFS())); connect(transposeAction, SIGNAL(triggered()), this, SLOT(transpose())); connect(toUdirectedAction, SIGNAL(triggered()), this, SLOT(toUndirected())); connect(stronglyConnectedAction, SIGNAL(triggered()), this, SLOT(stronglyConnected())); connect(graphColoringAction, SIGNAL(triggered()), this, SLOT(graphColoring())); //countOrderAction = new QAction(tr("Count order"), this); //checkAdjacencyAction = new QAction(tr("Check adjacency"), this); //isSubgraphAction = new QAction(tr("Is subgraph"), this); connect(displayAuthorsAction, SIGNAL(triggered()), this, SLOT(authors())); connect(displayAboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); // //Dodawanie akcji do MenuBar fileMenu = menuBar()->addMenu(tr("&Plik")); fileMenu->addAction(openAction); fileMenu->addAction(saveOneAction); fileMenu->addAction(newWindowAction); fileMenu->addAction(closeAction); //fileMenu->addAction(saveAllAction); fileMenu->addSeparator(); fileMenu->addAction(exitAction); algorithmMenu = menuBar()->addMenu(tr("Algorytmy")); //algorithmMenu->addAction(countOrderAction); algorithmMenu->addAction(BFSAction); algorithmMenu->addAction(DFSAction); algorithmMenu->addSeparator(); algorithmMenu->addAction(transposeAction); algorithmMenu->addAction(toUdirectedAction); //algorithmMenu->addAction(stronglyConnectedAction); algorithmMenu->addSeparator(); algorithmMenu->addAction(graphColoringAction); //algorithmMenu->addAction(checkAdjacencyAction); //algorithmMenu->addAction(isSubgraphAction); aboutMenu = menuBar()->addMenu(tr("O programie")); aboutMenu->addAction(displayHelpAction); aboutMenu->addAction(displayAuthorsAction); aboutMenu->addAction(displayAboutQtAction); // statusBarPtr = statusBar();// Ustawia pasek stanu statusBarPtr->showMessage(tr("Gotowy")); //POPRACOWAÆ NAD TYM NP DODAÆ WID¯ET QPROGRESSBAR LUB QLABEL // centralWidgetPtr = new MCentral; setCentralWidget(centralWidgetPtr); // secondWindow = NULL; //Inicjalizacja wskaŸnika na nowe okno // msgBox.setWindowTitle("Autor"); msgBox.setText(tr("Autor: \nKamil Burzynski.\nAlgorytmy na Grafach 2012\nUKSW")); // applicationName = tr("AGR v 0.4"); setWindowTitle(applicationName); setMinimumSize(400, 400); // opened = 0; // options = NULL; #ifdef MYDEBUG qDebug() << "Konczy konstruktor MWindow()"; #endif }
//MAIN GAME LOOP void Game::GameLoop() { //check time of last frame float frameTime = frameClock.getElapsedTime().asSeconds(); frameClock.restart(); //event loop sf::Event currentEvent; while(mainWindow.pollEvent(currentEvent)) { //gotta handle resize things here if(currentEvent.type == sf::Event::Resized) { //std::cerr << "resized" << std::endl; float aspectRatio = float(currentEvent.size.width)/float(currentEvent.size.height); float newHeight = (1024.f*currentEvent.size.height)/currentEvent.size.width; float newWidth = (768.f*currentEvent.size.width)/currentEvent.size.height; if(aspectRatio > (4.f/3.f)) { float displace = (newWidth - 1024.f)/(-2.f); View = sf::View(sf::FloatRect(displace, 0, newWidth, 768)); } else if(aspectRatio < (4.f/3.f)) { float displace = (newHeight - 768.f)/(-2.f); View = sf::View(sf::FloatRect(0, displace, 1024, newHeight)); } mainWindow.setView(View); } //broken fullscreen stuff, do not touch else if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::F)) { //mainWindow.close(); //std::vector<sf::VideoMode> FullscreenModes = sf::VideoMode::getFullscreenModes(); //mainWindow.create(FullscreenModes[0],"SHMUP Super Alpha", sf::Style::Fullscreen); } switch(gameState) { case GameOver: { if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::Return)) { scoreboard.clear(); gameState = Uninitialized; } if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape))) { gameState = Exiting; } break; } case Playing: { if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape))) { gameState = Exiting; } if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::P)) { sounds[2].play(); gameState = Paused; } break; } case Paused: { if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape))) { gameState = Exiting; } if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::P)) { sounds[2].play(); gameState = Playing; } break; } case Intro: { if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::Return)) { storyScreen++; sounds[1].play(); unsigned pos = 0; for(int i = 0; i < 10; i++) { pos = story.find_first_of('\n',pos+1); } buffer.assign(story,0,pos); story.erase(0,pos); } if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape))) { gameState = Exiting; } break; } } } //non event-triggered state stuff (every frame updates) switch(gameState) { case Uninitialized: { mainWindow.clear(); background0.Load("images/acespacebg0.png"); background1.Load("images/acespacebg1.png"); background0.sprite.setTextureRect(sf::Rect<int>(0,(2500-768),576,768)); background1.sprite.setTextureRect(sf::Rect<int>(0,(2500-768),576,768)); bgMove0 = 0; bgMove1 = 0; player1.Load("images/Player.png"); player1.SetPosition(576/2,700); player1.revive(); scoreboard.updatePower(0); scoreboard.updateLives(0); scoreboard.updateScore(-1); scoreboard.updateTargetHP(0,0); scoreboard.updateFont(&datagoth); scoreboard.clear(); } case ShowingSplash: { if(!ShowSplashScreen()) gameState = Exiting; else { gameState = Intro; unsigned pos = 0; for(int i = 0; i < 10; i++) { pos = story.find_first_of('\n',pos+1); } buffer.assign(story,0,pos); story.erase(0,pos); } break; } case Intro: { if(storyScreen == 5) { music[0].stop(); music[1].play(); gameState = Playing; scoreboard.updateLives(1); scoreboard.updatePower(5); scoreboard.updateScore(000000); scoreboard.updateTargetHP(0,0); //intial wave to seed the enemy list Enemy* newEnemy2 = new Enemy(2, 0, -100); newEnemy2->setDestination(200, 300); enemyList.push_front(*newEnemy2); Enemy* newEnemy3 = new Enemy(2, 576, -100); newEnemy3->setDestination(350, 300); enemyList.push_front(*newEnemy3); Enemy* newEnemy4 = new Enemy(2, 60, -100); newEnemy4->setDestination(200, 300); enemyList.push_front(*newEnemy4); Enemy* newEnemy5 = new Enemy(2, 536, -100); newEnemy5->setDestination(350, 300); enemyList.push_front(*newEnemy5); frameClock.restart(); } } case Playing: { //check movement CheckMovement(5, frameTime); if(player1.destroyCheck()) { enemyList.clear(); mainWindow.clear(); player1.clearProjectiles(); music[1].stop(); sounds[4].play(); scoreboard.updateLives(-1); gameState = GameOver; break; } UpdateProj(); UpdateEnemies(); //update paralaxed backgrounds if(bgMove0 > (2500-768)) bgMove0 = 0; bgMove0 += 1; background0.sprite.setTextureRect(sf::Rect<int>(0,(2500-768)-bgMove0,576,768)); break; } } if(bgMove1 > (2500-768)) bgMove1 = 0; bgMove1 += 3; background1.sprite.setTextureRect(sf::Rect<int>(0,(2500-768)-bgMove1,576,768)); //clean up sprites to be deleted CleanUp(); //draw game mainWindow.clear(sf::Color(0,0,0)); mainWindow.draw(wholeArea); background0.Draw(mainWindow); char fps[60]; sprintf(fps,"%.2f\nESC to Quit\nP to Pause\nSPACE to Fire\nWASD to Move",(float(1)/frameTime)); sf::String fpsString(fps); sf::Text text(fpsString, datagoth); text.setCharacterSize(20); text.setColor(sf::Color::White); text.setPosition(596, 650); sf::String sidebar(buffer+"\n\nPress Enter"); sf::Text textBox(sidebar,datagoth); if(gameState == GameOver) { sf::String gameOver("GAME OVER"); sf::Text endingMessage(gameOver, datagoth); endingMessage.setCharacterSize(50); //endingMessage.setStyle(sf::Text::Bold); endingMessage.setColor(sf::Color::Red); endingMessage.setPosition(288-(endingMessage.getGlobalBounds().width/2), 300); sf::String authors("Developed by:\nJohn New\nDevon Gardner\nJon Forcht\nDanny Krulick\n\n\n\n\n\n\nPress Enter to Restart"); sf::Text credits(authors, datagoth); credits.setCharacterSize(20); credits.setColor(sf::Color::White); credits.setPosition(288-(credits.getGlobalBounds().width/2), 500); mainWindow.draw(credits); mainWindow.draw(endingMessage); } DrawProj(); DrawEnemies(); if(player1.destroyCheck() == false) player1.Draw(mainWindow); background1.Draw(mainWindow); mainWindow.draw(spawnArea); mainWindow.draw(rightBound); mainWindow.draw(leftBound); mainWindow.draw(bottomBound); mainWindow.draw(text); if(gameState == Intro && storyScreen < 5) { textBox.setCharacterSize(20); textBox.setColor(sf::Color::White); textBox.setPosition(596, 250); mainWindow.draw(textBox); } scoreboard.drawScoreboard(mainWindow, player1.sprite); //finally, render the frame mainWindow.display(); }
int main(int argc, char **argv) { bool iserror = true; try { Wig2Bed::Input progInput(argc, argv); bool multiout = !progInput.basename_.empty(); int cntr = 1; bool startWrite = false; FILE* outfile = stdout; for(Wig2Bed::Input::InFileIterator i = progInput.inFiles_.begin(); i != progInput.inFiles_.end(); i++) { if ( multiout ) { std::stringstream con; con << progInput.basename_ << "." << cntr++; std::string s = con.str(); outfile = std::fopen(s.c_str(), "w"); } Bed::LineCountType line = 0; Bed::LineCountType posLines = 0; Bed::CoordType span = 0; Bed::CoordType step = 0; Bed::CoordType startPos = 0; Bed::CoordType endPos = 0; float score; char chromBuf[20]; bool isFixedStep = false; std::string currLine; startWrite = false; while(std::getline(**i, currLine)) { line++; /*Ignore leading white space and comments*/ std::size_t lineStartPos = currLine.find_first_not_of(" \t"); if ( lineStartPos == std::string::npos || currLine[lineStartPos] == '#' ) { if ( multiout && startWrite ) { startWrite = false; std::fclose(outfile); std::stringstream con; con << progInput.basename_ << "." << cntr++; std::string s = con.str(); outfile = std::fopen(s.c_str(), "w"); } continue; } currLine.assign(currLine, lineStartPos, currLine.size() - lineStartPos); /* Evaluate Wig Line */ if ( (std::strncmp(currLine.c_str(), "track", 5) == 0) || std::strncmp(currLine.c_str(), "browser", 7) == 0 ) { if ( multiout && startWrite ) { startWrite = false; std::fclose(outfile); std::stringstream con; con << progInput.basename_ << "." << cntr++; std::string s = con.str(); outfile = std::fopen(s.c_str(), "w"); } continue; } else if (std::strncmp(currLine.c_str(), "variableStep", 12) == 0) { int fields = std::sscanf(currLine.c_str(), "variableStep chrom=%s span=%" SCNu64 "\n", chromBuf, &span); if (fields < 1) { std::stringstream err; err << "Invalid variableStep header on line " << line << std::endl; throw(err.str()); } if (fields == 1) span = 1; isFixedStep = false; if ( multiout && startWrite ) { startWrite = false; std::fclose(outfile); std::stringstream con; con << progInput.basename_ << "." << cntr++; std::string s = con.str(); outfile = std::fopen(s.c_str(), "w"); } } else if (std::strncmp(currLine.c_str(), "fixedStep", 9) == 0) { int fields = std::sscanf(currLine.c_str(), "fixedStep chrom=%s start=%" SCNu64 " step=%" SCNu64 " span=%" SCNu64 "\n", chromBuf, &startPos, &step, &span); if (fields < 3) { std::stringstream err; err << "Invalid fixedStep header on line " << line << std::endl; throw(err.str()); } if(fields == 3) span = 1; isFixedStep = true; if ( multiout && startWrite ) { startWrite = false; std::fclose(outfile); std::stringstream con; con << progInput.basename_ << "." << cntr++; std::string s = con.str(); outfile = std::fopen(s.c_str(), "w"); } } else if (std::strncmp(currLine.c_str(), "chr", 3) == 0) { /*Bed Format*/ posLines++; int fields = std::sscanf(currLine.c_str(), "%s\t%" SCNu64 "\t%" SCNu64 "\t%f\n", chromBuf, &startPos, &endPos, &score); if(fields != 4) { std::stringstream err; err << "Invalid wig line: " << line << std::endl; throw(err.str()); } std::fprintf(outfile, "%s\t%" PRIu64 "\t%" PRIu64 "\tid-%" PRIu64 "\t%f\n", chromBuf, startPos-1, endPos-1, posLines, score); startWrite = true; } else { /* Data Value */ if(isFixedStep) { int fields = std::sscanf(currLine.c_str(), "%f\n", &score); if(fields != 1) { std::stringstream err; err << "Invalid wig line: " << line << std::endl; throw(err.str()); } posLines++; std::fprintf(outfile, "%s\t%" PRIu64 "\t%" PRIu64 "\tid-%" PRIu64 "\t%f\n", chromBuf, startPos-1, startPos+span-1, posLines, score); startPos += step; startWrite = true; } else { /* Variable step*/ int fields = std::sscanf(currLine.c_str(), "%" SCNu64 "\t%f\n", &startPos, &score); if(fields !=2) { std::stringstream err; err << "Invalid wig line: " << line << std::endl; throw(err.str()); } posLines++; std::fprintf(outfile, "%s\t%" PRIu64 "\t%" PRIu64 "\tid-%" PRIu64 "\t%f\n", chromBuf, startPos-1, startPos+span-1, posLines, score); startWrite = true; } } } } iserror = false; if ( multiout && startWrite ) std::fclose(outfile); } catch(Wig2Bed::Help h) { std::cout << prognm() << std::endl; std::cout << " citation: " + citation() << std::endl; std::cout << " version: " + version() << std::endl; std::cout << " authors: " + authors() << std::endl; std::cout << std::endl << Wig2Bed::Input::Usage() << std::endl << std::endl; iserror = false; } catch(const std::string& msg) { std::cerr << prognm() << std::endl; std::cerr << " citation: " << citation() << std::endl; std::cerr << " version: " + version() << std::endl; std::cerr << " authors: " + authors() << std::endl; std::cerr << std::endl << Wig2Bed::Input::Usage() << std::endl << std::endl; std::cerr << " " << msg << std::endl; iserror = true; } catch(const std::exception& ex) { std::cerr << ex.what() << std::endl; } catch(...) { std::cerr << "Error: Aborting" << std::endl; } if ( iserror ) return(EXIT_FAILURE); return(EXIT_SUCCESS); }