Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
gml_parser.cpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file gml_parser.cpp
1
/* This software is distributed under the GNU Lesser General Public License */
2
//==========================================================================
3
//
4
// gml_parser.cpp - parser for the GML-file-format specified in:
5
// Michael Himsolt, GML: Graph Modelling Language,
6
// 21.01.1997
7
//
8
//==========================================================================
9
// $Id: gml_parser.cpp,v 1.9 2001/11/07 13:58:10 pick Exp $
10
11
#include <
GTL/gml_parser.h
>
12
13
#include <cstdio>
14
#include <cstdlib>
15
#include <cassert>
16
#include <string.h>
17
18
#ifdef __GTL_MSVCC
19
# ifdef _DEBUG
20
# ifndef SEARCH_MEMORY_LEAKS_ENABLED
21
# error SEARCH NOT ENABLED
22
# endif
23
# define new DEBUG_NEW
24
# undef THIS_FILE
25
static
char
THIS_FILE[] = __FILE__;
26
# endif // _DEBUG
27
#endif // __GTL_MSVCC
28
29
__GTL_BEGIN_NAMESPACE
30
31
struct
GML_pair
*
GML_parser
(FILE*
source
,
struct
GML_stat
* stat,
int
open
) {
32
33
struct
GML_token
token;
34
struct
GML_pair
* pair;
35
struct
GML_pair
* list;
36
struct
GML_pair
*
tmp
= NULL;
37
struct
GML_list_elem
* tmp_elem;
38
39
assert
(stat);
40
41
pair = (
struct
GML_pair
*) malloc (
sizeof
(
struct
GML_pair
));
42
pair->
next
= NULL;
43
list = pair;
44
45
for
(;;) {
46
token =
GML_scanner
(source);
47
48
if
(token.
kind
==
GML_END
) {
49
if
(open) {
50
stat->
err
.
err_num
=
GML_OPEN_BRACKET
;
51
stat->
err
.
line
=
GML_line
;
52
stat->
err
.
column
=
GML_column
;
53
free (pair);
54
55
if
(tmp == NULL) {
56
return
NULL;
57
}
else
{
58
tmp->
next
= NULL;
59
return
list;
60
}
61
}
62
63
break
;
64
65
}
else
if
(token.
kind
==
GML_R_BRACKET
) {
66
if
(!open) {
67
stat->
err
.
err_num
=
GML_TOO_MANY_BRACKETS
;
68
stat->
err
.
line
=
GML_line
;
69
stat->
err
.
column
=
GML_column
;
70
free (pair);
71
72
if
(tmp == NULL) {
73
return
NULL;
74
}
else
{
75
tmp->
next
= NULL;
76
return
list;
77
}
78
}
79
80
break
;
81
82
}
else
if
(token.
kind
==
GML_ERROR
) {
83
stat->
err
.
err_num
= token.
value
.
err
.
err_num
;
84
stat->
err
.
line
= token.
value
.
err
.
line
;
85
stat->
err
.
column
= token.
value
.
err
.
column
;
86
free (pair);
87
88
if
(tmp == NULL) {
89
return
NULL;
90
}
else
{
91
tmp->
next
= NULL;
92
return
list;
93
}
94
95
}
else
if
(token.
kind
!=
GML_KEY
) {
96
stat->
err
.
err_num
=
GML_SYNTAX
;
97
stat->
err
.
line
=
GML_line
;
98
stat->
err
.
column
=
GML_column
;
99
free (pair);
100
101
if
(token.
kind
==
GML_STRING
) {
102
free (token.
value
.
str
);
103
}
104
105
if
(tmp == NULL) {
106
return
NULL;
107
}
else
{
108
tmp->
next
= NULL;
109
return
list;
110
}
111
}
112
113
if
(!stat->
key_list
) {
114
stat->
key_list
= (
struct
GML_list_elem
*)
115
malloc (
sizeof
(
struct
GML_list_elem
));
116
stat->
key_list
->
next
= NULL;
117
stat->
key_list
->
key
= token.
value
.
str
;
118
pair->
key
= token.
value
.
str
;
119
120
}
else
{
121
tmp_elem = stat->
key_list
;
122
123
while
(tmp_elem) {
124
if
(!strcmp (tmp_elem->
key
, token.
value
.
str
)) {
125
free (token.
value
.
str
);
126
pair->
key
= tmp_elem->
key
;
127
break
;
128
}
129
130
tmp_elem = tmp_elem->
next
;
131
}
132
133
if
(!tmp_elem) {
134
tmp_elem = (
struct
GML_list_elem
*)
135
malloc (
sizeof
(
struct
GML_list_elem
));
136
tmp_elem->
next
= stat->
key_list
;
137
stat->
key_list
= tmp_elem;
138
tmp_elem->
key
= token.
value
.
str
;
139
pair->
key
= token.
value
.
str
;
140
}
141
}
142
143
token =
GML_scanner
(source);
144
145
switch
(token.
kind
) {
146
case
GML_INT
:
147
pair->
kind
=
GML_INT
;
148
pair->
value
.
integer
= token.
value
.
integer
;
149
break
;
150
151
case
GML_DOUBLE
:
152
pair->
kind
=
GML_DOUBLE
;
153
pair->
value
.
floating
= token.
value
.
floating
;
154
break
;
155
156
case
GML_STRING
:
157
pair->
kind
=
GML_STRING
;
158
pair->
value
.
str
= token.
value
.
str
;
159
break
;
160
161
case
GML_L_BRACKET
:
162
pair->
kind
=
GML_LIST
;
163
pair->
value
.
list
=
GML_parser
(source, stat, 1);
164
165
if
(stat->
err
.
err_num
!=
GML_OK
) {
166
return
list;
167
}
168
169
break
;
170
171
case
GML_ERROR
:
172
stat->
err
.
err_num
= token.
value
.
err
.
err_num
;
173
stat->
err
.
line
= token.
value
.
err
.
line
;
174
stat->
err
.
column
= token.
value
.
err
.
column
;
175
free (pair);
176
177
if
(tmp == NULL) {
178
return
NULL;
179
}
else
{
180
tmp->
next
= NULL;
181
return
list;
182
}
183
184
default
:
185
stat->
err
.
line
=
GML_line
;
186
stat->
err
.
column
=
GML_column
;
187
stat->
err
.
err_num
=
GML_SYNTAX
;
188
free (pair);
189
190
if
(tmp == NULL) {
191
return
NULL;
192
}
else
{
193
tmp->
next
= NULL;
194
return
list;
195
}
196
}
197
198
tmp = pair;
199
pair = (
struct
GML_pair
*) malloc (
sizeof
(
struct
GML_pair
));
200
tmp->
next
= pair;
201
pair->
next
= NULL;
202
}
203
204
stat->
err
.
err_num
=
GML_OK
;
205
free (pair);
206
207
if
(tmp == NULL) {
208
return
NULL;
209
}
else
{
210
tmp->
next
= NULL;
211
return
list;
212
}
213
}
214
215
216
void
GML_free_list
(
struct
GML_pair
* list,
struct
GML_list_elem
* keys) {
217
218
struct
GML_pair
*
tmp
= list;
219
struct
GML_list_elem
* tmp_key;
220
221
while
(keys) {
222
free (keys->
key
);
223
tmp_key = keys->
next
;
224
free (keys);
225
keys = tmp_key;
226
}
227
228
while
(list) {
229
230
switch
(list->
kind
) {
231
case
GML_LIST
:
232
GML_free_list
(list->
value
.
list
, NULL);
233
break
;
234
235
case
GML_STRING
:
236
free (list->
value
.
str
);
237
break
;
238
239
default
:
240
break
;
241
}
242
243
tmp = list->
next
;
244
free (list);
245
list =
tmp
;
246
}
247
}
248
249
250
251
void
GML_print_list
(
struct
GML_pair
* list,
int
level
) {
252
253
struct
GML_pair
*
tmp
= list;
254
int
i
;
255
256
while
(tmp) {
257
258
for
(i = 0; i <
level
; i++) {
259
printf
(
" "
);
260
}
261
262
printf
(
"*KEY* : %s"
, tmp->
key
);
263
264
switch
(tmp->
kind
) {
265
case
GML_INT
:
266
printf
(
" *VALUE* (long) : %ld \n"
, tmp->
value
.
integer
);
267
break
;
268
269
case
GML_DOUBLE
:
270
printf
(
" *VALUE* (double) : %f \n"
, tmp->
value
.
floating
);
271
break
;
272
273
case
GML_STRING
:
274
printf
(
" *VALUE* (string) : %s \n"
, tmp->
value
.
str
);
275
break
;
276
277
case
GML_LIST
:
278
printf
(
" *VALUE* (list) : \n"
);
279
GML_print_list
(tmp->
value
.
list
, level+1);
280
break
;
281
282
default
:
283
break
;
284
}
285
286
tmp = tmp->
next
;
287
}
288
}
289
290
__GTL_END_NAMESPACE
291
292
//--------------------------------------------------------------------------
293
// end of file
294
//--------------------------------------------------------------------------
JETSCAPE
blob
main
external_packages
gtl
src
gml_parser.cpp
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:23
using
1.8.2 with
sPHENIX GitHub integration