From 17623b0805ec074d8fb4aa026f97d8f4abfd0da1 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Thu, 21 May 2020 13:16:56 -0400 Subject: Added binary handler for windows gui. Fixed opening and writing of binary files so it works on windows too. Removed all tabs from link lines for simpler processing. --- ag_binary.f90 | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ dumb_binary.f90 | 5 ++-- files.f90 | 20 ++++++++++++-- gemini-windows.prj | 13 ++++++++-- main.F90 | 2 ++ protocol.f90 | 7 ++--- 6 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 ag_binary.f90 diff --git a/ag_binary.f90 b/ag_binary.f90 new file mode 100644 index 0000000..f96e212 --- /dev/null +++ b/ag_binary.f90 @@ -0,0 +1,76 @@ +! Copyright (c) 2020 Jeffrey Armstrong +! +! Permission is hereby granted, free of charge, to any person obtaining a copy +! of this software and associated documentation files (the "Software"), to deal +! in the Software without restriction, including without limitation the rights +! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +! copies of the Software, and to permit persons to whom the Software is +! furnished to do so, subject to the following conditions: +! +! The above copyright notice and this permission notice shall be included in +! all copies or substantial portions of the Software. +! +! The Software shall be used for Good, not Evil. +! +! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +! SOFTWARE. + +module ag_binary +use binary +implicit none + + type, extends(binary_handler) :: appgraphics_binary_handler + + contains + + procedure :: handle_binary => ag_handle_binary + + end type + +contains + + function ag_handle_binary(self, mimetype, url, iostatus) result(unit_number) + use appgraphics + implicit none + + class(appgraphics_binary_handler)::self + character(*), intent(in)::mimetype + character(*), intent(in)::url + integer, intent(out)::iostatus + integer::unit_number + + character(256)::filename + integer::i, istatus + + iostatus = binary_ignore + + if(dlgyesno(DIALOG_INFO, "Binary file encountered. Would you like to save?")) then + + filename = ' ' + i = index(url, '/', back=.true.) + if(i > 0) then + filename = url(i+1:len_trim(url)) + end if + + if(dlgsavefile(filename)) then + unit_number = 0 + + open(newunit=unit_number, file=trim(filename), status='UNKNOWN', & + access='STREAM', form='UNFORMATTED', iostat=istatus) + if(istatus /= 0) then + iostatus = binary_error + else + iostatus = binary_okay + end if + end if + + end if + + end function ag_handle_binary + +end module ag_binary diff --git a/dumb_binary.f90 b/dumb_binary.f90 index f12bb66..b144eb7 100644 --- a/dumb_binary.f90 +++ b/dumb_binary.f90 @@ -35,7 +35,8 @@ implicit none contains function dumb_handle_binary(self, mimetype, url, iostatus) result(unit_number) - + implicit none + class(dumb_binary_handler)::self character(*), intent(in)::mimetype character(*), intent(in)::url @@ -78,7 +79,7 @@ contains unit_number = 0 open(newunit=unit_number, file=trim(filename), status='UNKNOWN', & - access='STREAM', form='FORMATTED', iostat=istatus) + access='STREAM', form='UNFORMATTED', iostat=istatus) if(istatus /= 0) then iostatus = binary_error else diff --git a/files.f90 b/files.f90 index 85eddb1..b9f6d5a 100644 --- a/files.f90 +++ b/files.f90 @@ -33,7 +33,7 @@ contains implicit none integer, intent(in)::unit_number - + Write(unit_number, '(A1)', advance='no') new_line('a') Write(unit_number, '(A17)') end_indicator end subroutine mark_file_end @@ -91,6 +91,20 @@ contains end subroutine read_line_text + subroutine replace_tabs(text) + implicit none + + character(*), intent(inout)::text + integer::i + + i = index(text, char(9)) + do while(i > 0) + text(i:i) = ' ' + i = index(text, char(9)) + end do + + end subroutine replace_tabs + subroutine process_line(single_line, file_type, preformatted_on) use layout implicit none @@ -110,10 +124,12 @@ contains line_length = len_trim(single_line%text) - if(line_length > 2 .AND. single_line%text(1:2) == "=>") then + if((.not. preformatted_on) .AND. line_length > 2 .AND. & + single_line%text(1:2) == "=>") then single_line%line_type = line_type_link single_line%text(1:2) = " " + call replace_tabs(single_line%text) single_line%text = adjustl(single_line%text) else if(line_length >= 3 .AND. single_line%text(1:3) == "```") then diff --git a/gemini-windows.prj b/gemini-windows.prj index 539171e..ad734ad 100644 --- a/gemini-windows.prj +++ b/gemini-windows.prj @@ -29,8 +29,17 @@ }], "Name":"+gemini-windows (lr87.exe)", "Files":[{ + "filename":".\\ag_binary.f90", + "enabled":"1" + },{ "filename":".\\ag_render.f90", "enabled":"1" + },{ + "filename":".\\binary.f90", + "enabled":"1" + },{ + "filename":".\\dumb_binary.f90", + "enabled":"1" },{ "filename":".\\dumb_render.f90", "enabled":"1" @@ -105,8 +114,8 @@ "Working Directory":"", "Launch Using MPI":"false", "Keep Console":"true", - "External Console":"true", - "Command Line Arguments":"gemini.conman.org", + "External Console":"false", + "Command Line Arguments":"", "Build Before Launch":"true" }, "Build Options":{ diff --git a/main.F90 b/main.F90 index af4a29d..24cecfc 100644 --- a/main.F90 +++ b/main.F90 @@ -25,6 +25,7 @@ use request #ifdef WINDOWS_GUI use ag_render, only: appgraphics_renderer +use ag_binary, only: appgraphics_binary_handler #else use dumb_render use dumb_binary @@ -49,6 +50,7 @@ implicit none #ifdef WINDOWS_GUI type(appgraphics_renderer)::r + type(appgraphics_binary_handler)::bh #else type(dumb_renderer)::r type(dumb_binary_handler)::bh diff --git a/protocol.f90 b/protocol.f90 index 881314b..49d8fc5 100644 --- a/protocol.f90 +++ b/protocol.f90 @@ -182,13 +182,14 @@ contains end do write(unit_number, '(A2)', advance='no') char(13)//char(10) + end if end if else if(binary_file .and. binary_status == binary_okay) then - write(binary_unit, '(A1)', advance='no') buffer(i) + write(binary_unit) buffer(i) else if(.not. binary_file) then @@ -206,9 +207,9 @@ contains if(binary_status == binary_okay) then close(binary_unit) - write(unit_number, *) "Binary file completed" + write(unit_number, *) new_line('a')//"Binary file completed" else - write(unit_number, *) "Binary file ignored" + write(unit_number, *) new_line('a')//"Binary file ignored" end if ! For now, just reset to gemini -- cgit v1.2.3