File: builders.pike

package info (click to toggle)
roxen 1.2beta2-3
  • links: PTS
  • area: contrib
  • in suites: slink
  • size: 16,920 kB
  • ctags: 8,589
  • sloc: ansic: 89,632; asm: 8,431; sh: 2,915; makefile: 1,784; cpp: 377
file content (300 lines) | stat: -rw-r--r-- 6,457 bytes parent folder | download | duplicates (4)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/* $Id: builders.pike,v 1.15 1998/03/05 03:15:39 mast Exp $ */

#include <module.h>
#include <confignode.h>
inherit "describers";
inherit "savers";

import Array;

/*#define CONFIG_DEBUG*/

import Array;

void low_build_variables(object node, mapping from)
{
  array m;
  object o;
  int i;

#ifdef CONFIG_DEBUG
  perror("low_build_variables()\n");
#endif

  m = values(from);
  sort(column(m,VAR_NAME),m);
  
  for(i=0; i<sizeof(m); i++)
  {
    if(m[i][VAR_TYPE] == TYPE_NODE)
    {
      o=node->descend(m[i][VAR_NAME]);
      o->type = NODE_MODULE_COPY_VARIABLES;
      o->data = m[i];
      o->changed = 0;
      o->folded = 1;
      o->describer = describe_module_subnode;
      low_build_variables(o,o->data[VAR_VALUE]->query());
    } else
      if(m[i][VAR_NAME] && m[i][VAR_CONFIGURABLE])
      {  
	string base, name;
	if(m[i][VAR_SHORTNAME][0] == '_')
	{
	  o=node->descend("Builtins")->descend(m[i][VAR_SHORTNAME]);
	  o->changed = 0;
	  o->folded = 1;
	}
	else if(sscanf(m[i][VAR_NAME], "%s:%s", base, name) == 2)
	{
	  sscanf(name, "%*[\t ]%s", name);
	  o=node->descend(base);
	  o->describer = describe_holder;
	  o->data = base;
	  o->changed = 0;
	  o->folded = 1;
	  o=o->descend(name);
	  o->changed = 0;
	  o->folded = 1;
	} else {
	  o=node->descend(m[i][VAR_SHORTNAME]);
	  o->changed = 0;
	  o->folded = 1;
	}
	o->type = NODE_MODULE_COPY_VARIABLE;
	o->saver = save_module_variable;
	o->changed = 0;
	o->folded = 1;
	o->data = m[i];
	o->describer = describe_module_variable;
      }
  }
  if(o=node->descend("Builtins", 1))
  {
    o->describer = describe_builtin_variables;
    o->changed = 0;
    o->folded = 1;
    o->data = 0;
    o->type = NODE_MODULE_COPY_BUILTIN_VARIABLES;
  }
}

void build_module_copy_variables(object node)
{
#ifdef CONFIG_DEBUG
  perror("build_module_copy_variables()\n");
#endif
  node->changed = 0;
  node->folded = 1;
  low_build_variables(node, node->data->query());
}

void build_module_master_copy_variables(object node)
{
#ifdef CONFIG_DEBUG
  perror("build_module_master_copy_variables("+node->data->name+")\n");
#endif
  low_build_variables(node, node->data->master->query());
}

void build_module_copy_status(object node)
{
#ifdef CONFIG_DEBUG
  perror("build_module_copy_status()\n");
#endif
}

void build_module_copy(object node)
{
  string res;
  object o;

#ifdef CONFIG_DEBUG
  perror("build_module_copy()\n");
#endif
  o=node->descend("Status");
  o->type = NODE_MODULE_COPY_STATUS;
  o->data = node->data->status;
  o->changed = 0;
  o->folded = 1;

  o->describer = describe_module_copy_status;
  build_module_copy_status(o);
  build_module_copy_variables(node);
}

void build_module(object node)
{
  string res;
  int t;
  mixed copies, mod;
  object o, c;

  if(!node->data->master && !node->data->copies) return;
  
  mod = node->data;
  copies = node->data->copies;

#ifdef CONFIG_DEBUG
  perror("build_module ("+mod->name+")\n");
#endif

  if(copies)
  {
    foreach(indices(copies), t)
    {
      o=node->descend((string)t);
      o->describer = describe_module_copy;
      o->saver = save_module_copy;
      o->changed = 0;
      o->folded = 1;
      o->type = NODE_MODULE_COPY;
      o->data = copies[t];
      build_module_copy(o);
    }
  } else {
    o=node->descend("Status");
    o->type = NODE_MODULE_COPY_STATUS;
    o->data = node->data->master->status;
    o->describer = describe_module_copy_status;
    o->changed = 0;
    o->folded = 1;
    build_module_copy_status(o);

    node->type = NODE_MODULE_MASTER_COPY; 
    node->saver = save_module_master_copy;
    node->changed = 0;
    node->folded = 1;
    build_module_master_copy_variables(node);
  }
}

void build_global_variables(object node)
{
  node->saver = save_global_variables;
  low_build_variables(node, node->data);
}

void build_configuration(object node)
{
  object cf;
  string res;
  array (mapping) modules;
  int i;
  cf = node->data;
#ifdef CONFIG_DEBUG
  perror("build_configuration("+node->data->name+")\n");
#endif
  
  object o;
  
  modules = sort_array(values(node->data->modules),
		       lambda(mapping a, mapping b) {
    return a->name > b->name;
  });

  // Configuration global variables recide in the roxen "module"... :)

  o=node->descend("Status");
  o->type = NODE_MODULE_COPY_STATUS;
  o->data = cf->status;
  o->describer = describe_module_copy_status;
  build_module_copy_status( o );

  o=node->descend("Global");
/*  roxen->current_configuration = o->config();*/
  o->data = cf->query();
  o->describer = describe_configuration_global_variables;
  o->type = NODE_CONFIG_GLOBAL_VARIABLES;
  o->saver = save_configuration_global_variables;
  low_build_variables(o, o->data);

  o->folded = 1;
  o->changed = 0;

  for(i=0; i<sizeof(modules); i++)
  {
    o=node->descend((string)modules[i]->name);
    o->data = modules[i];
    o->describer = describe_module;
    o->type = NODE_MODULE;
    o->folded = 1;
    o->changed = 0;
    build_module(o);
  }
}

void build_configurations(object node)
{
  int i;
  object o;
  array configurations;

#ifdef CONFIG_DEBUG
  perror("build_configurations()\n");
#endif

  if(node->data)
    configurations=sort_array(node->data, lambda(object a, object b) {
      return a->name > b->name;
    });
  node->changed = 0;

  if(configurations)
    for(i=0; i<sizeof(configurations); i++)
    {
      if(objectp(configurations[i]))
      {
	o=node->descend(configurations[i]->name);
	o->data = configurations[i];
	o->describer = describe_configuration;
	o->type = NODE_CONFIGURATION;
	o->saver = save_configuration;
	o->changed = 0;
	o->folded = 1;
	build_configuration( o );
      }
    }
}

void build_root(object root, void|int nodes)
{
  object o;

#ifdef CONFIG_DEBUG
  perror("build_root()\n");
#endif

  root->describer = describe_root;
/*root->data = roxen->configurations;*/
  
  o=root->descend("Errors");
  if(!o->data)
  {
    o->describer = describe_errors;
    o->data = roxen->error_log;
    o->type = NODE_ERRORS;
  }

  if(!nodes)
  {
    o=root->descend("Globals");
    o->describer = describe_global_variables;
    o->data=roxen->variables;
    o->type = NODE_GLOBAL_VARIABLES;
    build_global_variables( o );

    o=root->descend("Actions");
    o->describer = describe_actions;
    o->data = 0;
    o->type = NODE_WIZARDS;
   
    o=root->descend("Configurations");
    o->describer = describe_configurations;
    o->data = roxen->configurations;
    o->type = NODE_CONFIGURATIONS;
    build_configurations( o );
  }
}