#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 23 Nov 2016 15:10:28 +0100
changeset 21010 9efae8a7600b
parent 21009 d4035978c3c7
child 21011 00319cafe394
#FEATURE by cg class: Smalltalk changed: #start
Smalltalk.st
--- a/Smalltalk.st	Wed Nov 23 14:06:02 2016 +0100
+++ b/Smalltalk.st	Wed Nov 23 15:10:28 2016 +0100
@@ -4565,13 +4565,20 @@
             ].
 
             (isEval | isPrint | isFilter | isRepl | isRunMain) ifTrue:[
+                |args|
+                
                 isRepl ifFalse:[
                     CommandLineArguments size <= idx ifTrue:[
                         StandAlone := true.
                         self exitWithErrorMessage:'missing argument after -E/-P/-F/--run.'.
                     ].
-                    arg := CommandLineArguments at:idx + 1.
-                    CommandLineArguments removeAtIndex:idx+1.
+                    isFilter ifTrue:[
+                        args := CommandLineArguments copyFrom:idx + 1.
+                        CommandLineArguments removeFromIndex:idx+1.
+                    ] ifFalse:[
+                        arg := CommandLineArguments at:idx + 1.
+                        CommandLineArguments removeAtIndex:idx+1.
+                    ].
                 ].
                 CommandLineArguments removeAtIndex:idx.
 
@@ -4638,19 +4645,35 @@
                                 ].    
                                 self exit:128+(OperatingSystem sigINT).
                             ] do:[
+                                |filterCode filterStart filterEnd|
+                                
                                 isFilter ifTrue:[
                                     "/ --filter - apply code to each input line.
                                     "/ compile code only once
-                                    Compiler
-                                        compile:'doIt:line ',arg
-                                        forClass:String
-                                        notifying:(EvalScriptingErrorHandler new source:arg).
-
-                                    [Stdin atEnd] whileFalse:[
-                                        |line|
-
-                                        line := Stdin nextLine.
-                                        line doIt:line.
+                                    (args size == 1) ifTrue:[
+                                        filterCode := args at:1.
+                                    ] ifFalse:[
+                                        (args size == 3) ifTrue:[
+                                            filterStart := args at:1.
+                                            filterCode := args at:2.
+                                            filterEnd := args at:3.
+                                        ] ifFalse:[
+                                            StandAlone := true.
+                                            self exitWithErrorMessage:'--filter must be followed by 1 or 3 expression arg(s)'
+                                        ].
+                                        Compiler
+                                            compile:'doIt:line ',arg
+                                            forClass:String
+                                            notifying:(EvalScriptingErrorHandler new source:filterCode).
+
+                                        filterStart notEmptyOrNil ifTrue:[ Compiler evaluate:filterStart ].    
+                                        [Stdin atEnd] whileFalse:[
+                                            |line|
+
+                                            line := Stdin nextLine.
+                                            line doIt:line.
+                                        ].
+                                        filterEnd notEmptyOrNil ifTrue:[ Compiler evaluate:filterEnd ].    
                                     ].
                                 ] ifFalse:[
                                     (isPrint | isEval) ifTrue:[