home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
On Hand
/
On_Hand_From_Softbank_1994_Release_2_Disc_1_1994.iso
/
00091
/
s
/
stripscr.eds
< prev
next >
Wrap
Text File
|
1993-07-20
|
10KB
|
252 lines
*---------------------------------------------------------------------*
* STRIPSCR.EDS *
*---------------------------------------------------------------------*
*
* (c) Copyright 1987,1993 RELAY Technology Inc.
* All rights reserved.
*
* FUNCTION: Actual Editor Macro to perform the stripping of blank lines, comment
* lines, lines with comments and commands on the same line, and blank
* spaces at the beginning of lines. This Editor Macro also replaces
* references to GOTO, GOSUB and LOOP statement labels with absolute
* line numbers, to further enhance perfromance through minimizing
* file size and optimizing label references.
*
* This macro can be run from the editor command line, or can be
* executed via STRIPSCR.BAT, which serially optimizes a list of
* files.
*
* ------------------------------------------------------------------- *
* Module History *
* ------------------------------------------------------------------- *
* Options: NOMARKCHG *
* *
* Latest Revision - *
* $Revision: 5.3 $ *
* *
* Modification Log - *
* *
* M1399V60 Add STRIP option to LIBRARY.SCR *
* by JMM on 07/06/93 *
* M0307V51 Command Line On coniditons not converted to num. *
* by REB on 12/06/91 *
* M0289V51 Put Scripts under source control. *
* by REB on 11/26/91 *
* M0001V51 Prepare source for version 5.1 *
* by REB on 11/25/91 *
* *
* ------------------------------------------------------------------- *
*
* 07/05/88 Remove all blanks (spaces) at the beginning of a line.
* Also, add the copyright message and use only the fileid
* (not drive & path) on the header banner that gets added to
* the stripped script.
* 08/17/88 Cleanup for RELAY Gold Customizer's Toolbox 3.0.
* 01/20/89 Put copyright message in a variable at top of this EDS.
* 08/29/89 Incorporation of SPEED.EDS and LIBRARY.SCR for
* enhanced file optimization
* 01/15/90 Improved the way it looks for and changes label names
* to absolute line numbers.
* 01/18/90 Made change to allow for 999 labels in a script versus
* the previously allowed 99 labels.
* 03/20/91 Change to file with an extension of .SCX
* 05/14/91 If the command line is an 'ON' condition, do not change
* the label name to an absolute line number. The reason
* is that 'ON' conditions are global and remain in effect
* throughout nested scripts. The absolute line number
* referred to by an 'ON' condition in one script, may not
* coicide with that line number in any nested scripts.
* 07/05/93 Allow file extension to be specified by caller.
* Use &STRIPID global variable.
*------------------------------------------------------------------------------*
on error
set display off
* Parse options
&FILEAS = "&FDIR(&EFILEID)*.SCX" ;* Name to save file as
&ARG = 1
loop -OPT1 &N
if (&&ARG = NOFILE) &FILEAS = "" ; goto -OPT1
if (&&ARG = FILEAS) &ARG = &ARG+1 ; &FILEAS = &&ARG ; goto -OPT1
stop error "W&0 - Invalid option: &&ARG"
-OPT1 &ARG = &ARG+1
* Place the copyright message in the variable ©RITE. This is added to the
* top of the stripped script after all of the stripping process has finished.
©RITE = "* Copyright (c) 1993 Relay Technology Inc."
* Delete Comment lines (lines with '*' in column 1)
top
-DCOMM1 loop END1 until not found
quiet locate /*/ 1
if not found goto END1
delete
-END1 up
* Delete Comments found on lines with Commands (lines with ';*' in them)
top
-DCOMM2 loop END2 until not found
quiet locate /;*/
if not found goto END2
&STRIP=&instring(&erecord,";*")
&CLEANED=&substring(&erecord,1,&STRIP-1)
delete
up
add 1 "&CLEANED"
-END2 up
* Delete Blank lines
top
-DBLANK loop END3 until not found
quiet locate / / 1
if not found goto END3
if not (&length(&trim(&erecord))=0) goto DBLANK
delete
-END3 up
* Delete blanks at the beginning of lines
top
-DSPACES loop END4 until not found
quiet c / //* 1
-END4 top
if (&defined(STRIPID)=GLOBAL)
then add 1 "* &STRIPID"
else add 1 "* &substring(&fileid(&efileid),3)"
add 1 "©RITE"
* Replace LOOP, GOTO and GOSUB label references with absolute line numbers
-SPEED
* Set up variable that contains all the possible values for the "ON" conditions
&PARMS = "ATTNKEY,BREAK,DISCONNECT,ERROR,HANGUP,HOTKEY,IDLE,NOMEMORY,PRTSCREEN,RECEIVE,TIMEOUT,TIMER,NOTRESPONDING"
argstring &PARMS
parse "," ...
&SUB = 1
&TOTWORDS = &n ;* total number of "ON" conditions
* Load up all the keywords that could follow "ON" into an array (WORD1,WORD2,etc.)
loop KEYWORDS until (&SUB > &TOTWORDS)
&WORD&SUB = &&SUB
&SUB = &SUB + 1
-KEYWORDS
top
&CNT=1
loop FINDLABL until not found
quiet locate /-/1
if not found goto CONT
&TEMPREC=&erecord
&X=1
loop FINDSPAC *
&CHAR=&substring(&TEMPREC,&X,1)
if (&CHAR="") or (&CHAR=" ") then &LABELSZ=&X
then goto CONTA
&X=&X+1
-FINDSPAC
-CONTA
&LBLENGTH=&LABELSZ-2
&LABEL&CNT=&trim(&substring(&TEMPREC,2,&LBLENGTH))
&LBNUM&CNT=&eline
&CNT=&CNT+1
-FINDLABL
-CONT
&PASS=1
&DASH="-"
&MAX=&CNT-1
-CONT1
&LEV=1
&CMD1="gosub"
&CMD2="goto"
&CMD3="loop"
loop LEVELS until (&LEV > 3)
&CNT = 1
loop LABELS until (&CNT > &MAX)
top
&TEMPREC=""
-AGAIN
quiet locate /&CMD&LEV &DASH.&LABEL&CNT/
if not found goto NEXT
&TEMPREC=&erecord
gosub ONCHECK
&HRC = &retcode
if (&HRC = 1) goto AGAIN
&ARGLNGTH=&length("&CMD&LEV &DASH.&LABEL&CNT")
&STARTPOS = &instring(&TEMPREC,&CMD&LEV &DASH.&LABEL&CNT)
&ENDPOS = &STARTPOS + &ARGLNGTH - 1
* If starting position is one (1), make sure there is a blank space after the label
if (&STARTPOS <> 1) goto CONT2
if (&substring(&TEMPREC,&ENDPOS + 1,1) <> " ") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> "") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> ";") goto AGAIN
else goto CONT3
-CONT2
* Starting position is greater than one (1). Make sure there is a blank space on
* either side of the argument
if (&substring(&TEMPREC,&STARTPOS - 1,1) <> " ") and (&substring(&TEMPREC,&STARTPOS - 1,1) <> ";") goto AGAIN
if (&substring(&TEMPREC,&ENDPOS + 1,1) <> " ") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> "") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> ";") goto AGAIN
-CONT3
* Find beginning position of label in current line.
&LABELPOS=&instring(&TEMPREC,&DASH.&LABEL&CNT,&STARTPOS,&ENDPOS)
* Bring cursor to column 1
up 1
down 1
* Change the label to it's corresponding absolute line number
quiet change /&DASH.&LABEL&CNT/:&LBNUM&CNT/1 &LABELPOS
gosub CHKLEN
goto AGAIN
-NEXT
&CNT=&CNT+1
-LABELS
&LEV = &LEV + 1
-LEVELS
&PASS = &PASS + 1
if (&PASS > 2) goto ENDALL
else &DASH = ""
else goto CONT1
* Subroutine to check if the changed line now exceeds the 255 character limit.
* If so, change it back to the original form.
-CHKLEN
&TEMPREC=&erecord
&RECLEN=&length(&TEMPREC)
if (&RECLEN<=255) return
* Bring cursor to column 1
up 1
down 1
quiet change /:&LBNUM&CNT/&DASH.&LABEL&CNT/1 &LABELPOS
return
* Subroutine to check if the line contains an "ON" condition; if so the
* label name should not be changed to an absolute line number
-ONCHECK
&TEMPREC = &upper(&TEMPREC)
if (&instring(&TEMPREC,"ON ") = 0) return
argstring &TEMPREC
parse " " ...
&INC = 1
loop FINDON until (&INC > &n)
&TOKEN = &&INC
if (&instring(&TOKEN,";") > 0) &TOKEN = &substring(&TOKEN,&instring(&TOKEN,";")+1)
if (&TOKEN <> ON) goto FINDNEXT
&COND = &INC + 1
&CLEN = &length(&&COND)
&SUB = 1
loop FINDWORD until (&SUB > &TOTWORDS)
if (&&COND = &substring(&WORD&SUB,1,&CLEN)) return 1
&SUB = &SUB + 1
-FINDWORD
-FINDNEXT
&INC = &INC + 1
-FINDON
return
* Save file and stop execution
-ENDALL if (&FILEAS<>"") file &FILEAS