REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Detecting the LIBPATH values





 
/* sample REXX routine to get the values of LIBPATH, BEGINLIBPATH     */
/* and ENDLIBPATH                                                     */

  say "Detecting the values of LIBPATH, BEGINLIBPATH and ENDLIBPATH ..."

  BootDrive = "C:"
  thisRC = GetLibPath( bootDrive )

  select

    when thisRC = 0 then
    do
      say "  LIBPATH = " || LIBPATH
      say "  BEGINLIBPATH = " || BEGINLIBPATH
      say "  ENDLIBPATH = " || ENDLIBPATH
    end /* when */

    when thisRC = 2 then
    do
      say "  LIBPATH = "
      say "    -> File " || BootDrive || "\CONFIG.SYS not found!"
      say "  BEGINLIBPATH = " || BEGINLIBPATH
      say "  ENDLIBPATH = " || ENDLIBPATH
    end /* when */

    otherwise
    do
      say "Unexpected return code " || thisRC || "!"
    end /* otherwise */

  end /* select */

exit

/* ------------------------------------------------------------------ */
/* function: Get the value for LIBPATH, BEGINLIBPATH and ENDLIBPATH   */
/*                                                                    */
/* Usage:    GetLibPath bootDrive                                     */
/*                                                                    */
/* where:    bootDrive - boot drive (e.g. "C:")                       */
/*                                                                    */
/* returns:   0 - ok                                                  */
/*            2 - config.sys not found                                */
/*           -1 - parameter missing                                   */
/*                                                                    */
/* output:   LIBPATH - value of LIBPATH entry or empty string         */
/*           BEGINLIBPATH - value of BEGINLIBPATH or empty string     */
/*           ENDLIBPATH - value of ENDLIBPATH or empty string         */
/*                                                                    */
GetLibPath: PROCEDURE expose LIBPATH BEGINLIBPATH ENDLIBPATH
  parse arg bootDrive .

                    /* init the return code                           */
  thisRC = 0

                    /* check the parameter                            */
  if bootDrive <> "" then
  do
                    /* get the LIBPATH value                          */
    configSys = left( bootDrive,1 ) || ":\CONFIG.SYS"

    lineSeparator = "0D0A"x
    libpathStmt = lineSeparator || "LIBPATH="

    if stream( configSys, "c", "QUERY EXISTS" ) <> "" then
    do
      configSysLength = chars( configSys )

      call stream configSys, "c", "OPEN READ"
      configSYS = CharIn( configSys, 1, configSysLength )
      call stream configSys, "c", "CLOSE"

      parse upper var ConfigSYS . (libPathStmt) LIBPATH (lineSeparator) .
      LIBPATH = strip( LIBPATH )
    end
    else
      thisRC = -1

                    /* get the value of BEGINLIBPATH and ENDLIBPATH   */
    '@SET BEGINLIBPATH 2>NUL | rxqueue'
    '@SET ENDLIBPATH 2>NUL | rxqueue'

    if queued() <> 0 then
    do
      parse pull BEGINLIBPATH
      if BEGINLIBPATH = "(null)" then
        BEGINLIBPATH = ""
    end /* if queued() <> 0 then */
    else
      BEGINLIBPATH = ""

    if queued() <> 0 then
    do
      parse pull ENDLIBPATH
      if ENDLIBPATH = "(null)" then
        ENDLIBPATH = ""
    end /* if queued() <> 0 then */
    else
      ENDLIBPATH = ""

  end /* if bootDrive <> "" then */
  else
    thisRC = -1

RETURN thisRC

  

Inf-HTML End Run - Successful