Sorry previously I meant to fill in the blank on the xxx. But the script it is using is called Chat. Below please find the script.
;* Chat Script - Simulates old-style chat. *
;***************************************************************************
;* *
;* CHAT.WAS *
;* Copyright (C) 1995-1998 Datastorm Technologies, Inc. *
;* All rights reserved. *
;* *
;* Purpose: This script implements the old-style chat window, similar to *
;* that of the DOS version of PROCOMM PLUS. *
;* *
;* This ASPECT SCRIPT is intended only as a sample of ASPECT programming. *
;* DATASTORM makes no warranty of any kind, express or implied, including *
;* without limitation, any warranties of merchantability and/or fitness *
;* for a particular purpose. Use of this program is at your own risk. *
;* *
;* *
;***************************************************************************
;***************************************************************************
;* *
;* MACRO DEFINES *
;* *
;***************************************************************************
#define _INSIZE 13 ; Number from 3 to 21 that sets the
; size of the incoming and outgoing
; chat boxes.
#define _EATESC 1 ; Set this to 1 to eat escape
; sequences, set it to 0 to allow
; escape sequences.
;***************************************************************************
;* *
;* GLOBAL VARIABLES *
;* *
;***************************************************************************
integer StoreQSel ; Store the Quick Select Line.
integer StoreScrl ; Screen scroll state.
integer OutMode ; Current mode (0 = Char, 1 = Block).
integer CrMode ; CR / LF setting - not used.
integer hMenuId ; Used to turn of PW's menu bar.
integer XIn, YIn, XOut, YOut ; X's and Y's within each box.
integer YInMin, YInMax, YOutMin, YOutMax
integer MaxCols = $TERMCOLS, MaxRows = $TERMROWS
integer MaxX = MaxCols - 1 ; Maximum X value for a character.
integer InScrollPos ; In box scroll position.
integer OutScrollPos ; Out box scroll position.
string szPWB[5] ; Action bars when script starts.
integer MetaState ; State of the meta keys at startup.
#ifndef US ; if not compiled for the US version
integer OEMFlag ; used for OEM to ANSI conversion
#endif
;***************************************************************************
;* *
;* INCLUDE FILE *
;* *
;***************************************************************************
#include "CHATSTR.INC"
;***************************************************************************
;* *
;* MAIN *
;* *
;* This procedure calls the setup procedures, tells Aspect to handle key *
;* presses and incoming data, and sets up some WHEN events for keys, data, *
;* and user exit. *
;* *
;* Calls: SetupDisplay, SetParms, DataRcvd, KeyPress, CleanUp *
;* Called by: None *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc main
PWModeChange (0) ;make sure PW is in DATA mode.
SetParms() ;Set parameters needed in script.
SetupDisplay() ;Set up display and display vars.
set aspect keys on ;Tell Aspect to handle keys.
set aspect rxdata on ;Tell Aspect to handle incoming.
when $RXDATA call DataRcvd ;Set event for data received.
when $KEYHIT call KeyPress ;Set event for key pressed.
when USEREXIT call CleanUp ;Set event for user exit.
while 1 ;Loop forever, collecting events.
yield
endwhile
endproc
;***************************************************************************
;* *
;* Routines to handle outgoing data. *
;* *
;***************************************************************************
;***************************************************************************
;* *
;* KeyPress( None ) *
;* *
;* Processes key strokes when the user presses a key. This procedure is *
;* responsible for getting a key from the keyboard buffer, checking to see *
;* if the key is a valid key, and handling the key appropriately. *
;* *
;* Calls: ProcessKey, DoOutChr *
;* Called by: Called when a KEY is pressed. *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc KeyPress
integer KeyVal, Chr
when $KEYHIT SUSPEND ; Clear event for key pressed.
when $RXDATA SUSPEND ; Clear event for data received.
while $KEYHIT ; Execute loop while keys in buffer.
keyget KeyVal ; Key virtual key code from buffer.
Chr = ProcessKey( KeyVal ) ; Process the virtual key code.
if Chr >= 0 ; If it was a valid key, output
DoOutChr( Chr ) ; key to outgoing chat box.
endif
locate YOut XOut ; Put cursor at next position.
endwhile
when $KEYHIT RESUME
when $RXDATA RESUME
endproc
;***************************************************************************
;* *
;* ProcessKey( integer KeyVal ) *
;* *
;* This procedure takes the key code and converts it to its ASCII counter- *
;* part. If there is no ASCII counter-part, the procedure returns -1, *
;* beeps and displays a message on the status line. *
;* *
;* Calls: None *
;* Called by: KeyPress *
;* Modifies Globals: None *
;* Returns: integer ASCII equivalent to key pressed. *
;* *
;***************************************************************************
func ProcessKey : integer
param integer KeyVal
integer Chr
keytoansi KeyVal Chr ; Convert key to ASCII equivalent.
if Chr == -1 ; Process key if no equivalent.
switch KeyVal
case 0x041B ; Check for ALT-ESC for Windows.
case 0x0409 ; Check for ALT-TAB for Windows.
case 0x1890 ; Check for the NUMLOCK key.
case 0x0890 ; Unshifted and shifted.
case 0x0014 ; Check for the CAPSLOCK key.
case 0x1014 ; Unshifted and shifted.
termvkey KeyVal ; Output key code to term win.
endcase
case 0x0443 ; Check for ALT-C to clear screen.
SetupDisplay() ; Setup the display again.
endcase
case 0x001B ;case ESCAPE was pressed
CleanUp () ;this is needed for compatiablity with
endcase ;Windows 95
default
Chr = ( KeyVal << 8 ) >> 8 ; Extract key to get around
if Chr > 95 && Chr < 112 ; bug with KEYTOASCII regarding
if Chr <= 105 ; the numeric keypad. Remove
Chr = Chr - 48 ; this hack if problem gets
else ; fixed.
Chr = Chr - 64
endif
else ; Display error if key's invalid.
statmsg _KEYERRTXT KeyVal
beep
Chr = -1 ; Set Chr to -1 so that DoOutChr
endif ; won't be called.
endcase
endswitch
endif
return Chr ; Return character to calling proc.
endfunc
;***************************************************************************
;* *
;* DoOutChr( integer Chr ) *
;* *
;* This procedure takes the passed character, evaluates it, and outputs it *
;* to the outgoing chat box. It updates the X and Y cursor positioning *
;* and handles scrolling if needed. *
;* *
;* Calls: OutScroll *
;* Called by: KeyPress *
;* Modifies Globals: XOut, YOut *
;* Returns: None *
;* *
;***************************************************************************
proc DoOutChr
param integer Chr
switch Chr
case 0x0C ; Check for a form feed and eat it.
endcase
case 0x1B ; Check for an ESCAPE.
CleanUp() ; Call clean procedure to exit.
endcase
case 0x08
if XOut > 0 ; Make sure that X is greater than
XOut-- ; 0 and decrement cursor loc by
locate YOut XOut ; 1, output a normal space to
termwritec 0x20 ; delete character under cursor.
if OutMode ; Output backspace if not in block.
computc 0x08
endif
endif
endcase
case 0x0D ; Check for a return or a line
case 0x0A ; feed.
if ! OutMode ; Output line to remote if in block.
BlockOut()
endif
computc 0x0D ; Output the return to terminal.
XOut = 0, YOut++ ; Set X to 0 and increment Y.
if YOut > YOutMax ; Make sure that Y cursor location
OutScroll() ; is not greater than our max
YOut = (YOutMax - OutScrollPos) + 1 ; Y and if so, scroll.
endif
endcase
default ; Handle all other keys.
termwritec Chr ; Output character to terminal.
if OutMode ; Output character if not in block.
computc Chr
endif
XOut++ ; Increment X and Y, if needed.
if XOut > MaxX
if ! OutMode ; Output line to remote if in block.
BlockOut()
endif
XOut = 0, YOut++
if YOut > YOutMax ; If Y is greater than max Y,
OutScroll() ; scroll.
YOut = (YOutMax - OutScrollPos) + 1
endif
endif
endcase
endswitch
endproc
;***************************************************************************
;* *
;* BlockOut( None ) *
;* *
;* This procedure outputs the current line when you're in block type chat *
;* mode. *
;* *
;* Calls: None *
;* Called by: DoOutChr *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc BlockOut
string szBlock ; String to send to remote.
termgets YOut 0 szBlock XOut ; Get block from terminal screen.
comwrite szBlock XOut ; Send block to remote system.
endproc
;***************************************************************************
;* *
;* Routines to handle incoming data. *
;* *
;***************************************************************************
;***************************************************************************
;* *
;* DataRcvd( None ) *
;* *
;* This procedure handles incoming data and is called when data reaches *
;* the COM buffer. It keeps track of the X and Y cursor positioning within *
;* the incoming chat box and scrolls the chat box if needed. *
;* *
;* Calls: InScroll *
;* Called by: Called when incoming data is received. *
;* Modifies Globals: XIn, YIn *
;* Returns: None *
;* *
;***************************************************************************
proc DataRcvd
integer Chr
when $KEYHIT SUSPEND
when $RXDATA SUSPEND
while $RXDATA ; Loop while data in incoming buffer.
comgetc Chr ; Get character from buffer.
; X and Y.
switch Chr
case 0x08 ; Check for a backspace character.
if XIn > 0 ; If we're not at the beginning of
termputc YIn XIn Chr ; the line, back up the cursor
XIn-- ; and delete the character under
endif ; it.
endcase
case 0x0C ; Check for a form feed and eat it.
endcase
case 0x0D ; Check for a carriage return or
case 0x0A ; line feed. Adjust display to
XIn = 0, YIn++ ; handle line feed and scroll
if YIn > YInMax ; if necessary.
InScroll()
YIn = (YInMax - InScrollPos) + 1
endif
endcase
case 0x1B ; Special handling for escape
if _EATESC ; sequences.
exitswitch ; Exit past the default case.
endif
default ; Output character to incoming chat
termputc YIn XIn Chr
XIn++ ; Increment the In box X pointer.
if XIn > MaxX ; Make sure that we're not at end of
XIn = 0, YIn++ ; line and if so, adjust accord.
if YIn > YInMax ; Make sure we're not at maximum Y
InScroll() ; and if so, scroll.
YIn = (YInMax - InScrollPos) + 1
endif
endif
endcase
endswitch
endwhile
when $RXDATA RESUME
when $KEYHIT RESUME
endproc
;***************************************************************************
;* *
;* Incoming and outgoing chat box scrolling routines. *
;* *
;***************************************************************************
;***************************************************************************
;* *
;* InScroll( None ) *
;* *
;* This procedure handles scrolling of the incoming chat box. It uses the *
;* same primitive scrolling technique used in OutScroll. *
;* *
;* Calls: None *
;* Called by: DataRcvd *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc InScroll
integer Row, Start, Prev
string szLine
string szBlank
Start = (YInMax - InScrollPos) + 1 ; Find out where to begin.
strset szBlank 0 ' ' MaxCols
strputc szBlank MaxCols 0
for Row = Start upto YInMax ; Loop from starting line to ending
termgets Row 0 szLine MaxCols ; line and move each line up the
termputs Row 0 szBlank RAW
Prev = Row - InScrollPos ; terminal screen. Achieves the
if Prev >= YInMin
termputs Prev 0 szLine
endif
endfor
endproc
;***************************************************************************
;* *
;* OutScroll( None ) *
;* *
;* Handles scrolling within the outgoing chat box. Primitive scrolling *
;* routine scrolls by moving all lines in outgoing chat box up one and *
;* erasing the last line. *
;* *
;* Calls: None *
;* Called by: DoOutChr *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc OutScroll
integer Row, Start, Prev
string szLine
string szBlank
Start = (YOutMax - OutScrollPos) + 1; Find out where to begin.
strset szBlank 0 ' ' MaxCols
strputc szBlank MaxCols 0
for Row = Start upto YOutMax ; Loop from starting line to ending
termgets Row 0 szLine MaxCols ; line and move each line up the
locate Row 0
termwrites szBlank
Prev = Row - OutScrollPos ; terminal screen. Achieves the
if Prev >= YOutMin
locate Prev 0 ; scrolling.
termwrites szLine RAW
endif
endfor
endproc
;***************************************************************************
;* *
;* Screen preparation and chat configuration functions. *
;* *
;***************************************************************************
;***************************************************************************
;* *
;* SetupDisplay( None ) *
;* *
;* Sets up the terminal screen to prepare for chat mode. Calculates size *
;* of incoming chat and outgoing chat boxes and call InBoxCfg and OutBoxCfg*
;* to create them. *
;* *
;* Calls: InBoxCfg, OutBoxCfg *
;* Called by: Main *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc SetupDisplay
integer InBoxX, InBoxH
integer OutBoxX, OutBoxH
; Figure position and size of the incoming and outgoing data boxes.
InBoxX = 0, InBoxH = _INSIZE
if InBoxH < 3 ; Make sure that _INSIZE is a value
InBoxH = 3 ; between 3 and 21.
elseif InBoxH > 21
InBoxH = 21
endif
OutBoxX = InBoxX + InBoxH
OutBoxH = (MaxRows - OutBoxX) - 1
clear ; Clear the terminal screen.
InBoxCfg( InBoxX, InBoxH ) ; Display the incoming data box.
OutBoxCfg( OutBoxX, OutBoxH ) ; Display the outgoing data box.
locate YOutMin 0 ; Locate cursor in out box.
endproc
;***************************************************************************
;* *
;* InBoxCfg( integer Row, integer Height ) *
;* *
;* Figures the minimum and maximum Y values for the incoming chat window, *
;* and displays the incoming chat message bar. *
;* *
;* Calls: PutBar *
;* Called by: SetupDisplay *
;* Modifies Globals: YInMin, YInMax, XIn, YIn *
;* Returns: None *
;* *
;***************************************************************************
proc InBoxCfg
param integer Row, Height
YInMin = Row + 1 ; Figure dimensions for the incoming
YInMax = (Row + Height) - 1 ; chat box.
XIn = 0, YIn = YInMin
InScrollPos = Height / 2
PutBar( Row, _INBARTXT ) ; Display the incoming chat bar.
endproc
;***************************************************************************
;* *
;* OutBoxCfg( integer Row, integer Height ) *
;* *
;* Figures the minimum and maximum Y values for the outgoing chat window, *
;* and displays the outgoing chat message bar. *
;* *
;* Calls: PutBar *
;* Called by: SetupDisplay *
;* Modifies Globals: YOutMin, YOutMax, XOut, YOut *
;* Returns: None *
;* *
;***************************************************************************
proc OutBoxCfg
param integer Row, Height
integer ChatMsgPos
YOutMin = Row + 1 ; Figure dimensions for the outgoing
YOutMax = (Row + Height) - 1 ; chat box.
XOut = 0, YOut = YOutMin
ChatMsgPos = Row + Height ; Figure pos for chat mode message.
OutScrollPos = Height / 2
PutBar( Row, _OUTBARTXT ) ; Display outgoing char bar.
if ChatMsgPos < MaxRows ; Display chat mode message.
PutBar( ChatMsgPos, _CHATMSGTXT )
endif
endproc
;***************************************************************************
;* *
;* PutBar( integer Row, string Text ) *
;* *
;* Displays a bar with the specified text centered on the terminal screen *
;* at the specified row. *
;* *
;* Calls: None *
;* Called by: InBoxCfg, OutBoxCfg *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc PutBar
param integer YCoord
param string szText
integer TextPos, Len, SaveX, SaveY
string szBar
SaveX = $COL, SaveY = $ROW ; Save current cursor location.
strset szBar 0 'Û' MaxCols ; Create bar in bar string.
strputc szBar MaxCols 0 ; Add NULL to end of bar.
locate YCoord 0 ; Locate cursor at bar position.
termwrites szBar ; Output the bar.
if not strcmp szText "" ; Check to see if text is specified.
strlen szText Len ; Get length of text to display.
TextPos = ( MaxCols / 2 ) - ( Len / 2 ) ; Figure centering for text.
locate YCoord TextPos ; Locate cursor to display text.
szText = TXAnsiToOem(szText)
termwrites szText ; Display text centered on bar.
endif
locate SaveY, SaveX ; Relocate the cursor to saved pos.
endproc
;***************************************************************************
;* *
;* Cleanup and parameter setting procedures. *
;* *
;***************************************************************************
;***************************************************************************
;* *
;* CleanUp( None ) *
;* *
;* Provides a clean exit from the script file, clears the screen and sets *
;* parameters to previous settings. *
;* *
;* Calls: ResetParms *
;* Called by: Called when triggered by user's attempt to exit. *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc CleanUp
;Reset settings to state before
ResetParms() ;was run and clear terminal.
clear
exit ;Exit the chat mode script.
endproc
;***************************************************************************
;* *
;* SetParms( None ) *
;* *
;* This procedure is used to save and set any terminal, port, etc, settings*
;* required by the chat mode. ResetParms should reset the parameters when *
;* the chat script is exited. *
;* *
;* Calls: None *
;* Called by: Main *
;* Modifies Globals: StoreScrl *
;* Returns: None *
;* *
;***************************************************************************
proc SetParms
fetch terminal scroll StoreScrl ; Get state of terminal scroll.
fetch chatmode OutMode CrMode ; Get the current chat mode.
fetch actionbar top szPWB[0] ; Get TOP ActionBar.
fetch actionbar left szPWB[1] ; Get LEFT ActionBar.
fetch actionbar right szPWB[2] ; Get RIGHT ActionBar.
fetch actionbar bottom szPWB[3] ; Get BOTTOM ActionBar.
fetch actionbar float szPWB[4] ; Get FLOATING ActionBar.
fetch metakeys MetaState ; State of Meta Keys at startup.
fetch quickselect StoreQSel ; State of Quick Select Line.
set terminal scroll off ; Set terminal scroll to off.
set actionbar top "" ; Turn off the ActionBars.
set actionbar left ""
set actionbar right ""
set actionbar bottom ""
set actionbar float ""
set metakeys OFF ; Turn off the Meta Keys.
set quickselect OFF ; Turn off Quick Select Line.
menubar hMenuId ; Get rid of the PW menu bar.
menushow hMenuId
endproc
;***************************************************************************
;* *
;* ResetParms( None ) *
;* *
;* Restores parameters, set by SetParms, to their original values (before *
;* the script was executed). *
;* *
;* Calls: None *
;* Called by: CleanUp *
;* Modifies Globals: None *
;* Returns: None *
;* *
;***************************************************************************
proc ResetParms
set terminal scroll StoreScrl ; Restore scroll state.
if not strcmp szPWB[0] ""
set actionbar top szPWB[0] ; Reset top ActionBar.
endif
if not strcmp szPWB[1] ""
set actionbar left szPWB[1] ; Reset left ActionBar.
endif
if not strcmp szPWB[2] ""
set actionbar right szPWB[2] ; Reset right ActionBar.
endif
if not strcmp szPWB[3] ""
set actionbar bottom szPWB[3] ; Reset bottom ActionBar.
endif
if not strcmp szPWB[4] ""
set actionbar float szPWB[4] ; Reset floating ActionBar.
endif
set metakeys MetaState ; Restore the Meta Keys.
set quickselect StoreQSel ; Restore the Quick Select Line.
menushow $PWMENUDEF ; Restore the PW menu bar.
termkey 0x1B
endproc
;************************************************************************
;* *
;* PWMODECHANGE (integer) : integer *
;* *
;* This procedure checks the Mode that PW is in, and compares it to the *
;* parameter. If they are equal then PW is in the correct mode. *
;* Otherwise, it presents the user with a dialog box asking if they *
;* want to change to the correct mode or halt the script. *
;* *
;* The modes are as follows: *
;* 0 = Terminal *
;* 1 = FTP *
;* 2 = WWW *
;* 3 = EMAIL *
;* 4 = NEWS *
;* *
;* Calls: none *
;* *
;* Modifies globals: none *
;* *
;************************************************************************
func PWModeChange : integer
param integer nMode
integer nResponse
;* rude hack to allow CHAT to run in Telnet mode
if ($PWMode == 5) ;if telnet mode
return 1
endif
if (nMode != $PWMODE)
sdlgmsgbox PWMODESTR1 PWMODESTR2 EXCLAMATION YESNO nResponse
if (nResponse == 6)
pwmode nMode
else
exit
endif
endif
Return 1
endfunc
;*******************************
;OEM Ansi Functions
;*******************************
func RXOemToAnsi : string
param string OemStr
string AnsiStr
if !OEMFlag
oemtoansi OemStr AnsiStr
return AnsiStr
endif
return OemStr
endfunc
func TXAnsiToOem : string
param string AnsiStr
string OemStr
if !OEMFlag
ansitooem AnsiStr OemStr
return OemStr
endif
return AnsiStr
endfunc
;*** End of CHAT.WAS ***