Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DVT/Source/DVT/SopClassesManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ------------------------------------------------------
// ------------------------------------------------------
// DVTk - The Healthcare Validation Toolkit (www.dvtk.org)
// Copyright © 2009 DVTk
// Copyright © 2009 DVTk
// ------------------------------------------------------
// This file is part of DVTk.
//
Expand Down Expand Up @@ -239,7 +239,7 @@ private void AddSopClassesToDataGridFromDirectories()
{
string theErrorText;

theErrorText = string.Format("Definition file {0} could not be interpreted while reading directory:\n{1}\n\n", theDefinitionFileInfo.FullName, exception.Message);
theErrorText = string.Format("Definition file {0} could not be interpreted while reading directory:\n{1}\n\n", theDefinitionFileInfo.FullName, exception.ToString());

_RichTextBoxInfo.AppendText(theErrorText);
}
Expand Down
23 changes: 13 additions & 10 deletions DVTk_Library/Libraries/Definition/definition_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,19 @@ VALUE { RETURN(T_VALUE);}
RETURN(STRING);
}

INFO\([^\n]*\) {
if (yyleng >= sizeof(yylval.string))
{
yywarn("STRING too long!!! truncated") ;
yyleng = sizeof(yylval.string);
}
memcpy(yylval.string, yytext, yyleng);
yylval.string[yyleng] = '\0';
RETURN(STRING);
}
INFO\([^\n]*\) {
/* copy only the inner text between INFO( and ) into STRING */
int innerStart = 5; /* skip "INFO(" */
int innerLen = yyleng - innerStart - 1; /* remove trailing ')' */
if (innerLen < 0) innerLen = 0;
if (innerLen >= (int)sizeof(yylval.string)) {
yywarn("STRING too long!!! truncated");
innerLen = (int)sizeof(yylval.string) - 1;
}
memcpy(yylval.string, yytext + innerStart, innerLen);
yylval.string[innerLen] = '\0';
RETURN(STRING);
}


0(x|X)[0-9a-f]+ |
Expand Down
32 changes: 28 additions & 4 deletions DVTk_Library/Libraries/Definition/definition_parse.y
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
// Part of Dvtk Libraries - Internal Native Library Code
// Copyright © 2001-2006
// Copyright � 2001-2006
// Philips Medical Systems NL B.V., Agfa-Gevaert N.V.

/*
Expand Down Expand Up @@ -645,7 +645,31 @@ SequenceIntro : T_SQ ',' AttributeVM ','
attributes.push(currentAttribute_ptr);
}
}
;
| T_SQ ',' AttributeVM
{
if (!definitionParseOnly && !skipDefinition)
{
currentAttribute_ptr->SetVR(ATTR_VR_SQ);

currentItem_ptr = new DEF_ITEM_CLASS();

// create new value and value list, add item
currentValue_ptr = CreateNewValue(ATTR_VR_SQ);
currentValue_ptr->Set(currentItem_ptr);

// add value to attribute - indexed by value list index
currentAttribute_ptr->AddValue(currentValue_ptr, currentValueListIndex);
currentAttribute_ptr->SetValueType(ATTR_VAL_TYPE_NOVALUE, currentValueListIndex);

// the item is the new current attribute group.
// store the old one
groups.push(currentAttributeGroup_ptr);
currentAttributeGroup_ptr = currentItem_ptr;

// store currentAttribute_ptr
attributes.push(currentAttribute_ptr);
}
};

OtherValueDef : AttributeVR ',' AttributeVM ValuesDef
;
Expand Down Expand Up @@ -951,7 +975,7 @@ Condition :
// reset textual condition
lTextualCondition.erase();
}
}
}
| ':' T_WEAK '(' PrimaryCond ',' SecondaryCond ')'
{
if (!definitionParseOnly && !skipDefinition)
Expand Down Expand Up @@ -1699,4 +1723,4 @@ static void ResetVariables()
void resetDefinitionParser()
{
ResetVariables();
}
}
41 changes: 36 additions & 5 deletions DVTk_Library/Libraries/Definition/definitionfile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ------------------------------------------------------
// ------------------------------------------------------
// DVTk - The Healthcare Validation Toolkit (www.dvtk.org)
// Copyright © 2009 DVTk
// Copyright © 2009 DVTk
// ------------------------------------------------------
// This file is part of DVTk.
//
Expand All @@ -23,7 +23,8 @@
#include "definitiondetails.h"
#include "definition.h"
#include "Isession.h" // Session component interface

#include <fstream>
#include <sstream>

extern FILE* definitionin;
extern string definitionfilename;
Expand Down Expand Up @@ -524,9 +525,39 @@ bool DEFINITION_FILE_CLASS::GetDetails(DEF_DETAILS_CLASS& details)
delete fileContentM_ptr;
fileContentM_ptr = NULL;

char* errorText = new char[100];
// Read the offending line from file (best-effort) and include it in the error.
std::string offendingLine;
{
std::ifstream ifs(defFile.c_str());
if (ifs)
{
std::string tmp;
int ln = 0;
while (std::getline(ifs, tmp))
{
ln++;
if (ln == lineNumber)
{
offendingLine = tmp;
break;
}
}
}
}

// Build a descriptive error message that includes the line number and the line content (if available).
std::ostringstream oss;
oss << "Parse error in line " << lineNumber << ".";
if (!offendingLine.empty())
{
// Trim trailing CR if present (def files might have CRLF)
if (!offendingLine.empty() && offendingLine.back() == '\r') offendingLine.pop_back();
oss << " Offending line: \"" << offendingLine << "\"";
}

sprintf(errorText, "Parse error in line %i.", lineNumber);
std::string errStr = oss.str();
char* errorText = new char[errStr.size() + 1];
strcpy(errorText, errStr.c_str());
throw errorText;
}
}
Expand Down
Loading
Loading