Skip to content

Commit

Permalink
Give up; read whole file (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 8, 2024
1 parent 4a2b0c0 commit 2189b4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/src/fortran/lib/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ View source code :source:`fortran/include/constants.f90`
:type: integer
.. f:variable:: ERROR_UTILS_ALLOCATE_FAILED
:type: integer
.. f:variable:: ERROR_FILE_READ_FAILED
:type: integer

Denotes the exit codes of different failure modes, counting up from 1

Expand Down
1 change: 1 addition & 0 deletions fortran/src/include/constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module constants
integer, parameter :: ERROR_ANSWER_TYPE_MISMATCH = 3
integer, parameter :: ERROR_PRIME_ALLOCATE_FAILED = 4
integer, parameter :: ERROR_UTILS_ALLOCATE_FAILED = 5
integer, parameter :: ERROR_FILE_READ_FAILED = 6

! file/string sizes
integer, parameter :: DATA_MAX_NAME_SIZE = 32
Expand Down
12 changes: 8 additions & 4 deletions fortran/src/p0022.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ integer(i18t) function p0022() result(answer)
answer = 0
names = ''
unit = open_data_file(file_name)
read(unit, '(A)', IOSTAT=ios) contents
if (ios /= 0) then
stop -1
end if
do
read(unit, '(A)', IOSTAT=ios) contents
if (ios == -1) then
exit
elseif (ios /= 0)
stop ERROR_FILE_READ_FAILED
end if
end do
close(unit)
do j = 1, len_trim(contents)
select case (contents(j:j))
Expand Down

0 comments on commit 2189b4d

Please sign in to comment.