Skip to content

Commit 37930cb

Browse files
committed
Fix Flang issues. Write troff to file first.
1 parent 9d98234 commit 37930cb

File tree

8 files changed

+379
-354
lines changed

8 files changed

+379
-354
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,12 +1803,13 @@ purge: clean
18031803
$(RM) -rf $(DOCDIR)
18041804
@echo
18051805
@echo "--- Deleting stale test files ..."
1806-
$(RM) -rf test*.pdf
18071806
$(RM) -rf test*.db
18081807
$(RM) -rf test*.hdf5
1808+
$(RM) -rf test*.ms
1809+
$(RM) -rf test*.pdf
1810+
$(RM) -rf test*.png
18091811
$(RM) -rf test*.xml
18101812
$(RM) -rf test*.xml
1811-
$(RM) -rf test*.png
18121813

18131814
# ******************************************************************************
18141815
#

app/dmreport.f90

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ program dmreport
1313
integer, parameter :: APP_PATCH = 0
1414

1515
character(*), parameter :: APP_SUFFIX_EPS = '.eps' !! EPS file ending.
16+
character(*), parameter :: APP_SUFFIX_MS = '.ms' !! Troff file ending.
1617
character(*), parameter :: APP_SUFFIX_PDF = '.pdf' !! PDF file ending.
1718
character(*), parameter :: APP_SUFFIX_PS = '.ps' !! PS file ending.
1819

@@ -275,28 +276,40 @@ subroutine make_ps(report, error)
275276
type(report_type), intent(inout) :: report !! Report type.
276277
integer, intent(out), optional :: error !! Error code.
277278

278-
integer :: rc
279+
character(:), allocatable :: input, output
280+
integer :: rc, stat, unit
281+
282+
! Create output file (PostScript).
283+
output = dm_time_parse_string(report%output)
284+
285+
call dm_file_touch(output, error=rc)
286+
287+
if (dm_is_error(rc)) then
288+
call dm_error_out(rc, 'failed to create output file ' // output)
289+
return
290+
end if
291+
292+
! Open input file (troff).
293+
input = temporary_file(APP_TMP_DIR, APP_SUFFIX_MS)
294+
295+
rc = E_IO
296+
open (action='write', file=input, iostat=stat, newunit=unit, status='replace')
297+
298+
if (stat /= 0) then
299+
call dm_error_out(rc, 'failed to create input file ' // input)
300+
return
301+
end if
279302

280303
ps_block: block
281304
character(*), parameter :: RULE = ROFF_REQUEST_BR // ROFF_ESC_MVUP // ROFF_ESC_HR // ASCII_LF
282305
character(*), parameter :: SUB = 'sub'
283306
integer, parameter :: SUBR = 128, SUBG = 128, SUBB = 128 ! RGB colour of sub-heading.
284307

285-
character(:), allocatable :: path, roff
286308
character(FILE_PATH_LEN), allocatable :: eps_files(:)
287309
integer :: i, n
288310

289311
allocate (eps_files(0))
290312

291-
! Create output file.
292-
path = dm_time_parse_string(report%output)
293-
call dm_file_touch(path, error=rc)
294-
295-
if (dm_is_error(rc)) then
296-
call dm_error_out(rc, 'failed to open output file ' // path)
297-
exit ps_block
298-
end if
299-
300313
! Add document header.
301314
roff_block: block
302315
integer, parameter :: NCOL = 4, NFMT = 1, NROW = 2
@@ -315,19 +328,22 @@ subroutine make_ps(report, error)
315328
exit ps_block
316329
end if
317330

318-
! Create MS header and define colour.
319331
date = dm_time_date()
320-
roff = dm_roff_ms_header(title=report%title, author=report%author, institution=date, font_family=APP_ROFF_FONT, font_size=10, &
321-
left_header=report%title, center_header=report%subtitle, right_header=date, &
322-
left_footer='DMPACK ' // DM_VERSION_STRING, center_footer=ROFF_ESC_ENDASH // ' % ' // ROFF_ESC_ENDASH)
323-
roff = roff // dm_roff_defcolor(SUB, SUBR, SUBG, SUBB)
332+
333+
! Create MS header and define colour.
334+
write (unit, '(a)', advance='no') dm_roff_ms_header(title=report%title, author=report%author, institution=date, &
335+
font_family=APP_ROFF_FONT, font_size=10, left_header=report%title, &
336+
center_header=report%subtitle, right_header=date, &
337+
left_footer='DMPACK ' // DM_VERSION_STRING, &
338+
center_footer=ROFF_ESC_ENDASH // ' % ' // ROFF_ESC_ENDASH)
339+
write (unit, '(a)', advance='no') dm_roff_defcolor(SUB, SUBR, SUBG, SUBB)
324340

325341
! Add report overview table.
326342
format = reshape([ character(FMT_LEN) :: 'lb', 'l', 'lb', 'l' ], [ NCOL, NFMT ])
327343
data = reshape([ character(COL_LEN) :: 'Node Name:', node%name, 'From:', dm_time_to_human(report%from), &
328-
'Node ID:', node%id, 'To:', dm_time_to_human(report%to) ], &
329-
[ NCOL, NROW ])
330-
roff = roff // dm_roff_tbl(format, data) // dm_roff_ms_lp(report%meta)
344+
'Node ID:', node%id, 'To:', dm_time_to_human(report%to) ], [ NCOL, NROW ])
345+
346+
write (unit, '(2a)', advance='no') dm_roff_tbl(format, data), dm_roff_ms_lp(report%meta)
331347
end block roff_block
332348

333349
! Add plots.
@@ -343,7 +359,9 @@ subroutine make_ps(report, error)
343359
allocate (eps_files(n), source=repeat(' ', FILE_PATH_LEN))
344360

345361
! Add plot section title and meta description.
346-
roff = roff // dm_roff_ms_sh(2, report%plot%title) // RULE // dm_roff_ms_lp(report%plot%meta)
362+
write (unit, '(3a)', advance='no') dm_roff_ms_sh(2, report%plot%title), & ! Section title.
363+
RULE, & ! Horizontal rule.
364+
dm_roff_ms_lp(report%plot%meta) ! Meta description.
347365

348366
! Plot subsection loop.
349367
do i = 1, n
@@ -364,23 +382,22 @@ subroutine make_ps(report, error)
364382
! Add title, subtitle, and meta description.
365383
if (dm_is_ok(rc) .or. report%verbose) then
366384
if (dm_string_has(observ%subtitle)) then
367-
roff = roff // dm_roff_ms_sh(3, trim(observ%title) // ROFF_ESC_NBSP // &
368-
dm_roff_m(SUB, dm_roff_s(1, observ%subtitle, rel='-')))
385+
write (unit, '(a)', advance='no') dm_roff_ms_sh(3, trim(observ%title) // ROFF_ESC_NBSP // dm_roff_m(SUB, dm_roff_s(1, observ%subtitle, rel='-')))
369386
else
370-
roff = roff // dm_roff_ms_sh(3, observ%title)
387+
write (unit, '(a)', advance='no') dm_roff_ms_sh(3, observ%title)
371388
end if
372389

373-
if (dm_string_has(observ%meta)) roff = roff // dm_roff_ms_lp(observ%meta)
390+
if (dm_string_has(observ%meta)) write (unit, '(a)', advance='no') dm_roff_ms_lp(observ%meta)
374391
end if
375392

376393
! Handle errors.
377394
if (rc == E_DB_NO_ROWS) then
378-
if (report%verbose) roff = roff // roff_error_message('no observations found in database ' // report%plot%database)
395+
if (report%verbose) write (unit, '(a)', advance='no') roff_error_message('no observations found in database ' // report%plot%database)
379396
cycle
380397
end if
381398

382399
if (dm_is_error(rc)) then
383-
if (report%verbose) roff = roff // roff_error_message(dm_error_message(rc))
400+
if (report%verbose) write (unit, '(a)', advance='no') roff_error_message(dm_error_message(rc))
384401
cycle
385402
end if
386403

@@ -412,10 +429,10 @@ subroutine make_ps(report, error)
412429
call dm_plot_close(plot)
413430

414431
! Add EPS to markup.
415-
roff = roff // dm_roff_pspic(eps_files(i))
432+
write (unit, '(a)', advance='no') dm_roff_pspic(eps_files(i))
416433

417434
! Add page break.
418-
if (observ%pagebreak) roff = roff // ROFF_REQUEST_BP
435+
if (observ%pagebreak) write (unit, '(a)', advance='no') ROFF_REQUEST_BP
419436
end associate
420437
end do
421438
end block plot_block
@@ -443,18 +460,19 @@ subroutine make_ps(report, error)
443460

444461
! Add log section title and meta description.
445462
if (dm_is_ok(rc) .or. report%verbose) then
446-
roff = roff // dm_roff_ms_sh(2, report%log%title) // RULE // &
447-
dm_roff_ms_lp(report%log%meta)
463+
write (unit, '(3a)', advance='no') dm_roff_ms_sh(2, report%log%title), & ! Section title.
464+
RULE, & ! Horizontal rule.
465+
dm_roff_ms_lp(report%log%meta) ! Meta description.
448466
end if
449467

450468
! Handle errors.
451469
if (rc == E_DB_NO_ROWS) then
452-
if (report%verbose) roff = roff // roff_error_message('no logs found in database ' // report%log%database)
470+
if (report%verbose) write (unit, '(a)', advance='no') roff_error_message('no logs found in database ' // report%log%database)
453471
exit log_block
454472
end if
455473

456474
if (dm_is_error(rc)) then
457-
if (report%verbose) roff = roff // roff_error_message(dm_error_message(rc))
475+
if (report%verbose) write (unit, '(a)', advance='no') roff_error_message(dm_error_message(rc))
458476
exit log_block
459477
end if
460478

@@ -468,6 +486,7 @@ subroutine make_ps(report, error)
468486
'-', '-', '-', '-', '-', & ! Horizontal rule.
469487
'l', 'l', 'l', 'l', 'lw36' ], & ! Left aligned, with min. width.
470488
[ NCOL, NFMT ])
489+
471490
data(:, 1) = [ character(COL_LEN) :: 'Timestamp', 'Source', 'Level', 'Error', 'Message' ]
472491

473492
! Add table rows.
@@ -483,19 +502,22 @@ subroutine make_ps(report, error)
483502
end associate
484503
end do
485504

486-
roff = roff // dm_roff_tbl(format, data, expand=.true.)
505+
write (unit, '(a)', advance='no') dm_roff_tbl(format, data, expand=.true.)
487506
end block log_block
488507

489508
! Create PostScript file.
490-
rc = dm_roff_to_ps(roff, report%output, macro=ROFF_MACRO_MS, preconv=.true., tbl=.true.)
509+
rc = dm_roff_to_ps(input, output, macro=ROFF_MACRO_MS, preconv=.true., tbl=.true.)
491510

492511
! Remove temporary files.
512+
call dm_file_delete(input)
513+
493514
do i = 1, size(eps_files)
494-
if (.not. dm_string_has(eps_files(i))) cycle
495-
call dm_file_delete(eps_files(i))
515+
if (dm_string_has(eps_files(i))) call dm_file_delete(eps_files(i))
496516
end do
497517
end block ps_block
498518

519+
close (unit)
520+
499521
if (present(error)) error = rc
500522
end subroutine make_ps
501523

@@ -613,8 +635,8 @@ function html_plot(dps, response, unit, terminal, title, meta, color, width, hei
613635
! Select MIME type according to format.
614636
select case (plot%terminal)
615637
case (PLOT_TERMINAL_GIF); mime = MIME_GIF
616-
case (PLOT_TERMINAL_PNG, &
617-
PLOT_TERMINAL_PNGCAIRO); mime = MIME_PNG
638+
case (PLOT_TERMINAL_PNG); mime = MIME_PNG
639+
case (PLOT_TERMINAL_PNGCAIRO); mime = MIME_PNG
618640
case (PLOT_TERMINAL_SVG); mime = MIME_SVG
619641
case default
620642
! Fail-safe: should never occur.
@@ -729,8 +751,7 @@ integer function read_config(app) result(rc)
729751
rc = config%open(app%config, app%name)
730752

731753
if (dm_is_ok(rc)) then
732-
! Take the table from the top of the Lua stack,
733-
! do not load a table field.
754+
! Take the table from the top of the Lua stack, do not load a table field.
734755
call config%get(app%name, app%report, field=.false.)
735756
end if
736757

src/dm_freebsd.f90

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ integer function dm_freebsd_uptime_load_average(avg1, avg5, avg15) result(rc)
311311
!! * `E_READ` if pipe returned no bytes.
312312
!! * `E_SYSTEM` if system call failed.
313313
!!
314+
use :: dm_ascii, only: ASCII_LF
315+
314316
real, intent(out), optional :: avg1 !! Average, 1 min.
315317
real, intent(out), optional :: avg5 !! Average, 5 min.
316318
real, intent(out), optional :: avg15 !! Average, 15 min.
@@ -321,7 +323,7 @@ integer function dm_freebsd_uptime_load_average(avg1, avg5, avg15) result(rc)
321323

322324
io_block: block
323325
character(128) :: output
324-
integer :: i, stat
326+
integer :: i, j, stat
325327

326328
rc = E_PLATFORM
327329
if (PLATFORM_SYSTEM /= PLATFORM_SYSTEM_FREEBSD) exit io_block
@@ -330,10 +332,11 @@ integer function dm_freebsd_uptime_load_average(avg1, avg5, avg15) result(rc)
330332
if (dm_is_error(rc)) exit io_block
331333

332334
rc = E_FORMAT
333-
i = index(output, ':', back=.true.)
334-
if (i == 0 .or. i == len(output)) exit io_block
335+
i = index(output, ':', back=.true.)
336+
j = index(output, ASCII_LF, back=.true.)
337+
if (i == 0 .or. i == len(output) .or. i >= j) exit io_block
335338

336-
read (output(i + 1:), *, iostat=stat) values
339+
read (output(i + 1:j - 1), *, iostat=stat) values
337340
if (stat == 0) rc = E_NONE
338341
end block io_block
339342

0 commit comments

Comments
 (0)