1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: gtload 06.10.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 extern
17 {
18 method gtitem gtitem.insertchild( str name, gtitem after )
19 }
20
21 method gtitem gtitem.load( str in, gtitem after )
22 {
23 uint i off start nameoff
24 arrout out
25 // lex ilex
26 // uint ilex
27 stack sgt
28 uint igt // The current gtitem
29 str attrib
30
31 // print( in )
32 out.isize = sizeof( lexitem )
33 if this.getgt().utf8 && !in.isprefutf8()
34 {
35 ustr utemp
36 utemp = in
37 utemp.toutf8( in )
38 }
39 // lex_tbl( ilex, lexgt.ptr())
40 //ifdef $DEBUG : print("Load 0\n")
41 // gentee_lex( in->buf, this.maingt->gt.lexgt, out )
42 gentee_lex( &in, this.maingt->gt.lexgt, &out )
43 //ifdef $DEBUG : print("Load 1\n")
44 start = in.ptr()
45 off = out.data.ptr()
46 igt as this
47
48 fornum i, *out
49 {
50 str stemp
51 uint li
52
53 li as off->lexitem
54 //ifdef $DEBUG
55 //{
56 // print("type=\( li.ltype ) pos = \(li.pos) len=\(li.len )\n")
57 //}
58 switch li.ltype
59 {
60 case $gt_BEGIN
61 {
62 nameoff = li.pos + 1
63 sgt.push( &igt )
64 if in[ nameoff ] == '|' : nameoff++
65 if in[ nameoff ] == '*' : nameoff++
66
67 stemp.copy( start + nameoff, li.len - nameoff + li.pos )
68 // print("\(stemp)\n")
69 igt as igt.insertchild( stemp, after )
70 attrib.clear()
71 }
72 case $gt_NAME
73 {
74 attrib.copy( start + li.pos, li.len )
75 igt.set( attrib, "" )
76 }
77 case $gt_STRATTR
78 {
79 stemp.copy( start + li.pos, li.len )
80 if *attrib : igt.set( attrib, stemp )
81 else : igt.value = stemp
82 }
83 case $gt_STRDQ, $gt_STRQ
84 {
85 stemp.copy( start + li.pos + 1, li.len - 2 )
86 if *attrib : igt.set( attrib, stemp )
87 else : igt.value = stemp
88 }
89 case $gt_DATA
90 {
91 igt.value.copy( start + li.pos, li.len )
92 igt.value.trimsys()
93 }
94 case $gt_COMMENT
95 {
96 uint comment
97
98 comment as igt.insertchild( "", after )
99 comment.comment = 1
100 comment.value.copy( start + li.pos + 2, li.len - 4 )
101 }
102 case $gt_END
103 {
104 igt as sgt.popval()->gtitem
105 }
106 }
107 off += sizeof( lexitem )
108 }
109 //ifdef $DEBUG : print("Load OK\n")
110 return this
111 }
112
113 method gtitem gtitem.load( str in )
114 {
115 return this.load( in, 0xFFFFFFFF->gtitem )
116 }
117
118 method uint gt.read( str filename )
119 {
120 str stemp
121
122 stemp.read( filename )
123 this.root().load( stemp )
124 return *stemp != 0
125 }
126
127 method uint gtitem.read( str filename )
128 {
129 str stemp
130
131 stemp.read( filename )
132 this.load( stemp )
133 return *stemp != 0
134 }
Edit