-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRdf.cpp
More file actions
124 lines (88 loc) · 2.51 KB
/
Copy pathRdf.cpp
File metadata and controls
124 lines (88 loc) · 2.51 KB
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
// Rdf.cpp: implementation of the Rdf class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "renlib.h"
#include "Rdf.h"
#include "Utils.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
namespace
{
CString cFile("File: ");
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Rdf::Rdf()
{
}
//------------------------------------------------------------------------
Game& Rdf::getGame()
{
return mGame;
}
//------------------------------------------------------------------------
CString Rdf::getFilePath()
{
return mstrFilePath;
}
//------------------------------------------------------------------------
bool Rdf::OpenFile(const CString& strFile)
{
CFileException e;
if (!mGameFile.Open(strFile, CFile::modeRead, &e))
{
return false;
}
mstrFilePath = mGameFile.GetFilePath();
Parse();
mGameFile.Close();
return true;
}
//------------------------------------------------------------------------
void Rdf::Parse()
{
mGame.clear();
CString strLine;
mGameFile.ReadString(strLine);
//----------------------
int index1 = strLine.Find(":RDFA");
if (index1 == -1) return;
int index2 = strLine.Find(":", index1 + 1);
if (index2 == -1) return;
int index3 = strLine.Find("!", index2 + 1);
if (index3 == -1) return;
index2++;
CString str5A;
CString strMoves(strLine.Mid(index2, index3 - index2));
CPoint Coord;
while (strMoves.GetLength() >= 4)
{
CString strNumber(strMoves.Mid(0, 2));
CString strCoord(strMoves.Mid(2, 2));
if (str5A.IsEmpty() && strNumber == "A5" &&
strCoord[0] >= 'a' && strCoord[0] <= 'o' &&
strCoord[1] >= 'a' && strCoord[1] <= 'o')
{
Coord.x = strCoord[0] - 'a' + 1;
Coord.y = strCoord[1] - 'a' + 1;
str5A =
Utils::XCoordinateImage(Coord.x, true, false) +
Utils::YCoordinateImage(Coord.y, true);
}
else
{
Coord.x = strCoord[0] - 'A' + 1;
Coord.y = strCoord[1] - 'A' + 1;
mGame.addPos(Utils::PointToPos(Coord));
}
strMoves.Delete(0, 4);
}
const int lastMove = mGame.numberOfMoves();
mGame.addMultiLineComment(lastMove, "File: " + mGameFile.GetFileTitle());
mGame.addMultiLineComment(lastMove, "5A: " + str5A);
}