forked from andreww/fox
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathm_dom_exception.m4
96 lines (96 loc) · 3.51 KB
/
m_dom_exception.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
include(`foreach.m4')`'dnl
include(`m_dom_treewalk.m4')`'dnl
define(`TOHW_m_dom_throw_error',`dnl
dnl 1 is numerical code
dnl 2 is list of things to deallocate
dnl 3 is an optional thing to do before the return
if (getFoX_checks().or.$1<200) then
call throw_exception($1, "m4f_thisfunc", ex)
if (present(ex)) then
if (inException(ex)) then
ifelse($2, `', `',
m4_foreach(`x', `$2', `
if (associated(x)) deallocate(x)
'))`'dnl
ifelse($3, `', `', ` $3
')`'dnl
return
endif
endif
endif
')`'dnl
dnl
define(`TOHW_function', `dnl
define(`m4f_thisfunc', `$1')dnl
`'function $1`'dnl
(m4_foreach(`x', `$2', `x, ')ex)ifelse($3, `', `', `result($3)')
type(DOMException), intent(out), optional :: ex`'dnl
')`'dnl
dnl
define(`TOHW_subroutine', `dnl
define(`m4f_thisfunc', `$1')dnl
subroutine $1`'dnl
(m4_foreach(`x', `$2', `x, ')ex)
type(DOMException), intent(out), optional :: ex`'dnl
')`'dnl
dnl
define(`TOHW_m_dom_hierarchy_test',`dnl
select case(testParent%nodeType)
case (ELEMENT_NODE)
if (testChild%nodeType/=ELEMENT_NODE &
.and. testChild%nodeType/=TEXT_NODE &
.and. testChild%nodeType/=COMMENT_NODE &
.and. testChild%nodeType/=PROCESSING_INSTRUCTION_NODE &
.and. testChild%nodeType/=CDATA_SECTION_NODE &
.and. testChild%nodeType/=ENTITY_REFERENCE_NODE) then
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
endif
case (ATTRIBUTE_NODE)
if (testChild%nodeType/=TEXT_NODE &
.and. testChild%nodeType/=ENTITY_REFERENCE_NODE) then
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
endif
if (testChild%nodeType==ENTITY_REFERENCE_NODE) then
treeroot => testChild
TOHW_m_dom_treewalk(`
if (getNodeType(this)/=TEXT_NODE.and.getNodeType(this)/=ENTITY_REFERENCE_NODE) then
TOHW_m_dom_throw_error(FoX_HIERARCHY_REQUEST_ERR)
endif
',`')
endif
case (DOCUMENT_NODE)
if ((testChild%nodeType/=ELEMENT_NODE .or. &
(testChild%nodeType==ELEMENT_NODE &
.and.associated(testParent%docExtras%documentElement)`'dnl
ifelse(m4f_thisfunc, `replaceChild', ` &
.and.oldChild%nodeType/=ELEMENT_NODE')`'dnl
)) &
.and. testChild%nodeType/=PROCESSING_INSTRUCTION_NODE &
.and. testChild%nodeType/=COMMENT_NODE &
.and. (testChild%nodeType/=DOCUMENT_TYPE_NODE .or. &
(testChild%nodeType==DOCUMENT_TYPE_NODE &
.and.associated(testParent%docExtras%docType)`'dnl
ifelse(m4f_thisfunc, `replaceChild', ` &
.and.oldChild%nodeType/=DOCUMENT_TYPE_NODE')`'dnl
))) then
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
endif
case (DOCUMENT_FRAGMENT_NODE)
if (testChild%nodeType/=ELEMENT_NODE &
.and. testChild%nodeType/=TEXT_NODE &
.and. testChild%nodeType/=COMMENT_NODE &
.and. testChild%nodeType/=PROCESSING_INSTRUCTION_NODE &
.and. testChild%nodeType/=CDATA_SECTION_NODE &
.and. testChild%nodeType/=ENTITY_REFERENCE_NODE) then
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
endif
case (ENTITY_NODE)
continue ! only allowed by DOM parser, not by user.
! but entity nodes are always readonly anyway, so no problem
case (ENTITY_REFERENCE_NODE)
continue ! only allowed by DOM parser, not by user.
! but entity nodes are always readonly anyway, so no problem
case default
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
end select
')`'dnl