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