Changeset 4477


Ignore:
Timestamp:
Jan 6, 2004, 8:03:50 AM (17 years ago)
Author:
jkh
Message:

This is a basically rewritten port(1) contents target. Summary of changes:

  • Read the file in one line at a time, rather than all at once.
  • Use regexp to match each line on {contents \{(.*)\}$}, ensuring that only

the actual contents information will be matched.

  • Move file-close check to the end of the target.
  • Formatting fixes - stupid tabs!

These changes should be entirely transparent - it behaves exactly as it did
before.

Bug: 1252
Submitted by: Toby Peterson <tp62@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port/port.tcl

    r4098 r4477  
    178178        # make sure a port was given on the command line
    179179        if {![info exists portname]} {
    180            puts "You must specify a port"
    181            exit 1
     180            puts "You must specify a port"
     181            exit 1
    182182        }
    183183
    184184        # search for port
    185185        if {[catch {dportsearch ^$portname$} result]} {
    186            puts "port search failed: $result"
    187            exit 1
     186            puts "port search failed: $result"
     187            exit 1
    188188        }
    189189
     
    236236        # make sure a port was given on the command line
    237237        if {![info exists portname]} {
    238            puts "You must specify a port"
    239            exit 1
    240         }
    241 
     238            puts "You must specify a port"
     239            exit 1
     240        }
     241       
    242242        # search for port
    243243        if {[catch {dportsearch ^$portname$} result]} {
    244            puts "port search failed: $result"
    245            exit 1
    246         }
    247 
     244            puts "port search failed: $result"
     245            exit 1
     246        }
     247       
    248248        if {$result == ""} {
    249249            puts "No port $portname found."
    250250        }
    251 
     251       
    252252        array set portinfo [lindex $result 1]
    253 
     253       
    254254        # if this fails the port doesn't have any variants
    255255        if {![info exists portinfo(variants)]} {
    256256            puts "$portname has no variants"
    257257        } else {
    258         # print out all the variants
     258            # print out all the variants
    259259            for {set i 0} {$i < [llength $portinfo(variants)]} {incr i} {
    260260                puts "[lindex $portinfo(variants) $i]"
     
    265265        # make sure a port was given on the command line
    266266        if {![info exists portname]} {
    267            puts "You must specify a port"
    268            exit 1
    269         }
    270 
     267            puts "You must specify a port"
     268            exit 1
     269        }
     270       
    271271        set rfile [dportregistry::exists $portname]
    272272        if {$rfile != ""} {
     
    278278                set fd [open $rfile r]
    279279            }
    280             set entry [read $fd]
     280           
     281            while {-1 < [gets $fd line]} {
     282                set match [regexp {^contents \{(.*)\}$} $line dummy contents]
     283                if {$match == 1} {
     284                    puts "Contents of $shortname"
     285                    foreach f $contents {
     286                        puts "\t[lindex $f 0]"
     287                    }
     288                    break
     289                }
     290            }
     291           
     292            if {$match == 0} {
     293                puts "No contents list for $shortname"
     294                exit 1
     295            }
     296           
    281297            # kind of a corner case but I ran into it testing
    282298            if {[catch {close $fd} result]} {
    283299                puts "Port failed: $rfile may be corrupted"
    284                 exit 1
    285             }
    286 
    287             # look for a contents list
    288             set ix [lsearch $entry contents]
    289             if {$ix >= 0} {
    290                 set contents [lindex $entry [incr ix]]
    291                 set uninst_err 0
    292                 puts "Contents of $shortname"
    293                 foreach f $contents {
    294                     puts "\t[lindex $f 0]"
    295                 }
    296             } else {
    297                 puts "No contents list for $shortname"
    298                 exit 1
     300                exit 1
    299301            }
    300302        } else {
     
    314316        foreach {name array} $res {
    315317            array set portinfo $array
    316 
     318           
    317319            # XXX is this the right place to verify an entry?
    318320            if {![info exists portinfo(name)]} {
     
    351353        set target $action
    352354        if {[info exists portname]} {
    353                 # Escape regex special characters
    354                 regsub -all "(\\(){1}|(\\)){1}|(\\{1}){1}|(\\+){1}|(\\{1}){1}|(\\{){1}|(\\}){1}|(\\^){1}|(\\$){1}|(\\.){1}|(\\\\){1}" $portname "\\\\&" search_string
     355            # Escape regex special characters
     356            regsub -all "(\\(){1}|(\\)){1}|(\\{1}){1}|(\\+){1}|(\\{1}){1}|(\\{){1}|(\\}){1}|(\\^){1}|(\\$){1}|(\\.){1}|(\\\\){1}" $portname "\\\\&" search_string
    355357            if {[catch {set res [dportsearch ^$search_string\$]} result]} {
    356358                puts "port search failed: $result"
     
    375377            exit 1
    376378        }
    377 
     379       
    378380        dportclose $workername
    379381        exit $result
Note: See TracChangeset for help on using the changeset viewer.