[25251] trunk/base

source_changes at macosforge.org source_changes at macosforge.org
Wed May 16 12:58:32 PDT 2007


Revision: 25251
          http://trac.macosforge.org/projects/macports/changeset/25251
Author:   eridius at macports.org
Date:     2007-05-16 12:58:32 -0700 (Wed, 16 May 2007)

Log Message:
-----------
Add -E flag to reinplace

Modified Paths:
--------------
    trunk/base/ChangeLog
    trunk/base/doc/portfile.7
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/ChangeLog
===================================================================
--- trunk/base/ChangeLog	2007-05-16 19:32:17 UTC (rev 25250)
+++ trunk/base/ChangeLog	2007-05-16 19:58:32 UTC (rev 25251)
@@ -6,6 +6,8 @@
 
 (unreleased):
 
+    - Add -E flag to reinplace, does the same thing as in sed (eridius r25251).
+
     - Add support for [nosync] flag in sources.conf to prevent a source from syncing
       during a `port sync` or `port selfupdate` (eridius r25236).
       Example: file:///Users/landonf/misc/MacPorts/dports [nosync]

Modified: trunk/base/doc/portfile.7
===================================================================
--- trunk/base/doc/portfile.7	2007-05-16 19:32:17 UTC (rev 25250)
+++ trunk/base/doc/portfile.7	2007-05-16 19:58:32 UTC (rev 25251)
@@ -1591,8 +1591,17 @@
 .Dl adduser foo gid=[existsgroup foo]
 .It Ic nextgid
 Returns the highest used gid plus one.
-.It Ic reinplace Ar regex Ar filename
-Provide in-place sed like editing of a file.
+.It Xo
+.Ic reinplace
+.Op Fl E
+.Ar regex
+.Ar
+.Xc
+Provide in-place
+.Xr sed 1
+like editing of a file.
+The -E flag does the same thing as in
+.Xr sed 1
 .br
 .Sy Example:
 .Dl reinplace \*qs|/usr/local|${prefix}|g\*q doc/manpage.1

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2007-05-16 19:32:17 UTC (rev 25250)
+++ trunk/base/src/port1.0/portutil.tcl	2007-05-16 19:58:32 UTC (rev 25251)
@@ -661,13 +661,34 @@
 
 # reinplace
 # Provides "sed in place" functionality
-proc reinplace {pattern args}  {
-    if {$args == ""} {
-    	ui_error "reinplace: no value given for parameter \"file\""
-	return -code error "no value given for parameter \"file\" to \"reinplace\"" 
+proc reinplace {args}  {
+    set extended 0
+    while 1 {
+        set arg [lindex $args 0]
+        if {[string first - $arg] != -1} {
+            set args [lrange $args 1 end]
+            switch [string range $arg 1 end] {
+                E {
+                    set extended 1
+                }
+                - {
+                    break
+                }
+                default {
+                    error "reinplace: unknown flag '-$arg'"
+                }
+            }
+        } else {
+            break
+        }
     }
+    if {[llength $args] < 2} {
+        error "reinplace ?-E? pattern file ..."
+    }
+    set pattern [lindex $args 0]
+    set files [lrange $args 1 end]
     
-    foreach file $args {
+    foreach file $files {
 	if {[catch {set tmpfile [mkstemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
 		global errorInfo
 		ui_debug "$errorInfo"
@@ -680,7 +701,12 @@
 	    set tmpfile [lindex $tmpfile 1]
 	}
 	
-	if {[catch {exec sed $pattern < $file >@ $tmpfd} error]} {
+	set cmdline sed
+	if {$extended} {
+	    lappend cmdline -E
+	}
+	set cmdline [concat $cmdline [list $pattern < $file >@ $tmpfd]]
+	if {[catch {eval exec $cmdline} error]} {
 		global errorInfo
 		ui_debug "$errorInfo"
 	    ui_error "reinplace: $error"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070516/8c2fc54e/attachment.html


More information about the macports-changes mailing list