OSDN Git Service

cb8ae3276dc899fa1db9c15b88aec14b808e46f5
[jnethack/source.git] / sys / vms / install.com
1 $ ! vms/install.com -- set up nethack 'playground'
2 $! $NHDT-Date: 1524689428 2018/04/25 20:50:28 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.10 $
3 $! Copyright (c) 2016 by Robert Patrick Rankin
4 $! NetHack may be freely redistributed.  See license for details.
5 $ !
6 $ ! $NHDT-Date: 1524689428 2018/04/25 20:50:28 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.10 $
7 $ !
8 $ ! Use vmsbuild.com to create nethack.exe, makedefs, and lev_comp *first*.
9 $ !
10 $ ! Note: this command procedure is also used by the top level Makefile
11 $ ! if you build and install with MMS or MMK.  In that situation, only the
12 $ ! Makefile will need any editing.
13 $ !
14 $ ! Edit this file to define gamedir & gameuic, or else invoke it with two
15 $ ! command line parameters, as in:
16 $ !     @[.sys.vms]install "disk$users:[games.nethack]" "games"
17 $ ! or  @[.sys.vms]install "[-.play]" "[40,1]"
18 $ !
19 $       ! default location is old playground, default owner is installer
20 $       gamedir = f$trnlnm("NETHACKDIR")        !location of playground
21 $       if gamedir.eqs."" then  gamedir = f$trnlnm("HACKDIR")
22 $       gameuic = f$user()                      !owner of playground
23 $       ! --- nothing below this line should need to be changed ---
24 $       if p1.nes."" then  gamedir := 'p1'
25 $       if p2.nes."" then  gameuic := 'p2'
26 $
27 $       ! note: all filespecs contain some punctuation,
28 $       !       to avoid inadvertent logical name interaction
29 $       play_files = "PERM.,RECORD.,LOGFILE.,PANICLOG."
30 $       help_files = "HELP.,HH.,CMDHELP.,KEYHELP.,WIZHELP.,OPTHELP.," -
31                    + "HISTORY.,LICENSE."
32 $       data_files = "DATA.,RUMORS.,ORACLES.,OPTIONS.,QUEST.DAT,TRIBUTE."
33 $       sysconf_file = "[.sys.vms]sysconf"
34 $       guidebook  = "[.doc]Guidebook.txt"
35 $       invoc_proc = "[.sys.vms]nethack.com"
36 $       trmcp_file = "[.sys.share]termcap"
37 $       spec_files = "AIR.LEV,ASMODEUS.LEV,ASTRAL.LEV,BAALZ.LEV,BIGRM-%.LEV," -
38                    + "CASTLE.LEV,EARTH.LEV,FAKEWIZ%.LEV,FIRE.LEV," -
39                    + "JUIBLEX.LEV,KNOX.LEV,MEDUSA-%.LEV,MINEFILL.LEV," -
40                    + "MINETN-%.LEV,MINEND-%.LEV,ORACLE.LEV,ORCUS.LEV," -
41                    + "SANCTUM.LEV,SOKO%-%.LEV,TOWER%.LEV,VALLEY.LEV," -
42                    + "WATER.LEV,WIZARD%.LEV"
43 $       spec_input = "bigroom.des castle.des endgame.des " -
44                    + "gehennom.des knox.des medusa.des mines.des " -
45                    + "oracle.des sokoban.des tower.des yendor.des"
46 $       qstl_files = "%%%-GOAL.LEV,%%%-FIL%.LEV,%%%-LOCA.LEV,%%%-STRT.LEV"
47 $       qstl_input = "Arch.des Barb.des Caveman.des Healer.des " -
48                    + "Knight.des Monk.des Priest.des Ranger.des Rogue.des " -
49                    + "Samurai.des Tourist.des Wizard.des Valkyrie.des"
50 $       dngn_files = "DUNGEON."
51 $       dngn_input = "dungeon.pdf"
52 $       dlb_files  = help_files + "," + data_files + "," -
53                    + spec_files + "," + qstl_files + "," + dngn_files
54 $       data_libry = "nh-data.dlb"
55 $       xtrn_files = "LICENSE.,HISTORY.,OPTIONS.,SYMBOLS."
56 $ makedefs := $sys$disk:[-.util]makedefs
57 $ lev_comp := $sys$disk:[-.util]lev_comp
58 $ dgn_comp := $sys$disk:[-.util]dgn_comp
59 $ dlb      := $sys$disk:[-.util]dlb
60 $ milestone = "write sys$output f$fao("" !5%T "",0),"
61 $ if p3.nes."" .and. f$edit(p4,"UPCASE").nes."VERBOSE" then  milestone = "!"
62 $ echo = "write sys$output"
63 $ warn = echo   !could be "write sys$error"
64 $!
65 $! make sure we've got a playground location
66 $ gamedir := 'gamedir'
67 $ if gamedir.eqs."" then  gamedir = "[.play]"   !last ditch default
68 $ gamedir = f$parse(gamedir,,,,"SYNTAX_ONLY") - ".;"
69 $ if gamedir.eqs."" then  write sys$error "% must specify playground directory"
70 $ if gamedir.eqs."" then  exit %x1000002C       !ss$_abort
71 $
72 $!
73 $!      ['p3' is used in Makefile.top]
74 $ if p3.nes."" then  goto make_'p3'
75 $
76 $       milestone "<installation...>"
77 $!
78 $make_data_plus_dlb:
79 $make_data:
80 $       ! start from a known location -- [.sys.vms]
81 $       set default 'f$parse(f$environment("PROCEDURE"),,,"DIRECTORY")'
82 $! generate miscellaneous data files
83 $       set default [-.-.dat]   !move to data directory
84 $       milestone "(data)"
85 $ makedefs -d   !data.base -> data
86 $       milestone "(rumors)"
87 $ makedefs -r   !rumors.tru + rumors.fal -> rumors
88 $       milestone "(oracles)"
89 $ makedefs -h   !oracles.txt -> oracles
90 $       milestone "(dungeon preprocess)"
91 $ makedefs -e   !dungeon.def -> dungeon.pdf
92 $       milestone "(quest text)"
93 $ makedefs -q   !quest.txt -> quest.dat
94 $       milestone "(special levels)"
95 $ lev_comp 'spec_input' !special levels
96 $       milestone "(quest levels)"
97 $ lev_comp 'qstl_input' !quest levels
98 $       milestone "(dungeon compile)"
99 $ dgn_comp 'dngn_input' !dungeon database
100 $       set default [-]         !move up
101 $ if p3.nes."" .and. f$edit(p3,"UPCASE").nes."DATA_PLUS_DLB" then  exit
102 $
103 $make_dlb:
104 $       ! start from a known location -- [.sys.vms]
105 $       set default 'f$parse(f$environment("PROCEDURE"),,,"DIRECTORY")'
106 $! construct data library
107 $       set default [-.-.dat]   !move to data directory
108 $       milestone "(dlb setup)"
109 $! since DLB doesn't support wildcard expansion and we don't have shell
110 $! file globbing, start by making a file listing its intended contents
111 $ create nhdat.lst
112 $       if f$search("nhdat.lst;-1").nes."" then -
113                 purge/noConfirm/noLog nhdat.lst
114 $! an old data file might fool us later, so get rid of it
115 $       if f$search(data_libry).nes."" then -
116                 delete/noConfirm/noLog 'data_libry';*
117 $       if f$trnlnm("PFILE$").nes."" then  close/noLog pfile$
118 $ open/Append pfile$ nhdat.lst
119 $ i = 0
120 $dloop:
121 $   g = f$element(i,",",dlb_files)
122 $   if g.eqs."," then  goto ddone
123 $   wild = f$locate("*",g).ne.f$locate("%",g)
124 $   fcnt = 0
125 $floop:
126 $       f = f$search(g)
127 $       if f.eqs."" then  goto fdone
128 $       fcnt = fcnt + 1
129 $! strip device, directory, and version from name
130 $       f = f$parse(f,,,"NAME") + f$parse(f,,,"TYPE")
131 $! strip trailing dot, if present, and change case
132 $       f = f$edit(f + "#" - ".#" - "#","LOWERCASE")
133 $       if f$extract(3,1,f).eqs."-" then -      !"xyz-foo.lev" -> "Xyz-foo.lev"
134                 f = f$edit(f$extract(0,1,f),"UPCASE") + f$extract(1,255,f)
135 $       write pfile$ f
136 $       if wild then  goto floop
137 $fdone:
138 $   if fcnt.eq.0 then  warn "? no file(s) found for """,g,""""
139 $   i = i + 1
140 $   goto dloop
141 $ddone:
142 $ close pfile$
143 $       milestone "(dlb create)"
144 $ dlb "-cfI" 'data_libry' nhdat.lst
145 $       set default [-]         !move up
146 $ if p3.nes."" then  exit
147 $
148 $!
149 $! set up the playground and save directories
150 $       milestone "(directories)"
151 $make_directories:
152 $       srctree = f$environment("DEFAULT")
153 $       set default 'gamedir'
154 $ if f$parse("[-]").eqs."" then  create/dir/log [-] !default owner & protection
155 $ if f$parse("[]" ).eqs."" then - !needs to be world writable
156    create/directory/owner='gameuic'/prot=(s:rwe,o:rwe,g:rwe,w:rwe)/log []
157 $ if f$search("SAVE.DIR;1").eqs."" then -
158    create/directory/owner='gameuic'/prot=(s:rwe,o:rwe,g:rwe,w:rwe)/log -
159         [.SAVE]/version_limit=2
160 $       set default 'srctree'
161 $ if p3.nes."" then  exit
162 $!
163 $! create empty writeable files -- logfile, scoreboard, multi-user access lock
164 $! [if old versions are already present, validate and retain them if possible]
165 $make_writeable_files:
166 $       milestone "(writeable files)"
167 !-!$ create/owner='gameuic'/prot=(s:rwed,o:rwed,g:rwed,w:rwed) -
168 !-!     'gamedir''play_files'
169 $       i = 0
170 $ploop: if f$trnlnm("PFILE$").nes."" then  close/nolog pfile$
171 $       f = f$element(i,",",play_files)
172 $       if f.eqs."," then  goto pdone
173 $       i = i + 1
174 $       f = gamedir + f
175 $       if f$search(f).eqs."" then  goto pmake  !make it if not found
176 $       if f$file_attrib(f,"RFM").nes."STMLF" then  goto prej !must be stream_lf
177 $       open/read/error=prej pfile$ 'f'
178 $       read/end=ploop pfile$ pline     !empty is ok
179 $       close pfile$
180 $       pfield = f$element(0," ",pline) !1st field is version number
181 $       if f$locate(".",pfield).lt.f$length(pfield) then  goto ploop    !keep
182 $prej:  rename/new_vers 'f' *.old       !reject old version
183 $pmake: create/fdl=sys$input:/owner='gameuic' 'f'/log
184 file
185  organization sequential
186  protection (system:rwd,owner:rwd,group:rw,world:rw)
187 record
188  format stream_lf
189 $       goto ploop
190 $pdone:
191 $ if p3.nes."" then  exit
192 $!
193 $! copy over the remaining game files, then make them readonly
194 $make_readonly_files:
195 $       milestone "(readonly files)"
196 $ if f$search("[.dat]''data_libry'").nes.""
197 $ then  call copyfiles 'f$string(data_libry+","+xtrn_files)' [.dat] "r"
198 $ else  !'dlb_files' is too long for a single command
199 $       k = 200 + f$locate(",",f$extract(200,999,dlb_files))
200 $       call copyfiles 'f$extract(0,k,dlb_files)' [.dat] "r"
201 $       call copyfiles 'f$extract(k+1,999,dlb_files)' [.dat] "r"
202 $ endif
203 $ if p3.nes."" then  exit
204 $!
205 $make_executable:
206 $       milestone "(nethack.exe)"
207 $ call copy_file [.src]nethack.exe 'gamedir'nethack.exe "re"
208 $ if p3.nes."" then  exit
209 $!
210 $! provide invocation procedure (if available)
211 $make_procedure:
212 $ if f$search(invoc_proc).eqs."" then  goto skip_dcl
213 $ if f$search("''gamedir'nethack.com").nes."" then -
214     if f$cvtime(f$file_attr("''gamedir'nethack.com","RDT")) -
215       .ges. f$cvtime(f$file_attr(invoc_proc,"RDT")) then  goto skip_dcl
216 $       milestone "(nethack.com)"
217 $ call copy_file 'invoc_proc' 'gamedir'nethack.com "re"
218 $skip_dcl:
219 $ if p3.nes."" then  exit
220 $!
221 $! provide plain-text Guidebook doc file (if available)
222 $make_documentation:
223 $ if f$search(guidebook).eqs."" then  goto skip_doc
224 $       milestone "(Guidebook)"
225 $ call copy_file 'guidebook' 'gamedir'Guidebook.doc "r"
226 $skip_doc:
227 $ if p3.nes."" then  exit
228 $!
229 $! provide last-resort termcap file (if available)
230 $make_termcap:
231 $ if f$search(trmcp_file).eqs."" then  goto skip_termcap
232 $ if f$search("''gamedir'termcap").nes."" then  goto skip_termcap
233 $       milestone "(termcap)"
234 $ call copy_file 'trmcp_file' 'gamedir'termcap "r"
235 $skip_termcap:
236 $ if p3.nes."" then  exit
237 $!
238 $! provide template sysconf file (needed if nethack is built w/ SYSCF enabled)
239 $make_sysconf:
240 $ if f$search(sysconf_file).eqs."" then  goto skip_sysconf
241 $ if f$search("''gamedir'sysconf_file").nes."" then  goto skip_sysconf
242 $       milestone "(sysconf)"
243 $ call copy_file 'sysconf_file' 'gamedir'sysconf "r"
244 $!      owner should be able to manually edit sysconf; others shouldn't
245 $ set file/Prot=(s:rwd,o:rwd,g:r,w:r) 'gamedir'sysconf
246 $skip_sysconf:
247 $ if p3.nes."" then  exit
248 $!
249 $! done
250 $       milestone "<done>"
251 $ define/nolog nethackdir 'gamedir'
252 $ define/nolog hackdir 'gamedir'
253 $ echo -
254     f$fao("!/ Nethack installation complete. !/ Playground is !AS !/",gamedir)
255 $ exit
256 $
257 $!
258 $! copy one file, resetting the protection on an earlier version first
259 $copy_file: subroutine
260 $ if f$search(p2).nes."" then  set file/Prot=(s:rwed,o:rwed) 'p2'
261 $ copy/Prot=(s:'p3'wd,o:'p3'wd,g:'p3',w:'p3') 'p1' 'p2'
262 $ set file/Owner='gameuic'/Prot=(s:'p3',o:'p3') 'p2'
263 $endsubroutine !copy_file
264 $
265 $!
266 $! copy a comma-separated list of wildcarded files, one file at a time
267 $copyfiles: subroutine
268 $ i = 0
269 $lloop:
270 $   g = f$element(i,",",p1)
271 $   if g.eqs."," then  goto ldone
272 $   g = p2 + g
273 $   wild = f$locate("*",g).ne.f$locate("%",g)
274 $   fcnt = 0
275 $eloop:
276 $       f = f$search(g)
277 $       if f.eqs."" then  goto edone
278 $       fcnt = fcnt + 1
279 $       f = f - f$parse(f,,,"VERSION")
280 $       e = f$parse(f,,,"NAME") + f$parse(f,,,"TYPE")
281 $       call copy_file 'f' 'gamedir''e' "''p3'"
282 $       if wild then  goto eloop
283 $edone:
284 $   if fcnt.eq.0 then  warn "? no file(s) found for """,g,""""
285 $   i = i + 1
286 $   goto lloop
287 $ldone:
288 $endsubroutine !copyfiles
289 $
290 $!<eof>