cmCsv.h/c : Added cmCsvInsertSymHex(),cmCsvSetCellHex(), and cmInsertHexColAfter().

Also fixed bug in the cmCsvInsertXXXColAfter() where the return cell pointer
was not correctly set.
This commit is contained in:
kevin 2013-11-05 14:34:22 -08:00
parent 9181a5d804
commit e5ee6432c1
2 changed files with 57 additions and 5 deletions

58
cmCsv.c
View File

@ -729,6 +729,20 @@ unsigned cmCsvInsertSymUInt( cmCsvH_t h, unsigned v )
return cmInvalidId; return cmInvalidId;
} }
unsigned cmCsvInsertSymHex( cmCsvH_t h, unsigned v )
{
const char* fmt = "0x%x";
unsigned n = snprintf(NULL,0,fmt,v)+1;
char buf[n];
buf[0]= 0;
if( snprintf(buf,n,fmt,v) == n-1 )
return cmCsvInsertSymText(h,buf);
_cmCsvError(_cmCsvHandleToPtr(h),kDataCvtErrCsvRC,"The unsigned int 0x%x could not be converted to text.",v);
return cmInvalidId;
}
unsigned cmCsvInsertSymFloat( cmCsvH_t h, float v ) unsigned cmCsvInsertSymFloat( cmCsvH_t h, float v )
{ {
const char* fmt = "%f"; const char* fmt = "%f";
@ -812,6 +826,24 @@ cmCsvRC_t cmCsvSetCellUInt( cmCsvH_t h, unsigned row, unsigned col, unsigned
return kOkCsvRC; return kOkCsvRC;
} }
cmCsvRC_t cmCsvSetCellHex( cmCsvH_t h, unsigned row, unsigned col, unsigned v )
{
cmCsvCell_t* cp;
unsigned symId;
if((cp = _cmCsvCellPtr(h,row,col)) == NULL )
return cmErrLastRC(&_cmCsvHandleToPtr(h)->err);
if((symId = cmCsvInsertSymHex(h,v)) == cmInvalidId )
return cmErrLastRC(&_cmCsvHandleToPtr(h)->err);
cp->symId = symId;
cp->flags &= !kTypeTMask;
cp->flags |= kIntCsvTFl;
return kOkCsvRC;
}
cmCsvRC_t cmCsvSetCellFloat( cmCsvH_t h, unsigned row, unsigned col, float v ) cmCsvRC_t cmCsvSetCellFloat( cmCsvH_t h, unsigned row, unsigned col, float v )
{ {
cmCsvCell_t* cp; cmCsvCell_t* cp;
@ -985,7 +1017,7 @@ cmCsvRC_t cmCsvInsertTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
cmCsvCell_t* ncp; cmCsvCell_t* ncp;
if( cellPtrPtr != NULL ) if( cellPtrPtr != NULL )
cellPtrPtr = NULL; *cellPtrPtr = NULL;
if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC ) if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
if((rc = cmCsvSetCellText(h, ncp->row, ncp->col, text )) == kOkCsvRC ) if((rc = cmCsvSetCellText(h, ncp->row, ncp->col, text )) == kOkCsvRC )
@ -1001,7 +1033,7 @@ cmCsvRC_t cmCsvInsertIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
cmCsvCell_t* ncp; cmCsvCell_t* ncp;
if( cellPtrPtr != NULL ) if( cellPtrPtr != NULL )
cellPtrPtr = NULL; *cellPtrPtr = NULL;
if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC ) if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
if((rc = cmCsvSetCellInt(h, ncp->row, ncp->col, val )) == kOkCsvRC ) if((rc = cmCsvSetCellInt(h, ncp->row, ncp->col, val )) == kOkCsvRC )
@ -1017,7 +1049,7 @@ cmCsvRC_t cmCsvInsertUIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
cmCsvCell_t* ncp; cmCsvCell_t* ncp;
if( cellPtrPtr != NULL ) if( cellPtrPtr != NULL )
cellPtrPtr = NULL; *cellPtrPtr = NULL;
if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC ) if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
if((rc = cmCsvSetCellUInt(h, ncp->row, ncp->col, val )) == kOkCsvRC ) if((rc = cmCsvSetCellUInt(h, ncp->row, ncp->col, val )) == kOkCsvRC )
@ -1027,13 +1059,29 @@ cmCsvRC_t cmCsvInsertUIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
return rc; return rc;
} }
cmCsvRC_t cmCsvInsertHexColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId )
{
cmCsvRC_t rc;
cmCsvCell_t* ncp;
if( cellPtrPtr != NULL )
*cellPtrPtr = NULL;
if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
if((rc = cmCsvSetCellHex(h, ncp->row, ncp->col, val )) == kOkCsvRC )
if( cellPtrPtr != NULL )
*cellPtrPtr = ncp;
return rc;
}
cmCsvRC_t cmCsvInsertFloatColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, float val, unsigned lexTId ) cmCsvRC_t cmCsvInsertFloatColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, float val, unsigned lexTId )
{ {
cmCsvRC_t rc; cmCsvRC_t rc;
cmCsvCell_t* ncp; cmCsvCell_t* ncp;
if( cellPtrPtr != NULL ) if( cellPtrPtr != NULL )
cellPtrPtr = NULL; *cellPtrPtr = NULL;
if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC ) if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
if((rc = cmCsvSetCellFloat(h, ncp->row, ncp->col, val )) == kOkCsvRC ) if((rc = cmCsvSetCellFloat(h, ncp->row, ncp->col, val )) == kOkCsvRC )
@ -1049,7 +1097,7 @@ cmCsvRC_t cmCsvInsertDoubleColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
cmCsvCell_t* ncp; cmCsvCell_t* ncp;
if( cellPtrPtr != NULL ) if( cellPtrPtr != NULL )
cellPtrPtr = NULL; *cellPtrPtr = NULL;
if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC ) if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
if((rc = cmCsvSetCellDouble(h, ncp->row, ncp->col, val )) == kOkCsvRC ) if((rc = cmCsvSetCellDouble(h, ncp->row, ncp->col, val )) == kOkCsvRC )

View File

@ -109,13 +109,16 @@ extern "C" {
unsigned cmCsvInsertSymText( cmCsvH_t h, const char* text ); unsigned cmCsvInsertSymText( cmCsvH_t h, const char* text );
unsigned cmCsvInsertSymInt( cmCsvH_t h, int v ); unsigned cmCsvInsertSymInt( cmCsvH_t h, int v );
unsigned cmCsvInsertSymUInt( cmCsvH_t h, unsigned v ); unsigned cmCsvInsertSymUInt( cmCsvH_t h, unsigned v );
unsigned cmCsvInsertSymHex( cmCsvH_t h, unsigned v );
unsigned cmCsvInsertSymFloat( cmCsvH_t h, float v ); unsigned cmCsvInsertSymFloat( cmCsvH_t h, float v );
unsigned cmCsvInsertSymDouble( cmCsvH_t h, double v ); unsigned cmCsvInsertSymDouble( cmCsvH_t h, double v );
// Set the value associated with a cell. // Set the value associated with a cell.
cmCsvRC_t cmCsvSetCellText( cmCsvH_t h, unsigned row, unsigned col, const char* text ); cmCsvRC_t cmCsvSetCellText( cmCsvH_t h, unsigned row, unsigned col, const char* text );
cmCsvRC_t cmCsvSetCellInt( cmCsvH_t h, unsigned row, unsigned col, int v ); cmCsvRC_t cmCsvSetCellInt( cmCsvH_t h, unsigned row, unsigned col, int v );
cmCsvRC_t cmCsvSetCellUInt( cmCsvH_t h, unsigned row, unsigned col, unsigned v ); cmCsvRC_t cmCsvSetCellUInt( cmCsvH_t h, unsigned row, unsigned col, unsigned v );
cmCsvRC_t cmCsvSetCellHex( cmCsvH_t h, unsigned row, unsigned col, unsigned v );
cmCsvRC_t cmCsvSetCellFloat( cmCsvH_t h, unsigned row, unsigned col, float v ); cmCsvRC_t cmCsvSetCellFloat( cmCsvH_t h, unsigned row, unsigned col, float v );
cmCsvRC_t cmCsvSetCellDouble( cmCsvH_t h, unsigned row, unsigned col, double v ); cmCsvRC_t cmCsvSetCellDouble( cmCsvH_t h, unsigned row, unsigned col, double v );
@ -134,6 +137,7 @@ extern "C" {
cmCsvRC_t cmCsvInsertTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId ); cmCsvRC_t cmCsvInsertTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId );
cmCsvRC_t cmCsvInsertIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, int val, unsigned lexTId ); cmCsvRC_t cmCsvInsertIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, int val, unsigned lexTId );
cmCsvRC_t cmCsvInsertUIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId ); cmCsvRC_t cmCsvInsertUIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId );
cmCsvRC_t cmCsvInsertHexColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId );
cmCsvRC_t cmCsvInsertFloatColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, float val, unsigned lexTId ); cmCsvRC_t cmCsvInsertFloatColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, float val, unsigned lexTId );
cmCsvRC_t cmCsvInsertDoubleColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, double val, unsigned lexTId ); cmCsvRC_t cmCsvInsertDoubleColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, double val, unsigned lexTId );