summaryrefslogtreecommitdiff
path: root/src/stable/tafreader.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/stable/tafreader.cpp
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/tafreader.cpp')
-rw-r--r--src/stable/tafreader.cpp326
1 files changed, 163 insertions, 163 deletions
diff --git a/src/stable/tafreader.cpp b/src/stable/tafreader.cpp
index fb17aea..f21505e 100644
--- a/src/stable/tafreader.cpp
+++ b/src/stable/tafreader.cpp
@@ -14,12 +14,12 @@
14using namespace Bu; 14using namespace Bu;
15 15
16Bu::TafReader::TafReader( Bu::Stream &sIn ) : 16Bu::TafReader::TafReader( Bu::Stream &sIn ) :
17 c( 0 ), 17 c( 0 ),
18 la( 0 ), 18 la( 0 ),
19 sIn( sIn ), 19 sIn( sIn ),
20 iLine( 1 ), iCol( -1 ) 20 iLine( 1 ), iCol( -1 )
21{ 21{
22 next(); next(); 22 next(); next();
23} 23}
24 24
25Bu::TafReader::~TafReader() 25Bu::TafReader::~TafReader()
@@ -29,122 +29,122 @@ Bu::TafReader::~TafReader()
29 29
30Bu::TafGroup *Bu::TafReader::readGroup() 30Bu::TafGroup *Bu::TafReader::readGroup()
31{ 31{
32 ws(); 32 ws();
33 if( c != '{' ) 33 if( c != '{' )
34 throw TafException("%d:%d: Expected '{' got '%c'.", iLine, iCol, c ); 34 throw TafException("%d:%d: Expected '{' got '%c'.", iLine, iCol, c );
35 next(); 35 next();
36 ws(); 36 ws();
37 String sName = readStr(); 37 String sName = readStr();
38 TafGroup *pGroup = new TafGroup( sName ); 38 TafGroup *pGroup = new TafGroup( sName );
39 try 39 try
40 { 40 {
41 ws(); 41 ws();
42 if( c != ':' ) 42 if( c != ':' )
43 throw TafException("%d:%d: Expected ':' got '%c'.", 43 throw TafException("%d:%d: Expected ':' got '%c'.",
44 iLine, iCol, c ); 44 iLine, iCol, c );
45 next(); 45 next();
46 //printf("Node[%s]:\n", sName.getStr() ); 46 //printf("Node[%s]:\n", sName.getStr() );
47 47
48 groupContent( pGroup ); 48 groupContent( pGroup );
49 49
50 if( c != '}' ) 50 if( c != '}' )
51 throw TafException("%d:%d: Expected '}' got '%c'.", 51 throw TafException("%d:%d: Expected '}' got '%c'.",
52 iLine, iCol, c ); 52 iLine, iCol, c );
53 53
54 //next(); 54 //next();
55 55
56 return pGroup; 56 return pGroup;
57 } 57 }
58 catch(...) 58 catch(...)
59 { 59 {
60 delete pGroup; 60 delete pGroup;
61 throw; 61 throw;
62 } 62 }
63} 63}
64 64
65void Bu::TafReader::groupContent( Bu::TafGroup *pGroup ) 65void Bu::TafReader::groupContent( Bu::TafGroup *pGroup )
66{ 66{
67 for(;;) 67 for(;;)
68 { 68 {
69 ws(); 69 ws();
70 if( c == '{' ) 70 if( c == '{' )
71 { 71 {
72 pGroup->addChild( readGroup() ); 72 pGroup->addChild( readGroup() );
73 next(); 73 next();
74 } 74 }
75 else if( c == '}' ) 75 else if( c == '}' )
76 return; 76 return;
77 else if( c == '/' && la == '*' ) 77 else if( c == '/' && la == '*' )
78 pGroup->addChild( readComment() ); 78 pGroup->addChild( readComment() );
79 else if( c == '/' && la == '/' ) 79 else if( c == '/' && la == '/' )
80 pGroup->addChild( readComment( true ) ); 80 pGroup->addChild( readComment( true ) );
81 else if( c == ':' ) 81 else if( c == ':' )
82 throw TafException("%d:%d: Encountered stray ':' in taf stream.", 82 throw TafException("%d:%d: Encountered stray ':' in taf stream.",
83 iLine, iCol ); 83 iLine, iCol );
84 else 84 else
85 pGroup->addChild( readProperty() ); 85 pGroup->addChild( readProperty() );
86 } 86 }
87} 87}
88 88
89Bu::TafProperty *Bu::TafReader::readProperty() 89Bu::TafProperty *Bu::TafReader::readProperty()
90{ 90{
91 String sName = readStr(); 91 String sName = readStr();
92 ws(); 92 ws();
93 if( c != '=' ) 93 if( c != '=' )
94 { 94 {
95 //printf(" %s (true)\n", sName.getStr() ); 95 //printf(" %s (true)\n", sName.getStr() );
96 return new Bu::TafProperty( "", sName ); 96 return new Bu::TafProperty( "", sName );
97 } 97 }
98 next(); 98 next();
99 String sValue = readStr(); 99 String sValue = readStr();
100 return new Bu::TafProperty( sName, sValue ); 100 return new Bu::TafProperty( sName, sValue );
101 //printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); 101 //printf(" %s = %s\n", sName.getStr(), sValue.getStr() );
102} 102}
103 103
104Bu::TafComment *Bu::TafReader::readComment( bool bEOL ) 104Bu::TafComment *Bu::TafReader::readComment( bool bEOL )
105{ 105{
106 String sCmnt; 106 String sCmnt;
107 next(); 107 next();
108 if( bEOL ) 108 if( bEOL )
109 { 109 {
110 for(;;) 110 for(;;)
111 { 111 {
112 next(); 112 next();
113 if( c == '\n' && la == '\r' ) 113 if( c == '\n' && la == '\r' )
114 { 114 {
115 next(); next(); 115 next(); next();
116 break; 116 break;
117 } 117 }
118 else if( c == '\n' || c == '\r' ) 118 else if( c == '\n' || c == '\r' )
119 { 119 {
120 next(); 120 next();
121 break; 121 break;
122 } 122 }
123 sCmnt += c; 123 sCmnt += c;
124 } 124 }
125 } 125 }
126 else 126 else
127 { 127 {
128 for(;;) 128 for(;;)
129 { 129 {
130 next(); 130 next();
131 if( c == '*' && la == '/' ) 131 if( c == '*' && la == '/' )
132 { 132 {
133 next(); next(); 133 next(); next();
134 break; 134 break;
135 } 135 }
136 sCmnt += c; 136 sCmnt += c;
137 } 137 }
138 } 138 }
139 139
140 return new TafComment( sCmnt, bEOL ); 140 return new TafComment( sCmnt, bEOL );
141} 141}
142 142
143Bu::String Bu::TafReader::readStr() 143Bu::String Bu::TafReader::readStr()
144{ 144{
145 ws(); 145 ws();
146 String s; 146 String s;
147 if( c == '"' ) 147 if( c == '"' )
148 { 148 {
149 next(); 149 next();
150 for(;;) 150 for(;;)
@@ -162,7 +162,7 @@ Bu::String Bu::TafReader::readStr()
162 c = (unsigned char)strtol( code, NULL, 16 ); 162 c = (unsigned char)strtol( code, NULL, 16 );
163 } 163 }
164 else if( c == '"' ) 164 else if( c == '"' )
165 c = '"'; 165 c = '"';
166 else if( c == '\\' ) 166 else if( c == '\\' )
167 c = '\\'; 167 c = '\\';
168 else if( c == 'n' ) 168 else if( c == 'n' )
@@ -174,79 +174,79 @@ Bu::String Bu::TafReader::readStr()
174 iLine, iCol, c ); 174 iLine, iCol, c );
175 } 175 }
176 else if( c == '"' ) 176 else if( c == '"' )
177 break; 177 break;
178 s += c; 178 s += c;
179 next(); 179 next();
180 } 180 }
181 next(); 181 next();
182 } 182 }
183 else 183 else
184 { 184 {
185 for(;;) 185 for(;;)
186 { 186 {
187 if( isws() || c == '}' || c == '{' || c == ':' || c == '=' ) 187 if( isws() || c == '}' || c == '{' || c == ':' || c == '=' )
188 break; 188 break;
189 s += c; 189 s += c;
190 next(); 190 next();
191 } 191 }
192 } 192 }
193 193
194 return s; 194 return s;
195} 195}
196 196
197void Bu::TafReader::ws() 197void Bu::TafReader::ws()
198{ 198{
199 for(;;) 199 for(;;)
200 { 200 {
201 if( !isws() ) 201 if( !isws() )
202 return; 202 return;
203 203
204 next(); 204 next();
205 } 205 }
206} 206}
207 207
208bool Bu::TafReader::isws() 208bool Bu::TafReader::isws()
209{ 209{
210 return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); 210 return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
211} 211}
212 212
213void Bu::TafReader::next() 213void Bu::TafReader::next()
214{ 214{
215 if( c == '\n' ) 215 if( c == '\n' )
216 { 216 {
217 iLine++; 217 iLine++;
218 iCol = 1; 218 iCol = 1;
219 } 219 }
220 else 220 else
221 iCol++; 221 iCol++;
222 if( c == '}' ) 222 if( c == '}' )
223 { 223 {
224 rawread( &c ); 224 rawread( &c );
225 if( c != '}' ) 225 if( c != '}' )
226 rawread( &la ); 226 rawread( &la );
227 } 227 }
228 else 228 else
229 { 229 {
230 c = la; 230 c = la;
231 if( c != '}' ) 231 if( c != '}' )
232 rawread( &la ); 232 rawread( &la );
233 } 233 }
234} 234}
235 235
236void Bu::TafReader::rawread( char *c ) 236void Bu::TafReader::rawread( char *c )
237{ 237{
238 if( sIn.read( c, 1 ) < 1 ) 238 if( sIn.read( c, 1 ) < 1 )
239 { 239 {
240 if( sIn.isEos() ) 240 if( sIn.isEos() )
241 { 241 {
242 throw TafException("%d:%d: Premature end of stream.", 242 throw TafException("%d:%d: Premature end of stream.",
243 iLine, iCol, c ); 243 iLine, iCol, c );
244 } 244 }
245 else 245 else
246 { 246 {
247 throw TafException("%d:%d: No data read, but not end of stream?", 247 throw TafException("%d:%d: No data read, but not end of stream?",
248 iLine, iCol, c ); 248 iLine, iCol, c );
249 } 249 }
250 } 250 }
251} 251}
252 252