[44077] trunk/base/src/port/port.tcl

raimue at macports.org raimue at macports.org
Sat Dec 20 19:24:59 PST 2008


Revision: 44077
          http://trac.macports.org/changeset/44077
Author:   raimue at macports.org
Date:     2008-12-20 19:24:58 -0800 (Sat, 20 Dec 2008)
Log Message:
-----------
port/port.tcl:
Refactor the friendly field mapping into its own proc

Modified Paths:
--------------
    trunk/base/src/port/port.tcl

Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl	2008-12-21 03:24:45 UTC (rev 44076)
+++ trunk/base/src/port/port.tcl	2008-12-21 03:24:58 UTC (rev 44077)
@@ -203,6 +203,28 @@
 }
 
 
+##
+# Maps friendly field names to their real name
+# Names which do not need mapping are not changed.
+#
+# @param field friendly name
+# @return real name
+proc map_friendly_field_names { field } {
+    switch -- $field {
+        variant -
+        platform -
+        maintainer {
+            set field "${field}s"
+        }
+        category {
+            set field "categories"
+        }
+    }
+
+    return $field
+}
+
+
 proc registry_installed {portname {portversion ""}} {
     set ilist [registry::installed $portname $portversion]
     if { [llength $ilist] > 1 } {
@@ -891,12 +913,8 @@
             regexp {^(\w+):(.*)} $token matchvar field pat
 
             # Remap friendly names to actual names
-            switch -- $field {
-                variant -
-                platform -
-                maintainer { set field "${field}s" }
-                category { set field "categories" }
-            }                           
+            set field [map_friendly_field_names $field]
+
             add_multiple_ports reslist [get_matching_ports $pat no regexp $field]
             set el 1
         }
@@ -1386,15 +1404,7 @@
             ui_warn "port info --index does not work with 'current' pseudo-port"
             continue
         }
-        
-        # Map from friendly to less-friendly but real names
-        array set name_map "
-            category        categories
-            maintainer      maintainers
-            platform        platforms
-            variant         variants
-        "
-                
+
         # Understand which info items are actually lists
         # (this could be overloaded to provide a generic formatting code to
         # allow us to, say, split off the prefix on libs)
@@ -1443,10 +1453,7 @@
             }
             
             # Map from friendly name
-            set ropt $opt
-            if {[info exists name_map($opt)]} {
-                set ropt $name_map($opt)
-            }
+            set ropt [map_friendly_field_names $opt]
             
             # If there's no such info, move on
             if {![info exists portinfo($ropt)]} {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20081220/9517d0b9/attachment.html>


More information about the macports-changes mailing list