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 >
Text File  |  1993-07-20  |  10KB  |  252 lines

  1. *---------------------------------------------------------------------*
  2. *                            STRIPSCR.EDS                             *
  3. *---------------------------------------------------------------------*
  4. *
  5. * (c) Copyright 1987,1993 RELAY Technology Inc.
  6. *     All rights reserved.
  7. *
  8. * FUNCTION: Actual Editor Macro to perform the stripping of blank lines, comment
  9. *           lines, lines with comments and commands on the same line, and blank
  10. *           spaces at the beginning of lines.  This Editor Macro also replaces
  11. *           references to GOTO, GOSUB and LOOP statement labels with absolute
  12. *           line numbers, to further enhance perfromance through minimizing
  13. *           file size and optimizing label references.
  14. *
  15. *           This macro can be run from the editor command line, or can be
  16. *           executed via STRIPSCR.BAT, which serially optimizes a list of
  17. *           files.
  18. *
  19. * ------------------------------------------------------------------- *
  20. *                            Module History                           *
  21. * ------------------------------------------------------------------- *
  22. * Options: NOMARKCHG                                                  *
  23. *                                                                     *
  24. * Latest Revision -                                                   *
  25. *         $Revision:   5.3  $                                         *
  26. *                                                                     *
  27. * Modification Log -                                                  *
  28. *                                                                     *
  29. *        M1399V60 Add STRIP option to LIBRARY.SCR                     *
  30. *                 by JMM on 07/06/93                                  *
  31. *        M0307V51 Command Line On coniditons not converted to num.    *
  32. *                 by REB on 12/06/91                                  *
  33. *        M0289V51 Put Scripts under source control.                   *
  34. *                 by REB on 11/26/91                                  *
  35. *        M0001V51 Prepare source for version 5.1                      *
  36. *                  by REB on 11/25/91                                 *
  37. *                                                                     *
  38. * ------------------------------------------------------------------- *
  39. *
  40. *           07/05/88 Remove all blanks (spaces) at the beginning of a line.
  41. *                    Also, add the copyright message and use only the fileid
  42. *                    (not drive & path) on the header banner that gets added to
  43. *                    the stripped script.
  44. *           08/17/88 Cleanup for RELAY Gold Customizer's Toolbox 3.0.
  45. *           01/20/89 Put copyright message in a variable at top of this EDS.
  46. *           08/29/89 Incorporation of SPEED.EDS and LIBRARY.SCR for
  47. *                    enhanced file optimization
  48. *           01/15/90 Improved the way it looks for and changes label names
  49. *                    to absolute line numbers.
  50. *           01/18/90 Made change to allow for 999 labels in a script versus
  51. *                    the previously allowed 99 labels.
  52. *           03/20/91 Change to file with an extension of .SCX
  53. *           05/14/91 If the command line is an 'ON' condition, do not change
  54. *                    the label name to an absolute line number. The reason
  55. *                    is that 'ON' conditions are global and remain in effect 
  56. *                    throughout nested scripts. The absolute line number
  57. *                    referred to by an 'ON' condition in one script, may not
  58. *                    coicide with that line number in any nested scripts.
  59. *           07/05/93 Allow file extension to be specified by caller.
  60. *                    Use &STRIPID global variable.
  61. *------------------------------------------------------------------------------*
  62. on error
  63. set display off
  64.  
  65. * Parse options
  66.          &FILEAS = "&FDIR(&EFILEID)*.SCX"       ;* Name to save file as
  67.          &ARG = 1
  68.          loop -OPT1 &N
  69.          if (&&ARG = NOFILE) &FILEAS = "" ; goto -OPT1
  70.          if (&&ARG = FILEAS) &ARG = &ARG+1 ; &FILEAS = &&ARG ; goto -OPT1
  71.          stop error "W&0 - Invalid option: &&ARG"
  72. -OPT1    &ARG = &ARG+1
  73.  
  74. * Place the copyright message in the variable ©RITE.  This is added to the
  75. * top of the stripped script after all of the stripping process has finished.
  76.  
  77.           ©RITE = "* Copyright (c) 1993 Relay Technology Inc."
  78.  
  79. * Delete Comment lines (lines with '*' in column 1)
  80.           top
  81. -DCOMM1   loop END1 until not found
  82.             quiet locate /*/ 1
  83.             if not found goto END1
  84.             delete
  85. -END1       up
  86.  
  87.  
  88. * Delete Comments found on lines with Commands (lines with ';*' in them)
  89.          top
  90. -DCOMM2  loop END2 until not found
  91.            quiet locate /;*/
  92.            if not found goto END2
  93.            &STRIP=&instring(&erecord,";*")
  94.            &CLEANED=&substring(&erecord,1,&STRIP-1)
  95.            delete
  96.            up
  97.            add 1 "&CLEANED"
  98. -END2      up
  99.  
  100. * Delete Blank lines
  101.          top
  102. -DBLANK  loop END3 until not found
  103.            quiet locate /                                    / 1
  104.            if not found goto END3
  105.            if not (&length(&trim(&erecord))=0) goto DBLANK
  106.            delete
  107. -END3      up
  108.  
  109. * Delete blanks at the beginning of lines
  110.          top
  111. -DSPACES loop END4 until not found
  112.            quiet c / //* 1
  113. -END4      top
  114.  
  115.          if (&defined(STRIPID)=GLOBAL)
  116.          then add 1 "* &STRIPID"
  117.          else add 1 "* &substring(&fileid(&efileid),3)"
  118.          add 1 "©RITE"
  119.  
  120. * Replace LOOP, GOTO and GOSUB label references with absolute line numbers
  121. -SPEED
  122. * Set up variable that contains all the possible values for the "ON" conditions
  123.          &PARMS = "ATTNKEY,BREAK,DISCONNECT,ERROR,HANGUP,HOTKEY,IDLE,NOMEMORY,PRTSCREEN,RECEIVE,TIMEOUT,TIMER,NOTRESPONDING"
  124.          argstring &PARMS
  125.          parse "," ...
  126.          &SUB = 1
  127.          &TOTWORDS = &n             ;* total number of "ON" conditions
  128.  
  129. * Load up all the keywords that could follow "ON" into an array (WORD1,WORD2,etc.)
  130.          loop KEYWORDS until (&SUB > &TOTWORDS)
  131.            &WORD&SUB = &&SUB
  132.            &SUB = &SUB + 1
  133. -KEYWORDS
  134.  
  135.          top
  136.          &CNT=1
  137.          loop FINDLABL until not found
  138.            quiet locate /-/1
  139.            if not found goto CONT
  140.            &TEMPREC=&erecord
  141.          &X=1
  142.          loop FINDSPAC *
  143.            &CHAR=&substring(&TEMPREC,&X,1)
  144.          if (&CHAR="") or (&CHAR=" ") then &LABELSZ=&X
  145.            then goto CONTA
  146.          &X=&X+1
  147. -FINDSPAC
  148. -CONTA
  149.          &LBLENGTH=&LABELSZ-2
  150.          &LABEL&CNT=&trim(&substring(&TEMPREC,2,&LBLENGTH))
  151.          &LBNUM&CNT=&eline
  152.          &CNT=&CNT+1
  153. -FINDLABL
  154.  
  155. -CONT
  156.          &PASS=1
  157.          &DASH="-"
  158.          &MAX=&CNT-1
  159. -CONT1
  160.          &LEV=1
  161.          &CMD1="gosub"
  162.          &CMD2="goto"
  163.          &CMD3="loop"
  164.          loop LEVELS until (&LEV > 3)
  165.            &CNT = 1
  166.            loop LABELS until (&CNT > &MAX)
  167.              top
  168.              &TEMPREC=""
  169. -AGAIN
  170.              quiet locate /&CMD&LEV &DASH.&LABEL&CNT/
  171.              if not found goto NEXT
  172.              &TEMPREC=&erecord
  173.              gosub ONCHECK
  174.              &HRC = &retcode
  175.              if (&HRC = 1) goto AGAIN
  176.              &ARGLNGTH=&length("&CMD&LEV &DASH.&LABEL&CNT")
  177.              &STARTPOS = &instring(&TEMPREC,&CMD&LEV &DASH.&LABEL&CNT)
  178.              &ENDPOS = &STARTPOS + &ARGLNGTH - 1
  179.  
  180. * If starting position is one (1), make sure there is a blank space after the label
  181.              if (&STARTPOS <> 1) goto CONT2
  182.              if (&substring(&TEMPREC,&ENDPOS + 1,1) <> " ") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> "") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> ";") goto AGAIN
  183.                else goto CONT3
  184.  
  185. -CONT2
  186. * Starting position is greater than one (1). Make sure there is a blank space on
  187. * either side of the argument
  188.              if (&substring(&TEMPREC,&STARTPOS - 1,1) <> " ") and (&substring(&TEMPREC,&STARTPOS - 1,1) <> ";") goto AGAIN
  189.              if (&substring(&TEMPREC,&ENDPOS + 1,1) <> " ") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> "") and (&substring(&TEMPREC,&ENDPOS + 1,1) <> ";") goto AGAIN
  190.  
  191. -CONT3
  192. * Find beginning position of label in current line.
  193.              &LABELPOS=&instring(&TEMPREC,&DASH.&LABEL&CNT,&STARTPOS,&ENDPOS)
  194.  
  195. * Bring cursor to column 1
  196.              up 1
  197.              down 1
  198.  
  199. * Change the label to it's corresponding absolute line number
  200.              quiet change /&DASH.&LABEL&CNT/:&LBNUM&CNT/1 &LABELPOS
  201.              gosub CHKLEN
  202.              goto AGAIN
  203. -NEXT
  204.          &CNT=&CNT+1
  205. -LABELS
  206.          &LEV = &LEV + 1
  207. -LEVELS
  208.          &PASS = &PASS + 1
  209.          if (&PASS > 2) goto ENDALL
  210.            else &DASH = ""
  211.            else goto CONT1
  212.  
  213. * Subroutine to check if the changed line now exceeds the 255 character limit.
  214. * If so, change it back to the original form.
  215. -CHKLEN
  216.          &TEMPREC=&erecord
  217.          &RECLEN=&length(&TEMPREC)
  218.          if (&RECLEN<=255) return
  219.  
  220. * Bring cursor to column 1
  221.          up 1
  222.          down 1
  223.          quiet change /:&LBNUM&CNT/&DASH.&LABEL&CNT/1 &LABELPOS
  224.          return
  225.  
  226. * Subroutine to check if the line contains an "ON" condition; if so the
  227. * label name should not be changed to an absolute line number
  228. -ONCHECK
  229.          &TEMPREC = &upper(&TEMPREC)
  230.          if (&instring(&TEMPREC,"ON ") = 0) return
  231.          argstring &TEMPREC
  232.          parse " " ...
  233.          &INC = 1
  234.          loop FINDON until (&INC > &n)
  235.            &TOKEN = &&INC
  236.            if (&instring(&TOKEN,";") > 0) &TOKEN = &substring(&TOKEN,&instring(&TOKEN,";")+1)
  237.            if (&TOKEN <> ON) goto FINDNEXT
  238.            &COND = &INC + 1
  239.            &CLEN = &length(&&COND)
  240.            &SUB = 1
  241.            loop FINDWORD until (&SUB > &TOTWORDS)
  242.              if (&&COND = &substring(&WORD&SUB,1,&CLEN)) return 1
  243.              &SUB = &SUB + 1
  244. -FINDWORD
  245. -FINDNEXT
  246.            &INC = &INC + 1
  247. -FINDON
  248.          return
  249.  
  250. * Save file and stop execution
  251. -ENDALL  if (&FILEAS<>"") file &FILEAS
  252.