platform{} statement

Gustaf Neumann neumann at wu.ac.at
Fri Jun 3 13:05:36 PDT 2016


Am 03.06.16 um 14:55 schrieb René J. V. Bertin:
> Rainer Müller wrote:
>
>> The definition of the platform proc is here:
>>
>>
> https://trac.macports.org/browser/trunk/base/src/port1.0/portutil.tcl?rev=149111#L765
>> Extending that syntax with an optional code block after an "else"
>> keyword would be possible.
> Once I knew it was possible it wasn't very hard to figure out how. Is there a
> more efficient way to determine if an else keyword has been given (both in the
> parser and in the actual executor?
>
The code below is more in line with current tcl code practice
(untested, using e.g. tcl index expressions).

-g

proc platform {os args} {
     global os.platform os.subplatform os.arch os.major

     set len [llength $args]
     if {$len < 1} {
         return -code error "Malformed platform specification"
     }
     if {[lindex $args end-1] eq "else"} {
	set code [lindex $args end-2]
	set altcode [lindex $args end]
	set consumed 3
     } else {
	set code [lindex $args end]
	set altcode ""
	set consumed 1
     }

     foreach arg [lrange $args 0 end-$consumed] {
         if {[regexp {(^[0-9]+$)} $arg match result]} {
             set release $result
         } elseif {[regexp {([a-zA-Z0-9]*)} $arg match result]} {
             set arch $result
         }
     }

     set match 0
     # 'os' could be a platform or an arch when it's alone
     if {$len == 1 && ($os == ${os.platform} || $os == ${os.subplatform} || $os == ${os.arch})} {
         set match 1
     } elseif {($os == ${os.platform} || $os == ${os.subplatform})
               && (![info exists release] || ${os.major} == $release)
               && (![info exists arch] || ${os.arch} == $arch)} {
         set match 1
     }

     # Execute the code if this platform matches the platform we're on
     if {$match} {
         uplevel 1 $code
     } elseif {$altcode ne ""} {
	uplevel 1 $altcode
     }
}



More information about the macports-dev mailing list