subroutinefypp_process
subroutine fypp_process(path, defines, includes, text, stat, errmsg)
The output of Fypp for file path. Each of defines is NAME or NAME=expression.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| path | character(len=*) | in | the file | |
| defines | type(string_t) | in | dimension(:) | the variables to set |
| includes | type(string_t) | in | dimension(:) | where to look for included files |
| text | character(len=:) | out | allocatable | the output |
| stat | integer | out | nonzero on failure | |
| errmsg | character(len=:) | out | allocatable | what is wrong |
Calls
Source
Show the code
subroutine fypp_process(path, defines, includes, text, stat, errmsg)
character(len=*), intent(in) :: path !! the file
type(string_t), intent(in) :: defines(:) !! the variables to set
type(string_t), intent(in) :: includes(:) !! where to look for included files
character(len=:), allocatable, intent(out) :: text !! the output
integer, intent(out) :: stat !! nonzero on failure
character(len=:), allocatable, intent(out) :: errmsg !! what is wrong
type(fypp_t) :: c
type(value_t) :: v
type(buffer_t) :: out
character(len=:), allocatable :: rendered
integer, allocatable :: names(:), values(:)
integer :: k, at
stat = 0
text = ''
errmsg = ''
c%includes = includes
allocate (c%names(256), c%exprs(1024), c%nodes(1024), c%frames(MAX_FRAMES), c%macros(32))
allocate (c%bound(32), c%bound_values(32), c%spans(1024))
allocate (names(size(defines)), values(size(defines)))
do k = 1, size(defines)
at = index(defines(k)%s, '=')
values(k) = 0
if (at == 0) then
call intern(c, trim(adjustl(defines(k)%s)), names(k))
else
call intern(c, trim(adjustl(defines(k)%s(:at - 1))), names(k))
call compile(c, defines(k)%s(at + 1:), values(k))
end if
end do
c%root = new_node(c, 0)
call add_body(c, c%root, 0)
call parse_file(c, path)
if (.not. allocated(c%error) .and. c%depth /= 0) c%error = 'a block is not closed'
if (allocated(c%error)) then
stat = 1
errmsg = c%error
return
end if
allocate (c%globals(c%num_names), c%is_set(c%num_names))
c%is_set = .false.
do k = 1, size(defines)
if (values(k) > 0) then
call evaluate(c, values(k), v)
else
v = value_t()
end if
c%globals(names(k)) = v
c%is_set(names(k)) = .true.
end do
call render_body(c, c%nodes(c%root)%block%bodies(1), out, .true.)
if (allocated(c%error)) then
stat = 1
errmsg = c%error
return
end if
call take(out, rendered)
call fold_output(c, rendered, text)
end subroutine fypp_process