-- ENVIRON.EX -- Example Euphoria DOS code to show the environment variables of the current -- program. Runs well on XP running qemu emulator with FreeDOS, don't works -- directly on WinXP command promtp -- Marco A. Achury 2008 www.geocities.com/marcoachury/eudos/ include machine.e -- Return memory segment of PSP segment for the current program. function PSP_Segment () sequence regs -- CPU registers regs = repeat(0,10) regs[REG_AX] = #5100 -- mov ah, 51h regs = dos_interrupt(#21, regs) -- int 21h return (regs[REG_BX]) -- mov SegmentPSP, bx end function -- Get program prefix of the current running program. function Get_PSP() integer Add sequence PSP Add = PSP_Segment() Add = Add * 16 PSP = peek({Add, 256}) return PSP end function --Get from a memory address a string of characters. --delimited by a zero function get_asciiz(atom add) sequence s integer i atom a s = {} i = 0 while 1 do a=peek(add+i) if a=0 then exit end if s= append(s,a) i +=1 end while return s end function function environ() sequence PSP atom env_add sequence raw_env -- sequence env integer offset sequence z PSP = Get_PSP() env_add= PSP[45] + PSP[46] * 256 env_add = env_add * 16 raw_env={} offset=0 while 1 do z = get_asciiz(env_add+offset) if equal(z,{}) then return raw_env end if raw_env=append(raw_env, z) offset = offset + length(z) + 1 end while -- TODO: return data on nice format -- {{Variable1, Value1},{Variable2, Value2},{Variable3, Value3},...} -- env={} -- for i=1 to length(raw_env) do -- offset=find('=', raw_env[i]) -- env = append(env, {raw_env[1..offset-1], raw_env[offset+1..$]}) -- raw_env[i]={} -- end for -- return env end function procedure main() sequence a a=environ() for i=1 to length(a) do puts(1, a[i] & "\n") end for end procedure main()