aboutsummaryrefslogtreecommitdiff
path: root/player/main.F90
blob: 127a8f755a39a3358d1908ec192003721a905627 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
program player
use config
implicit none

    character(len=1024)::option

    integer::slen
    integer::i
    
    identity = " "
    
    i = 1
    do while(i <= command_argument_count())
        call get_command_argument(i, option)
    
        if(option(1:1) /= "-") then
            captain = option
    
        else if(trim(option) == "-h") then
            call usage()
            stop
        
        else if(trim(option) == "-w") then
            i = i + 1
            call get_command_argument(i, length=slen)
            allocate(character(len=slen) :: working_directory)
            call get_command_argument(i, working_directory)
            
        else if(trim(option) == "-l") then
            i = i + 1
            call get_command_argument(i, length=slen)
            allocate(character(len=slen) :: logfile)
            call get_command_argument(i, logfile)
            
        else if(trim(option) == "-i") then
            i = i + 1
            call get_command_argument(i, identity)
            
        end if
        
        i = i + 1
    end do
    
    ! Assign working directory from command if not specified
    if(.not. associated(working_directory)) then
        call get_command_argument(0, length=slen)
        allocate(character(len=slen) :: working_directory)
        call get_command_argument(i, working_directory)
        i = index(working_directory, "/", back=.true.)
        if(i == 0) then
            i = index(working_directory, "/", back=.true.)
        endif
        if(i == 0) then
            Print *, "Could not determine working_directory"
            stop
        else
            working_directory(i:slen) = ' '
        end if
    end if
    
    ! Assign a temporary directory and file for a log file
    ! NOTE: will fail on Windows
    if(.not. associated(logfile)) then
        allocate(character(len=256) :: logfile)
        logfile = "/tmp/levitating.log"
    end if
    
    ! Assign this computer an identity if not explicitly specified
    if(len_trim(identity) == 0) then
#ifdef GNU
        call hostnm(identity)
#else
        Print *, "Could not determine host identity"
        stop
#endif
    end if
    
    ! Change directory to the working directory now
    call chdir(working_directory)
    
    do while(.true.)
    
        
    
    end do
    
contains

    subroutine usage()
    implicit none
    
        character(len=256)::pname
        
        call get_command_argument(0, pname)
    
        Print *, "Usage: "//trim(pname)//" <options> <captain>"
        Print *, " "
        Print *, "captain is the build control server"
        Print *, " "
        
        Print *, "Options:"
        Print *, "    -h            Display this help"
        Print *, "    -w <dir>      Use dir as the working directory"
        Print *, "    -l <log>      Use log as the logfile"
        Print *, "    -i <identity> This players identity"
        
    end subroutine usage
    
end program player