#! /usr/lib/veetest/veetest -r
(revision "B.00.00")
(date "Mon 26/Oct/1992")
(component 0 "ROOTCONTEXT"
 (interface
 )
 (implementation
  (locked no)
  (trigMode deg)
  (nextID 1)
  (component 0 "SHELLESCAPE"
   (name "Get Environment Variable")
   (description 54 4
    Use this device to retrieve the contents of an
    exported shell variable.  Input is a text string
    with the name of the variable to examine, such as
    "HOME".  Output value is a text string with the
    contents of the variable; an empty (nil) string is
    returned if the variable is defined but has no
    value.  The Exit Code is 0 if the named variable
    is defined, and 1 if not defined.
    
    HOW IT WORKS:
    
    The Execute Program device is used to run a copy of
    /bin/sh, using the -s option to indicate shell
    commands should be read from stdin rather than a
    script file.  The WRITE TEXT transactions in the
    escape are sent to the stdin of ksh, where they
    are interpreted as if read from a file.  The READ
    TEXT transaction obtains data from the stdout of
    the ksh.  The stderr of the ksh is not captured
    and any error messages will be written to stderr.
    
    The following shell script is constructed from
    the WRITE transactions, where "var" is the text
    string:
    
         echo $var
         [ "$var" ] && exit 1
    
    The WRITE TEXT "echo $",var EOL transaction asks
    the shell to echo the contents of the environment
    variable constructed by prepending a $ to the text
    name supplied by the user on the var input.  The
    shell responds with the contents of the string,
    if any, followed by a newline.  (The newline from
    the echo is important, since it marks the end of
    the echoed string.)
    
    The READ TEXT into the value output pin uses the
    TOKEN read mode to construct the output token from
    all characters EXCLUDING the "\n" newline.  A text
    string read mode, since it expects at least one
    non-white-space character, would never be complete
    if the variable had a nil value.  The TOKEN read
    uses all characters up to the \n, allowing a nil
    output to properly be read.  Note:  the next char
    to be read would be the \n, so a READ TEXT null
    CHAR would be needed to position the read pointer
    at the start of the next input line.
    
    The final WRITE TEXT transaction is used to run a
    ksh test "[ "$var" ]" to see if the variable was
    defined.  If not, the ksh exits with 1 as the Exit
    code.  Note the use of the \" (quoted ") to imbed
    the quotes around the $var in the test.
   )
   (interface
    (sequence in)
    (sequence out)
    (input 1
     (type data)
     (name "var")
     (tag "var")
     (optional yes)
    )
    (output 1
     (type data)
     (name "Exit code")
     (lock name constraints)
    )
    (output 2
     (type data)
     (name "value")
     (lock constraints)
     (optional yes)
    )
   )
   (implementation
    (attr iopath pipe read "pipe"
     (readTerm "\n")
     (fs " ")
     (eol "\n")
     (multiField fullSyntax)
     (arrayFormat block)
    )
    (attr iopath pipe write "pipe"
     (readTerm "\n")
     (fs " ")
     (eol "\n")
     (multiField fullSyntax)
     (arrayFormat block)
    )
    (procedure
      WRITE TEXT "echo $",var EOL
      READ TEXT value TOKEN EXCLUDE:"\n"
      WRITE TEXT "[ \"$",var,"\" ] || exit 1" EOL
    )
    (component shell "none")
    (component command "/bin/sh -s")
    (component deathWait "Yes")
   )
   (views
    (icon
     (origin 267 248)
     (extent 226 25)
    )
    (detail
     (origin 119 191)
     (extent 463 138)
    )
    (terminals on)
    (active icon)
   )
  )
  (configuration
  )
 )
 (views
  (detail
   (origin 0 62)
   (extent 880 413)
   (configuration
   )
  )
  (active detail)
  (numberFormats
   (realFormat standard)
   (realSigDigits 4)
   (realRadixSpec 4)
   (integerBase decimal)
  )
  (waveformSettings
   (timeSpan 0.02)
   (numPoints 256)
  )
 )
)
