# Emulate the Bourne Shell's read command, which reads a line of
# input, breaking it up into words, which are then assigned, one-by-
# one, to the variables whose names are passed as arguments. If no
# variable name is specified, the input line is read but discarded.
# The # status code is set to 0 if successful or non-zero if end-of-
# file was encountered.
# Copyright (c) 1996-2012 by Hamilton Laboratories. All rights reserved.
proc read( Rvariables )
local input, Ri, nR, ni
@ nR = $#Rvariables - 1
set input = $getline:x
@ ni = $#input - 1
if (!eofgetline) then
if (nR == 0) then
eval @ $Rvariables = input
else
if (nR > 0 ) then
if (nR < ni) then
for Ri = 0 to nR do
eval "@ $Rvariables[Ri] = input[Ri]"
end
for Ri = nR + 1 to ni do
eval "@ $Rvariables[nR][Ri - nR] = input[Ri]"
end
else
for Ri = 0 to ni do
eval "@ $Rvariables[Ri] = input[Ri]"
end
for Ri = ni + 1 to nR do
eval set $Rvariables[Ri] =
end
end
end
end
@ status = 0
else
for Ri = 0 to $#Rvariables - 1 do
eval set $Rvariables[Ri] =
end
@ status = 38 # ERROR_HANDLE_EOF
end
end
read $argv
|