Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
tools.tcl
00001 # $Id$ #
00002 
00003 #
00004 #/** jafar tcl tools. \file tools.tcl \ingroup kernel */
00005 #
00006 
00007 namespace eval kernel {
00008 
00009     # proc print {obj} {
00010     #     regexp {_${[0-9][a-f]}*_p_${[0-9][a-z]}*__${[0-9][a-z]}*__} $obj m1 ptr n1 n2
00011     # }
00012 
00013     proc help {procname} {
00014   # reports a proc's args and leading comments.
00015   # usage: help procname
00016   # Multiple documentation lines are allowed.
00017   # documentation can be ended by a blank line
00018 
00019   # This comment should not appear in the docstring
00020   set res "{usage: $procname [args $procname]}"
00021   
00022   set procBody [split [info body $procname] \n]
00023   set firstLine [lindex $procBody 0]
00024   if {[string trim $firstLine] eq ""} {
00025       set procBody [lrange $procBody 1 end]
00026   }
00027 
00028   foreach line $procBody {
00029       if {[string trim $line] eq ""} break
00030           if ![regexp {\s*#(.+)} $line -> line] break
00031     lappend res [string trim $line]
00032     set blankLine false
00033       }
00034       join $res \n
00035   }
00036 
00037     proc args {procname} {
00038   # Signature of a proc: arguments with defaults
00039   set res ""
00040   foreach a [info args $procname] {
00041       if [info default $procname $a default] {
00042     lappend a $default
00043       }
00044       lappend res $a
00045   }
00046   set res
00047     }
00048 
00049     proc ask {procname} {
00050   # interactively asks for proc arguments
00051   # it also takes into account default arguments if any
00052   set command [list $procname]
00053   foreach arg [info args $procname] {
00054       set hasDefault [info default $procname $arg defaultValue]
00055       set notok 1
00056       while {$notok} {
00057     puts -nonewline "$arg \[$defaultValue\]: "
00058     flush stdout
00059     set c [gets stdin argsValue($arg)]
00060     if "$c>0" {
00061         set notok 0
00062     } elseif "$hasDefault" {
00063         set argsValue($arg) $defaultValue
00064         set notok 0
00065     }
00066       }
00067       lappend command "$argsValue($arg)"
00068   }
00069   puts "evaluating \{$command\}"
00070   uplevel 1 "eval $command"
00071     }
00072 
00073     proc addHashedDirectory {dir} {
00074   # add a directory to the list of hashed directory
00075   # see also rehash
00076 
00077   global jafar_macros
00078   lappend jafar_macros $dir
00079     }
00080 
00081     proc rehash {} {
00082   # re-source user macros in hashed directories list
00083   # see also addHashedDirectory
00084   
00085   global jafar_macros
00086   
00087   if "![info exist jafar_macros]" {
00088       puts "jafar_macros variable is not set"
00089       return
00090   }
00091 
00092   foreach dir $jafar_macros {
00093       if [file exist $dir] {
00094     puts "$dir"
00095 
00096     set tclFilesList [glob -nocomplain -directory "$dir" *.tcl]
00097     
00098     foreach file $tclFilesList {
00099         puts -nonewline "  [lindex [file split $file] end]..."
00100         flush stdout
00101         if { [catch {uplevel source $file} error] } {
00102       puts "Warning: $error"
00103         } else {
00104       puts "ok"
00105         }
00106     }
00107       } else {
00108     puts "** skipping $dir **"
00109       }
00110   }
00111     }
00112 
00113     proc putsDbg {message
00114       {level 3} } {
00115   kernel::sendDebug $message $level
00116     }
00117 
00118     namespace export help
00119     namespace export args
00120     namespace export ask
00121     namespace export rehash
00122     namespace export putsDbg
00123 }
00124 
00125 package provide kernel 0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:17 for Jafar by doxygen 1.7.6.1
LAAS-CNRS