Example #1
0
static void
set_KDE_config_item_value (xml_elem_t * item, const char *value)
{
	while (item->child != NULL)
		xml_elem_delete (&(item->child), item->child);
	if (value) {
		item->child = create_CDATA_tag ();
		item->child->parm = mystrdup (value);
	}
}
Example #2
0
xml_elem_t* load_KDE_config(const char* realfilename) 
{
	xml_elem_t* config = create_CONTAINER_tag();
	FILE *fp = fopen( realfilename, "r" );
	
	if( fp != NULL ) 
	{	
		char buffer[8192];
		xml_elem_t* group = NULL ; 
		
		while(fgets(&buffer[0], sizeof(buffer), fp) != NULL)
		{
			xml_elem_t* tag ; 
			int i = 0; 

			while( isspace(buffer[i]) ) ++i ;
			if( buffer[i] == '#' )
			{
				++i;
				if( (tag = make_kde_config_comment_tag()) != NULL )
				{	
					int len = strlen( &buffer[i] ) ;
					while( len > 0 && isspace( buffer[i+len-1] ) ) --len ;
					if( len > 0 ) 
					{
						tag->child = create_CDATA_tag();	  
						tag->child->parm = mystrndup( &buffer[i], len );
					}
					if( group == NULL ) 
					{
						group = make_kde_config_group_tag(NULL);		   
						config->child = group;
					}
					xml_insert( group, tag );
				}
			}else if( buffer[i] == '[' ) 
			{
				++i;
				if( (tag = make_kde_config_group_tag(&buffer[i])) != NULL )
				{	
					if( group ) 
						group->next = tag ; 
					else
						config->child = tag ;						
					group = tag ;
				}
			}else if( buffer[i] != '\0' )
			{
				int name_len ; 
				tag = make_kde_config_item_tag(&buffer[i], &name_len);
				if( tag ) 
				{              /* now we need to parse value and then possibly a comment : */
					char *val = stripcpy(&buffer[i+name_len+1] );
					if( group == NULL ) 
					{
						group = make_kde_config_group_tag(NULL);		   
						config->child = group;
					}

					xml_insert( group, tag );
					
					if( val ) 
					{
						if( val[0] != '\0' ) 
						{	
							tag->child = create_CDATA_tag();
							tag->child->parm = val ; 
						}else
							free( val );
					}	 
				}	 
			}			 
		}	 

		fclose( fp );
	}
	return config;
}