subroutinepreprocessprivate
subroutine preprocess(s, path, text)
Replace text by the output of the preprocessor for path, or keep it if that fails.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| s | type(settings_t) | in | the settings | |
| path | character(len=*) | in | the file | |
| text | character(len=:) | inout | allocatable | the text |
Calls
- temporary_directory
- unique_tag
- preprocessor_command
- run_command
- quoted_path
- read_whole_file
- warn
- remove_file
Source
Show the code
subroutine preprocess(s, path, text)
type(settings_t), intent(in) :: s !! the settings
character(len=*), intent(in) :: path !! the file
character(len=:), allocatable, intent(inout) :: text !! the text
character(len=:), allocatable :: output, errors, command, directory, result, msg
character(len=32) :: tag
integer :: exit_code, stat
call temporary_directory(directory)
call unique_tag(tag)
output = join_path(directory, 'fdoc-'//trim(tag)//'.out')
errors = join_path(directory, 'fdoc-'//trim(tag)//'.err')
command = preprocessor_command(s, path)
call run_command(command//' > '//quoted_path(output)//' 2> '//quoted_path(errors), exit_code)
if (exit_code == 0) then
call read_whole_file(output, result, stat, msg)
if (stat == 0) call move_alloc(result, text)
else
call warn('preprocessing failed, reverting to the file itself: '//command)
end if
call remove_file(output)
call remove_file(errors)
end subroutine preprocess