I've changed the implementation and I would like to know if you think that it can be made public with the next release (the changes are based on 3.6.0). I'm not familiar with the procedure but as starting point I paste the relevant snippets here:
(1) getLine() function changed to
Code: Select all
static char * getLine(FILE *f)
{
assert(f!= NULL);
if (!f)
return NULL;
long startPos = ftell(f);
size_t lineLength = 0; //without line ending
int filePosInc = 0; //set the file position to the last line ending of this line
int validLineConfidence = 0; //a tag must be present for a line to make it valid "(1234,1234)" so check for "(", "," and ")" and min lenght 11
while(true)
{
char car = fgetc(f);
if (car == EOF)
{
if (lineLength == 0)
return NULL;
break;
}
else if (car == '\n' || car == '\r')
{
++filePosInc;
char nextCar = fgetc(f);
if (nextCar == '\n' && car == '\r' || nextCar == '\r' && car == '\n' )
++filePosInc;
break;
}
if (car == '(' || car == ',' || car == ')')
++validLineConfidence;
++lineLength;
}
char* line= new char[lineLength + 1]; //+1 for null termination
line[lineLength]= 0x0;
fseek(f, startPos, SEEK_SET); //set back to position for line analysis
size_t readBytes = fread(line, 1, lineLength, f);
assert(readBytes == lineLength);
fseek(f, filePosInc, SEEK_CUR); //read through the line endings
/* strip any trailing white space */
stripTrailingWhitespace(line);
//check if line can be valid
if (validLineConfidence< 3 || lineLength< 11)
line[0]= 0x0; //invalidates line
return line;
}
Code: Select all
FILE *dumpfile = fopen(opt_ifname, "rb");
(3) readDumpFile() must be adapted to use lineBuf as loop variable
I did a lot of automated testing for the new getLine() to make it work for the different line endings. It also now checks if the line contains a tag (prevents errors from the parser if there is garbage in the file). I could not detect a noticeable performance decrease for the additional counting part.
For me it makes no sense that, for creating a DICOM file from a dump, you have to have a fixed line size and data exceeding it is just ignored.
Could you please let me know how to proceed.