aboutsummaryrefslogtreecommitdiff
path: root/test.f90
blob: df42126f820253a7ef47bfd386efdb79da0d3999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
program test_render
use file_handling
use layout
use dumb_render
implicit none

    character(256)::path, arg
    integer::i

    type(line), pointer::first_line
    integer::iostatus
    character(32)::mime
    
    type(dumb_renderer)::r

    if(command_argument_count() < 1) then
        call usage()
        stop 0
    end if
    
    mime = "text/plain"
    
    do i = 1, command_argument_count()
        call get_command_argument(i, arg)
        if(trim(arg) == "-g") then
            mime = "text/gemini"
        else if(arg(1:1) == "-") then
            Print *, "Unknown option: "//trim(arg)
            Print *, " "
            call usage()
            stop 0
        else
            path = arg
        end if
    end do
          
    first_line => load_filename(trim(path), iostatus, mime)
    if(iostatus == 0) then
        call r%initialize()
        call layout_lines(first_line, r)
    else
        Print *, "Error occurred while loading "//trim(path)
    end if
            
    contains
    
    subroutine usage()
    implicit none

        character(256)::exe
                
        call get_command_argument(0, exe)
        Print *, "Usage: "//trim(exe)//" [-g] <file to load>"
        Print *, " "
        Print *, "    -g    Treat file as text/gemini"
        Print *, " "
        
    end subroutine usage
    
end program test_render