* xmlXPathNodeSetAdd: * @cur: the initial node set * @val: a new xmlNodePtr * * add a new xmlNodePtr to an existing NodeSet * * Returns 0 in case of success, and -1 in case of error */
| 2907 | * Returns 0 in case of success, and -1 in case of error |
| 2908 | */ |
| 2909 | int |
| 2910 | xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) { |
| 2911 | int i; |
| 2912 | |
| 2913 | if ((cur == NULL) || (val == NULL)) return(-1); |
| 2914 | |
| 2915 | /* @@ with_ns to check whether namespace nodes should be looked at @@ */ |
| 2916 | /* |
| 2917 | * prevent duplicates |
| 2918 | */ |
| 2919 | for (i = 0;i < cur->nodeNr;i++) |
| 2920 | if (cur->nodeTab[i] == val) return(0); |
| 2921 | |
| 2922 | /* |
| 2923 | * grow the nodeTab if needed |
| 2924 | */ |
| 2925 | if (cur->nodeMax == 0) { |
| 2926 | cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * |
| 2927 | sizeof(xmlNodePtr)); |
| 2928 | if (cur->nodeTab == NULL) |
| 2929 | return(-1); |
| 2930 | memset(cur->nodeTab, 0 , |
| 2931 | XML_NODESET_DEFAULT * sizeof(xmlNodePtr)); |
| 2932 | cur->nodeMax = XML_NODESET_DEFAULT; |
| 2933 | } else if (cur->nodeNr == cur->nodeMax) { |
| 2934 | xmlNodePtr *temp; |
| 2935 | |
| 2936 | if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) |
| 2937 | return(-1); |
| 2938 | temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * |
| 2939 | sizeof(xmlNodePtr)); |
| 2940 | if (temp == NULL) |
| 2941 | return(-1); |
| 2942 | cur->nodeMax *= 2; |
| 2943 | cur->nodeTab = temp; |
| 2944 | } |
| 2945 | if (val->type == XML_NAMESPACE_DECL) { |
| 2946 | xmlNsPtr ns = (xmlNsPtr) val; |
| 2947 | xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); |
| 2948 | |
| 2949 | if (nsNode == NULL) |
| 2950 | return(-1); |
| 2951 | cur->nodeTab[cur->nodeNr++] = nsNode; |
| 2952 | } else |
| 2953 | cur->nodeTab[cur->nodeNr++] = val; |
| 2954 | return(0); |
| 2955 | } |
| 2956 | |
| 2957 | /** |
| 2958 | * xmlXPathNodeSetAddUnique: |
no test coverage detected