-
Notifications
You must be signed in to change notification settings - Fork 2
/
gamediff.cc
158 lines (141 loc) · 4.06 KB
/
gamediff.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* This file is part of the Advance project.
*
* Copyright (C) 2002 Andrea Mazzoleni
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "portable.h"
#include "gamediff.h"
#include "lib/readinfo.h"
#include <iomanip>
rom::rom()
{
}
rom::rom(const rom& A)
: name(A.name), size(A.size), crc(A.crc) {
}
bool rom::operator<(const rom& A) const
{
if (crc_get() < A.crc_get())
return true;
if (crc_get() > A.crc_get())
return false;
return size_get() < A.size_get();
}
bool rom::operator==(const rom& A) const
{
return crc_get() == A.crc_get() && size_get() == A.size_get();
}
std::ostream& operator<<(std::ostream& os, const rom& A)
{
os << "rom ( name " << A.name_get() << " size " << std::dec << A.size_get() << " crc " << std::hex << A.crc_get() << " )";
return os;
}
bool include(const rom_set& A, const rom_set& B)
{
for(rom_set::const_iterator i=B.begin();i!=B.end();++i) {
rom_set::const_iterator j = A.find(*i);
if (j==A.end())
return false;
}
return true;
}
bool equal(const rom_set& A, const rom_set& B)
{
if (A.size() != B.size())
return false;
rom_set::const_iterator i, j;
for(i=B.begin(), j=A.begin();i!=B.end();++i) {
if (*i != *j)
return false;
}
return true;
}
game::game()
{
}
game::game(const game& A)
: name(A.name), roms(A.roms)
{
}
bool game::operator<(const game& A) const
{
return name_get() < A.name_get();
}
std::ostream& operator<<(std::ostream &os, const game& A)
{
os << "game (" << std::endl;
os << "\tname " << A.name_get() << std::endl;
for(rom_set::const_iterator i=A.roms_get().begin();i!=A.roms_get().end();++i)
os << "\t" << *i << std::endl;
os << ")" << std::endl;
return os;
}
bool game_set_load::load(bool remove_merge)
{
info_t token = info_token_get();
while (token!=info_eof) {
if (token != info_symbol) return false;
if (strcmp(info_text_get(), "game")==0) {
if (info_token_get() != info_open) return false;
game g;
token = info_token_get();
while (token != info_close) {
if (token != info_symbol)
return false;
if (strcmp(info_text_get(), "name")==0) {
if (info_token_get() != info_symbol) return false;
g.name_set(info_text_get());
} else if (strcmp(info_text_get(), "rom")==0) {
if (info_token_get() != info_open) return false;
token = info_token_get();
rom r;
bool merge = false;
while (token != info_close) {
if (token != info_symbol) return false;
if (strcmp(info_text_get(), "size")==0) {
if (info_token_get() != info_symbol) return false;
r.size_set(atoi(info_text_get()));
} else if (strcmp(info_text_get(), "crc")==0 || strcmp(info_text_get(), "crc32")==0) {
if (info_token_get() != info_symbol) return false;
r.crc_set(strtoul(info_text_get(), 0, 16));
} else if (strcmp(info_text_get(), "name")==0) {
if (info_token_get() != info_symbol) return false;
r.name_set(info_text_get());
} else if (strcmp(info_text_get(), "merge")==0) {
if (info_token_get() != info_symbol) return false;
merge = true;
} else {
if (info_skip_value() == info_error) return false;
}
token = info_token_get();
}
if (!(remove_merge && merge))
g.roms_get().insert(r);
} else {
if (info_skip_value() == info_error) return false;
}
token = info_token_get();
}
insert(g);
} else {
if (info_skip_value() == info_error)
return false;
}
token = info_token_get();
}
return true;
}