moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / tools / mihail.cpp
bloba9a839f6cb83899a5abc7f7c0bd0a323276d77a5
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #include <iostream>
13 #include <fstream>
14 #include <sstream>
15 #include <string>
17 #include "hscore.h"
18 #include "fesave.h"
21 static truth DebugDraw (festring Filename) {
23 inputfile HighScore(Filename, 0, false);
24 if (!HighScore.IsOpen()) return false;
25 HighScore.Get();
26 if (HighScore.Eof()) return false;
28 inputfile HighScore(Filename, 0, false);
29 uShort HVersion;
30 HighScore >> HVersion;
31 std::cout << "\nFile is version " << HVersion << std::endl;
32 return true;
36 static int OutputHTML (festring InputFilename) {
37 highscore Input;
38 Input.Load(InputFilename);
39 std::cout << "<TABLE BORDER=3> \n <TR> <TH>Rank</TH> <TH>Who</TH> <TH>Score</TH>\n";
40 for (int c = 0; c < Input.GetSize();++c) {
41 festring Rank,Score;
42 Score << Input.GetScore(c);
43 Rank << c+1 << festring(".");
44 std::cout
45 << std::string("<TR> <TD>")
46 << Rank.CStr()
47 << std::string("</TD> <TD>")
48 << Input.GetEntry(c).CStr()
49 << std::string("</TD> <TD>")
50 << Score.CStr()
51 << std::string("</TD> </TR>\n");
53 std::cout << "</TABLE>";
54 return 0;
58 int Main (int argc, char **argv) {
59 if (argc == 3) {
60 festring Arg = festring(argv[1]);
61 if (Arg == "-l") {
62 highscore Input(argv[2]);
63 if (!Input.GetSize()) std::cout << "No games. No winners.\n";
64 std::cout << std::endl;
65 for (festring::sizetype c = 0; c < (festring::sizetype)Input.GetSize(); ++c)
66 std::cout << c+1 << " " << Input.GetEntry(c).CStr() << " " << Input.GetScore(c) << "\n";
67 return 0;
69 if (Arg == "-h") return OutputHTML(argv[2]);
70 if (Arg == "-d") {
71 if (!DebugDraw(argv[2])) {
72 std::cout << "\nProblem showing version number\n";
73 return 1;
75 return 0;
77 return 1;
80 if (argc == 4) {
81 highscore Input;
82 Input.Load(argv[1]);
83 if (!Input.CheckVersion()) {
84 std::cout << "Version check not ok with " << argv[1] << std::endl;
85 return 2;
87 highscore Output;
88 Output.Load(argv[2]);
89 if (!Output.CheckVersion()) {
90 std::cout << "Version check not ok with " << argv[2] << std::endl;
91 return 2;
93 if(!Input.MergeToFile(&Output))
94 std::cout << "\n All entries also found in " << argv[2] << ". Oh well.\n";
95 Output.Save(argv[3]);
96 return 0;
98 std::cout << "\nTo list scores in highscore file:\n mihail -l [filename] \n\nTo merge 2 files\n mihail [1st input filename] [2nd input filename] [output filename] \n\nTo give version number of highscore file\n mihail -d [filename]\nNotice that first filename in merges gives also version number\n";
99 return 1;