Format text from file name in directory dir, and write or report the result.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(cli_t), | intent(in) | :: | cli |
the parsed command line |
||
| type(config_cache_t), | intent(inout) | :: | cache |
configurations found so far |
||
| character(len=*), | intent(in) | :: | name |
the file, for messages and diff headers and to write
the result to; |
||
| character(len=*), | intent(in) | :: | dir |
the directory whose configuration applies |
||
| character(len=*), | intent(in) | :: | text |
the source as read |
||
| logical, | intent(in) | :: | to_stdout |
write the result to standard output instead of to |
integer function process_text(cli, cache, name, dir, text, to_stdout) result(status) !! Format `text` from file `name` in directory `dir`, and write or report the result. type(cli_t), intent(in) :: cli !! the parsed command line type(config_cache_t), intent(inout) :: cache !! configurations found so far character(len=*), intent(in) :: name !! the file, for messages and diff headers and to write !! the result to; `<stdin>` for standard input character(len=*), intent(in) :: dir !! the directory whose configuration applies character(len=*), intent(in) :: text !! the source as read logical, intent(in) :: to_stdout !! write the result to standard output instead of to `name` type(format_options_t) :: opts character(len=:), allocatable :: out, errmsg type(diagnostic_t), allocatable :: diags(:) integer :: stat, d logical :: changed status = EXIT_OK call options_for(cli, cache, dir, opts, stat, errmsg) if (stat /= 0) then write (error_unit, '(a)') name//': error: '//errmsg status = EXIT_ERROR return end if call format_text(text, opts, out, stat, errmsg, diags) if (.not. cli%quiet) then do d = 1, size(diags) write (error_unit, '(a)') name//':'//to_s(diags(d)%line)//': warning: '//diags(d)%message end do end if if (stat /= FMT_OK) then write (error_unit, '(a)') name//': error: '//errmsg status = EXIT_ERROR return end if changed = out /= text .or. len(out) /= len(text) if (cli%diff .and. changed) write (output_unit, '(a)', advance='no') unified_diff(text, out, name) if (cli%check) then if (changed) then if (.not. cli%diff) write (output_unit, '(a)') name//': would be reformatted' status = EXIT_CHANGED end if else if (cli%diff) then continue else if (to_stdout) then write (output_unit, '(a)', advance='no') out else if (changed) then call write_file(name, out, stat, errmsg) if (stat /= 0) then write (error_unit, '(a)') name//': error: '//errmsg status = EXIT_ERROR end if end if end function process_text