1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* prof_section.c --- routines that manipulate the profile_section_t
* object
*
* XXX this file is still under construction.
*/
#include <stdio.h>
#include <string.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <errno.h>
#include "prof_int.h"
/*
* This routine frees a profile_section
*/
void profile_free_section(sect)
profile_section_t sect;
{
if (sect->name)
free(sect->name);
sect->magic = 0;
free(sect);
}
/*
* This routine creates a profile_section from its parent. If the
* parent is NULL, then a top-level profile section is created.
*
* Top-level profile sections are different from normal
* profile_sections in that top-level sections are agregated across
* multiple files, where as subsections are not.
*/
errcode_t profile_get_subsection(profile, parent, name, ret_name,
ret_section)
profile_t profile;
profile_section_t parent;
const char * name;
char ** ret_name;
profile_section_t *ret_section;
{
profile_section_t section;
prf_file_t file;
errcode_t retval;
section = malloc(sizeof(struct _profile_section_t));
if (section == 0)
return ENOMEM;
memset(section, 0, sizeof(struct _profile_section_t));
section->magic = PROF_MAGIC_SECTION;
section->name = malloc(strlen(name)+1);
if (section->name == 0) {
free(section);
return ENOMEM;
}
strcpy(section->name, name);
section->file_ptr = file = profile->first_file;
section->profile = profile;
if (parent == 0) {
/*
* If parent is NULL, then we are creating a
* top-level section which hangs off the root.
*
* We make sure that the section exists in least one
* file.
*/
section->top_lvl = 1;
if (name == 0)
return PROF_TOPSECTION_ITER_NOSUPP;
while (file) {
retval = profile_find_node_subsection(file->root,
name, §ion->state,
ret_name, §ion->sect);
file = file->next;
if (retval == 0)
break;
if (retval == PROF_NO_SECTION)
continue;
profile_free_section(section);
return retval;
}
if (section->sect == 0 && file == 0) {
profile_free_section(section);
return PROF_NO_SECTION;
}
*ret_section = section;
return 0;
}
section->top_lvl = 0;
if (parent->top_lvl) {
section->top_lvl_search = 1;
} else {
section->top_lvl_search = 0;
if (parent->sect == 0) {
profile_free_section(section);
return PROF_INVALID_SECTION;
}
section->parent = parent->sect;
retval = profile_find_node_subsection(parent->sect,
name, §ion->state, ret_name, §ion->sect);
if (retval) {
profile_free_section(section);
return retval;
}
}
*ret_section = section;
return 0;
}
errcode_t profile_next_section(section, ret_name)
profile_section_t section;
char **ret_name;
{
prf_file_t file;
errcode_t retval;
if (section->top_lvl)
return PROF_END_OF_SECTIONS;
else {
if (section->sect == 0)
return PROF_INVALID_SECTION;
retval = profile_find_node_subsection(section->parent,
section->name, §ion->state, ret_name, §ion->sect);
if (retval == PROF_NO_SECTION)
retval = PROF_END_OF_SECTIONS;
return retval;
}
}
errcode_t profile_get_relation(section, name, ret_values)
profile_section_t section;
const char *name;
char ***ret_values;
{
prf_file_t file;
char **values;
int num_values;
int max_values;
char *value;
errcode_t retval;
max_values = 10;
values = malloc(sizeof(char *) * max_values);
if (section->top_lvl) {
for (file = section->profile->first_file; file;
file = file->next) {
retval = profile_find_node_relation(file->root,
section->name, §ion->state, 0, &value);
if (retval)
continue;
}
} else {
if (section->sect == 0)
return PROF_INVALID_SECTION;
}
return 0;
}
|