Fix not reading file correctly

This commit is contained in:
Rasmus Rasmussen 2025-01-24 18:49:27 +01:00
parent cfcd98a239
commit 666aab275c
3 changed files with 11 additions and 8 deletions

View File

@ -1,5 +1,5 @@
program main program main
use WebServer, only: get_progress !use WebServer, only: get_progress
use FileReader, only: read_file use FileReader, only: read_file
use Greeter, only: say_hello use Greeter, only: say_hello
@ -8,6 +8,6 @@ program main
character, allocatable :: Data character, allocatable :: Data
call say_hello() call say_hello()
call get_progress() !call get_progress()
call read_file("/home/skingging/Documents/Projects/Fortran/Web-Server-In-Fortran/html/index.html", Data) call read_file("/home/skingging/Documents/Projects/Fortran/Web-Server-In-Fortran/html/index.html", Data)
end program main end program main

View File

@ -1,5 +1,5 @@
module FileReader module FileReader
!implicit none implicit none
public :: read_file public :: read_file
contains contains
@ -10,8 +10,8 @@ module FileReader
logical :: res logical :: res
character (len=*), intent (in) :: FileName character (len=*), intent (in) :: FileName
character (len=*), allocatable, intent (out) :: Data character (len=*), allocatable, intent (out) :: Data
character(len=:), allocatable :: TempData character (len=:), allocatable :: TempData
character(len=256) :: LineBuffer character (len=256) :: LineBuffer
inquire( file=trim(FileName), exist=res ) inquire( file=trim(FileName), exist=res )
@ -26,10 +26,8 @@ module FileReader
allocate(character(len=0) :: TempData) ! Start with an empty string allocate(character(len=0) :: TempData) ! Start with an empty string
read(io, *, iostat=iostat)
do do
read(io, *, IOSTAT=iostat) LineBuffer read(io, '(A)', IOSTAT=iostat) LineBuffer
if (iostat /= 0) exit ! Exit loop on end-of-file or error if (iostat /= 0) exit ! Exit loop on end-of-file or error
! Append the current line to TempData. CHAR(10) is a newline ! Append the current line to TempData. CHAR(10) is a newline

View File

@ -7,6 +7,11 @@ module WebServer
public :: get_progress public :: get_progress
contains contains
! https://github.com/modern-fortran/tcp-client-server/blob/master/server.f90
subroutine get_progress subroutine get_progress
! Send a GET request to retrieve JSON data ! Send a GET request to retrieve JSON data
response = request(url='https://proxy.rbwr.dk/progress') response = request(url='https://proxy.rbwr.dk/progress')