This code runs well on FreeDOS

Using Euphoria language you can put the whole
environmental variables table on a sequence (array)

Marco A. Achury

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
        if a=0 then
            puts(1, s)
            return s
        end if
        s= append(s,a)
        i +=1
    end while
end function

function environ()
    sequence PSP
    atom env_add
    sequence raw_env
    integer offset
    sequence z
    PSP = Get_PSP()
    env_add= (PSP[45] + (PSP[46]*256))*16
--  trace(1)
    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
end function

procedure main()
    sequence a
    a = environ()
    for i=1 to  length (a) do
        puts (1, a[i] &"\n")
    end for
end procedure

if getc(0) then
end if

This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
Freedos-user mailing list

Reply via email to