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
|
program fortran_fcgi
use fcgi_protocol
implicit none
type(DICT_STRUCT), pointer :: dict => null()
integer :: unitNo ! unit number for a scratch file
unitNo = getpid() ! use process ID as unit number
open (unit=unitNo, status='scratch')
do while (fcgip_accept_environment_variables() >= 0)
call fcgip_make_dictionary(dict, unitNo)
call respond(dict, unitNo)
call fcgip_put_file(unitNo)
end do
close (unitNo)
contains
subroutine respond(dict, unitNo)
type(DICT_STRUCT), pointer, intent(in) :: dict
integer, intent(in) :: unitNo
character(len=80) :: scriptName
write (unitNo, '(a)') &
'<!DOCTYPE html>', &
'<html lang="en">', &
'<head><meta charset="utf-8" />', &
'<title>Fortran FastCGI</title></head>', &
'<body>', &
'<h1>Fortran FastCGI</h1>'
call cgi_get(dict, 'DOCUMENT_URI', scriptName)
select case (trim(scriptName))
case ('/foo')
write (unitNo, '(a)') '<p>foo</p>'
end select
write (unitNo, '(a)') '</body>', '</html>'
end subroutine respond
end program fortran_fcgi
|