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