'**** HEADER ************************************************************
'EXNET-N1.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 nconn()
'**** FUNCTION DECLARATIONS *********************************************
'library
external vkeybox() nconn() scrollbox() relperf() progtag() progress()
'core
global setup() proj_control() abort() fake_nconn() norm_exit()
global fake_project()
'**** VARIABLE DECLARATIONS *********************************************
'library
' ********************************************
'declare as external if setenv() used properly
public uconn
public ptstr ptval
' ********************************************
'core
global rpi failcode old_conn
'**** CODE **************************************************************

MAIN
   setup()
   proj_control()
   norm_exit()
END MAIN

function proj_control()
local choice
while TRUE
   screen clear box 1 1 scrheight scrwidth 0 0 no-border
   screen print scrheight 1 0 15 \
          (format("Selection option -or- Press {Esc} to end simulation.", \
          "M"|str(scrwidth)))
   if vkeybox(5,30,"1Transactions" & \
                   "6File_Maintenance" & \
                   "1Reports" & \
                   "9Exit_to_SmartWareII" & \
                   "9Quit_to_DOS","") < 0
        exit while
   end if

   ' make sure network connection is valid before proceeding

   ' **********************************************************
   ' the following would be the actual nconn() call in practice
   '   nconn()
   ' **********************************************************
   ' this is the "simulation code"
   fake_nconn()
   ' **********************************************************

   screen clear box scrheight 1 scrheight scrwidth 0 0 no-border

   if uconn = 0
        while TRUE
             ' keeps user in the abort() until the network
             ' administrator clears the workstation.
             if abort() = 0
               '   quit quit
               ' for the simulation, don't "quit quit"
               ptstr = "f"
               exit while
             end if
        end while
   end if

   ' project options, all returning to this routine for simulation

   case ptstr
     when "t"
          fake_project("TRANACTIONS")
     when "m"
          fake_project("FILE MAINTENANCE")
     when "r"
          fake_project("REPORTS")
     when "s"
          fake_project("EXIT TO SMARTWARE II")
     when "d"
          fake_project("QUIT TO DOS")
     otherwise
          progress(0,15, \
                  "In practice, QUIT QUIT would abort SmartWare II here",1)
          wait 2
  end case
end while
end function 'proj_control()

function fake_project(msg)
progress(0,15,"This would be the project:"&msg,1)
progtag(15,0,"Press any key")
inchar
end function 'fake_project()

function abort()
beep 2
screen print scrheight 1 0 15 \
       (format("Press {Alt-Esc} AFTER workstation is cleared !!!", \
       "M"|str(scrwidth)))
scrollbox(fgerror,bgerror, \
         "NETWORK ERROR! Ask network administator to CLEAR station:"& \
         str(old_conn)&"!",rpi)
if ptval = {Alt-Esc}
     return (0)
else
     return (-1)
end if
end function 'abort()

function fake_nconn()
' fail every other call for simulation
if mod(failcode,2)=0
     uconn = 0
else
     uconn = 1
end if
failcode = failcode + 1
end function

function setup()
load "displib.psl" from-file
load "uintlib.psl" from-file
load "netlib-n.psl" from-file
uconn = 24     ' a simulation of preserving the valid connection number
               ' going into the application.
relperf()
rpi = ptval
failcode = 1
old_conn = uconn    ' preserve "good" connection number for reference
end function 'setup()

function norm_exit()
unload "netlib-n.psl"
unload "uintlib.psl"
unload "displib.psl"
end function 'norm_exit()
