DOS Environment Variables
Vector 5:4, page 95
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 95
Passing bits of information from DOS into your APL application can be done in many devious ways. The least useful is probably the X,Y,Z startup options, which give you the possibility of just three integers! Another approach is to have a standard ASCII file (not a .ASF like APLLIBS) called something like CONFIG.APL with various settings written into it. This is fine for specific applications, but of course it is one more thing to lose, or put in the wrong directory, or whatever.
If you want something relatively small and simple, why not use the excellent DOS facility which effectively lets you define global variables in the DOS environment? This method has the advantage that it is easy for any non-APL user to change the settings (probably with a quick edit on AUTOEXEC.BAT) and the values are always available to your application. The only snag is tracking down the settings from within APL … for the code fragment below you must thank M. Philippe Denoyelle of the French group AFCET:
R←DOS∆SYMB REQ;AV;S;V;X;⎕IO;⎕SEG
--------------------------------
[1] ⍝ Read any DOS SET xxx=yyy commands in the environment
[2] ⍝ Note that '@' is '⍙' and '$' is '∆' and '=' is '←'
[3] ⍝
[4] ⍝ REQ is the prefix we want, e.g. SYMB '⍙P' will collect
[5] ⍝ any vars beginning with '@p' in DOS.
[6] ⎕IO←0
[7] ⍝ Find "Program Segment Prefix" ....
[8] ⎕SEG←0 ⋄ S←¯16+256⊥⎕PEEK 130 129
[9] ⎕SEG←S ⋄ S←256⊥⎕PEEK 45 44
[10] V←⍬
[11] Retr:⎕SEG←S ⋄ V←V,⎕PEEK⍳256 ⋄ X← 0 0 ⍷V ⋄ →(∨/X)↑Done
[12] S←S+16 ⋄ →Retr
[13] ⍝ Translate from numeric, and erect into a table.
[14] Done:AV←⎕AV ⋄ AV[64 36 61]←'⍙∆←'
[15] V←AV[(X⍳1)↑V] ⋄ R←⎕TCNUL ∆TAB V
[16] REQ←,REQ ⋄ →(⍴REQ)↓0
[17] R←(R[;⍳⍴REQ]∧.=REQ)⌿R
∇
DOS∆SYMB 'C'
COMSPEC←D:\COMMAND.COM