'**** HEADER ************************************************************
'EXNET-N3.PF3 (release .02)
'Copyright (c) 1990-1991 Applied Resource Technologies, Inc.
'P.O. Box 64381, Dallas, Texas 75206 U.S.A. (214) 855-0449
'Description: Demonstrates nuserlist()
'**** FUNCTION DECLARATIONS *********************************************
'library
external nuserlist() popuplist() replstr()
'core
global setup() parse_users() see_users() main_exit()
'**** VARIABLE DECLARATIONS *********************************************
'library
public lpath ulist[1,5] ucount uconn    ' declare EXTERNAL if setenv()
public ptstr                            ' is used first
'core
global usr_str
'**** CODE **************************************************************

MAIN
if setup() = 0                ' load libraries & setup variables
     if parse_users() = 0     ' get userlist & make into string group
          see_users()         ' show conn#-name string group on screen
     else
          main_exit(-2)
     end if
else
     main_exit(-1)
end if
main_exit(0)
END MAIN

function setup()
lpath = "\smartii\poptools\lib\"   'change if not system directory
error off
clearerror
load lpath|"netlib-n.psl" in-memory
load lpath|"uintlib.psl" in-memory
load lpath|"strlib.psl" in-memory
error on
return (lerror)
end function 'setup()

function parse_users()
local i c# usr_name
screen print scrheight-3 1 bginvpleasing bgstandard \
       (format("Standby... getting user list","L"|str(scrwidth)))
if nuserlist() = 0
screen print scrheight-3 1 bginvpleasing bgstandard \
       (format("Formatting","L"|str(scrwidth)))
     for i = 1 to ucount
          if ulist[i,3] <> uconn   ' filters out "self"
               c# = format(str(ulist[i,3]),"R3")  'get user's connection # &
                                   ' pad connection number for right justify
               usr_name = ulist[i,4]    ' get user's anme
               if replstr(c# & usr_name,chr(32),chr(255) ) = 0
                    ' replace all spaces with invisible "hard" characters
                    usr_str = usr_str & ptstr
                    ' adds the string to the string group
               end if
          end if
     end for
     if len(trim(usr_str)) > 0
          return (0)
     else
          return (-1)
     end if
else
     return (-1)
end if
end function 'parse_users()

function see_users()
local scn msg
screen print scrheight-3 1 0 0 (format("","L"|str(scrwidth)))
msg = "EXNET-N3.PF3 demo of nuserlist()   Press {Esc} when done"
screen save scrheight 1 scrheight scrwidth scn
screen print scrheight 1 fginvpleasing bginvpleasing \
       (format(msg,"M"|str(scrwidth)))
popuplist(3,30,18,usr_str,"",1,0)
screen shortrestore scn
end function 'see_users()

function main_exit(e)
unload "netlib-n.psl"
unload "uintlib.psl"
unload "strlib.psl"
if e < 0
     beep
     message case e (-1,"Error during setup") \
                    (-2,"Failure to parse user list")
end if
end function 'main_exit()


