aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-05-06 17:42:40 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-05-06 17:42:40 -0400
commit09a2a56e22ce36238dce94f927f1909b63493960 (patch)
tree2a1f9c7c5287553bf29b67d86661eaede5783eb5
parent9c957c4a0964ee1f5b0ff582543b9f526978c47e (diff)
downloadLR-87-09a2a56e22ce36238dce94f927f1909b63493960.tar.gz
LR-87-09a2a56e22ce36238dce94f927f1909b63493960.zip
File type is now returned for evaluation. Initial routines for saving implemented but unused.
-rw-r--r--dumb_render.f9021
-rw-r--r--main.F9024
-rw-r--r--protocol.f9044
-rw-r--r--render.f9034
4 files changed, 113 insertions, 10 deletions
diff --git a/dumb_render.f90 b/dumb_render.f90
index 7ff4e6d..c3b49a1 100644
--- a/dumb_render.f90
+++ b/dumb_render.f90
@@ -44,6 +44,8 @@ implicit none
procedure :: request_action => dumb_action
+ procedure :: request_save_filename => dumb_request_save_filename
+
end type dumb_renderer
contains
@@ -309,8 +311,25 @@ contains
end if
end if
-
end function dumb_action
+ function dumb_request_save_filename(self, url, mimetype, filename)
+ implicit none
+
+ class(dumb_renderer)::self
+ character(*), intent(in)::url
+ character(*), intent(in)::mimetype
+ character(*), intent(out)::filename
+ logical::dumb_request_save_filename
+
+ Print *, "*** Response type is "//trim(mimetype)
+ Write(*, '(1X, A26)', advance='no') "*** Save file as: "
+
+ Read(*, *) filename
+
+ dumb_request_save_filename = (len_trim(filename) > 0)
+
+ end function dumb_request_save_filename
+
end module dumb_render \ No newline at end of file
diff --git a/main.F90 b/main.F90
index 7b2319d..13ff29a 100644
--- a/main.F90
+++ b/main.F90
@@ -22,6 +22,7 @@ implicit none
logical::populated
integer::return_code
+ character(256)::return_type
integer, parameter::io = 100
@@ -77,7 +78,7 @@ implicit none
call r%report_status("Requesting "//trim(current_url))
- return_code = request_url(current_url, io)
+ return_code = request_url(current_url, io, return_type)
populated = .true.
call update_status(r, current_url, return_code)
@@ -103,12 +104,21 @@ implicit none
locations_visited => add_location(locations_visited, current_url)
- first_line => load_unit(io, file_type_gemini)
- loaded = .true.
- call r%new_page()
- call r%report_status("Performing Layout")
- call layout_lines(first_line, r)
-
+ if(r%type_supported(return_type)) then
+
+ first_line => load_unit(io, file_type_gemini)
+ loaded = .true.
+ call r%new_page()
+ call r%report_status("Performing Layout")
+ call layout_lines(first_line, r)
+
+ else
+
+ call r%draw_error("Cannot display file of type "//return_type)
+ call back_location(locations_visited, current_url)
+
+ end if
+
end if
do while(loaded .and. running)
diff --git a/protocol.f90 b/protocol.f90
index 76fb8d4..194e0e7 100644
--- a/protocol.f90
+++ b/protocol.f90
@@ -14,7 +14,44 @@ implicit none
contains
- function request_url(url, unit_number, server_name) result(returncode)
+ subroutine read_mimetype(unit_number, return_type)
+ implicit none
+ integer, intent(in)::unit_number
+ character(*), intent(out)::return_type
+
+ character::c
+ integer::iostatus, i
+
+ return_type = " "
+
+ ! Advance past status and space
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ do while(c /= " " .and. c /= char(9) .and. iostatus == 0)
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ end do
+ do while((c == " " .or. c == char(9)) .and. iostatus == 0)
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ end do
+
+ if(iostatus == 0) then
+ ! c now contains the first entry of the mimetype
+ i = 0
+ do while(iostatus == 0)
+ i = i + 1
+ return_type(i:i) = c
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ end do
+
+ end if
+
+ ! Default
+ if(len_trim(return_type) == 0) then
+ return_type = "text/gemini"
+ end if
+
+ end subroutine read_mimetype
+
+ function request_url(url, unit_number, return_type, server_name) result(returncode)
use request
use iso_c_binding
use file_handling, only: mark_file_end
@@ -22,6 +59,7 @@ contains
character(*), intent(inout)::url
integer, intent(in)::unit_number
+ character(*), intent(out)::return_type
character(*), intent(in), optional::server_name
integer::returncode
@@ -64,9 +102,11 @@ contains
call mark_file_end(unit_number)
rewind(unit_number)
- read(unit_number, '(I1)', iostat=iostatus) returncode
+ read(unit_number, '(I1)', iostat=iostatus, advance='no') returncode
if(iostatus /= 0) then
returncode = STATUS_BADRESPONSE
+ else
+ call read_mimetype(unit_number, return_type)
end if
else
diff --git a/render.f90 b/render.f90
index 578948c..0045c22 100644
--- a/render.f90
+++ b/render.f90
@@ -7,6 +7,10 @@ implicit none
integer, parameter::render_action_back = 4
integer, parameter::render_action_quit = 5
+ character(11), dimension(2)::base_supported_types = &
+ ["text/plain ", &
+ "text/gemini" ]
+
type, abstract :: renderer
integer::y
@@ -15,6 +19,7 @@ implicit none
contains
procedure::render_proportional
+ procedure::type_supported
procedure(initialize), deferred::initialize
procedure(prepare_for_layout), deferred::prepare_for_layout
@@ -128,8 +133,37 @@ implicit none
end function request_action
end interface
+ abstract interface
+ function request_save_filename(self, url, mimetype, filename)
+ import::renderer
+ class(renderer)::self
+ character(*), intent(in)::url
+ character(*), intent(in)::mimetype
+ character(*), intent(out)::filename
+ logical::request_save_filename
+ end function request_save_filename
+ end interface
+
contains
+ function type_supported(self, mimetype)
+ implicit none
+
+ class(renderer)::self
+ character(*), intent(in)::mimetype
+ logical::type_supported
+ integer::i
+
+ type_supported = .false.
+ do i = 1, size(base_supported_types)
+ if(trim(mimetype) == trim(base_supported_types(i))) then
+ type_supported = .true.
+ exit
+ end if
+ end do
+
+ end function type_supported
+
function width_of_line(r, text, startpos, endpos)
implicit none