source: trunk/src/core/scew_extras.c @ 77

Last change on this file since 77 was 77, checked in by dkearney, 15 years ago
  1. initial checkin of RpLibrary? code, includes c++/c/fortran bindings
  2. minor modifications to makefiles to accommodate new code
  3. updated README in src to tell how to compile code in src and test
File size: 1.0 KB
Line 
1#include "scew.h"
2
3#include "xelement.h"
4#include "xerror.h"
5
6#include <assert.h>
7
8#include "scew_extras.h"
9
10scew_element*
11scew_element_parent(scew_element const* element)
12{
13    assert(element != NULL);
14    return element->parent;
15}
16
17scew_element**
18scew_element_list_all(scew_element const* parent, unsigned int* count)
19{
20    unsigned int curr = 0;
21    unsigned int max = 0;
22    scew_element** list = NULL;
23    scew_element* element;
24
25    assert(parent != NULL);
26    assert(count != NULL);
27
28    element = scew_element_next(parent, 0);
29    while (element)
30    {
31        if (curr >= max)
32        {
33            max = (max + 1) * 2;
34            list = (scew_element**) realloc(list,
35                                            sizeof(scew_element*) * max);
36            if (!list)
37            {
38                set_last_error(scew_error_no_memory);
39                return NULL;
40            }
41        }
42        list[curr++] = element;
43
44        element = scew_element_next(parent, element);
45    }
46
47    *count = curr;
48
49    return list;
50}
Note: See TracBrowser for help on using the repository browser.