// Joe Gillotti - 10/16/2011 // // compile with -lpcrecpp /* joe@adore:/mnt/nfs/aero_more/joe/backups/prog_test/c++/pcre$ ./pcretest We've got 12 players! $[harckor]$ with 13 kills and 12 deaths -=G.A.B=- with 0 kills and 0 deaths Amijo with 1 kills and 1 deaths Exzekutor<>GIN with 33 kills and 33 deaths Filozof with 17 kills and 18 deaths FreeMan with 0 kills and 0 deaths Kciuku & Pocwicz! with 96 kills and 94 deaths Lech Poznan with 35 kills and 35 deaths [!@#$niszczyciel$#@!] with 32 kills and 32 deaths ^^ThOmAs^^ with 9 kills and 9 deaths kciuku-pocwicz with 0 kills and 0 deaths ninja with 1 kills and 1 deaths joe@adore:/mnt/nfs/aero_more/joe/backups/prog_test/c++/pcre$ */ #include #include #include #include struct player { unsigned int kills; unsigned int deaths; }; int main () { std::map players; std::map::iterator players_it; std::ifstream soldat_log ("KillLog-10-09-15-01.txt", std::ios::in | std::ios::binary | std::ios::ate); if (!soldat_log.is_open()) { std::cerr << "Couldn't open logfile" << std::endl; return 1; } std::ifstream::pos_type size = soldat_log.tellg(); char *file_contents = new char[size]; soldat_log.seekg(0); soldat_log.read(file_contents, size); soldat_log.close(); pcrecpp::RE re("\\n---\\s(\\d{2}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2})\\n(.+)\\n(.+)\\n(Ak\\-74|Barret M82A1|Barrett M82A1|Bow|Chainsaw|Clusters|Combat Knife|Desert Eagles|FN Minimi|Flame Bow|Flamer|Grenade|HK MP5|Hands|LAW|M79|Ruger 77|Spas\\-12|Stationary gun|Steyr AUG|USSOCOM|XM214 Minigun|Selfkill)"); pcrecpp::StringPiece log_content(file_contents); delete[] file_contents; std::string date, killer, victim, wep; player tmp; while (re.FindAndConsume(&log_content, &date, &killer, &victim, &wep)) { // Fuck suiciders if (killer.compare(victim) == 0) continue; if (players.count(killer) == 1) { players.find(killer)->second.kills++; } else { tmp.kills = 1; tmp.deaths = 0; players[killer] = tmp; } if (players.count(victim) == 1) { players.find(killer)->second.deaths++; } else { tmp.kills = 0; tmp.deaths = 1; players[victim] = tmp; } } std::cout << "We've got " << players.size() << " players!" << std::endl; for (players_it = players.begin(); players_it != players.end(); players_it++) std::cout << (*players_it).first << " with " << (*players_it).second.kills << " kills and " << (*players_it).second.deaths << " deaths" << std::endl; return 0; }