aboutsummaryrefslogtreecommitdiff
path: root/captain/special.f90
blob: 26f31e323ca0c19a8aa2d6ed30e342c845b56b01 (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
61
62
63
64
65
66
67
68
69
70
71
module special_filenames
implicit none

contains

    function get_special_full_filename(category, filename) result(res)
    use utilities, only: combine_paths
    use config
    implicit none
    
        character(*), intent(in)::category, filename
        character(len=:), pointer::res

        res => null()

        if(trim(category) == "releases") then
            allocate(character(len=(len_trim(release_dir)+len_trim(filename)+1)) :: res)
            call combine_paths(release_dir, filename, res)
        else if(trim(category) == "uploads") then
            allocate(character(len=(len_trim(release_dir)+len_trim(filename)+1)) :: res)
            call combine_paths(release_dir, filename, res)
        else if(trim(category) == "results") then
            allocate(character(len=(len_trim(results_dir)+len_trim(filename)+1)) :: res)
            call combine_paths(results_dir, filename, res)
        else if(trim(category) == "static") then
            allocate(character(len=(len_trim(static_dir)+len_trim(filename)+1)) :: res)
            call combine_paths(static_dir, filename, res)
        else if(trim(category) == "favicon.txt") then
            allocate(character(len=(len_trim(static_dir)+len_trim(filename)+1)) :: res)
            call combine_paths(static_dir, filename, res)
        else if(trim(category) == "instructions") then
            allocate(character(len=(len_trim(instructions_dir)+len_trim(filename)+1)) :: res)
            call combine_paths(instructions_dir, filename, res)
        end if
        
    end function get_special_full_filename
    
    function get_instructions_static_filename(instruction_id) result(res)
    use captain_db
    implicit none
    
        integer, intent(in)::instruction_id
        character(len=:), pointer::res
        
        character(PLAYER_NAME_LENGTH)::instruction_name
        
        call get_instruction_name(instruction_id, instruction_name)
        
        res => get_special_full_filename("instructions", trim(instruction_name)//".json")
        
    end function get_instructions_static_filename
    
    function get_task_result_static_filename(job_id, task_num) result(res)
    use config
    implicit none
    
        integer, intent(in)::job_id, task_num
        character(len=:), pointer::res
        character(64)::filename
        
        character(12)::job_text, task_text
        
        write(job_text, '(I8)') job_id
        write(task_text, '(I8)') task_num
        filename = "results-job"//trim(adjustl(job_text))//"-task"//trim(adjustl(task_text))//".txt"
    
        res => get_special_full_filename("results", filename)
        
    end function get_task_result_static_filename
    
end module special_filenames