Skip to content

Commit

Permalink
Carry baseURIs around with entities, and do all opening of files
Browse files Browse the repository at this point in the history
and strings using URIs
  • Loading branch information
Toby White authored and Toby White committed Mar 28, 2008
1 parent 044da3f commit dbe193c
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 115 deletions.
30 changes: 22 additions & 8 deletions common/m_common_entities.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module m_common_entities

use fox_m_fsys_array_str, only: str_vs, vs_str_alloc
use fox_m_fsys_format, only: str_to_int_10, str_to_int_16
use fox_m_utils_uri, only: URI, destroyURI
use m_common_charset, only: digits, hexdigits
use m_common_error, only: FoX_error

Expand All @@ -19,6 +20,7 @@ module m_common_entities
character(len=1), dimension(:), pointer :: publicId => null()
character(len=1), dimension(:), pointer :: systemId => null()
character(len=1), dimension(:), pointer :: notation => null()
type(URI), pointer :: baseURI
end type entity_t

type entity_list
Expand Down Expand Up @@ -70,6 +72,7 @@ function shallow_copy_entity(ent1) result(ent2)
ent2%publicId => ent1%publicId
ent2%systemId => ent1%systemId
ent2%notation => ent1%notation
ent2%baseURI => ent1%baseURI

end function shallow_copy_entity

Expand Down Expand Up @@ -123,6 +126,8 @@ subroutine destroy_entity(ent)
deallocate(ent%systemId)
deallocate(ent%notation)

if (associated(ent%baseURI)) call destroyURI(ent%baseURI)

end subroutine destroy_entity


Expand Down Expand Up @@ -170,6 +175,7 @@ function pop_entity_list(ents) result(name)
ents%list(i) = shallow_copy_entity(ents_tmp(i))
enddo
name = str_vs(ents_tmp(i)%name)

call destroy_entity(ents_tmp(i))
deallocate(ents_tmp)
end function pop_entity_list
Expand All @@ -192,13 +198,14 @@ subroutine print_entity_list(ents)
end subroutine print_entity_list


subroutine add_entity(ents, name, text, publicId, systemId, notation, wfc)
subroutine add_entity(ents, name, text, publicId, systemId, notation, baseURI, wfc)
type(entity_list), intent(inout) :: ents
character(len=*), intent(in) :: name
character(len=*), intent(in) :: text
character(len=*), intent(in) :: publicId
character(len=*), intent(in) :: systemId
character(len=*), intent(in) :: notation
type(URI), pointer :: baseURI
logical, intent(in) :: wfc

type(entity_t), pointer :: ents_tmp(:)
Expand All @@ -225,40 +232,47 @@ subroutine add_entity(ents, name, text, publicId, systemId, notation, wfc)
ents%list(i)%publicId => vs_str_alloc(publicId)
ents%list(i)%systemId => vs_str_alloc(systemId)
ents%list(i)%notation => vs_str_alloc(notation)
ents%list(i)%baseURI => baseURI
end subroutine add_entity


subroutine add_internal_entity(ents, name, text, wfc)
subroutine add_internal_entity(ents, name, text, baseURI, wfc)
type(entity_list), intent(inout) :: ents
character(len=*), intent(in) :: name
character(len=*), intent(in) :: text
type(URI), pointer :: baseURI
logical, intent(in) :: wfc

call add_entity(ents, name=name, text=text, &
publicId="", systemId="", notation="", wfc=wfc)
publicId="", systemId="", notation="", baseURI=baseURI, wfc=wfc)
end subroutine add_internal_entity


subroutine add_external_entity(ents, name, systemId, wfc, publicId, notation)
subroutine add_external_entity(ents, name, systemId, baseURI, wfc, publicId, notation)
type(entity_list), intent(inout) :: ents
character(len=*), intent(in) :: name
character(len=*), intent(in) :: systemId
character(len=*), intent(in), optional :: publicId
character(len=*), intent(in), optional :: notation
type(URI), pointer :: baseURI
logical, intent(in) :: wfc

if (present(publicId) .and. present(notation)) then
call add_entity(ents, name=name, text="", &
publicId=publicId, systemId=systemId, notation=notation, wfc=wfc)
publicId=publicId, systemId=systemId, notation=notation, &
wfc=wfc, baseURI=baseURI)
elseif (present(publicId)) then
call add_entity(ents, name=name, text="", &
publicId=publicId, systemId=systemId, notation="", wfc=wfc)
publicId=publicId, systemId=systemId, notation="", &
wfc=wfc, baseURI=baseURI)
elseif (present(notation)) then
call add_entity(ents, name=name, text="", &
publicId="", systemId=systemId, notation=notation, wfc=wfc)
publicId="", systemId=systemId, notation=notation, &
wfc=wfc, baseURI=baseURI)
else
call add_entity(ents, name=name, text="", &
publicId="", systemId=systemId, notation="", wfc=wfc)
publicId="", systemId=systemId, notation="", &
wfc=wfc, baseURI=baseURI)
endif
end subroutine add_external_entity

Expand Down
26 changes: 18 additions & 8 deletions common/m_common_struct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module m_common_struct
#ifndef DUMMYLIB
! Common parts of an XML document. Shared by both SAX & WXML.

use FoX_utils, only: URI

use m_common_charset, only: XML1_0
use m_common_entities, only: entity_list, init_entity_list, destroy_entity_list, &
add_internal_entity, add_external_entity
Expand Down Expand Up @@ -64,47 +66,55 @@ subroutine destroy_xml_doc_state(xds)
deallocate(xds%intSubset)
end subroutine destroy_xml_doc_state

subroutine register_internal_PE(xds, name, text, wfc)
subroutine register_internal_PE(xds, name, text, wfc, baseURI)
type(xml_doc_state), intent(inout) :: xds
character(len=*), intent(in) :: name
character(len=*), intent(in) :: text
logical, intent(in) :: wfc
type(URI), pointer :: baseURI

call add_internal_entity(xds%PEList, name=name, text=text, wfc=wfc)
call add_internal_entity(xds%PEList, name=name, text=text, &
wfc=wfc, baseURI=baseURI)

end subroutine register_internal_PE

subroutine register_external_PE(xds, name, systemId, wfc, publicId)
subroutine register_external_PE(xds, name, systemId, wfc, baseURI, publicId)
type(xml_doc_state), intent(inout) :: xds
character(len=*), intent(in) :: name
character(len=*), intent(in) :: systemId
logical, intent(in) :: wfc
character(len=*), intent(in), optional :: publicId
type(URI), pointer :: baseURI

call add_external_entity(xds%PEList, name=name, &
publicId=publicId, systemId=systemId, wfc=wfc)
publicId=publicId, systemId=systemId, &
wfc=wfc, baseURI=baseURI)
end subroutine register_external_PE

subroutine register_internal_GE(xds, name, text, wfc)
subroutine register_internal_GE(xds, name, text, wfc, baseURI)
type(xml_doc_state), intent(inout) :: xds
character(len=*), intent(in) :: name
character(len=*), intent(in) :: text
logical, intent(in) :: wfc
type(URI), pointer :: baseURI

call add_internal_entity(xds%entityList, name=name, text=text, wfc=wfc)
call add_internal_entity(xds%entityList, name=name, text=text, &
wfc=wfc, baseURI=baseURI)

end subroutine register_internal_GE

subroutine register_external_GE(xds, name, systemId, wfc, publicId, notation)
subroutine register_external_GE(xds, name, systemId, wfc, baseURI, publicId, notation)
type(xml_doc_state), intent(inout) :: xds
character(len=*), intent(in) :: name
character(len=*), intent(in) :: systemId
logical, intent(in) :: wfc
character(len=*), intent(in), optional :: publicId
character(len=*), intent(in), optional :: notation
type(URI), pointer :: baseURI

call add_external_entity(xds%entityList, name=name, &
systemId=systemId, publicId=publicId, notation=notation, wfc=wfc)
systemId=systemId, publicId=publicId, notation=notation, &
wfc=wfc, baseURI=baseURI)
end subroutine register_external_GE

#endif
Expand Down
Loading

0 comments on commit dbe193c

Please sign in to comment.