浏览代码

cmXml.c : Rewrote _cmXmlNodeHasChildR() to fix bug where all possible children were not visited.

master
Kevin Larke 8 年前
父节点
当前提交
98a2e83bc0
共有 1 个文件被更改,包括 47 次插入96 次删除
  1. 47
    96
      cmXml.c

+ 47
- 96
cmXml.c 查看文件

@@ -287,19 +287,7 @@ const cmChar_t* _cmXmlAdvanceOne( cmXml_t* p )
287 287
   if( _cmXmlAdvance(p) )
288 288
     return p->c;
289 289
 
290
-  return NULL;
291
-  
292
-  /*
293
-  if( _cmXmlIsEof(p) )
294
-    return NULL;
295
-
296
-  p->c += 1;
297
-
298
-  if( *p->c == '\n' )
299
-    p->line += 1;
300
-  
301
-  return _cmXmlIsEof(p) ? NULL : p->c;
302
-  */
290
+  return NULL;  
303 291
 }
304 292
 
305 293
 cmXmlRC_t  _cmXmlParseAttr( cmXml_t* p, cmChar_t endChar,  cmXmlNode_t* np )
@@ -1021,7 +1009,40 @@ unsigned _cmXmlLabelCount( const cmChar_t* firstLabel, va_list vl )
1021 1009
   return n;
1022 1010
 }
1023 1011
 
1012
+const cmXmlNode_t*  _cmXmlNodeHasChildR( const cmXmlNode_t* np, unsigned argIdx, const cmChar_t**argV, unsigned argN, const cmChar_t* attrLabel, const cmChar_t* valueStr)
1013
+{
1014
+  const cmXmlNode_t* cnp = np->children;
1015
+  for(; cnp!=NULL; cnp=cnp->sibling)
1016
+    if( cmTextCmp(cnp->label,argV[argIdx]) == 0 )
1017
+    {
1018
+      // The node path ending at cnp matches all node labels up through argV[argIdx]
1019
+
1020
+      // if there are still node labels to match in argV[]
1021
+      if( argIdx < argN-1 )
1022
+        return _cmXmlNodeHasChildR(cnp,argIdx+1,argV,argN,attrLabel,valueStr);
1023
+
1024
+      // The path ending at cnp matches all node labels in argV[].
1025
+
1026
+      // if an attr. label was given 
1027
+      if( attrLabel != NULL )
1028
+      {
1029
+        const cmXmlAttr_t* a;
1030
+        if((a = cmXmlFindAttrib(cnp,attrLabel)) == NULL )
1031
+          continue;
1032
+
1033
+        // if a value string was given
1034
+        if( valueStr != NULL )
1035
+          if( cmTextCmp(a->value,valueStr) != 0 )
1036
+            continue;
1037
+      }
1038
+
1039
+      return cnp;      
1040
+    }
1041
+  
1042
+  return NULL;
1043
+}
1024 1044
 
1045
+/*
1025 1046
 const cmXmlNode_t*  _cmXmlNodeHasChildR( const cmXmlNode_t* np, unsigned argIdx, const cmChar_t**argV, unsigned argN, const cmChar_t* attrLabel, const cmChar_t* valueStr)
1026 1047
 {
1027 1048
   if( argIdx == argN )
@@ -1032,19 +1053,23 @@ const cmXmlNode_t*  _cmXmlNodeHasChildR( const cmXmlNode_t* np, unsigned argIdx,
1032 1053
   for(; cnp!=NULL; cnp=cnp->sibling)
1033 1054
     if( cmTextCmp(cnp->label,argV[argIdx]) == 0 )
1034 1055
     {
1035
-      const cmXmlNode_t* tnp = _cmXmlNodeHasChildR(cnp,argIdx+1,argV,argN,attrLabel,valueStr);
1056
+      const cmXmlNode_t* tnp;
1036 1057
 
1037
-      if( attrLabel != NULL )
1058
+      if((tnp = _cmXmlNodeHasChildR(cnp,argIdx+1,argV,argN,attrLabel,valueStr)) != NULL)
1038 1059
       {
1039
-        const cmXmlAttr_t* a;
1040
-        if((a = cmXmlFindAttrib(np,attrLabel)) == NULL )
1041
-          continue;
1042
-
1043 1060
 
1044
-        if( valueStr != NULL )
1061
+        if( attrLabel != NULL )
1045 1062
         {
1046
-          if( cmTextCmp(a->value,valueStr) != 0 )
1063
+          const cmXmlAttr_t* a;
1064
+          if((a = cmXmlFindAttrib(tnp,attrLabel)) == NULL )
1047 1065
             continue;
1066
+
1067
+
1068
+          if( valueStr != NULL )
1069
+          {
1070
+            if( cmTextCmp(a->value,valueStr) != 0 )
1071
+              continue;
1072
+          }
1048 1073
         }
1049 1074
       }
1050 1075
       
@@ -1054,6 +1079,7 @@ const cmXmlNode_t*  _cmXmlNodeHasChildR( const cmXmlNode_t* np, unsigned argIdx,
1054 1079
 
1055 1080
   return NULL;
1056 1081
 }
1082
+*/
1057 1083
 
1058 1084
 const cmXmlNode_t*  _cmXmlNodeHasChildV( const cmXmlNode_t* np, const cmChar_t* label, va_list vl, unsigned argN, const cmChar_t* attrLabel, const cmChar_t* valueStr )
1059 1085
 {
@@ -1066,33 +1092,6 @@ const cmXmlNode_t*  _cmXmlNodeHasChildV( const cmXmlNode_t* np, const cmChar_t*
1066 1092
   return _cmXmlNodeHasChildR(np,0,argV,argN,attrLabel,valueStr);
1067 1093
 }
1068 1094
 
1069
-/*
1070
-const cmXmlNode_t*  _cmXmlNodeHasChildV( const cmXmlNode_t* np, const cmChar_t* label, va_list vl, unsigned argN )
1071
-{
1072
-  unsigned i;
1073
-  
1074
-  // get next label to match
1075
-  for(i=0; i<argN; ++i)
1076
-  {
1077
-    assert( label != NULL);
1078
-    
1079
-    np = np->children;
1080
-    for(; np!=NULL; np=np->sibling)
1081
-      if( cmTextCmp(np->label,label) == 0 )
1082
-        break;
1083
-
1084
-    // if the end of the child list was encountered - with no match
1085
-    if( np == NULL )
1086
-      return NULL;
1087
-
1088
-    label = va_arg(vl,const cmChar_t*);
1089
-
1090
-  }
1091
-
1092
-  return np;
1093
-}
1094
-*/
1095
-
1096 1095
 bool    cmXmlNodeHasChildV( const cmXmlNode_t* np, const cmChar_t* label, va_list vl )
1097 1096
 {
1098 1097
   return _cmXmlNodeHasChildV(np,label,vl,_cmXmlLabelCount(label,vl),NULL,NULL)!=NULL;
@@ -1107,54 +1106,6 @@ bool    cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label, ... )
1107 1106
   return fl;
1108 1107
 }
1109 1108
 
1110
-/*
1111
-bool    _cmXmlNodeHasChildWithAttrAndValueV( const cmXmlNode_t* np, const cmChar_t* label, va_list vl0, bool valueFl )
1112
-{
1113
-  unsigned argN = _cmXmlLabelCount(label,vl0);
1114
-  unsigned    n = valueFl ? 2 : 1;  
1115
-  va_list vl1;
1116
-  unsigned i;
1117
-  
1118
-  assert( argN > n-1 ); // an attribute label must be given.
1119
-
1120
-  if( argN <= n-1 )
1121
-    return false;
1122
-
1123
-  argN -= n;
1124
-
1125
-  va_copy(vl1,vl0);
1126
-  np = _cmXmlNodeHasChildV(np,label,vl1,argN);
1127
-  va_end(vl1);
1128
-
1129
-  if( np == NULL )
1130
-    return false;
1131
-  
1132
-  // advance vl0 to the attribute label
1133
-  for(i=1; i<argN; ++i)
1134
-  {
1135
-    label = va_arg(vl0,const cmChar_t*);
1136
-    assert( label != NULL );
1137
-  }
1138
-
1139
-  // get the attr label
1140
-  label = va_arg(vl0,const cmChar_t*);
1141
-
1142
-  const cmXmlAttr_t* a;
1143
-  if((a = cmXmlFindAttrib(np,label)) == NULL )
1144
-    return false;
1145
-
1146
-
1147
-  if( valueFl )
1148
-  {
1149
-    label = va_arg(vl0,const cmChar_t*);
1150
-    if( cmTextCmp(a->value,label) != 0 )
1151
-      return false;
1152
-  }
1153
-
1154
-  return true;
1155
- }
1156
-*/
1157
-
1158 1109
 bool    _cmXmlNodeHasChildWithAttrAndValueV( const cmXmlNode_t* np, const cmChar_t* label, va_list vl0, bool valueFl )
1159 1110
 {
1160 1111
   unsigned           argN      = _cmXmlLabelCount(label,vl0);

正在加载...
取消
保存