~ubuntu-branches/ubuntu/wily/octave-miscellaneous/wily

« back to all changes in this revision

Viewing changes to src/xmltree_read.act

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Sébastien Villemot, Rafael Laboissiere
  • Date: 2012-04-02 13:20:23 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120402132023-t41xaso7sl5cex90
Tags: 1.1.0-1
[ Sébastien Villemot ]
* Imported Upstream version 1.1.0
* debian/patches/match-cell-array.patch: remove patch (applied upstream)
* debian/patches/waitbar-rename.patch: remove patch (applied upstream)
* debian/patches/no-flexml.patch: remove obsolete patch, flex no longer used
  (Closes: #666294)
* debian/copyright: reflect upstream changes
* debian/octave-miscellaneous.docs: remove, no more docs in the package
* debian/clean: remove obsolete file
* debian/rules: remove hack for wrong permissions in upstream tarball

[ Rafael Laboissiere ]
* debian/watch: Use the SourceForge redirector

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!-- -*- XML -*- -->
2
 
<!--
3
 
  -- Copyright (C) 2004 Laurent Mazet
4
 
  --
5
 
  -- This program is free software; you can redistribute it and/or modify
6
 
  -- it under the terms of the GNU General Public License as published by
7
 
  -- the Free Software Foundation; either version 2 of the License, or
8
 
  -- (at your option) any later version.
9
 
  --
10
 
  -- This program is distributed in the hope that it will be useful,
11
 
  -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
  -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
  -- GNU General Public License for more details.
14
 
  --
15
 
  -- You should have received a copy of the GNU General Public License
16
 
  -- along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 
  -->
18
 
 
19
 
<!-- 2004-01-25
20
 
  --   initial release
21
 
  -->
22
 
 
23
 
<!DOCTYPE actions SYSTEM "flexml-act.dtd">
24
 
 
25
 
<actions>
26
 
 
27
 
<!-- Top -->
28
 
 
29
 
<top><![CDATA[
30
 
#ifndef _MSC_VER
31
 
#include <stdlib.h>
32
 
#endif
33
 
#include "xmltree.h"
34
 
 
35
 
#define warning perror
36
 
 
37
 
element **current;
38
 
element *root;
39
 
list *lastlist;
40
 
]]></top>
41
 
 
42
 
<!-- Data -->
43
 
 
44
 
<start tag='octave'><![CDATA[
45
 
root = new_element();
46
 
root->def_value = value_data;
47
 
current = &(root->child);
48
 
 
49
 
lastlist = new_list(lastlist);
50
 
lastlist->root = current;
51
 
]]></start>
52
 
 
53
 
<end tag='octave'><![CDATA[
54
 
current = lastlist->root;
55
 
lastlist = pop_list(lastlist);
56
 
current = &((*current)->next);
57
 
]]></end>
58
 
 
59
 
<!-- Scalar -->
60
 
 
61
 
<start tag='scalar'><![CDATA[
62
 
*current = new_element();
63
 
 
64
 
if ({name}) {
65
 
  (*current)->name = (char *) malloc(strlen({name})+1);
66
 
  strcpy ((*current)->name, {name});
67
 
}
68
 
 
69
 
(*current)->def_value = value_scalar;
70
 
switch ({value}) {
71
 
  case {value=true}: (*current)->const_value = const_true; break;
72
 
  case {value=false}: (*current)->const_value = const_false; break;
73
 
  case {value=inf}: (*current)->const_value = const_inf; break;
74
 
  case {value=neginf}: (*current)->const_value = const_neginf; break;
75
 
  case {value=nan}: (*current)->const_value = const_nan; break;
76
 
  case {value=na}: (*current)->const_value = const_na; break;
77
 
  default: (*current)->const_value = const_undef;
78
 
}
79
 
]]></start>
80
 
 
81
 
<end tag='scalar'><![CDATA[
82
 
if (((*current)->const_value == const_undef) && ({#PCDATA}))
83
 
  (*current)->scalar_value = strtod ({#PCDATA}, NULL);
84
 
 
85
 
(*(lastlist->root))->nb_elements++;
86
 
 
87
 
current = &((*current)->next);
88
 
]]></end>
89
 
 
90
 
<!-- String -->
91
 
 
92
 
<start tag='string'><![CDATA[
93
 
*current = new_element();
94
 
 
95
 
if ({name}) {
96
 
  (*current)->name = (char *) malloc(strlen({name})+1);
97
 
  strcpy ((*current)->name, {name});
98
 
}
99
 
 
100
 
if ({length})
101
 
  (*current)->length = strtol ({length}, NULL, 10);
102
 
 
103
 
(*current)->def_value = value_string;
104
 
]]></start>
105
 
 
106
 
<end tag='string'><![CDATA[
107
 
if ({#PCDATA}) {
108
 
 
109
 
  int len = strlen({#PCDATA});
110
 
  /* check length parameter */
111
 
  if ((*current)->length != len) {
112
 
    warning("incorrect length parameter for string\n");
113
 
    (*current)->length = len;
114
 
  }
115
 
 
116
 
  (*current)->string_value = (char *) malloc ((len+1) * sizeof(char));
117
 
  strcpy((*current)->string_value, {#PCDATA});
118
 
}
119
 
 
120
 
(*(lastlist->root))->nb_elements++;
121
 
 
122
 
current = &((*current)->next);
123
 
]]></end>
124
 
 
125
 
<!-- Complex -->
126
 
 
127
 
<start tag='complex'><![CDATA[
128
 
*current = new_element();
129
 
 
130
 
if ({name}) {
131
 
  (*current)->name = (char *) malloc(strlen({name})+1);
132
 
  strcpy ((*current)->name, {name});
133
 
}
134
 
 
135
 
(*current)->def_value = value_complex;
136
 
 
137
 
lastlist = new_list(lastlist);
138
 
lastlist->root = current;
139
 
current = &((*current)->child);
140
 
]]></start>
141
 
 
142
 
<end tag='complex'><![CDATA[
143
 
current = lastlist->root;
144
 
lastlist = pop_list(lastlist);
145
 
 
146
 
(*(lastlist->root))->nb_elements++;
147
 
 
148
 
current = &((*current)->next);
149
 
]]></end>
150
 
 
151
 
<!-- Array -->
152
 
 
153
 
<start tag='array'><![CDATA[
154
 
*current = new_element();
155
 
 
156
 
if ({name}) {
157
 
  (*current)->name = (char *) malloc(strlen({name})+1);
158
 
  strcpy ((*current)->name, {name});
159
 
}
160
 
 
161
 
if ({rows})
162
 
  (*current)->rows = strtol ({rows}, NULL, 10);
163
 
 
164
 
(*current)->def_value = value_array;
165
 
 
166
 
lastlist = new_list(lastlist);
167
 
lastlist->root = current;
168
 
current = &((*current)->child);
169
 
]]></start>
170
 
 
171
 
<end tag='array'><![CDATA[
172
 
/* check rows parameter */
173
 
if ((*(lastlist->root))->rows != (*(lastlist->root))->nb_elements) {
174
 
  warning("incorrect length parameter for array\n");
175
 
  (*(lastlist->root))->rows = (*(lastlist->root))->nb_elements;
176
 
}
177
 
 
178
 
current = lastlist->root;
179
 
lastlist = pop_list(lastlist);
180
 
 
181
 
(*(lastlist->root))->nb_elements++;
182
 
 
183
 
current = &((*current)->next);
184
 
]]></end>
185
 
 
186
 
<!-- Matrix -->
187
 
 
188
 
<start tag='matrix'><![CDATA[
189
 
*current = new_element();
190
 
 
191
 
if ({name}) {
192
 
  (*current)->name = (char *) malloc(strlen({name})+1);
193
 
  strcpy ((*current)->name, {name});
194
 
}
195
 
 
196
 
if ({rows})
197
 
  (*current)->rows = strtol ({rows}, NULL, 10);
198
 
 
199
 
if ({columns})
200
 
  (*current)->columns = strtol ({columns}, NULL, 10);
201
 
 
202
 
(*current)->def_value = value_matrix;
203
 
 
204
 
lastlist = new_list(lastlist);
205
 
lastlist->root = current;
206
 
current = &((*current)->child);
207
 
]]></start>
208
 
 
209
 
<end tag='matrix'><![CDATA[
210
 
/* check (rows, columns) parameters */
211
 
if ((*(lastlist->root))->rows * (*(lastlist->root))->columns != 
212
 
    (*(lastlist->root))->nb_elements) {
213
 
  warning("incorrect (rows, columns) parameters for matrix: reshaping matrix into vector\n");
214
 
  (*(lastlist->root))->rows = 1;
215
 
  (*(lastlist->root))->columns = (*(lastlist->root))->nb_elements;  
216
 
}
217
 
 
218
 
current = lastlist->root;
219
 
lastlist = pop_list(lastlist);
220
 
 
221
 
(*(lastlist->root))->nb_elements++;
222
 
 
223
 
current = &((*current)->next);
224
 
]]></end>
225
 
 
226
 
<!-- Structure -->
227
 
 
228
 
<start tag='structure'><![CDATA[
229
 
*current = new_element();
230
 
 
231
 
if ({name}) {
232
 
  (*current)->name = (char *) malloc(strlen({name})+1);
233
 
  strcpy ((*current)->name, {name});
234
 
}
235
 
 
236
 
(*current)->def_value = value_structure;
237
 
 
238
 
lastlist = new_list(lastlist);
239
 
lastlist->root = current;
240
 
current = &((*current)->child);
241
 
]]></start>
242
 
 
243
 
<end tag='structure'><![CDATA[
244
 
/* no check possible (sic) */
245
 
 
246
 
current = lastlist->root;
247
 
lastlist = pop_list(lastlist);
248
 
 
249
 
(*(lastlist->root))->nb_elements++;
250
 
 
251
 
current = &((*current)->next);
252
 
]]></end>
253
 
 
254
 
<!-- List -->
255
 
 
256
 
<start tag='list'><![CDATA[
257
 
*current = new_element();
258
 
 
259
 
if ({name}) {
260
 
  (*current)->name = (char *) malloc(strlen({name})+1);
261
 
  strcpy ((*current)->name, {name});
262
 
}
263
 
 
264
 
if ({length})
265
 
  (*current)->length = strtol ({length}, NULL, 10);
266
 
 
267
 
(*current)->def_value = value_list;
268
 
 
269
 
lastlist = new_list(lastlist);
270
 
lastlist->root = current;
271
 
current = &((*current)->child);
272
 
]]></start>
273
 
 
274
 
<end tag='list'><![CDATA[
275
 
/* check length parameter */
276
 
if ((*(lastlist->root))->length != (*(lastlist->root))->nb_elements) {
277
 
  warning("incorrect length parameter for list\n");
278
 
  (*(lastlist->root))->length = (*(lastlist->root))->nb_elements;
279
 
}
280
 
 
281
 
current = lastlist->root;
282
 
lastlist = pop_list(lastlist);
283
 
 
284
 
(*(lastlist->root))->nb_elements++;
285
 
 
286
 
current = &((*current)->next);
287
 
]]></end>
288
 
 
289
 
<!-- Cell -->
290
 
 
291
 
<start tag='cell'><![CDATA[
292
 
*current = new_element();
293
 
 
294
 
if ({name}) {
295
 
  (*current)->name = (char *) malloc(strlen({name})+1);
296
 
  strcpy ((*current)->name, {name});
297
 
}
298
 
 
299
 
if ({rows})
300
 
  (*current)->rows = strtol ({rows}, NULL, 10);
301
 
 
302
 
if ({columns})
303
 
  (*current)->columns = strtol ({columns}, NULL, 10);
304
 
 
305
 
(*current)->def_value = value_cell;
306
 
 
307
 
lastlist = new_list(lastlist);
308
 
lastlist->root = current;
309
 
current = &((*current)->child);
310
 
]]></start>
311
 
 
312
 
<end tag='cell'><![CDATA[
313
 
/* check (rows, columns) parameters */
314
 
if ((*(lastlist->root))->rows * (*(lastlist->root))->columns != 
315
 
    (*(lastlist->root))->nb_elements) {
316
 
  warning("incorrect (rows, columns) parameters for cell: reshaping cell into list\n");
317
 
  (*(lastlist->root))->def_value = value_list;
318
 
  (*(lastlist->root))->length = (*(lastlist->root))->nb_elements;  
319
 
}
320
 
 
321
 
current = lastlist->root;
322
 
lastlist = pop_list(lastlist);
323
 
 
324
 
(*(lastlist->root))->nb_elements++;
325
 
 
326
 
current = &((*current)->next);
327
 
]]></end>
328
 
 
329
 
<!-- Main -->
330
 
 
331
 
<main>
332
 
element *read_xmltree (const char *file) {
333
 
 
334
 
  current = NULL;
335
 
  root = NULL;
336
 
  lastlist = NULL;
337
 
 
338
 
  xml_in = fopen(file, "r");
339
 
  if (!xml_in)
340
 
    perror("can't open file\n");
341
 
 
342
 
  xml_lex();
343
 
  fclose(xml_in);
344
 
  
345
 
  return root;
346
 
}
347
 
</main>
348
 
 
349
 
</actions>