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 uint ilast = &after
30 str attrib
31
32 // print( in )
33 out.isize = sizeof( lexitem )
34 if this.getgt().utf8 && !in.isprefutf8()
35 {
36 ustr utemp
37 utemp = in
38 utemp.toutf8( in )
39 }
40 // lex_tbl( ilex, lexgt.ptr())
41 //ifdef $DEBUG : print("Load 0\n")
42 // gentee_lex( in->buf, this.maingt->gt.lexgt, out )
43 gentee_lex( &in, this.maingt->gt.lexgt, &out )
44 //ifdef $DEBUG : print("Load 1\n")
45 start = in.ptr()
46 off = out.data.ptr()
47 igt as this
48
49 fornum i, *out
50 {
51 str stemp
52 uint li
53
54 li as off->lexitem
55 //ifdef $DEBUG
56 //{
57 // print("type=\( li.ltype ) pos = \(li.pos) len=\(li.len )\n")
58 //}
59 switch li.ltype
60 {
61 case $gt_BEGIN
62 {
63 nameoff = li.pos + 1
64 sgt.push( &igt )
65 if in[ nameoff ] == '|' : nameoff++
66 if in[ nameoff ] == '*' : nameoff++
67
68 stemp.copy( start + nameoff, li.len - nameoff + li.pos )
69 // print("\(stemp)\n")
70 igt as igt.insertchild( stemp, ilast->gtitem )
71 if *sgt == 1 : ilast = &igt
72 attrib.clear()
73 }
74 case $gt_NAME
75 {
76 attrib.copy( start + li.pos, li.len )
77 igt.set( attrib, "" )
78 }
79 case $gt_STRATTR
80 {
81 stemp.copy( start + li.pos, li.len )
82 if *attrib : igt.set( attrib, stemp )
83 else : igt.value = stemp
84 }
85 case $gt_STRDQ, $gt_STRQ
86 {
87 stemp.copy( start + li.pos + 1, li.len - 2 )
88 if *attrib : igt.set( attrib, stemp )
89 else : igt.value = stemp
90 }
91 case $gt_DATA
92 {
93 igt.value.copy( start + li.pos, li.len )
94 igt.value.trimsys()
95 uint off
96 while ( off = igt.value.findchfrom( '&', off )) < *igt.value
97 {
98 if "&x3c;".eqlenign( igt.value.ptr() + off )
99 {
100 igt.value.replace( off, 5, "<")
101 }
102 off++
103 }
104 // igt.value.replace( "&x3c;", "<", $QS_IGNCASE )
105 }
106 case $gt_COMMENT
107 {
108 uint comment
109
110 comment as igt.insertchild( "", ilast->gtitem )
111 ilast = &igt
112 comment.comment = 1
113 comment.value.copy( start + li.pos + 2, li.len - 4 )
114 }
115 case $gt_END
116 {
117 igt as sgt.popval()->gtitem
118 }
119 }
120 off += sizeof( lexitem )
121 }
122 //ifdef $DEBUG : print("Load OK\n")
123 return ?( ilast, ilast->gtitem, this )
124 }
125
126 method gtitem gtitem.load( str in )
127 {
128 return this.load( in, 0xFFFFFFFF->gtitem )
129 }
130
131 method uint gt.read( str filename )
132 {
133 str stemp
134
135 stemp.read( filename )
136 this.root().load( stemp )
137 return *stemp != 0
138 }
139
140 method uint gtitem.read( str filename )
141 {
142 str stemp
143
144 stemp.read( filename )
145 this.load( stemp )
146 return *stemp != 0
147 }
148
Редактировать