;THE VIRTUAL EMULATOR V1.0 Script to detect and strip/convert incoming data. ;***************************************************************************** ;* * ;* EMULATOR.WAS * ;* Copyright (C) 1992 Datastorm Technologies, Inc. * ;* All rights reserved. * ;* * ;* This script will detect and either strip or convert a user programmed * ;* string of data. It is designed to allow 5 seperate strings to be enabled * ;* simultaneously. The data strings may consist of escape sequences, text, * ;* or any other string of data which may be received through the com port. * ;* * ;* 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. * ;***************************************************************************** ;***************************************************************************** ;* GLOBAL VARIABLES * ;***************************************************************************** integer ButtonNum[5],BoxTrue ;Globals for dialog box string InputOutput[10] ;Globals for dialog box ;***************************************************************************** ;* * ;* MAIN * ;* The Main procedure calls InitialSet procedure to set variables to default * ;* values. Then it calls AddMenuItem procedure which adds Emulator to the * ;* current menu. After adding the menu item, it activates a WHEN which * ;* monitors menu activity. If the new menu item is chosen, it calls * ;* MenuChecker, which acts upon the selected menu item. * ;* * ;* * ;* Calls: InitialSet, AddMenuItem, MenuChecker * ;* Modifies globals: None * ;***************************************************************************** proc Main InitialSet() ;Calls proc to set variables AddMenuItem() ;Calls proc to setup menu when $ASPMENU call MenuChecker ;Acts upon user menu choice while 1 ;Loops forever endwhile endproc ;***************************************************************************** ;* * ;* MenuChecker * ;* The procedure MenuChecker acts upon the menu item chosen by the user. * ;* If the user chooses exit, the script ends. If the user chooses configure,* ;* then the Drawbox procedure is called to bring up the dialog box. This * ;* procedure also disables all script control over data to prevent data loss.* ;* After returning from the DrawBox procedure, the menu WHEN is re-enabled. * ;* In addition, the DataHandle procedure is called which actually retrieves * ;* and writes data to the terminal screen. * ;* * ;* Calls: DrawBox, DataHandle * ;* Called by: Main * ;* Modifies globals: None * ;***************************************************************************** proc MenuChecker integer MenuTemp ;Temporary integer variable MenuTemp=$ASPMENU ;Menu activity variable set aspect RXDATA OFF ;Script data control off when CLEAR ;Clear out all WHENS switch MenuTemp ;Menu choice switch case 1 ;If choice was configure DrawBox() ;Dialog box procedure when $ASPMENU call MenuChecker ;Re-activates menu WHEN DataHandle() ;Data control procedure endcase case 2 ;If Exit was choice exit ;Ends script endcase endswitch endproc ;***************************************************************************** ;* * ;* DataHandle * ;* The procedure DataHandle retrieves data from the com port and writes data * ;* to the terminal screen. * ;* * ;* Calls: None * ;* Called by: MenuChecker * ;* Modifies globals: None * ;***************************************************************************** proc DataHandle ;Read and write data proc integer Data1 ;Read and write variable while 1 ;Loop forever while $RXDATA ;Watch port for data comgetc Data1 ;Get data termwritec Data1 ;Write data to terminal endwhile endwhile endproc ;***************************************************************************** ;* * ;* AddMenuItem * ;* The procedure AddMenuItem adds the Emulator choice to the current menu. * ;* After adding Emulator as a pop-up menu, it then adds the two items Exit * ;* and Configure to the Emulator menu. After adding all changes, it issues * ;* the MENUSHOW command to display the added options. * ;* * ;* Calls: None * ;* Called by: Main * ;* Modifies globals: None * ;***************************************************************************** proc AddMenuItem ;Adds menu items to menu integer PWMenuID,MenuID1 ;Variables for menu id's PWMenuID=$PWMENUBAR ;Gets current menu menupopup PWMenuID "E&mulator" MenuID1 ;Adds popup to current menu menuitem MenuID1 1 "&Configure" ;Adds item to popup menu menuitem MenuID1 2 "&Exit Script" ;Adds item to popup menu menushow PWMenuID ;Causes changes to be visable endproc ;***************************************************************************** ;* * ;* DrawBox * ;* The procedure DrawBox draws and displays the configuration dialog box. * ;* From here the user can configure, load and save defaults, and activate * ;* help if needed. The box is drawn, and then the EnableIt procedure runs to * ;* enable/disable required edit box fields. The script then fires a WHEN to * ;* watch for user activity and call the BoxUpdate procedure to act upon the * ;* user choices. * ;* * ;* Calls: EnableIt, BoxUpdate * ;* Called by: MenuChecker * ;* Modifies globals: InputOutput, ButtonNum, BoxTrue * ;***************************************************************************** proc DrawBox ;Dialog box procedure dialogbox 0 75 50 250 250 27 "THE VIRTUAL EMULATOR Configuration Editor" pushbutton 6 170 210 54 14 "&Load Defaults" DEFAULT pushbutton 1 30 185 54 14 "&Clear Fields" pushbutton 2 30 210 54 14 "E&xit Script" pushbutton 3 100 185 54 14 "Set as &Default" pushbutton 4 100 210 54 14 "Emulator &Help" pushbutton 5 170 185 54 14 "&Start" OK text 37 10 21 5 12 "1" LEFT editbox 7 20 20 42 12 InputOutput[0] 12 text 38 10 51 15 12 "2" LEFT editbox 8 20 50 42 12 InputOutput[1] 12 text 39 10 81 15 12 "3" LEFT editbox 9 20 80 42 12 InputOutput[2] 12 text 40 10 111 15 12 "4" LEFT editbox 10 20 110 42 12 InputOutput[3] 12 text 41 10 141 15 12 "5" LEFT editbox 11 20 140 42 12 InputOutput[4] 12 editbox 12 188 20 42 12 InputOutput[5] 12 editbox 13 188 50 42 12 InputOutput[6] 12 editbox 14 188 80 42 12 InputOutput[7] 12 editbox 15 188 110 42 12 InputOutput[8] 12 editbox 16 188 140 42 12 InputOutput[9] 12 radiogroup 17 ButtonNum[0] radiobutton 42 75 20 22 12 "Off" radiobutton 18 106 20 25 12 "Strip" radiobutton 19 139 20 45 12 "Convert to:" endgroup groupbox 20 17 13 216 22 radiogroup 21 ButtonNum[1] radiobutton 43 75 50 22 12 "Off" radiobutton 22 106 50 25 12 "Strip" radiobutton 23 139 50 45 12 "Convert to:" endgroup groupbox 24 17 43 216 22 radiogroup 25 ButtonNum[2] radiobutton 44 75 80 22 12 "Off" radiobutton 26 106 80 25 12 "Strip" radiobutton 27 139 80 45 12 "Convert to:" endgroup groupbox 28 17 73 216 22 radiogroup 29 ButtonNum[3] radiobutton 45 75 110 22 12 "Off" radiobutton 30 106 110 25 12 "Strip" radiobutton 31 139 110 45 12 "Convert to:" endgroup groupbox 32 17 103 216 22 radiogroup 33 ButtonNum[4] radiobutton 46 75 140 22 12 "Off" radiobutton 34 106 140 25 12 "Strip" radiobutton 35 139 140 45 12 "Convert to:" endgroup groupbox 36 17 133 216 22 enddialog EnableIt() ;Enable/disable procedure when DIALOG 0 call BoxUpdate ;Waits for a change while BoxTrue==1 ;Variable used to close box endwhile endproc ;***************************************************************************** ;* * ;* BoxUpdate * ;* The procedure BoxUpdate is called to act upon user choices made in the * ;* dialog box. * ;* * ;* Calls: DefaultFile, InitialSet, EnableIt, SaveDefaultFile, EmulatorHelp, * ;* and OkButton * ;* Called by: DrawBox * ;* Modifies globals: None * ;***************************************************************************** proc BoxUpdate ;Act upon dialog change integer Temp1 ;Temporary variable dlgevent 0 Temp1 ;Returns the effected control switch Temp1 ;Switch based on control case 6 ;Load default file choice DefaultFile() ;Load default procedure endcase case 1 ;Clear fields choice InitialSet() ;Reset variables EnableIt() ;Reset enable/disable fields endcase case 3 ;Save default choice SaveDefaultFile() ;Save default procedure endcase case 4 ;Help choice EmulatorHelp() ;Help procedure endcase case 2 ;Exit script choice exit ;Exit script endcase case 5 ;Start Choice OkButton() ;Start emulating procedure endcase default ;Any other choice EnableIt() ;Set enable/disable fields endcase endswitch dlgupdate 0 1 41 ;Updates dialog box endproc ;***************************************************************************** ;* * ;* EmulatorHelp * ;* The procedure EmulatorHelp displays a dialog box which presents the user * ;* with a series of text explanations and instructions for using the script. * ;* * ;* Calls: None * ;* Called by: BoxUpdate * ;* Modifies globals: None * ;***************************************************************************** proc EmulatorHelp ;Help procedure integer TempInt ;Temporary variable dialogbox 1 0 0 300 280 65 PARENT 0 ;Dialog box with help text pushbutton 1 130 250 40 14 "E&xit" CANCEL DEFAULT text 2 29 30 242 40 "Thank you for trying THE VIRTUAL EMULATOR. This \ script was designed to allow the user to type in a series of characters, \ and then depending upon the selected choice, either ignore, strip, or replace\ those characters with a different sequence." LEFT text 3 29 70 242 16 "The left edit box would be the set of characters \ that the script is watching for, the radio buttons tell the script what \ action to take upon finding the sequence" LEFT text 4 29 86 242 16 "of characters, and if the choice is to \ replace the characters, then the right most edit box should contain the \ replacement characters plus any needed spaces." LEFT text 5 29 115 242 24 "The characters to be searched for may contain \ normal text, escape sequences, or any other series of characters that \ may come through the port. The search is case sensitive." LEFT text 6 29 150 242 24 "If OFF is the selected choice then the edit boxes \ for that row will be disabled. If STRIP is the selected choice, then\ only the right hand edit box will be disabled." LEFT text 7 29 180 242 16 "I have included the option of saving to a default \ file. The default file name is VIRTEMUL.TXT and will be located in the \ directory the script started from. " LEFT text 8 29 210 242 24 "CAUTION: Due to the manner in which ASPECT watches\ for sequences coming from the port, certain sequences or characters may not\ show up if they match sequences being searched for." LEFT text 9 110 8 80 12 "Virtual Emulator Help!" CENTER enddialog while 1 ;Loop forever dlgevent 1 TempInt ;Watches for dialog event switch TempInt ;Acts upon event case 0 ;If no event continue endcase default ;Any event close text dialog exitwhile ;Break out of infinite loop endcase endswitch endwhile dlgdestroy 1 CANCEL ;Destroy the help dialog box endproc ;***************************************************************************** ;* * ;* SaveDefaultFile * ;* The procedure SaveDefaultFile tests for existance of a default file, and * ;* according to user input will allow user to create/overwrite the default * ;* file by calling the CreateFile procedure. The default path is the current* ;* aspect path, and the default filename is VIRTEMUL.TXT. These are combined* ;* and passed to the CreateFile procedure. * ;* * ;* Calls: CreateFile * ;* Called by: BoxUpdate * ;* Modifies globals: None * ;***************************************************************************** proc SaveDefaultFile ;Save default file procedure integer WarnChoice ;Variable for user choice string DfltFileName="VIRTEMUL.TXT" ;Variables for file/path string DefaultFilePath ;Variables for file/path strfmt DefaultFilePath "%s\%s" $ASPECTPATH DfltFileName ;Complete filename findfirst DefaultFilePath ;Looks for existing file if SUCCESS ;Tests results sdlgmsgbox "Warning!" "Do you want to overwrite the existing Default\ File?" QUESTION OKCANCEL WarnChoice 2 ;Displays warning message if WarnChoice==1 ;Checks user response CreateFile(DefaultFilePath) ;Call file creation procedure endif else ;If no existing default file CreateFile(DefaultFilePath) ;Call file creation procedure endif endproc ;***************************************************************************** ;* * ;* CreateFile(string) * ;* The procedure CreateFile receives the string DefaultFilePath from the * ;* SaveDefaultFile pocedure. This string contains the combined path and * ;* filename. A string is then built to be saved in the default file. * ;* A sequence is used to seperate items in the string. The default seperator* ;* sequence is: "{?{". If an error occurs during the save, the ErrorHandle * ;* procedure is called. * ;* * ;* Calls: ErrorHandle * ;* Called by: SaveDefaultFile * ;* Modifies globals: InputOutput, ButtonNum * ;***************************************************************************** proc CreateFile ;Default file creation proc param string DefaultFilePath ;File name and path variable integer TempInt=0,Counter ;Temporary variables string SeperatorSeq="{?{",TempString ;File Variables and seperator string TempString2,DefaultFileString ;File Variables and seperator fopen 0 DefaultFilePath CREATE ;Create default file if FAILURE ;Checks for errors ErrorHandle() ;Call error procedure else ;If no errors occur DefaultFileString="" ;Resets variable for Counter=0 upto 9 strfmt TempString "%s%s" InputOutput[Counter] SeperatorSeq ;Builds data string strfmt DefaultFileString "%s%s" DefaultFileString TempString ;Builds data string endfor for Counter =0 upto 4 itoa ButtonNum[Counter] TempString2 ;Converts to string for file strfmt TempString "%s%s" TempString2 SeperatorSeq ;Builds data string strfmt DefaultFileString "%s%s" DefaultFileString TempString ;Builds data string endfor fputs 0 DefaultFileString ;Writes to Default file endif endproc ;***************************************************************************** ;* * ;* DefaultFile * ;* The procedure DefaultFile tests for the existance of a default file and * ;* calls the GetData procedure if a default file exists. If an error occurs,* ;* the ErrorHandle procedure is called. After loading the default file the * ;* EnableIt procedure is called to enable/disable the edit box fields. If * ;* no default file exists, the NoDefaultFile procedure is called. * ;* * ;* Calls: ErrorHandle, GetData, EnableIt, NoDefaultFile * ;* Called by: BoxUpdate * ;* Modifies globals: None * ;***************************************************************************** proc DefaultFile ;Load default file procedure string DefaultFilePath,DfltFileName="VIRTEMUL.TXT" ;File path variables strfmt DefaultFilePath "%s\%s" $ASPECTPATH DfltFileName ;Builds data string findfirst DefaultFilePath ;Searches for default file if SUCCESS ;If it finds it fopen 0 DefaultFilePath READ ;Opens default file if FAILURE ;Checks for errors ErrorHandle() ;Error procedure else ;If no errors GetData() ;Calls data input proc endif EnableIt() ;Sets enable/disable fields else ;If no Default file exists NoDefaultFile() ;No default file procedure endif endproc ;***************************************************************************** ;* * ;* NoDefaultFile * ;* The procedure NoDefaultFile displays a message if no default file was * ;* found. * ;* * ;* Calls: None * ;* Called by: DefaultFile * ;* Modifies globals: None * ;***************************************************************************** proc NoDefaultFile ;No default file procedure integer TempInteger ;Temporary variable sdlgmsgbox "Default File Error!" "There is no Default File available!" \ EXCLAMATION OK TempInteger 1 ;Error no default file endproc ;***************************************************************************** ;* * ;* GetData * ;* The procedure GetData opens and retrieves the default data string from the* ;* default file. * ;* * ;* Calls: None * ;* Called by: DefaultFile * ;* Modifies globals: InputOutput, ButtonNum * ;***************************************************************************** proc GetData ;Retrieve data from file proc integer Counter ;Counter variable string DefaultFileString,TempString ;Input strings while not feof 0 ;Checks for end of file fgets 0 DefaultFileString ;Get string from file for Counter=0 upto 9 strextract InputOutput[Counter] DefaultFileString "{?{" Counter ;Seperate data string endfor for Counter =0 upto 4 strextract TempString DefaultFileString "{?{" Counter+10 ;Seperate data string atoi TempString ButtonNum[Counter] ;Converts string back to int. endfor endwhile endproc ;***************************************************************************** ;* * ;* ErrorHandle * ;* The procedure ErrorHandle displays an error message and exits the script * ;* if a major error occurs. * ;* * ;* Calls: None * ;* Called by: CreateFile, DefaultFile * ;* Modifies globals: None * ;***************************************************************************** proc ErrorHandle ;Error procedure integer TempInteger ;Temporary variable sdlgmsgbox "Error Detected" "An error has occurred!" EXCLAMATION OK TempIn\ teger 1 BEEP ;Error message cause unknown dlgdestroy 0 CANCEL ;Destroy dialog box BoxTrue=0 ;End dialog loop exit ;Exit script endproc ;***************************************************************************** ;* * ;* EnableIt * ;* The procedure EnableIt checks the current status of the radio buttons on * ;* the dialog box and enables or disables edit box fields accordingly. * ;* * ;* Calls: None * ;* Called by: DrawBox, BoxUpdate, DefaultFile * ;* Modifies globals: ButtonNum * ;***************************************************************************** proc EnableIt ;Set enable/disable field integer TempCounter=0 ;Counter variable for TempCounter=0 upto 4 if ButtonNum[TempCounter]==TempCounter+42 ;Tests radio buttons for off disable dlgctrl 0 TempCounter+7 ;Disables replace if off disable dlgctrl 0 TempCounter+12 ;Disables search if off elseif ButtonNum[TempCounter]==(TempCounter*4)+18 ;Tests for strip disable dlgctrl 0 TempCounter+12 ;Disables replace if strip enable dlgctrl 0 TempCounter+7 ;Enables search if strip else ;Tests for convert enable dlgctrl 0 TempCounter+12 ;Enable replace if convert enable dlgctrl 0 TempCounter+7 ;Enable search if convert endif endfor endproc ;***************************************************************************** ;* * ;* OkButton * ;* The procedure OkButton activates the WHENS according to the radio button * ;* positions. Then the dialog box is removed and the script begins accepting* ;* and acting upon the data. * ;* * ;* Calls: MatchCount, Match1, Match2, Match3, Match4, Match5 * ;* Called by: BoxUpdate * ;* Modifies globals: BoxTrue, ButtonNum, InputOutput * ;***************************************************************************** proc OkButton ;Start emulating procedure dlgdestroy 0 OK ;Destroys dialog box BoxTrue=0 ;Ends dialog box loop if ButtonNum[0]==18 ;Tests current button setting when TARGET 1 InputOutput[0] MATCHCASE STRIP call MatchCount ;If strip elseif ButtonNum[0]==42 ;Tests current button setting when TARGET 1 CLEAR ;If off else ;Tests current button setting when TARGET 1 InputOutput[0] MATCHCASE STRIP call Match1 ;If convert endif if ButtonNum[1]==22 ;Tests current button setting when TARGET 2 InputOutput[1] MATCHCASE STRIP call MatchCount ;If strip elseif ButtonNum[1]==43 ;Tests current button setting when TARGET 2 CLEAR ;If off else ;Tests current button setting when TARGET 2 InputOutput[1] MATCHCASE STRIP call Match2 ;If convert endif if ButtonNum[2]==26 ;Tests current button setting when TARGET 3 InputOutput[2] MATCHCASE STRIP call MatchCount ;If strip elseif ButtonNum[2]==44 ;Tests current button setting when TARGET 3 CLEAR ;If off else ;Tests current button setting when TARGET 3 InputOutput[2] MATCHCASE STRIP call Match3 ;If convert endif if ButtonNum[3]==30 ;Tests current button setting when TARGET 4 InputOutput[3] MATCHCASE STRIP call MatchCount ;If strip elseif ButtonNum[3]==45 ;Tests current button setting when TARGET 4 CLEAR ;If off else ;Tests current button setting when TARGET 4 InputOutput[3] MATCHCASE STRIP call Match4 ;If convert endif if ButtonNum[4]==34 ;Tests current button setting when TARGET 5 InputOutput[4] MATCHCASE STRIP call MatchCount ;If strip elseif ButtonNum[4]==46 ;Tests current button setting when TARGET 5 CLEAR ;If off else ;Tests current button setting when TARGET 5 InputOutput[4] MATCHCASE STRIP call Match5 ;If convert endif set aspect RXDATA ON ;Enables script data control endproc ;***************************************************************************** ;* * ;* Match1 * ;* The procedure Match1 will replace the selected data with the user prog- * ;* ammed data if the radio button choice was set to convert. * ;* * ;* Calls: None * ;* Called by: OkButton * ;* Modifies globals: InputOutput * ;***************************************************************************** proc Match1 ;If WHEN 1 replace fires termwrites InputOutput[5] ;Replacement data to terminal endproc ;***************************************************************************** ;* * ;* Match2 * ;* The procedure Match2 will replace the selected data with the user prog- * ;* ammed data if the radio button choice was set to convert. * ;* * ;* Calls: None * ;* Called by: OkButton * ;* Modifies globals: InputOutput * ;***************************************************************************** proc Match2 ;If WHEN 2 replace fires termwrites InputOutput[6] ;Replacement data to terminal endproc ;***************************************************************************** ;* * ;* Match3 * ;* The procedure Match3 will replace the selected data with the user prog- * ;* ammed data if the radio button choice was set to convert. * ;* * ;* Calls: None * ;* Called by: OkButton * ;* Modifies globals: InputOutput * ;***************************************************************************** proc Match3 ;If WHEN 3 replace fires termwrites InputOutput[7] ;Replacement data to terminal endproc ;***************************************************************************** ;* * ;* Match4 * ;* The procedure Match4 will replace the selected data with the user prog- * ;* ammed data if the radio button choice was set to convert. * ;* * ;* Calls: None * ;* Called by: OkButton * ;* Modifies globals: InputOutput * ;***************************************************************************** proc Match4 ;If WHEN 4 replace fires termwrites InputOutput[8] ;Replacement data to terminal endproc ;***************************************************************************** ;* * ;* Match5 * ;* The procedure Match5 will replace the selected data with the user prog- * ;* ammed data if the radio button choice was set to convert. * ;* * ;* Calls: None * ;* Called by: OkButton * ;* Modifies globals: InputOutput * ;***************************************************************************** proc Match5 ;If WHEN 5 replace fires termwrites InputOutput[9] ;Replacement data to terminal endproc ;***************************************************************************** ;* * ;* MatchCount * ;* The procedure MatchCount is a short procedure which is called by the WHEN * ;* statements if the radio button choice is set to strip. This procedure was* ;* not given any function to help increase script speed. The WHEN has to * ;* call a procedure, so this empty procedure was created. * ;* * ;* Calls: None * ;* Called by: OkButton * ;* Modifies globals: None * ;***************************************************************************** proc MatchCount ;Empty strip procedure endproc ;***************************************************************************** ;* * ;* InitialSet * ;* The procedure InitialSet sets all variables to default values. * ;* * ;* Calls: None * ;* Called by: Main, BoxUpdate * ;* Modifies globals: ButtonNum, BoxTrue, InputOutput * ;***************************************************************************** proc InitialSet ;Variable setup procedure integer Counter ;Counter variable for Counter=0 upto 4 ButtonNum[Counter]=(42+Counter) ;Sets radio button defaults endfor BoxTrue=1 ;Dialog box control variable for Counter=0 upto 9 InputOutput[Counter]="" ;Sets edit box string default endfor endproc