home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / lib / tcl / parray.tcl < prev    next >
Encoding:
Text File  |  1996-10-12  |  1.6 KB  |  42 lines

  1. # parray:
  2. # Print the contents of a global array on stdout.
  3. #
  4. # Copyright (c) 1991-1993 The Regents of the University of California.
  5. # All rights reserved.
  6. #
  7. # Permission is hereby granted, without written agreement and without
  8. # license or royalty fees, to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose, provided that the
  10. # above copyright notice and the following two paragraphs appear in
  11. # all copies of this software.
  12. #
  13. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  14. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  15. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  16. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. #
  18. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  19. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  20. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  21. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  22. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  23. #
  24.  
  25. proc parray a {
  26.     upvar 1 $a array
  27.     if [catch {array size array}] {
  28.     error "\"$a\" isn't an array"
  29.     }
  30.     set maxl 0
  31.     foreach name [lsort [array names array]] {
  32.     if {[string length $name] > $maxl} {
  33.         set maxl [string length $name]
  34.     }
  35.     }
  36.     set maxl [expr {$maxl + [string length $a] + 2}]
  37.     foreach name [lsort [array names array]] {
  38.     set nameString [format %s(%s) $a $name]
  39.     puts stdout [format "%-*s = %s" $maxl $nameString $array($name)]
  40.     }
  41. }
  42.