| 1 | #!/bin/sh |
|---|
| 2 | #-*-tcl-*- |
|---|
| 3 | # the next line restarts using wish \ |
|---|
| 4 | exec wish "$0" -- ${1+"$@"} |
|---|
| 5 | |
|---|
| 6 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | # FILE : init_toltk.tcl |
|---|
| 8 | # PURPOSE : This file loads packages and libraries and initializes a project. |
|---|
| 9 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 10 | |
|---|
| 11 | package require Tk |
|---|
| 12 | |
|---|
| 13 | set trace 0 |
|---|
| 14 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 15 | proc Tolcon_Trace { msg {tags ""} {args ""} } { |
|---|
| 16 | # |
|---|
| 17 | # PURPOSE: Writes a trace message in a toplevel window. It's used for |
|---|
| 18 | # debugging. If release versions uncomment the initial return. |
|---|
| 19 | # |
|---|
| 20 | # PARAMETERS: |
|---|
| 21 | # msg -> Message to trace |
|---|
| 22 | # |
|---|
| 23 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 24 | global trace |
|---|
| 25 | if {$trace eq 0} { |
|---|
| 26 | return |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | set w .__debugwin |
|---|
| 30 | if { ![winfo exists $w] } { |
|---|
| 31 | toplevel $w |
|---|
| 32 | ScrolledWindow $w.sw |
|---|
| 33 | text $w.sw.t |
|---|
| 34 | $w.sw setwidget $w.sw.t |
|---|
| 35 | # tags of text widget |
|---|
| 36 | $w.sw.t tag configure bold -font {Tahoma 8 bold} |
|---|
| 37 | $w.sw.t tag configure big -font {Tahoma 10 bold} |
|---|
| 38 | $w.sw.t tag configure verybig -font {Tahoma 12 bold} |
|---|
| 39 | $w.sw.t tag configure normal -font {Tahoma 8} |
|---|
| 40 | $w.sw.t tag configure small -font {Tahoma 7} |
|---|
| 41 | $w.sw.t tag configure centered -justify center |
|---|
| 42 | $w.sw.t tag configure underline -underline on |
|---|
| 43 | $w.sw.t tag configure red -foreground red |
|---|
| 44 | $w.sw.t tag configure green -foreground darkgreen |
|---|
| 45 | $w.sw.t tag configure blue -foreground darkblue |
|---|
| 46 | $w.sw.t tag configure grey -foreground darkgrey |
|---|
| 47 | |
|---|
| 48 | #::BayesText::MenuCreate $w.sw.t |
|---|
| 49 | pack $w.sw -fill both -expand yes |
|---|
| 50 | } |
|---|
| 51 | $w.sw.t insert end "$msg\n" $tags |
|---|
| 52 | $w.sw.t see end |
|---|
| 53 | update |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | proc TraceMainGeometry { msg } { |
|---|
| 57 | puts "== $msg == wm geometry . == [wm geometry .]" |
|---|
| 58 | puts "== $msg == winfo geometry . == [winfo geometry .]" |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 62 | proc LoadPackages {} { |
|---|
| 63 | # |
|---|
| 64 | # PURPOSE: Load packages |
|---|
| 65 | # |
|---|
| 66 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 67 | package require snit |
|---|
| 68 | package require BWidget |
|---|
| 69 | package require msgcat |
|---|
| 70 | namespace import msgcat::* |
|---|
| 71 | package require Tktable |
|---|
| 72 | package require -exact BLT 2.4 |
|---|
| 73 | package require autoscroll 1.1 |
|---|
| 74 | package require tclodbc |
|---|
| 75 | package require -exact Toltcl 3.3 |
|---|
| 76 | package require rmtps_client |
|---|
| 77 | package require byswidget |
|---|
| 78 | package require mkWidgets 1.3 |
|---|
| 79 | #NOTE. Por precaución cargamos el paquete aqui |
|---|
| 80 | #En un futuro cambiar |
|---|
| 81 | package require bfunctions |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 85 | proc OpenAssocFile {file {run 0} {inc 0}} { |
|---|
| 86 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 87 | switch [string toupper [file extension $file]] { |
|---|
| 88 | ".SQL" { |
|---|
| 89 | #::Editor::Open $file |
|---|
| 90 | } |
|---|
| 91 | ".PRJ" { |
|---|
| 92 | if { $inc } { |
|---|
| 93 | ::tol::console eval "Set IncludePRJ(Text \"$file\")" |
|---|
| 94 | } else { |
|---|
| 95 | ::TolProject::Open $file $run |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | ".BDT" { |
|---|
| 99 | if { $inc } { |
|---|
| 100 | ::tol::console eval "Set IncludeBDT(Text \"$file\")" |
|---|
| 101 | } else { |
|---|
| 102 | ::EditTable::Open $file |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | ".BST" { |
|---|
| 106 | if { $inc } { |
|---|
| 107 | ::tol::console eval "Set IncludeBST(Text \"$file\")" |
|---|
| 108 | } else { |
|---|
| 109 | ::EditTable::Open $file |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | ".BMT" { |
|---|
| 113 | if { $inc } { |
|---|
| 114 | ::tol::console eval "Set IncludeBMT(Text \"$file\")" |
|---|
| 115 | } else { |
|---|
| 116 | ::EditTable::Open $file |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | ".TOL" { |
|---|
| 120 | if { $inc } { |
|---|
| 121 | ::tol::console eval "Set IncludeTOL(Text \"$file\")" |
|---|
| 122 | } else { |
|---|
| 123 | ::Editor::Open $file $run |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 131 | proc loadInfoProjects { prjini } { |
|---|
| 132 | # |
|---|
| 133 | # PURPOSE: Loads in a list the name and paths of each project to load |
|---|
| 134 | # |
|---|
| 135 | # RETURN: the list with the data |
|---|
| 136 | # |
|---|
| 137 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 138 | global iniparse |
|---|
| 139 | global toltk_library |
|---|
| 140 | global toltk_script_path |
|---|
| 141 | |
|---|
| 142 | set values {} |
|---|
| 143 | # File exists ? |
|---|
| 144 | set ok 0 |
|---|
| 145 | if { [ file isfile $prjini ] } { |
|---|
| 146 | if { [ file readable $prjini ] } { |
|---|
| 147 | set ok 1 |
|---|
| 148 | set fileProject [ file normalize $prjini ] |
|---|
| 149 | # se intentara leer el iniproject.tol desde este sitio |
|---|
| 150 | lappend values Project,path,root [ file dir $fileProject ] |
|---|
| 151 | } else { |
|---|
| 152 | tk_messageBox -default ok -icon error \ |
|---|
| 153 | -message [ mc "The project does not exist, file not found or not readable: %s" $prj ] \ |
|---|
| 154 | -parent . -title "Error" -type ok |
|---|
| 155 | return "" |
|---|
| 156 | } |
|---|
| 157 | } else { |
|---|
| 158 | # comportamiento anterior, pudiera limpiarse |
|---|
| 159 | lappend values Project,path,root "" |
|---|
| 160 | set pathInitTol "" |
|---|
| 161 | set dir $prjini |
|---|
| 162 | set dirPrjIni "[file normalize $dir]/../../../" |
|---|
| 163 | set fileProject [file join $dirPrjIni "project.ini"] |
|---|
| 164 | if {[file exists $fileProject]} { |
|---|
| 165 | set ok [ file writable $fileProject ] |
|---|
| 166 | } else { |
|---|
| 167 | set fileProject [file join $dir "project.ini"] |
|---|
| 168 | if {[file exists $fileProject]} { |
|---|
| 169 | set ok [ file writable $fileProject ] |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | # exists project.ini ? |
|---|
| 174 | if {$ok} { |
|---|
| 175 | set id [iniparse:openfile $fileProject] |
|---|
| 176 | catch { ::iniFile::Create $fileProject } |
|---|
| 177 | foreach prj $iniparse($id,sections) { |
|---|
| 178 | if { $prj eq "Project" } { |
|---|
| 179 | lappend values Project,title [::iniFile::Read Project title {}] |
|---|
| 180 | lappend values Project,splash [::iniFile::Read Project splash {}] |
|---|
| 181 | lappend values Project,names [lrange $iniparse($id,sections) 1 end] |
|---|
| 182 | } else { |
|---|
| 183 | set name [::iniFile::Read $prj name ""] |
|---|
| 184 | set path [::iniFile::Read $prj path ""] |
|---|
| 185 | if { [string length $path] } { |
|---|
| 186 | set _path [file join $toltk_library $path] |
|---|
| 187 | if { [file exists $_path] } { |
|---|
| 188 | set $path $_path |
|---|
| 189 | } else { |
|---|
| 190 | #si la ruta se da relativa y tolbase se ejecuta desde archivo asociado |
|---|
| 191 | set __path [file join $toltk_script_path $path] |
|---|
| 192 | if { [file exists $__path] } { |
|---|
| 193 | set $path $__path |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | set pathtcl [file join $path tcl] |
|---|
| 197 | } else { |
|---|
| 198 | set path [file join $toltk_library toltk] |
|---|
| 199 | set pathtcl $path |
|---|
| 200 | } |
|---|
| 201 | # check exists file ? |
|---|
| 202 | if {[string length $name] && [string length $path] && |
|---|
| 203 | [file exists [file join $pathtcl ${name}.tcl]]} { |
|---|
| 204 | lappend values ${prj},name $name |
|---|
| 205 | lappend values ${prj},path $path |
|---|
| 206 | lappend values ${prj},path,tcl $pathtcl |
|---|
| 207 | } else { |
|---|
| 208 | # erase prj in list of project |
|---|
| 209 | array set arrtemp $values |
|---|
| 210 | set lstAux $arrtemp(Project,names) |
|---|
| 211 | set arrtemp(Project,names) [lreplace $arrtemp(Project,names) \ |
|---|
| 212 | [lsearch -exac $arrtemp(Project,names) $prj] \ |
|---|
| 213 | [lsearch -exac $arrtemp(Project,names) $prj]] |
|---|
| 214 | set values [array get arrtemp] |
|---|
| 215 | unset arrtemp |
|---|
| 216 | # show mwssage |
|---|
| 217 | if {[string length $name] && [string length $path]} { |
|---|
| 218 | tk_messageBox -default ok -icon error \ |
|---|
| 219 | -message "The project does not exist: $prj ([file join $pathtcl ${name}.tcl])" \ |
|---|
| 220 | -parent . -title "Error" -type ok |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | iniparse:closefile $id |
|---|
| 226 | } |
|---|
| 227 | return $values |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | if {[info exist ::env(DEBUG_TOLTCL)] && $::env(DEBUG_TOLTCL) eq "yes"} { |
|---|
| 231 | set tt_debug "d" |
|---|
| 232 | } else { |
|---|
| 233 | set tt_debug "" |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | set info_script [info script] |
|---|
| 238 | if {[file type $info_script] eq "link"} { |
|---|
| 239 | set info_script [file readlink $info_script] |
|---|
| 240 | } |
|---|
| 241 | set toltk_script_path [ file normalize [file dirname $info_script] ] |
|---|
| 242 | # load tclIndex |
|---|
| 243 | set dir $toltk_script_path |
|---|
| 244 | source [file join $toltk_script_path "tclIndex"] |
|---|
| 245 | unset dir |
|---|
| 246 | |
|---|
| 247 | set executable_path [ file normalize [file dirname [info nameofexecutable] ] ] |
|---|
| 248 | array set GuiVersionInfo {major 1 minor 1 release 6 comment "cvs trunk"} |
|---|
| 249 | |
|---|
| 250 | # path user |
|---|
| 251 | if { [string equal $tcl_platform(platform) "windows"] } { |
|---|
| 252 | set home_path $env(USERPROFILE) |
|---|
| 253 | } else { |
|---|
| 254 | set home_path $env(HOME) |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | if { ![info exists toltk_library] } { |
|---|
| 258 | set toltk_library [file normalize [file join $toltk_script_path ..]] |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | if { ![info exists toltk_bin] } { |
|---|
| 262 | set toltk_bin [file normalize [file join $toltk_library ../bin]] |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | if {[lsearch $auto_path $toltk_library] == -1} { |
|---|
| 266 | set auto_path [linsert $auto_path 0 $toltk_library] |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | if { ![info exists blt_libPath] } { |
|---|
| 270 | set blt_libPath [file join $toltk_library blt] |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if { ![info exists env(BLT_LIBRARY)] } { |
|---|
| 274 | set env(BLT_LIBRARY) [file join $toltk_library blt] |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | if { ![info exists tkTable_libPath] } { |
|---|
| 278 | set tkTable_libPath [file join $toltk_library Tktable] |
|---|
| 279 | set env(TK_TABLE_LIBRARY) [file join $toltk_library Tktable] |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | if { ![info exists byswidget_library] } { |
|---|
| 283 | set byswidget_library [file normalize [file join $toltk_script_path byswidget]] |
|---|
| 284 | } |
|---|
| 285 | # NOTE: necessary for TkCVS |
|---|
| 286 | if { ![info exists tkcvs_library] } { |
|---|
| 287 | set tkcvs_library [file normalize [file join $toltk_script_path tkcvs]] |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | if {[lsearch $auto_path $toltk_library] == -1} { |
|---|
| 291 | set auto_path [linsert $auto_path end $byswidget_library] |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | # Load project |
|---|
| 295 | namespace import project::* |
|---|
| 296 | set project::data(iniproject) 1 |
|---|
| 297 | set project::data(defaultpackages) 1 |
|---|
| 298 | set state "" |
|---|
| 299 | set project::data(-project) $toltk_script_path |
|---|
| 300 | foreach option $argv { |
|---|
| 301 | if { $state eq "" } { |
|---|
| 302 | switch -- $option { |
|---|
| 303 | -b { |
|---|
| 304 | set project::data(oculto) 1 |
|---|
| 305 | } |
|---|
| 306 | -np { |
|---|
| 307 | set project::data(iniproject) 0 |
|---|
| 308 | } |
|---|
| 309 | -ndp { |
|---|
| 310 | set project::data(defaultpackages) 0 |
|---|
| 311 | } |
|---|
| 312 | -project { |
|---|
| 313 | set state "project" |
|---|
| 314 | } |
|---|
| 315 | default { |
|---|
| 316 | puts "unknown option $option" |
|---|
| 317 | } |
|---|
| 318 | } |
|---|
| 319 | } else { |
|---|
| 320 | switch $state { |
|---|
| 321 | project { |
|---|
| 322 | set project::data(-project) [ file normalize $option ] |
|---|
| 323 | } |
|---|
| 324 | default { |
|---|
| 325 | puts "unknown state $state" |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | set state "" |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | # Get info about project |
|---|
| 333 | set infoProjects [ loadInfoProjects $project::data(-project) ] |
|---|
| 334 | project::project $infoProjects |
|---|
| 335 | |
|---|
| 336 | # load iniFile |
|---|
| 337 | ::iniFile::Create [file join $home_path "tolcon.ini"] |
|---|
| 338 | |
|---|
| 339 | # load language files, stored in msgs subdirectory |
|---|
| 340 | set lang [::iniFile::Read TolConsole language es] |
|---|
| 341 | |
|---|
| 342 | ::msgcat::mclocale $lang |
|---|
| 343 | |
|---|
| 344 | # Load Packages |
|---|
| 345 | LoadPackages |
|---|
| 346 | |
|---|
| 347 | Tolcon_Trace "toltk_script_path=$toltk_script_path" |
|---|
| 348 | |
|---|
| 349 | Tolcon_Trace "begin" |
|---|
| 350 | if { [winfo exists .__debugwin] } { |
|---|
| 351 | wm geometry .__debugwin 1000x170+20+550 |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | ::msgcat::mcload [file join $toltk_script_path msgs] |
|---|
| 355 | #option read [file join $::BWIDGET::LIBRARY "lang" "${lang}.rc"] startupFile |
|---|
| 356 | |
|---|
| 357 | # inicializo el kernel de tol con el lenguaje apropiado |
|---|
| 358 | |
|---|
| 359 | set _lang [ string range $lang 0 1 ] |
|---|
| 360 | if { $_lang ne "es" && $_lang ne "en" } { |
|---|
| 361 | # tol just know to deal with english or spanish |
|---|
| 362 | set _lang "en" |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | ::tol::initkernel $_lang vA |
|---|
| 366 | |
|---|
| 367 | # Evalute the client TOL code to expose rmtps_client functionality |
|---|
| 368 | # |
|---|
| 369 | ::rmtps_client::define_TOLAPI |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | #Cargo word.tcl (version modificada por Bayes) |
|---|
| 373 | AutoLoadWord |
|---|
| 374 | |
|---|
| 375 | Tolcon_Trace "Librerias cargadas" |
|---|
| 376 | |
|---|
| 377 | ::tol::language $_lang |
|---|
| 378 | Supertext::overrideTextCommand |
|---|
| 379 | # force BWidget autoload |
|---|
| 380 | Bitmap::use |
|---|
| 381 | |
|---|
| 382 | set toltk_images_path [file join ${toltk_script_path} images] |
|---|
| 383 | if { [lsearch $Bitmap::path $toltk_images_path] == -1 } { |
|---|
| 384 | lappend Bitmap::path [file join $toltk_script_path images] |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | #Añado las opciones de un text a la ventana de debug |
|---|
| 388 | if { [winfo exists .__debugwin] } { |
|---|
| 389 | ::BayesText::MenuCreate .__debugwin.sw.t |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | # cargo los hooks ya que no entran en el mecanismo de tclIndex |
|---|
| 393 | source [file join $toltk_script_path tolmethods.tcl] |
|---|
| 394 | |
|---|
| 395 | catch { |
|---|
| 396 | project::init |
|---|
| 397 | } msgerr |
|---|
| 398 | Tolcon_Trace "$msgerr : $::errorInfo" "red bold" |
|---|
| 399 | |
|---|
| 400 | # Show Info GCFFile |
|---|
| 401 | ::TolConsole::GetGCFFile |
|---|
| 402 | |
|---|
| 403 | Tolcon_Trace "argv0= $::argv0, argc= $::argc, argv= $::argv" |
|---|
| 404 | #puts "argv0= $::argv0, argc= $::argc, argv= $::argv" |
|---|
| 405 | |
|---|
| 406 | set loadandrun 0 |
|---|
| 407 | set include 0 |
|---|
| 408 | set salir 0 |
|---|
| 409 | foreach file $argv { |
|---|
| 410 | if { [string equal $file "-b"] } { set salir 1 } |
|---|
| 411 | if { [string equal $file "-r"] } { |
|---|
| 412 | set loadandrun 1 |
|---|
| 413 | continue |
|---|
| 414 | } |
|---|
| 415 | if { [string equal $file "-i"] } { |
|---|
| 416 | set include 1 |
|---|
| 417 | continue |
|---|
| 418 | } |
|---|
| 419 | OpenAssocFile $file $loadandrun $include |
|---|
| 420 | set loadandrun 0 |
|---|
| 421 | set include 0 |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | if { $salir } { exit } |
|---|
| 425 | |
|---|
| 426 | # Gives a name for the application |
|---|
| 427 | #if {$project::data(name) eq ""} { |
|---|
| 428 | # set prj "" |
|---|
| 429 | #} else { |
|---|
| 430 | # set prj "- $project::data(name)" |
|---|
| 431 | #} |
|---|
| 432 | #wm title . "TOLBase $prj" |
|---|
| 433 | # Show the dialog |
|---|
| 434 | |
|---|
| 435 | #::TolConsole::ODBCShow |
|---|