subroutineload_project
subroutine load_project(path, directory, s, body, stat, errmsg)
Read the settings and front page text of the project. Settings come from an [extra.fdoc] or
[extra.ford] table in fpm.toml if there is one, and otherwise from the metadata of the project
file. With no path the project file is ford.md, if it exists: [extra.fdoc] does not need one,
as the text of the front page can be in its front_page, or the file named by front_page_file.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| path | character(len=*) | in | the project file, or | |
| directory | character(len=*) | in | its directory | |
| s | type(settings_t) | out | the settings | |
| body | character(len=:) | out | allocatable | the front page text |
| stat | integer | out | nonzero on failure | |
| errmsg | character(len=:) | out | allocatable | what is wrong |
Calls
Source
Show the code
subroutine load_project(path, directory, s, body, stat, errmsg)
character(len=*), intent(in) :: path !! the project file, or `''`
character(len=*), intent(in) :: directory !! its directory
type(settings_t), intent(out) :: s !! the settings
character(len=:), allocatable, intent(out) :: body !! the front page text
integer, intent(out) :: stat !! nonzero on failure
character(len=:), allocatable, intent(out) :: errmsg !! what is wrong
type(metadata_t) :: meta
character(len=:), allocatable :: text, file, front
logical :: found, exists
integer :: k
s = new_settings()
stat = 0
file = path
if (len(file) == 0) then
inquire (file=join_path(directory, 'ford.md'), exist=exists)
if (exists) file = join_path(directory, 'ford.md')
end if
text = ''
if (len(file) > 0) then
call read_whole_file(file, text, stat, errmsg)
if (stat /= 0) return
end if
call load_fpm_settings(join_path(directory, 'fpm.toml'), s, found, front, stat, errmsg)
if (stat /= 0) return
if (found) then
if (allocated(front)) then
body = front
else
body = text
end if
return
end if
if (len(file) == 0) then
stat = 1
errmsg = 'no project file: give one, or add an [extra.fdoc] table to fpm.toml'
return
end if
if (ends_with(file, 'fpm.toml')) then
stat = 1
errmsg = file//' has no [extra.fdoc] or [extra.ford] table: give the project file instead'
return
end if
call parse_metadata(text, meta)
body = join(meta%body, achar(10))
do k = 1, size(meta%items)
associate (item => meta%items(k))
if (.not. is_option(item%key)) then
call warn("In '"//file//"': Ignoring unknown Ford metadata key '"//item%key//"'")
cycle
end if
call set_option(s, item%key, item%values, stat, errmsg)
if (stat /= 0) then
errmsg = "Error parsing settings from '"//file//"': "//errmsg
return
end if
end associate
end do
end subroutine load_project