BSD 4_3 release
[unix-history] / usr / src / usr.lib / libU77 / ioinit.f
CommitLineData
d97d324a 1C
161423a6
RE
2C Copyright (c) 1980 Regents of the University of California.
3C All rights reserved. The Berkeley software License Agreement
4C specifies the terms and conditions for redistribution.
5C
95f51977 6C @(#)ioinit.f 5.1 (Berkeley) 6/8/85
161423a6
RE
7C
8C
d97d324a 9C ioinit - initialize the I/O system
161423a6 10C
d97d324a 11C synopsis:
fa0a061b
DW
12C logical function ioinit (cctl, bzro, apnd, prefix, vrbose)
13C logical cctl, bzro, apnd, vrbose
d97d324a
DW
14C character*(*) prefix
15C
16C where:
fa0a061b
DW
17C cctl is .true. to turn on fortran-66 carriage control
18C bzro is .true. to cause blank space to be zero on input
19C apnd is .true. to open files at their end
d97d324a
DW
20C prefix is a string defining environment variables to
21C be used to initialize logical units.
22C vrbose is .true. if the caller wants output showing the lu association
23C
24C returns:
25C .true. if all went well
26C
27C David L. Wasley
28C U.C.Bekeley
29C
fa0a061b
DW
30 logical function ioinit (cctl, bzro, apnd, prefix, vrbose)
31 logical cctl, bzro, apnd, vrbose
d97d324a
DW
32 character*(*) prefix
33
fa0a061b 34 automatic iok, fenv, ienv, ename, fname, form, blank
a0d2d119 35 logical iok, fenv, ienv
ae7c4c0e 36 integer*2 ieof, ictl, izro
fa0a061b 37 character form, blank
d97d324a
DW
38 character*32 ename
39 character*256 fname
ae7c4c0e 40 common /ioiflg/ ieof, ictl, izro
d97d324a 41
fa0a061b
DW
42 if (cctl) then
43 ictl = 1
44 form = 'p'
d97d324a 45 else
fa0a061b
DW
46 ictl = 0
47 form = 'f'
d97d324a
DW
48 endif
49
fa0a061b
DW
50 if (bzro) then
51 izro = 1
52 blank = 'z'
d97d324a 53 else
fa0a061b
DW
54 izro = 0
55 blank = 'n'
56 endif
57
58 open (unit=5, form=form, blank=blank)
59 open (unit=6, form=form, blank=blank)
60
61 if (apnd) then
ae7c4c0e 62 ieof = 1
fa0a061b 63 else
ae7c4c0e 64 ieof = 0
d97d324a
DW
65 endif
66
67 iok = .true.
a0d2d119
DW
68 fenv = .false.
69 ienv = .false.
d97d324a
DW
70 lp = len (prefix)
71
72 if ((lp .gt. 0) .and. (lp .le. 30) .and. (prefix .ne. " ")) then
a0d2d119 73 ienv = .true.
d97d324a
DW
74 nb = index (prefix, " ")
75 if (nb .eq. 0) nb = lp + 1
76 ename = prefix
a0d2d119 77 if (vrbose) write (0, 2002) ename(:nb-1)
d97d324a
DW
78 do 200 lu = 0, 19
79 write (ename(nb:), "(i2.2)") lu
80 call getenv (ename, fname)
81 if (fname .eq. " ") go to 200
82
83 open (unit=lu, file=fname, form='f', access='s', err=100)
84 if (vrbose) write (0, 2000) lu, fname(:lnblnk(fname))
a0d2d119 85 fenv = .true.
d97d324a
DW
86 go to 200
87
a0d2d119 88 100 write (0, 2003) ename(:nb+1)
d97d324a
DW
89 call perror (fname(:lnblnk(fname)))
90 iok = .false.
91
92 200 continue
93 endif
94
95 if (vrbose) then
a0d2d119 96 if (ienv .and. (.not. fenv)) write (0, 2001) ename(:nb-1)
fa0a061b 97 write (0, 2004) cctl, bzro, apnd
d97d324a
DW
98 call flush (0)
99 endif
100
101 ioinit = iok
102 return
103
104 2000 format ('ioinit: logical unit ', i2,' opened to ', a)
a0d2d119
DW
105 2001 format ('ioinit: no initialization found for ', a)
106 2002 format ('ioinit: initializing from ', a, 'nn')
107 2003 format ('ioinit: ', a, ' ', $)
fa0a061b 108 2004 format ('ioinit: cctl=', l, ', bzro=', l, ', apnd=', l)
d97d324a 109 end