Changeset 222b440
- Timestamp:
- 2012-06-05T20:19:56Z (12 years ago)
- Branches:
- master
- Children:
- 15581c1
- Parents:
- d219296
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/xmltree.c
rd219296 r222b440 277 277 } 278 278 279 static void xt_to_string_real( struct xt_node *node, GString *str )279 static void xt_to_string_real( struct xt_node *node, GString *str, int indent ) 280 280 { 281 281 char *buf; … … 283 283 int i; 284 284 285 if( indent > 1 ) 286 g_string_append_len( str, "\n\t\t\t\t\t\t\t\t", 287 indent < 8 ? indent : 8 ); 288 285 289 g_string_append_printf( str, "<%s", node->name ); 286 290 … … 307 311 308 312 for( c = node->children; c; c = c->next ) 309 xt_to_string_real( c, str ); 313 xt_to_string_real( c, str, indent ? indent + 1 : 0 ); 314 315 if( indent > 0 && node->children ) 316 g_string_append_len( str, "\n\t\t\t\t\t\t\t\t", 317 indent < 8 ? indent : 8 ); 310 318 311 319 g_string_append_printf( str, "</%s>", node->name ); … … 315 323 { 316 324 GString *ret; 317 char *real;318 325 319 326 ret = g_string_new( "" ); 320 xt_to_string_real( node, ret ); 321 322 real = ret->str; 323 g_string_free( ret, FALSE ); 324 325 return real; 327 xt_to_string_real( node, ret, 0 ); 328 return g_string_free( ret, FALSE ); 329 } 330 331 /* WITH indentation! */ 332 char *xt_to_string_i( struct xt_node *node ) 333 { 334 GString *ret; 335 336 ret = g_string_new( "" ); 337 xt_to_string_real( node, ret, 1 ); 338 return g_string_free( ret, FALSE ); 326 339 } 327 340 328 341 void xt_print( struct xt_node *node ) 329 342 { 330 int i; 331 struct xt_node *c; 332 333 /* Indentation */ 334 for( c = node; c->parent; c = c->parent ) 335 fprintf( stderr, " " ); 336 337 /* Start the tag */ 338 fprintf( stderr, "<%s", node->name ); 339 340 /* Print the attributes */ 341 for( i = 0; node->attr[i].key; i ++ ) 342 { 343 char *v = g_markup_escape_text( node->attr[i].value, -1 ); 344 fprintf( stderr, " %s=\"%s\"", node->attr[i].key, v ); 345 g_free( v ); 346 } 347 348 /* /> in case there's really *nothing* inside this tag, otherwise 349 just >. */ 350 /* If this tag doesn't have any content at all... */ 351 if( node->text == NULL && node->children == NULL ) 352 { 353 fprintf( stderr, "/>\n" ); 354 return; 355 /* Then we're finished! */ 356 } 357 358 /* Otherwise... */ 359 fprintf( stderr, ">" ); 360 361 /* Only print the text if it contains more than whitespace (TEST). */ 362 if( node->text_len > 0 ) 363 { 364 for( i = 0; node->text[i] && isspace( node->text[i] ); i ++ ); 365 if( node->text[i] ) 366 { 367 char *v = g_markup_escape_text( node->text, -1 ); 368 fprintf( stderr, "%s", v ); 369 g_free( v ); 370 } 371 } 372 373 if( node->children ) 374 fprintf( stderr, "\n" ); 375 376 for( c = node->children; c; c = c->next ) 377 xt_print( c ); 378 379 if( node->children ) 380 for( c = node; c->parent; c = c->parent ) 381 fprintf( stderr, " " ); 382 383 /* Non-empty tag is now finished. */ 384 fprintf( stderr, "</%s>\n", node->name ); 343 char *str = xt_to_string_i( node ); 344 fprintf( stderr, "%s", str ); 345 g_free( str ); 385 346 } 386 347 -
lib/xmltree.h
rd219296 r222b440 84 84 struct xt_node *xt_from_string( const char *in ); 85 85 char *xt_to_string( struct xt_node *node ); 86 char *xt_to_string_i( struct xt_node *node ); 86 87 void xt_print( struct xt_node *node ); 87 88 struct xt_node *xt_dup( struct xt_node *node ); -
storage_xml.c
rd219296 r222b440 373 373 374 374 tree = xml_generate( irc ); 375 xml = xt_to_string ( tree );375 xml = xt_to_string_i( tree ); 376 376 len = strlen( xml ); 377 377 if( write( fd, xml, len ) != len ||
Note: See TracChangeset
for help on using the changeset viewer.