home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 April A
/
Pcwk4a98.iso
/
Wtestowe
/
OnNet16
/
STRIPSCR.EDS
< prev
next >
Wrap
Text File
|
1997-01-08
|
7KB
|
224 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 *
*---------------------------------------------------------------------*
* *
* Latest Revision - *
* *
* $Revision: 1.8 $ *
* *
* Modification Log - *
* *
* M0001V70 Put Relay Source Files under PVCS Control *
* by JMM on 12/18/95 *
* *
*---------------------------------------------------------------------*
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