@cire - I think you may be misunderstanding my question. Not your fault as I am probably being very unclear as to what I'm trying to accomplish here, and the fact that I haven't provided any code isn't helping anything...
So, to be clear, I have determined that sscanf is doing it's job too slowly. All I need sscanf to do is take in some buffer, read an ASCII value and convert it to hex for me. So I wrote a quicker conversion function (but it's shitty).
inline signed short ConvertAsciiHexCharToInt( char byAsciiChar )
// 0 - 9
// A - F
// a - f
char byRetValue = -1;
if( byAsciiChar >= '0' && byAsciiChar <= '9' )
byRetValue = byAsciiChar - '0';
else if( byAsciiChar >= 'A' && byAsciiChar <= 'F' )
byRetValue = byAsciiChar - 'A' + 0x0A;
else if( byAsciiChar >= 'a' && byAsciiChar <= 'f' )
byRetValue = byAsciiChar - 'a' + 0x0A;
inline signed short ConvertAsciiHexToInt( char* pbyBuffer )
signed short wRetValue = -1;
signed short wUpper = ConvertAsciiHexCharToInt( pbyBuffer );
signed short wLower = ConvertAsciiHexCharToInt( pbyBuffer );
// This checks if either sign bit is set (negative) most efficiently...
if( wUpper | wLower > 0)
// MAKEWORD is a macro that will shift these suckers over to high byte and low byte
wRetValue = MAKEWORD( wUpper , wLower );
Now, the code I'm trying to refactor would do something like this previously:
unsigned int dwRecordLength = 0;
sscanf( (const char*)( pbyBuffer + dwPos ), %02X, &dwRecordLength );
I'm trying to replace that with this:
// Get the byte count
char byByteCount = ConvertAsciiHexToInt( pbyBuffer+dwPos );
Remember these are just code snippets, there is a total of about 3 or 4 of these calls all siting in a while( not done parsing file ) loop. For a file about 350KB the first code would take about 6 seconds, with my improvements that's down to a fraction of a second, but still somewhat significant (about 100-350ms or so...)
Okay now hopefully you see why I don't want to use sscanf.
NOW BACK TO MY ORIGINAL QUESTION!!!!
I need to parse Intel Hex Records, that's what these files are
Does anyone know of any good libraries for parsing this stuff? Anyone ever done this before and have any suggestions/tips?