diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/BCDDFile.cs | 22 | ||||
| -rw-r--r-- | src/PBNBoard.cs | 2 | ||||
| -rw-r--r-- | src/PBNFile.cs | 39 |
3 files changed, 45 insertions, 18 deletions
diff --git a/src/BCDDFile.cs b/src/BCDDFile.cs index 36a0872..03d0af2 100644 --- a/src/BCDDFile.cs +++ b/src/BCDDFile.cs @@ -9,6 +9,7 @@ namespace BCDD public List<String> errors; private String filename; private PBNFile file; + private String shortname; public static int filesCounter; public static ManualResetEvent filesCountdown = new ManualResetEvent(false); @@ -21,17 +22,30 @@ namespace BCDD this.errors = new List<String>(); this.filename = filename; this.file = new PBNFile(filename); + this.shortname = Path.GetFileName(this.filename); + if (this.file.ParseErrors.Count > 0) + { + this.error("PBN format errors encountered"); + foreach (KeyValuePair<int, String> kv in this.file.ParseErrors) + { + this.error(kv.Value, "", kv.Key); + } + } } - private void error(String message, String boardNo = "") + private void error(String message, String boardNo = "", int lineNo = -1) { if (!"".Equals(boardNo)) { - message = String.Format("[{0}:{1}] {2}", this.filename, boardNo, message); + message = String.Format("[{0}:B#{1}] {2}", this.shortname, boardNo, message); + } + else if (lineNo > -1) + { + message = String.Format("[{0}:L#{1}] {2}", this.shortname, lineNo, message); } else { - message = String.Format("[{0}] {1}", this.filename, message); + message = String.Format("[{0}] {1}", this.shortname, message); } errors.Add(message); Console.WriteLine("ERROR: " + message); @@ -39,7 +53,7 @@ namespace BCDD private void info(String boardNo, String ddTable, ParContract contract) { - Console.WriteLine(String.Format("[{0}:{1}] {2} {3}", this.filename, boardNo, ddTable, contract)); + Console.WriteLine(String.Format("[{0}:{1}] {2} {3}", this.shortname, boardNo, ddTable, contract)); } private void processBoard(object state) diff --git a/src/PBNBoard.cs b/src/PBNBoard.cs index 15acbe0..2ecaca8 100644 --- a/src/PBNBoard.cs +++ b/src/PBNBoard.cs @@ -60,7 +60,7 @@ namespace BCDD this.Fields.Add(field);
}
if (!this.HasField("Deal")) {
- throw new FieldNotFoundException("'Deal' field not found");
+ throw new FieldNotFoundException("PBN section doesn't contain 'Deal' field");
}
if (!this.HasField("Dealer"))
{
diff --git a/src/PBNFile.cs b/src/PBNFile.cs index b26f84c..f2a1465 100644 --- a/src/PBNFile.cs +++ b/src/PBNFile.cs @@ -9,6 +9,7 @@ namespace BCDD class PBNFile
{
public List<PBNBoard> Boards;
+ public Dictionary<int, String> ParseErrors;
private String filename;
private String tmpFileName;
@@ -18,28 +19,40 @@ namespace BCDD public PBNFile(String filename)
{
this.filename = filename;
+ this.ParseErrors = new Dictionary<int, string>();
this.Boards = new List<PBNBoard>();
- String[] contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToArray();
+ List<String> contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToList();
+ if (!contents.Last().Equals(""))
+ {
+ contents.Add("");
+ }
List<String> lines = new List<String>();
- foreach (String line in contents)
+ int lineNo = 0;
+ for (int l = 0; l < contents.Count; l++)
{
- if (line.Length == 0)
+ String line = contents[l];
+ if (line.Length != 0)
{
- if (lines.Count > 0)
- {
- this.Boards.Add(new PBNBoard(lines));
- lines = new List<String>();
- }
+ lines.Add(line);
+ continue;
}
else
{
- lines.Add(line);
+ if (lines.Count > 0) // ignore leading or multiple empty lines
+ {
+ try
+ {
+ this.Boards.Add(new PBNBoard(lines));
+ }
+ catch (Exception ex)
+ {
+ this.ParseErrors[lineNo+1] = ex.Message;
+ }
+ lines = new List<String>();
+ lineNo = l;
+ }
}
}
- if (lines.Count > 0)
- {
- this.Boards.Add(new PBNBoard(lines));
- }
if (!this.Boards[0].HasField("Event"))
{
this.Boards[0].WriteEvent("");
|
