/*----------------------------------------------------------------------*/ /* (c) Copyright Roger Lacroix 1998 | | | | Designed, developed and programmed by Roger Lacroix | +------------------------------------------------------------------------+ | | | Netview.CMD V1.00 | | | | This program will screen-scrape a 3270 window. The 3270 window | | must be running Netview with the "Window" or "Browse" command | | entered. | | | | Requirements: | | This programs requires OS/2 V2.0 or later and VREXX V1.0 . | | | | Restrictions: | | None | | | | Netview Command (accesses R2D2 PU) | | window ROP PUS034 TYPE C:\LOG\G1.LOG | | browse swpus034 | | | | Useability: | | This programs can be run from any of the following locations: | | - Floppy drive "A:" | | - Hard drive "C:" | | - LAN drive "Y:" | | | +-----------------------------------------------------------------------*/ trace o /*-----------------------------------------------------------------------+ | First we must initialize all constants, variables and error msg table. | +-----------------------------------------------------------------------*/ call INIT_VARIABLES '@echo off' /* location of netview and vrexx's dll */ PARSE SOURCE location location = SUBSTR(location,14) /* get start location of netview.cmd */ drive = FILESPEC("DRIVE",location) dir = FILESPEC("PATH",location) IF POS('\',dir) = LASTPOS('\',dir) then NOP /* in root directory? */ ELSE dir = SUBSTR(dir,1,LENGTH(dir)-1) newdir=DIRECTORY(drive''dir) signal on failure name CLEANUP signal on halt name CLEANUP signal on syntax name CLEANUP if RxFuncQuery("VINIT") then call RxFuncAdd 'VINIT', 'VREXX', 'VINIT' else nop initcode = VInit() if initcode = 'ERROR' then signal CLEANUP /*----------------------+ | Mainline | +----------------------*/ button1 = 'OK' call GET_LOGFILE /* get user info. */ do while button1 = 'OK' call LOG_FUNCTION 'OPEN' /* open the file */ call HOST /* do host processing */ call LOG_FUNCTION 'CLOSE' /* close the file */ call GET_LOGFILE /* get user info. */ end call VExit call Rxfuncdrop "VINIT" return /*-----------------------+ | Error exit routine | +-----------------------*/ CLEANUP: Beep(200,250) if initcode = 'INITCODE' then do Say '' Say '' Say Centre('+-------------------------------------------+',78) Say Centre('| |',78) Say Centre('| Warning!!! You forgot to install VREXX. |',78) Say Centre('| |',78) Say Centre('| Press "ENTER" to exit the program. |',78) Say Centre('| |',78) Say Centre('+-------------------------------------------+',78) PULL nothing end else do call VExit end call Rxfuncdrop "VINIT" EXIT /*------------------------------------+ | Get file name, LU and timeout info | +------------------------------------*/ GET_LOGFILE: rc = init() /* Initialize HLLAPI */ call VDIALOGPOS 80,15 ans.0 = prompt.0 /* set # of answers */ ans.1 = log_file /* set default log file name */ ans.2 = lu /* set default lu name */ ans.3 = timeout /* set default timeout value */ continue = 'Y' do while continue = 'Y' button1 = VMultBox('Enter File and LU info.', prompt, width, hide, ans, 3) log_file= ans.1 /* get the user's log file name */ lu = TRANSLATE(STRIP(ans.2)) /* get the user's lu name */ timeout = ans.3 /* get the user's timeout value */ continue = 'N' if button1 = 'OK' then do select when log_file = ' ' then erc = ERROR_HANDLER(11) when VERIFY(timeout,numbers) <> 0 | timeout = ' ' then erc = ERROR_HANDLER(12) otherwise rc = VALIDATE_HOST_LU(lu) /* validate LU */ end /* select */ if e_ptr <> 0 then erc = ERROR_DISPLAY(2) else NOP end else NOP /* pressed CANCEL */ ans.0 = prompt.0 /* set # of answers */ end if LastPOS('.',log_file) > LASTPOS('\',log_file) then do /* remove extension */ temp = Substr(log_file,1,LastPOS('.',log_file)-1) log_file_b1 = temp".l01" /* backup #1 logfile */ log_file_b2 = temp".l02" /* backup #2 logfile */ end else do /* no extension */ log_file_b1 = log_file".l01" /* backup #1 logfile */ log_file_b2 = log_file".l02" /* backup #2 logfile */ end return /*--------------------------------------------------------+ | Subroutine to handle opening and closing the log file | +--------------------------------------------------------*/ LOG_FUNCTION: PARSE ARG string if string = 'OPEN' then do if STREAM(log_file_b1,'C','QUERY EXIST') <> ' ' then do 'DEL 'log_file_b2 'COPY 'log_file_b1' 'log_file_b2 'DEL 'log_file_b1 end else NOP if STREAM(log_file,'C','QUERY EXIST') <> ' ' then do 'COPY 'log_file' 'log_file_b1 'DEL 'log_file end else NOP call STREAM log_file,'C','OPEN WRITE' /* open the log file */ end else do if string = 'CLOSE' then do call STREAM log_file,'C','CLOSE' /* close the file */ end else do Say "Invalid call to LOG_FUNCTION() string="string end end return 0 /*-----------------------------------------------------------------------+ | Write the results of an action to the logfile and the log event window.| | Possible values for rc_log: | | 0 - everything is ok | +-----------------------------------------------------------------------*/ LOG_WRITE: PARSE ARG log_input top_adjust = 0 bot_adjust = 0 line1 = SUBSTR(log_input,1,col) if Substr(line1,2,21) = netview_window then do PARSE VALUE line1 WITH "CNMKWIND OUTPUT FROM" . "LINE"linenum" OF "totallines . top_adjust = 0 bot_adjust = 0 end else do PARSE VALUE line1 WITH "NETVIEW.BRWS -" . "LINE"linenum"TO"cur_bottom" OF "totallines . top_adjust = 2 bot_adjust = 1 end totallines = Strip(totallines) linenum = Strip(linenum) if (totallines - linenum + 1) <> (row - 3) then do /* normal line processing */ do i_lw = (2+top_adjust) to (row-2-bot_adjust) temp = Strip(SUBSTR(log_input,(i_lw-1)*col + 1,col),'T') nothing = LINEOUT(log_file,temp) end end else /* last line processing */ do remainder = totallines // (row-3) do i_lw = (row-remainder-1+top_adjust) to (row-2-bot_adjust) temp = Strip(SUBSTR(log_input,(i_lw-1)*col + 1,col),'T') nothing = LINEOUT(log_file,temp) end end return 0 /*-----------------------------------------------------+ | Validate the host LU the user has specified. | +-----------------------------------------------------*/ VALIDATE_HOST_LU: ARG lu select when lu = '' then rc_lu = 41 when LENGTH(lu) > 1 then rc_lu = 42 otherwise do rc_lu = HLLAPI("Connect",lu) rc1 = HLLAPI("Connect_PM",lu) end end /* select */ select when rc_lu = 1 then erc = ERROR_HANDLER(41,lu) when rc_lu = 4 then erc = ERROR_HANDLER(42,lu) when rc_lu = 5 then erc = ERROR_HANDLER(43,lu) when rc_lu = 9 then erc = ERROR_HANDLER(44,lu) when rc_lu = 11 then erc = ERROR_HANDLER(45,lu) when rc_lu = 41 then erc = ERROR_HANDLER(46) when rc_lu = 42 then erc = ERROR_HANDLER(47,lu) otherwise do /* rc1 = HLLAPI("Set_window_status",lu,"NIMIZED") */ /* leave it alone */ rc1 = HLLAPI("Disconnect") /* reset LU */ rc1 = HLLAPI("Disconnect_PM",lu) rc1 = HLLAPI("reset_system") end end /* select */ return rc_lu /*------------------------------------------------------+ | Process all the centres that the user has selected. | +------------------------------------------------------*/ HOST: rc = init() /* Initialize HLLAPI */ rc = connect(lu) /* Connect to Host */ rc = SENDKEY_FUNC("@R") /* reset the LU */ button7 = 'nothing' call FIND_NETVIEW_SCREEN rc_ms = 0 if button7 = 'CANCEL' then NOP /* host screen at unknown place AND user cancelled*/ else do rc = HLLAPI("Query_session_status" , lu) b12 = C2D(Substr(rc,12,1)) b13 = C2D(Substr(rc,13,1)) b14 = C2D(Substr(rc,14,1)) b15 = C2D(Substr(rc,15,1)) b16 = C2D(Substr(rc,16,1)) b17 = C2D(Substr(rc,17,1)) row = b13""b12 col = b15""b14 codepage = b17""b16 /* Say "Rows="row" - Columns="col" - Code Page="codepage */ call SCRAPE_SCREEN end rc = resetlu() return /*----------------------+ | Initialize HLLAPI | +----------------------*/ INIT: if rxfuncquery("HLLAPI") then call rxfuncadd "hllapi","saahlapi","hllapisrv" rc = HLLAPI("Set_session_parms","CONPHYS") return rc /*----------------------+ | Connect to Host | +----------------------*/ CONNECT: ARG lu rc = HLLAPI("Connect",lu) rc = HLLAPI("Connect_PM",lu) rc = HLLAPI("Set_window_status",lu,"RESTORE") /* rc = HLLAPI("Set_window_status",lu,"ZORDER","BOTTOM") */ /* bottom window */ rc = HLLAPI("Set_window_status",lu,"ZORDER","TOP") /* top window */ rc = HLLAPI("Set_session_parms","IPAUSE") return rc /*-------------------------------------+ | Find the main Vtam screen | +-------------------------------------*/ FIND_NETVIEW_SCREEN: old_screen = 'nothing' last_time = TIME('S') rc = WAIT_TIMEOUT() waiting = 1 do while waiting = 1 select when POS(netview_window,screen) <> 0 then /* netview window */ do waiting = 0 rc = 0 LEAVE end when POS(netview_browse,screen) <> 0 then /* netview browse */ do waiting = 0 rc = 0 LEAVE end otherwise do erc = ERROR_HANDLER(31) erc = ERROR_HANDLER(32) erc = ERROR_DISPLAY(3) if button7 = 'CANCEL' then do waiting = 0 rc = 99 LEAVE end else NOP /* OK - therefore loop back and check again */ end end /* select */ rc = WAIT_TIMEOUT() end /* do while */ return rc /*----------------------------------------------------------------+ | Scrap the Netview window screen. | +----------------------------------------------------------------*/ SCRAPE_SCREEN: rc_ss = 0 goto_top = 0 old_screen = 'nothing' rc_ss = WAIT_TIMEOUT("LGN-SCR") waiting_ss = 1 do while (waiting_ss = 1 & rc_ss <> 99) select when POS(rbc_main,screen) <> 0 | POS(ms_sel,screen) <> 0 then do waiting_ss = 0 /* exit loop */ LEAVE end when goto_top = 0 then do rc = SENDKEY("@0@T TOP") /* goto top of netview window data */ goto_top = 1 end when POS("DSI264I RUNCMD FAILED",screen) <> 0 then do call LOG_WRITE screen /* error with netview command */ waiting_ss = 0 /* exit loop */ LEAVE end when POS(netview_window,screen) <> 0 |, /* netview window */ POS(netview_browse,screen) <> 0 then /* netview browse */ do call LOG_WRITE screen rc = SENDKEY_FUNC("@8") /* pf8 - page down */ last_time = TIME('S') if POS("DSI268I RUNCMD COMPLETE",screen) <> 0 |, POS("*** BOTTOM OF DATA ****",screen) <> 0 then do waiting_ss = 0 /* exit loop */ LEAVE end else NOP end otherwise NOP end /* select */ rc = WAIT_TIMEOUT() if rc > rc_ss then rc_ss = rc else NOP end /* do while */ return rc_ss /*-----------------------------------------------+ | Wait and check for new info. on the screen. | | Also, has the time-out expired?? | +-----------------------------------------------*/ WAIT_TIMEOUT: PARSE ARG wt_str rc_wt = 0 not_changed = 1 do while not_changed = 1 rc = HLLAPI("Start_host_notify",lu,"P") rc = HLLAPI("Pause",netdelay,lu"#") rc = HLLAPI("Stop_host_notify",lu) screen = HLLAPI("Copy_PS_to_str",1,row*col) cur_time = TIME('S') select when cur_time > last_time + timeout then do call TIME_OUT_ERROR_DISPLAY if button10 = 'OK' then do last_time = TIME('S') /* user wants to wait AGAIN */ end else do /* user pressed cancel */ not_changed = 0 /* exit loop */ rc_wt = 99 /* timeout has expired */ end end when STRIP(screen) = ' ' then /* blank screen - ignore it */ do NOP end when POS("Please Stand by..",screen) <> 0 then do NOP end /*------------------------------------------------------------+ | At logon screen, sometimes the system is very slow. | | Because we entered "h.4.1", this has changed the screen, | | but REALLY the screen has not changed. Therefore ignore it.| +------------------------------------------------------------*/ when wt_str = "LGN-SCR" & , (POS(rbc_main,screen) <> 0 |, POS(ms_sel,screen) <> 0 |, POS("PF1 =Help PF2 =Suspend PF3 =End ",screen) <> 0) then do NOP end when old_screen <> screen then do not_changed = 0 /* yes, screen has changed */ rc_wt = 0 old_screen = screen /* save a copy of the screen */ end otherwise NOP end /* select */ end /* do while */ return rc_wt /*-----------------------------+ | Send keystrokes to host LU | +-----------------------------*/ SENDKEY: PARSE ARG string rc = HLLAPI("Sendkey",string) old_screen = HLLAPI("Copy_PS_to_str",1,row*col) rc = HLLAPI("Sendkey","@E") /* send enter keystroke */ /* rc = HLLAPI("Pause",netdelay,lu"#") */ return rc /*--------------------------------------+ | Send function keystrokes to host LU | | - copy 1st because function keys | | do not change the screen!!!!! | +--------------------------------------*/ SENDKEY_FUNC: PARSE ARG string old_screen = HLLAPI("Copy_PS_to_str",1,row*col) /* copy 1st because function keys do not change the screen */ rc = HLLAPI("Sendkey",string) /* rc = HLLAPI("Pause",netdelay,lu"#") */ return rc /*--------------------------------------------+ | Finished communication, tell api about it | +--------------------------------------------*/ RESETLU: /* rc = HLLAPI("Set_window_status",lu,"NIMIZED") */ /* leave it alone */ rc = HLLAPI("Disconnect") rc = HLLAPI("Disconnect_PM",lu) rc = HLLAPI("reset_system") call Rxfuncdrop "HLLAPI" return rc /*--------------------------+ | Error handling routine | +--------------------------*/ ERROR_HANDLER: PARSE ARG e_num,str1 e_ptr = e_ptr +1 error.0 = e_ptr error.e_ptr = e_msg.e_num''str1 ee = TRUNC(e_num/10) error_title = e_title.ee continue = 'Y' return 0 /*--------------------------+ | Error handling routine | +--------------------------*/ ERROR_DISPLAY: PARSE ARG but button7 = VMsgBox(error_title,error,but) e_ptr = 0 error.= '' return 0 /*-----------------------------------+ | Time-out Error handling routine | +-----------------------------------*/ TIME_OUT_ERROR_DISPLAY: ti_error.0 = 5 ti_error.1 = 'The specified time-out value ('timeout') has expired.' ti_error.2 = '' ti_error.3 = 'Press OK to wait another 'timeout' seconds ' ti_error.4 = ' or' ti_error.5 = 'Press CANCEL to quit.' button10 = VMsgBox('Time-out Value has expired.',ti_error,3) return 0 /*------------------------------------------------------------+ | Initialize all constants, msg table and error msg table. | +------------------------------------------------------------*/ INIT_VARIABLES: lu = 'A' /* Default Session short name */ netdelay = 1 /* Allow 0.5 seconds for network delay */ timeout = 30 /* Default user timeout value (seconds) */ log_file = 'e:\netview.log' /* log filename */ log_file_b1 = 'e:\netview.l01' /* backup #1 logfile */ log_file_b2 = 'e:\netview.l02' /* backup #2 logfile */ row = 24 col = 80 yesno = 'YyNn' numbers = '0123456789' /*-----------------------------------------+ | Host panel identifiers | +-----------------------------------------*/ rbc_main = "Panel: RBSDMP4" /* main main!!! */ ms_main = "KLGLGON1" ms_wait = "KLSUINI1" ms_sel = "KLSVSEL1 CL/SUPERSESSION Main Menu" ms_exit = "KLSEXIT1" netview_window = "CNMKWIND OUTPUT FROM" netview_browse = "NETVIEW.BRWS -" /*-----------------------------------------+ | Table of Error Messages | +-----------------------------------------*/ e_msg.11="GT.E.011 - PC filename is blank." e_msg.12="GT.E.012 - Please enter a valid number for the time-out value." e_msg.31="GT.E.031 - Put your Host LU at Netview and run the window command." e_msg.32=" " e_msg.41="GT.E.041 - The Host LU that you have specified is invalid. ===> " e_msg.42="GT.E.042 - The Host LU is busy. ===> " e_msg.43="GT.E.043 - The Host LU is locked. ===> " e_msg.44="GT.E.044 - Received a system error. ===> " e_msg.45="GT.E.045 - The Host LU is connected to another application. ===> " e_msg.46="GT.E.046 - Please specify a Host LU. " e_msg.47="GT.E.047 - The Host LU is invalid Host LU. ===> " e_msg.99="GT.E.099 - " e_title.1 = "Error with user input." e_title.2 = "" e_title.3 = "Error finding a recognizable VTAM panel." e_title.4 = "Error with Host LU." e_ptr = 0 /* pointer in the error message buffer */ prompt.0 = 3 ; width.0 = 3 ; hide.0 = 3 prompt.1 = 'Log File ' ; width.1 = 20; hide.1 = 0 /* echo input */ prompt.2 = 'Which Host LU: ' ; width.2 = 2 ; hide.2 = 0 /* echo input */ prompt.3 = 'Time-out value (sec.)'; width.3 = 4 ; hide.3 = 0 /* echo input */ return