'**** HEADER ************************************************************
'EXNET-N2.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 nsendmsg()
'**** FUNCTION DECLARATIONS *********************************************
'library
external nsendmsg() progtag() progress()
'core
global setup() msg_log() norm_exit()
'**** VARIABLE DECLARATIONS *********************************************
'library
' ********************************************
'declare as external if setenv() used properly
public uname uconn userv ulist[1,5] ucount ptstr
' ********************************************
'core
global logname prate
'**** CODE **************************************************************

MAIN
   setup()
   if nsendmsg(1) = 0
        msg_log()
   end if
   norm_exit()
END MAIN

function msg_log()
local lpcol rpcol prow pchar msg i j k l charset
screen clear box 1 1 scrheight scrwidth 0 0 no-border
progress(fgpleasing,bgpleasing,"Updating file server broadcast message log",1)
progtag(fgediting,bgediting,         "     Standby                              ")

' get the row that the progtag() is on
prow  = value(group(ptstr,1))+1
' get a column just to the right of the word "standby"
lpcol = value(group(ptstr,2))+15
' get the column that is two columns from the right progress() border
rpcol = value(group(ptstr,3))-value(group(ptstr,2))

' select print symbol to start with during log write
charset = 1
pchar = spsymmap(38)

j = 0
l = 1

for i = 1 to ucount      ' step through the entire user list
     ' while getting and writing message send data, print dots
     ' the milli-wait here is for example display... omit if desired
     milli-wait prate
     screen print prow lpcol+j fgediting bgediting pchar
     if ulist[i,1] = spsymmap(28) ' if the user had been selected, add to log
          k = 1
          while TRUE
               if k = 10
                    logname = left(logname,7)|str(l)|right(logname,4)
                    l = l + 1
               end if
               error off
               fopen logname as 1
               if cerror = 0
                    ' build test string with time
                    ' & date
                    ' with this user's name
                    ' the addressee of message
                    ' and result of transmission
                    msg = today & \
                          time24 & \
                          uname & \
                          ulist[i,4] & \
                          ulist[i,5]
                    fseek 1 EOF
                    fwrite 1 from msg
                    fclose 1
                    error on
                    exit while
               end if
          milli-wait int(uniform(100))  'random wait from .001 to .1 seconds
          end while
     end if
     if j = rpcol
          j = 0
          if charset = 3
               charset = 1
          else
               charset=charset+1
          end if
          pchar = case charset (1,spsymmap(38)) \
                               (2,spsymmap(37)) \
                               (3,spsymmap(28))
     else
          j = j + 1
     end if
end for

for i = j to rpcol
     milli-wait prate
     screen print prow lpcol+i fgediting bgediting pchar     'finish the "dots" line
end for

end function 'msg_log()

function setup()
load "displib.psl" from-file
load "netlib-n.psl" from-file
logname = "nsendmsg.log"
prate = 200
end function 'setup()

function norm_exit()
unload "netlib-n.psl"
unload "displib.psl"
end function 'norm_exit()

