static void fs_xml_convert( void *fs ) { fs_xml *xml = (fs_xml *)fs; if ( xml ) { convert_xml_tag( xml->tag ); } }
static void convert_xml_tag( xml_tag *tag ) { char **ap = NULL; if (tag == NULL) return; tag->cdata = cet_convert_string(tag->cdata); tag->parentcdata = cet_convert_string(tag->parentcdata); ap = tag->attributes; while (*ap) { *ap = cet_convert_string(*ap); ap++; } convert_xml_tag(tag->sibling); convert_xml_tag(tag->child); }
Bool convert_xml_file( const char *syntax_dir, const char *file, ASXMLInterpreterState *state ) { char *source_file ; char *doc_str ; Bool empty_file = False ; source_file = make_file_name( syntax_dir, file ); doc_str = load_file(source_file); LOCAL_DEBUG_OUT( "file %s loaded", source_file ); /*LOCAL_DEBUG_OUT( "file %s loaded into {%s}", source_file, doc_str ); */ if( doc_str != NULL ) { xml_elem_t* doc; xml_elem_t* ptr; if( file[0] == '_' && !get_flags( state->flags, ASXMLI_ProcessingOptions )) state->pre_options_size += strlen(doc_str) ; else set_flags( state->flags, ASXMLI_ProcessingOptions ); doc = xml_parse_doc(doc_str, DocBookVocabulary); LOCAL_DEBUG_OUT( "file %s parsed, child is %p", source_file, doc->child ); if( doc->child ) { LOCAL_DEBUG_OUT( "child tag = \"%s\", childs child = %p", doc->child->tag, doc->child->child); empty_file = ( doc->child->tag_id == DOCBOOK_section_ID && doc->child->child == NULL ); if( doc->child->child ) { empty_file = ( doc->child->child->tag_id == XML_CDATA_ID && doc->child->child->next == NULL ); LOCAL_DEBUG_OUT( "childs child tag = \"%s\", parm = \"%s\"", doc->child->child->tag, doc->child->child->parm); } } LOCAL_DEBUG_OUT( "file %s %s", source_file, empty_file?"empty":"not empty" ); if( !empty_file ) { for (ptr = doc->child ; ptr ; ptr = ptr->next) { LOCAL_DEBUG_OUT( "converting child <%s>", ptr->tag ); convert_xml_tag( ptr, NULL, state ); LOCAL_DEBUG_OUT( "done converting child <%s>", ptr->tag ); } } /* Delete the xml. */ LOCAL_DEBUG_OUT( "deleting xml %p", doc ); xml_elem_delete(NULL, doc); LOCAL_DEBUG_OUT( "freeing doc_str %p", doc_str ); free( doc_str ); } LOCAL_DEBUG_OUT( "done with %s", source_file ); free( source_file ); fprintf( state->dest_fp, "\n" ); return !empty_file; }
void convert_xml_tag( xml_elem_t *doc, xml_elem_t **rparm, ASXMLInterpreterState *state ) { xml_elem_t* parm = NULL; xml_elem_t* ptr ; const char *tag_name = doc->tag; if( state->doc_type != DocType_XML ) { parm = xml_parse_parm(doc->parm, DocBookVocabulary); if( doc->tag_id > 0 && doc->tag_id < DOCBOOK_SUPPORTED_IDS ) if( SupportedDocBookTagInfo[doc->tag_id].handle_start_tag ) SupportedDocBookTagInfo[doc->tag_id].handle_start_tag( doc, parm, state ); }else { if( doc->tag_id == DOCBOOK_refsect1_ID ) tag_name = SupportedDocBookTagInfo[DOCBOOK_section_ID].tag; fprintf( state->dest_fp, "<%s", tag_name ); if( doc->parm ) { char *ptr = NULL; if( doc->tag_id == DOCBOOK_ulink_ID ) ptr = strchr( doc->parm, '#' ); if( ptr != NULL ) { *ptr = '\0' ; fprintf( state->dest_fp, " %s.html#%s", doc->parm, ptr+1 ); *ptr = '#' ; }else fprintf( state->dest_fp, " %s", doc->parm ); } fputc( '>', state->dest_fp ); } for (ptr = doc->child ; ptr ; ptr = ptr->next) { /* LOCAL_DEBUG_OUT( "handling tag's data \"%s\"", ptr->parm ); */ if (ptr->tag_id == XML_CDATA_ID ) { const char *data_ptr = ptr->parm ; int len = 0 ; if( state->doc_type == DocType_NROFF ) { while( data_ptr[0] == '\n' ) ++data_ptr ; } len = strlen( data_ptr ); if( len > 0 && state->doc_type == DocType_NROFF) { int i ; while( len > 0 && data_ptr[len-1] == '\n' ) --len ; /* we want to skip as much whitespace as possible in NROFF */ for( i = 0 ; i < len ; ++i ) if( !isspace(data_ptr[i]) ) break; if( i == len ) len = 0 ; else if( !get_flags( state->flags, ASXMLI_LiteralLayout ) ) { int from , to ; Bool written = 0 ; for( i = 0 ; i < len ; ++i ) { while( isspace(data_ptr[i]) && i < len ) ++i ; from = i ; while( !isspace(data_ptr[i]) && i < len ) ++i ; to = i ; if( to > from ) { if( written > 0 ) fputc( ' ', state->dest_fp ); write_doc_cdata( &data_ptr[from], to-from, state ); written += to - from ; } } len = 0 ; } } if( len > 0 ) write_doc_cdata( data_ptr, len, state ); }else convert_xml_tag( ptr, NULL, state ); } /* LOCAL_DEBUG_OUT( "handling end tag with func %p", SupportedDocBookTagInfo[doc->tag_id].handle_end_tag ); */ if( state->doc_type != DocType_XML ) { if( doc->tag_id > 0 && doc->tag_id < DOCBOOK_SUPPORTED_IDS ) if( SupportedDocBookTagInfo[doc->tag_id].handle_end_tag ) SupportedDocBookTagInfo[doc->tag_id].handle_end_tag( doc, parm, state ); /* LOCAL_DEBUG_OUT( "xml_elem_delete for parm %p", parm ); */ if (rparm) *rparm = parm; else xml_elem_delete(NULL, parm); }else { fprintf( state->dest_fp, "</%s>", tag_name ); } }