Explorar el Código

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

Also fixed bug in the cmCsvInsertXXXColAfter() where the return cell pointer
was not correctly set.
master
kevin hace 11 años
padre
commit
e5ee6432c1
Se han modificado 2 ficheros con 57 adiciones y 5 borrados
  1. 53
    5
      cmCsv.c
  2. 4
    0
      cmCsv.h

+ 53
- 5
cmCsv.c Ver fichero

@@ -729,6 +729,20 @@ unsigned   cmCsvInsertSymUInt(   cmCsvH_t h, unsigned v )
729 729
   return cmInvalidId;
730 730
 }
731 731
 
732
+unsigned   cmCsvInsertSymHex(   cmCsvH_t h, unsigned v )
733
+{
734
+  const char* fmt = "0x%x";
735
+  unsigned    n   = snprintf(NULL,0,fmt,v)+1;
736
+  char        buf[n];
737
+
738
+  buf[0]= 0;
739
+  if( snprintf(buf,n,fmt,v) == n-1 )
740
+    return cmCsvInsertSymText(h,buf);
741
+  
742
+  _cmCsvError(_cmCsvHandleToPtr(h),kDataCvtErrCsvRC,"The unsigned int 0x%x could not be converted to text.",v);
743
+  return cmInvalidId;
744
+}
745
+
732 746
 unsigned   cmCsvInsertSymFloat(  cmCsvH_t h, float v )
733 747
 {
734 748
   const char* fmt = "%f";
@@ -812,6 +826,24 @@ cmCsvRC_t  cmCsvSetCellUInt(   cmCsvH_t h, unsigned row, unsigned col, unsigned
812 826
   return kOkCsvRC;  
813 827
 }
814 828
 
829
+cmCsvRC_t  cmCsvSetCellHex(   cmCsvH_t h, unsigned row, unsigned col, unsigned v )
830
+{
831
+  cmCsvCell_t* cp;
832
+  unsigned     symId;
833
+
834
+  if((cp = _cmCsvCellPtr(h,row,col)) == NULL )
835
+    return cmErrLastRC(&_cmCsvHandleToPtr(h)->err);
836
+
837
+  if((symId = cmCsvInsertSymHex(h,v)) == cmInvalidId )
838
+    return cmErrLastRC(&_cmCsvHandleToPtr(h)->err);
839
+  
840
+  cp->symId = symId;
841
+  cp->flags &= !kTypeTMask;
842
+  cp->flags |= kIntCsvTFl;
843
+
844
+  return kOkCsvRC;  
845
+}
846
+
815 847
 cmCsvRC_t  cmCsvSetCellFloat(  cmCsvH_t h, unsigned row, unsigned col, float v )
816 848
 {
817 849
   cmCsvCell_t* cp;
@@ -985,7 +1017,7 @@ cmCsvRC_t  cmCsvInsertTextColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
985 1017
   cmCsvCell_t* ncp;
986 1018
 
987 1019
   if( cellPtrPtr != NULL )
988
-    cellPtrPtr = NULL;
1020
+    *cellPtrPtr = NULL;
989 1021
 
990 1022
   if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
991 1023
     if((rc = cmCsvSetCellText(h, ncp->row, ncp->col, text )) == kOkCsvRC )
@@ -1001,7 +1033,7 @@ cmCsvRC_t  cmCsvInsertIntColAfter(    cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
1001 1033
   cmCsvCell_t* ncp;
1002 1034
 
1003 1035
   if( cellPtrPtr != NULL )
1004
-    cellPtrPtr = NULL;
1036
+    *cellPtrPtr = NULL;
1005 1037
 
1006 1038
   if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
1007 1039
     if((rc = cmCsvSetCellInt(h, ncp->row, ncp->col, val )) == kOkCsvRC )
@@ -1017,7 +1049,7 @@ cmCsvRC_t  cmCsvInsertUIntColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
1017 1049
   cmCsvCell_t* ncp;
1018 1050
 
1019 1051
   if( cellPtrPtr != NULL )
1020
-    cellPtrPtr = NULL;
1052
+    *cellPtrPtr = NULL;
1021 1053
 
1022 1054
   if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
1023 1055
     if((rc = cmCsvSetCellUInt(h, ncp->row, ncp->col, val )) == kOkCsvRC )
@@ -1027,13 +1059,29 @@ cmCsvRC_t  cmCsvInsertUIntColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
1027 1059
   return rc;
1028 1060
 }
1029 1061
 
1062
+cmCsvRC_t  cmCsvInsertHexColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId )
1063
+{
1064
+  cmCsvRC_t    rc;
1065
+  cmCsvCell_t* ncp;
1066
+
1067
+  if( cellPtrPtr != NULL )
1068
+    *cellPtrPtr = NULL;
1069
+
1070
+  if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
1071
+    if((rc = cmCsvSetCellHex(h, ncp->row, ncp->col, val )) == kOkCsvRC )
1072
+      if( cellPtrPtr != NULL )
1073
+        *cellPtrPtr = ncp;
1074
+  
1075
+  return rc;
1076
+}
1077
+
1030 1078
 cmCsvRC_t  cmCsvInsertFloatColAfter(  cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, float val, unsigned lexTId )
1031 1079
 {
1032 1080
   cmCsvRC_t    rc;
1033 1081
   cmCsvCell_t* ncp;
1034 1082
 
1035 1083
   if( cellPtrPtr != NULL )
1036
-    cellPtrPtr = NULL;
1084
+    *cellPtrPtr = NULL;
1037 1085
 
1038 1086
   if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
1039 1087
     if((rc = cmCsvSetCellFloat(h, ncp->row, ncp->col, val )) == kOkCsvRC )
@@ -1049,7 +1097,7 @@ cmCsvRC_t  cmCsvInsertDoubleColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCs
1049 1097
   cmCsvCell_t* ncp;
1050 1098
 
1051 1099
   if( cellPtrPtr != NULL )
1052
-    cellPtrPtr = NULL;
1100
+    *cellPtrPtr = NULL;
1053 1101
 
1054 1102
   if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
1055 1103
     if((rc = cmCsvSetCellDouble(h, ncp->row, ncp->col, val )) == kOkCsvRC )

+ 4
- 0
cmCsv.h Ver fichero

@@ -109,13 +109,16 @@ extern "C" {
109 109
   unsigned   cmCsvInsertSymText(   cmCsvH_t h, const char* text );
110 110
   unsigned   cmCsvInsertSymInt(    cmCsvH_t h, int v );
111 111
   unsigned   cmCsvInsertSymUInt(   cmCsvH_t h, unsigned v );
112
+  unsigned   cmCsvInsertSymHex(    cmCsvH_t h, unsigned v );
112 113
   unsigned   cmCsvInsertSymFloat(  cmCsvH_t h, float v );
113 114
   unsigned   cmCsvInsertSymDouble( cmCsvH_t h, double v );  
114 115
 
116
+
115 117
   // Set the value associated with a cell.
116 118
   cmCsvRC_t  cmCsvSetCellText(   cmCsvH_t h, unsigned row, unsigned col, const char* text );
117 119
   cmCsvRC_t  cmCsvSetCellInt(    cmCsvH_t h, unsigned row, unsigned col, int v );
118 120
   cmCsvRC_t  cmCsvSetCellUInt(   cmCsvH_t h, unsigned row, unsigned col, unsigned v );
121
+  cmCsvRC_t  cmCsvSetCellHex(    cmCsvH_t h, unsigned row, unsigned col, unsigned v );
119 122
   cmCsvRC_t  cmCsvSetCellFloat(  cmCsvH_t h, unsigned row, unsigned col, float v );
120 123
   cmCsvRC_t  cmCsvSetCellDouble( cmCsvH_t h, unsigned row, unsigned col, double v );
121 124
 
@@ -134,6 +137,7 @@ extern "C" {
134 137
   cmCsvRC_t  cmCsvInsertTextColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId );
135 138
   cmCsvRC_t  cmCsvInsertIntColAfter(    cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, int val,         unsigned lexTId );
136 139
   cmCsvRC_t  cmCsvInsertUIntColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val,    unsigned lexTId );
140
+  cmCsvRC_t  cmCsvInsertHexColAfter(    cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val,    unsigned lexTId );
137 141
   cmCsvRC_t  cmCsvInsertFloatColAfter(  cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, float val,       unsigned lexTId );
138 142
   cmCsvRC_t  cmCsvInsertDoubleColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, double val,      unsigned lexTId );
139 143
 

Loading…
Cancelar
Guardar