Ignore:
Timestamp:
Jun 4, 2003, 11:18:47 PM (16 years ago)
Author:
landonf
Message:

Update reinplace to support multiple files and avoid unneccesary pattern mangling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portutil.tcl

    r2448 r2749  
    376376# reinplace
    377377# Provides "sed in place" functionality
    378 proc reinplace {oddpattern file}  {
    379     set backpattern [strsed $oddpattern {g/\//\\\\\//}]
    380     set pattern [strsed $backpattern {g/\|/\//}]
    381 
    382     if {[catch {set tmpfile [mktemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
    383         ui_error "reinplace: $error"
    384         return -code error "reinplace failed"
    385     }
    386 
    387     if {[catch {exec sed $pattern < $file > $tmpfile} error]} {
    388         ui_error "reinplace: $error"
     378proc reinplace {pattern args}  {
     379    if {$args == ""} {
     380        ui_error "reinplace: no value given for parameter \"file\""
     381        return -code error "no value given for parameter \"file\" to \"reinplace\""
     382    }
     383
     384    foreach file $args {
     385        if {[catch {set tmpfile [mktemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
     386            ui_error "reinplace: $error"
     387            return -code error "reinplace failed"
     388        }
     389
     390        if {[catch {exec sed $pattern < $file > $tmpfile} error]} {
     391            ui_error "reinplace: $error"
     392            file delete "$tmpfile"
     393            return -code error "reinplace failed"
     394        }
     395
     396        if {[catch {exec cp $tmpfile $file} error]} {
     397            ui_error "reinplace: $error"
     398            file delete "$tmpfile"
     399            return -code error "reinplace failed"
     400        }
    389401        file delete "$tmpfile"
    390         return -code error "reinplace failed"
    391     }
    392 
    393     if {[catch {exec cp $tmpfile $file} error]} {
    394         ui_error "reinplace: $error"
    395         file delete "$tmpfile"
    396         return -code error "reinplace failed"
    397     }
    398     file delete "$tmpfile"
     402    }
    399403    return
    400404}
Note: See TracChangeset for help on using the changeset viewer.