-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rdfile.cpp
883 lines (781 loc) · 20.6 KB
/
Rdfile.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
//----------------------------------------------------------------------------------------
//
// This file and all other Easy Bridge source files are copyright (C) 2002 by Steven Han.
// Use of this file is governed by the GNU General Public License.
// See the files COPYING and COPYRIGHT for details.
//
//----------------------------------------------------------------------------------------
// Rdfile.cpp : implementation of file reading
//
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBdoc.h"
#include "EasyBvw.h"
#include "Player.h"
#include "mainfrm.h"
#include "MainFrameOpts.h"
#include "filecode.h"
#include "progopts.h"
#include "deck.h"
#include "card.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
//
// Easy Bridge File Format codes
//
const char* tszBlockName[] = {
"",
"[[File Information]]",
"[[File Description]]",
"[[Hand Information]]",
"[[Round Information]]",
"[[Game Information]]",
"[[Game Record]]",
"[[Match Information]]",
"[[Misc Information]]",
"[[File Comments]]",
"[[South Play Analysis]]",
"[[West Play Analysis]]",
"[[North Play Analysis]]",
"[[East Play Analysis]]",
};
const char* tszItemName[] = {
// 0..9
"",
"Program ID",
"Program Major Version",
"Program Minor Version",
"Program Incremental Version",
"Program Build Number",
"Program Build Date",
"File Date",
"", "",
// 10..19
"Current Hand(North)",
"Current Hand(East)",
"Current Hand(South)",
"Current Hand(West)",
"Original Hand(North)",
"Original Hand(East)",
"Original Hand(South)",
"Original Hand(West)",
"", "",
// 20..29
"Lead Player for Current Hand",
"# Cards Played in Current Round",
"Trick Card #1 (South)",
"Trick Card #2 (West)",
"Trick Card #3 (North)",
"Trick Card #4 (East)",
"", "", "", "",
// 30..49
"Game Status Code",
"Is Rubber In Progress?",
"Is Game in Progress?",
"Is Bidding in Progress?",
"Was Hand Dealt?",
"Dealer",
"Contract Suit",
"Contract Level",
"Contract Modifier",
"Number of Bids Made",
"Bidding History",
"Declarer",
"", "", "", "", "", "", "", "",
// 50..79
"Number of Tricks Played in Game",
"# of Tricks won in Game by N/S",
"# of Tricks won in Game by E/W",
"", "", "", "", "", "", "",
"Lead Player for Current Game",
"GameTrick #1",
"GameTrick #2",
"GameTrick #3",
"GameTrick #4",
"GameTrick #5",
"GameTrick #6",
"GameTrick #7",
"GameTrick #8",
"GameTrick #9",
"GameTrick #10",
"GameTrick #11",
"GameTrick #12",
"GameTrick #13",
"", "", "", "", "", "",
// 80..99
"North/South Bonus Points",
"North/South Game 1 Points",
"North/South Game 2 Points",
"North/South Game 3 Points",
"North/South Games Won",
"East/West Bonus Points",
"East/West Game 1 Points",
"East/West Game 2 Points",
"East/West Game 3 Points",
"East/West Games Won",
"Current Game",
"Bonus Score Record",
"Game Score Record",
"", "",
"", "", "", "", "",
// 100..109
"Automatically Show File Comments",
"Automatically Show Bidding History",
"Automatically Show Play History",
"Automatically Show Analysis Dialogs",
"", "", "", "", "", "",
//
};
//
const int MAXLINELEN = 1024;
const int MAXBUFLEN = 1024;
static char szBuffer[MAXBUFLEN+1];
static CString strBuf, strBiddingHistory;
static int nLineLen = 0;
static int nDataPosition = 0;;
//
//---------------------------------------------------------
//
BOOL CEasyBDoc::ReadFile(CArchive& ar)
{
int i,nRtnCode,nLineCode,nSectionCode;
int nIndex,nValue,nOffset,nLen;
int nPlayOffset, nPos;
int nBidIndex = 0;
CString strMessage,string,partString;
CCard* pCard;
double fValue;
BOOL bValue;
BOOL bFileInfoFound = FALSE;
// read
m_nLineNumber = 0;
try
{
for(;;)
{
nRtnCode = ReadLine(ar, strBuf);
next: if (nRtnCode == EOF)
break;
if (nRtnCode == 0)
continue;
if ((strBuf[0] == '#') || (strBuf[0] == '*'))
continue;
nLineLen = nRtnCode;
nLineCode = ParseLine(strBuf,nLineLen);
if (nLineCode < 0)
{
// section signifier
nSectionCode = -nLineCode;
if (nSectionCode == BLOCK_FILEINFO)
{
//
bFileInfoFound = TRUE;
// file info; skip this section
do {
nRtnCode = ReadLine(ar, strBuf);
} while ((nRtnCode != EOF) && (strBuf.Left(2) != "[["));
//
goto next;
}
//
if (nSectionCode == BLOCK_FILEDESC)
{
// file description; read until next block
m_strFileDescription.Empty();
do {
nRtnCode = ReadLine(ar, strBuf);
if (strBuf.Left(2) != "[[")
{
strBuf += "\r\n";
m_strFileDescription += strBuf;
}
} while ((nRtnCode != EOF) && (strBuf.Left(2) != "[["));
// trim ending CR/LF
int nLen = m_strFileDescription.GetLength();
if ((nLen >= 2) && (m_strFileDescription[nLen-1] == _T('\n')))
m_strFileDescription = m_strFileDescription.Left(nLen-2);
//
goto next;
}
else if (nSectionCode == BLOCK_COMMENTS)
{
// file comments
for (;;)
{
nRtnCode = ReadLine(ar, strBuf);
if ((nRtnCode == EOF) || (strBuf.Left(2) == "[["))
{
// update file comments dialog if it's open
CWnd* pWnd = pMAINFRAME->GetDialog(twFileCommentsDialog);
if (pWnd)
pWnd->SendMessage(WM_COMMAND, WMS_UPDATE_TEXT, FALSE);
goto next;
}
strBuf += "\r\n";
m_strFileComments += strBuf;
}
}
else if ((nSectionCode == BLOCK_SOUTH_ANALYSIS) ||
(nSectionCode == BLOCK_WEST_ANALYSIS) ||
(nSectionCode == BLOCK_NORTH_ANALYSIS) ||
(nSectionCode == BLOCK_EAST_ANALYSIS))
{
// don't bother to save the analysis
int nPlayer = nSectionCode - BLOCK_SOUTH_ANALYSIS;
CString strAnalysisBiffer;
do {
nRtnCode = ReadLine(ar, strBuf);
// strBuf += "\r\n";
// strAnalysisBiffer += strBuf;
} while ((nRtnCode != EOF) && (strBuf.Left(2) != "[["));
// m_player[nPlayer].SetValueString(tszAnalysis, strAnalysisBiffer);
goto next;
}
}
else if (nLineCode > 0)
{
// first skip spaces
nLen = strBuf.GetLength();
while ((nDataPosition < nLen) &&
(strBuf[nDataPosition] == ' '))
nDataPosition++;
if (nDataPosition >= nLen)
continue;
// then get data item
string = strBuf.Mid(nDataPosition);
nValue = atoi(string);
fValue = atof(string);
if ((string == "Yes") || (string == "1"))
bValue = TRUE;
else
bValue = FALSE;
switch(nLineCode)
{
case ITEM_PROGRAM_ID:
m_strFileProgTitle = string;
break;
case ITEM_MAJOR_VERSIONNO:
m_nFileProgMajorVersion = nValue;
break;
case ITEM_MINOR_VERSIONNO:
m_nFileProgMinorVersion = nValue;
break;
case ITEM_INCREMENT_VERSIONNO:
m_nFileProgIncrementVersion = nValue;
break;
case ITEM_BUILD_NUMBER:
m_nFileProgBuildNumber = nValue;
break;
case ITEM_BUILD_DATE:
m_strFileProgBuildDate = string;
break;
case ITEM_FILE_DATE:
m_strFileDate = string;
break;
// hand info, 10..19
case ITEM_CURRHAND_NORTH:
AssignCards(string,NORTH);
break;
case ITEM_CURRHAND_EAST:
AssignCards(string,EAST);
break;
case ITEM_CURRHAND_SOUTH:
AssignCards(string,SOUTH);
break;
case ITEM_CURRHAND_WEST:
AssignCards(string,WEST);
break;
case ITEM_ORIGHAND_NORTH:
AssignCards(string,NORTH,TRUE);
break;
case ITEM_ORIGHAND_EAST:
AssignCards(string,EAST,TRUE);
break;
case ITEM_ORIGHAND_SOUTH:
AssignCards(string,SOUTH,TRUE);
break;
case ITEM_ORIGHAND_WEST:
AssignCards(string,WEST,TRUE);
break;
// current round info
case ITEM_CURR_ROUND_LEAD:
m_nRoundLead = StringToPosition(string);
break;
case ITEM_NUM_CARDS_PLAYED_IN_ROUND:
m_numCardsPlayedInRound = nValue;
break;
case ITEM_TRICK_CARD_1:
m_pCurrTrick[0] = deck.GetCard(string);
break;
case ITEM_TRICK_CARD_2:
m_pCurrTrick[1] = deck.GetCard(string);
break;
case ITEM_TRICK_CARD_3:
m_pCurrTrick[2] = deck.GetCard(string);
break;
case ITEM_TRICK_CARD_4:
m_pCurrTrick[3] = deck.GetCard(string);
break;
// game status info
case ITEM_VIEW_STATUS_CODE:
pVIEW->SetCurrentMode((CEasyBView::ScreenMode)nValue);
break;
case ITEM_RUBBER_IN_PROGRESS:
theApp.SetValue(tbRubberInProgress, bValue);
break;
case ITEM_GAME_IN_PROGRESS:
// TEMP
// theApp.SetValue(tbGameInProgress, FALSE);
theApp.SetValue(tbGameInProgress, bValue);
break;
case ITEM_BIDDING_IN_PROGRESS:
theApp.SetValue(tbBiddingInProgress, bValue);
break;
case ITEM_HANDS_DEALT:
m_bHandsDealt = bValue;
break;
case ITEM_CONTRACT_SUIT:
nLen = string.GetLength();
m_nContractSuit = CharToSuit(string.GetAt(0));
break;
case ITEM_CONTRACT_LEVEL:
m_nContractLevel = nValue;
break;
case ITEM_CONTRACT_MODIFIER:
switch(nValue)
{
case 0:
m_bDoubled = FALSE;
m_bRedoubled = FALSE;
m_nContractModifier = 0;
break;
case 1:
m_bDoubled = TRUE;
m_bRedoubled = FALSE;
m_nContractModifier = 1;
break;
case 2:
m_bDoubled = FALSE;
m_bRedoubled = TRUE;
m_nContractModifier = 2;
break;
}
break;
case ITEM_DEALER:
m_nDealer = StringToPosition(string);
break;
case ITEM_NUM_BIDS:
// m_numBidsMade = nValue;
break;
case ITEM_BIDDING_HISTORY:
strBiddingHistory = string;
break;
case ITEM_DECLARER:
m_nDeclarer = StringToPosition(string);
m_nContractTeam = GetPlayerTeam(m_nDeclarer);
m_nDefendingTeam = (m_nContractTeam == NORTH_SOUTH)? EAST_WEST : NORTH_SOUTH;
break;
// game record
case ITEM_NUM_TRICKS_PLAYED:
m_numTricksPlayed = nValue;
break;
case ITEM_NUM_TRICKS_WON_NS:
m_numTricksWon[0] = nValue;
break;
case ITEM_NUM_TRICKS_WON_EW:
m_numTricksWon[1] = nValue;
break;
case ITEM_GAME_LEAD:
m_nGameLead = StringToPosition(string);
break;
case ITEM_GAME_TRICK_1: case ITEM_GAME_TRICK_2:
case ITEM_GAME_TRICK_3: case ITEM_GAME_TRICK_4:
case ITEM_GAME_TRICK_5: case ITEM_GAME_TRICK_6:
case ITEM_GAME_TRICK_7: case ITEM_GAME_TRICK_8:
case ITEM_GAME_TRICK_9: case ITEM_GAME_TRICK_10:
case ITEM_GAME_TRICK_11: case ITEM_GAME_TRICK_12:
case ITEM_GAME_TRICK_13:
try
{
nIndex = nLineCode - ITEM_GAME_TRICK_1;
nOffset = 0;
nLen = string.GetLength();
// first read the lead player for the trick
partString = string.Mid(nOffset);
m_nTrickLead[nIndex] = StringToPosition(partString);
nOffset = string.Find(' ');
//
for(i=0;i<4;i++)
{
while((nOffset < nLen) && (string[nOffset] == ' '))
nOffset++;
partString = string.Mid(nOffset);
nOffset += 2;
if (partString.IsEmpty())
{
strMessage.Format("Incomplete Trick record at line %d;\n%s",
m_nLineNumber, string);
AfxMessageBox(strMessage);
break;
}
//
if (partString.Left(2) == "--")
{
m_pGameTrick[nIndex][i] = NULL;
}
else
{
pCard = deck.GetCard(partString);
m_pGameTrick[nIndex][i] = pCard;
}
}
// insert the trick record into the game record
// in the proper order
nPlayOffset = nIndex * 4;
nPos = m_nTrickLead[nIndex];
for(i=0;i<4;i++)
{
CCard* pCard = m_pGameTrick[nIndex][nPos];
if (pCard)
m_nPlayRecord[nPlayOffset+i] = pCard->GetDeckValue();
nPos = GetNextPlayer(nPos);
}
// and finally read the trick's winner
while((nOffset < nLen) && (string[nOffset] == ' '))
nOffset++;
partString = string.Mid(nOffset);
m_nTrickWinner[nIndex] = StringToPosition(partString);
}
catch(...)
{
// error
}
break;
// match info
case ITEM_SCORE_NS_BONUS:
m_nBonusScore[NORTH_SOUTH] = nValue;
break;
case ITEM_SCORE_NS_GAME0:
m_nGameScore[0][NORTH_SOUTH] = nValue;
break;
case ITEM_SCORE_NS_GAME1:
m_nGameScore[1][NORTH_SOUTH] = nValue;
break;
case ITEM_SCORE_NS_GAME2:
m_nGameScore[2][NORTH_SOUTH] = nValue;
break;
case ITEM_SCORE_NS_GAMES_WON:
m_numGamesWon[NORTH_SOUTH] = nValue;
break;
case ITEM_SCORE_EW_BONUS:
m_nBonusScore[EAST_WEST] = nValue;
break;
case ITEM_SCORE_EW_GAME0:
m_nGameScore[0][EAST_WEST] = nValue;
break;
case ITEM_SCORE_EW_GAME1:
m_nGameScore[1][EAST_WEST] = nValue;
break;
case ITEM_SCORE_EW_GAME2:
m_nGameScore[2][EAST_WEST] = nValue;
break;
case ITEM_SCORE_EW_GAMES_WON:
m_numGamesWon[EAST_WEST] = nValue;
break;
case ITEM_CURRENT_GAME_INDEX:
m_nCurrGame = nValue-1;
break;
case ITEM_BONUS_SCORE_RECORD:
m_strArrayBonusPointsRecord.Add(StripQuotes(string));
break;
case ITEM_GAME_SCORE_RECORD:
m_strArrayTrickPointsRecord.Add(StripQuotes(string));
break;
// misc info
case ITEM_AUTOSHOW_COMMENTS:
m_bShowCommentsUponOpen = bValue;
break;
case ITEM_AUTOSHOW_BID_HISTORY:
m_bShowBidHistoryUponOpen = bValue;
break;
case ITEM_AUTOSHOW_PLAY_HISTORY:
m_bShowPlayHistoryUponOpen = bValue;
break;
case ITEM_AUTOSHOW_ANALYSES:
m_bShowAnalysesUponOpen = bValue;
break;
}
}
else
{
/*
// unknown line
strMessage.Format("Found Unknown line\n%s.\nContinue?",strBuf);
if (AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
break;
*/
}
}
}
catch(...)
{
// handle any improper file error here
ClearAllInfo();
// AfxMessageBox("An error ocurred while reading the game file.");
return FALSE;
}
// see if this was a valid file
if (!bFileInfoFound)
{
AfxMessageBox("This is not a proper Easy Bridge game file.");
AfxThrowFileException(CFileException::generic);
}
//
// do some sanity checks
//
m_nContract = MAKEBID(m_nContractSuit, m_nContractLevel);
if (!ISPLAYER(m_nDeclarer) || !ISBID(m_nContract))
theApp.SetValue(tbGameInProgress, FALSE);
//
// parse the bidding history
//
if (!ISPLAYER(m_nDeclarer))
m_nDeclarer = SOUTH;
nPos = m_nDeclarer;
m_nCurrPlayer = nPos;
int nTeam = GetPlayerTeam(nPos);
nOffset = 0;
//
nLen = strBiddingHistory.GetLength();
for(i=0;;i++)
{
// skip leading spaces
while((nOffset < nLen) && (strBiddingHistory[nOffset] == ' '))
nOffset++;
if (nOffset >= nLen)
break;
// grab the next bid
partString = strBiddingHistory.Mid(nOffset);
int nBid = ContractStringToBid(partString);
// and record it
m_nBiddingHistory[m_numBidsMade] = nBid;
m_numBidsMade++;
m_nCurrPlayer = GetNextPlayer(m_nCurrPlayer);
int nBiddingRound = i % 4;
m_nBidsByPlayer[nPos][nBiddingRound] = nBid;
// see if this is an actual numeric bid
if (ISBID(nBid))
{
m_nValidBidHistory[m_numValidBidsMade] = nBid;
m_numValidBidsMade++;
m_nLastValidBid = nBid;
m_nLastValidBidTeam = nTeam;
}
// skip over remainder of current bid string
while((nOffset < nLen) && (strBiddingHistory[nOffset] != ' '))
nOffset++;
// and move to the next player
nPos = GetNextPlayer(nPos);
nTeam = GetOpposingTeam(nTeam);
}
if (ISBID(m_nContract))
UpdateBiddingHistory();
// tally some figures
m_nTotalScore[0] = m_nGameScore[0][0] + m_nGameScore[1][0] +
m_nGameScore[2][0] + m_nBonusScore[0];
m_nTotalScore[1] = m_nGameScore[0][1] + m_nGameScore[1][1] +
m_nGameScore[2][1] + m_nBonusScore[1];
// vulnerability
if ((m_numGamesWon[0] > 0) && (m_numGamesWon[1] > 0))
{
m_nVulnerableTeam = BOTH;
m_bVulnerable[0] = m_bVulnerable[1] = TRUE;
}
else if (m_numGamesWon[0] > 0)
{
m_nVulnerableTeam = NORTH_SOUTH;
m_bVulnerable[0] = TRUE;
}
else if (m_numGamesWon[1] > 0)
{
m_nVulnerableTeam = EAST_WEST;
m_bVulnerable[1] = TRUE;
}
else
{
m_nVulnerableTeam = NEITHER;
}
//
// set contract info
//
m_nContract = ContractParamsToBid(m_nContractSuit,m_nContractLevel);
m_nTrumpSuit = m_nContractSuit;
m_nBiddingRound = nBidIndex;
// set play info
if (ISBID(m_nContract) && ISPLAYER(m_nDeclarer))
{
// contract has been reached
m_nDummy = GetPartner((int) m_nDeclarer);
m_nGameLead = GetNextPlayer(m_nDeclarer);
m_nRoundLead = m_nGameLead;
m_nCurrPlayer = m_nRoundLead;
m_nTrickLead[0] = m_nRoundLead;
// m_pPlayer[m_nDummy]->SetDummyFlag(TRUE);
// m_pPlayer[m_nDeclarer]->SetDeclarerFlag(TRUE);
}
else
{
// contract has NOT been reached, so restart
m_nCurrPlayer = m_nDealer;
m_numBidsMade = 0;
}
// restore initial hands (temp?)
for(i=0;i<4;i++)
m_pPlayer[i]->RestoreInitialHand();
// not reviewing game
m_bReviewingGame = FALSE;
// all done
return TRUE;
}
//
void CEasyBDoc::AssignCards(CString& str, int nPosition, BOOL bInitialHand)
{
int i,nOffset=0;
int nLen = str.GetLength();
BOOL bError = FALSE;
CCard* pCard;
//
for(i=0;i<13;i++)
{
// skip spaces
while((nOffset < nLen) && (str[nOffset] == ' '))
nOffset++;
// get next card string
if (nOffset < nLen)
{
pCard = deck.GetCard(str.Mid(nOffset));
nOffset += 2;
if (pCard == NULL)
{
bError = TRUE;
}
else
{
if (bInitialHand)
PLAYER(nPosition).AddCardToInitialHand(pCard);
else
PLAYER(nPosition).AddCardToHand(pCard,FALSE);
}
}
else
{
break;
}
if (bError)
{
CString strMessage;
strMessage.Format("Illegal card assignment on line %d, index %d;\n%s",
m_nLineNumber,i,strBuf);
AfxMessageBox(strMessage);
break;
}
}
}
//
//---------------------------------------------------------
//
int CEasyBDoc::ParseLine(CString& string, int nLineLength)
{
int i,nEnd;
// int nLen,nCode;
// compare against block designators
for(i=0;i<NUM_BLOCKS;i++)
{
if (string == tszBlockName[i])
return -i;
}
// not a block item, so scan the line for an '=' sign
// to see if this is a data item
for(nEnd=0;nEnd<nLineLength;nEnd++)
if (string[nEnd] == '=')
break;
// see if we reached the end -- if so, return negative
if (nEnd == nLineLength)
return 0;
// else save the value marker
nDataPosition = nEnd + 1;
// and trim ending spaces
while ((nEnd > 0) && (string[nEnd-1] == ' '))
nEnd--;
// and check for a valid item code
for(i=0;i<NUM_ITEMS;i++)
{
if (string.Left(nEnd) == tszItemName[i])
return i;
}
// nothing found
return 0;
}
//
//---------------------------------------------------------
//
//
int CEasyBDoc::ReadLine(CArchive&ar, CString& strDest)
{
int i,len,nBytesRead;
BYTE byte;
char* pBuf;
CString strBuffer;
// initialize string to null
strDest = "";
// read data
nBytesRead = 0;
pBuf = strBuffer.GetBuffer(MAXLINELEN+2);
do {
TRY
{
ar >> byte;
if (byte == '\r')
continue;
pBuf[nBytesRead++] = (char) byte;
}
CATCH(CArchiveException, arException)
{
if (arException->m_cause == CArchiveException::endOfFile)
if (nBytesRead > 0)
return 0;
else
return EOF;
}
AND_CATCH (CFileException, fileException)
{
if (fileException->m_cause == CFileException::endOfFile)
if (nBytesRead > 0)
return 0;
else
return EOF;
}
END_CATCH
} while ((byte != '\n') && (nBytesRead <= MAXLINELEN) && (byte != EOF));
//
strBuffer.ReleaseBuffer(nBytesRead);
// check for EOF
if(nBytesRead == 0)
return EOF;
// find end of line - 10(LF) or 13(CR)
len = nBytesRead;
for(i=0;i<nBytesRead;i++)
{
if((strBuffer[i] == 10) || (strBuffer[i] == 13))
{
len = i;
break;
}
}
strDest = strBuffer.Left(len);
// return to calling function
m_nLineNumber++;
return len;
}