1######################################################################### 2# COPYRIGHT (C) 2003 EDF R&D WWW.CODE-ASTER.ORG # 3# # 4# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR # 5# MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS # 6# PUBLISHED BY THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE # 7# LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION. # 8# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, # 9# BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF # 10# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU # 11# GENERAL PUBLIC LICENSE FOR MORE DETAILS. # 12# # 13# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE # 14# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO : EDF R&D CODE_ASTER, # 15# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE. # 16######################################################################### 17 18# $Id: messages.tcl 1023 2005-10-27 08:04:48Z mcourtoi $ 19 20# mots-clés du fichier de messages 21################################################################# 22proc ashare::init_mots_msg { } { 23# MCS : Mots-Clés Simples 24# MCF : Mot-Clé Facteur (un seul) 25# SSF : mots-clés Simples Sous un mot-clé Facteur 26# fichier des messages 27 set ashare::mots(MCS_msg) { nb_err nb_inf nb_ihm } 28 set ashare::mots(MCF_msg) { langue } 29 set ashare::mots(SSF_msg) { ihm erreur info } 30} 31 32# affichage des messages d'erreur et info 33################################################################# 34proc ashare::mess { typ indice {args ""} } { 35 set msg "" 36 if { $typ == "erreur" } { 37 if { $ashare::fen_log < 2 } { set ashare::fen_log 0 } 38 append msg "<$ashare::msg($ashare::lang,$typ,txt)" 39 append msg [format " %03d%1s" $indice ">"] 40 } elseif { $typ == "info" } { 41 append msg "<$ashare::msg($ashare::lang,$typ,txt)>" 42 } elseif { $typ == "ihm" } { 43 # RAS 44 } else { 45 set iret "<ERROR 000> Bad message type." 46 ashare::log $iret 47 return $iret 48 } 49# construction du format (pour décalage) 50 if { $typ != "ihm" } { 51 set fmt "%" 52# append fmt [string length $msg] 53 append fmt "s%s" 54 append msg " " 55 } 56# insertion des arguments 57 append msg $ashare::msg($ashare::lang,$typ,$indice) 58 set narg [llength $args] 59 for {set i 1} {$i <= $narg} {incr i} { 60 regsub -all "@$i@" $msg [lindex $args [expr $i - 1]] msg 61 } 62 regsub -all "@\[0-9\]*@" $msg "-" msg 63# 64 set CR "@n@" 65 if { $typ == "ihm" } { 66 regsub -all $CR $msg "\n" msg2 67 } else { 68 set msg2 "" 69 set n 0 70 set n1 1 71 while { $n1 > 0 } { 72 set n1 [string first $CR $msg $n] 73 set sub [string range $msg $n [expr $n1 - 1]] 74 if { $n1 < 0 } { 75 set sub [string range $msg $n [string length $msg]] 76 } 77 if { $n != 0 } { 78 set sub [format "$fmt" "" $sub] 79 } 80 ashare::log $sub 81 append msg2 $sub 82 append msg2 "\n" 83 set n [expr $n1 + [string length $CR]] 84 } 85 } 86 return $msg2 87} 88 89# initialisation des messages erreur/info/ihm 90################################################################# 91proc ashare::lire_msg { fich } { 92 set iret [ashare::lire_mc_val $fich mots vale nlu ] 93 if { $iret != 0 } { 94 return $iret } 95 96 # phase de vérif 97 # mots-clés reconnus 98 set mots_cles $ashare::mots(MCS_msg) 99 append mots_cles $ashare::mots(MCF_msg) 100 # mots-clés sous le mot-clé "langue" 101 set mots_smcf $ashare::mots(SSF_msg) 102 append mots_cles $mots_smcf 103 # les mots-clés sont obligatoires 104 set pmcs [llength $mots_smcf] 105 set pmcf [expr [llength $mots_cles] - $pmcs - 1] 106 for { set k 0 } { $k < [ llength $mots_cles ] } { incr k } { 107 set mcs [lindex $mots_cles $k] 108 } 109 110 set nberr 0 111 set lang "" 112 set lang_lue 0 113 set ashare::llang(nb_lang) 0 114 set type "" 115 set nb(erreur) 0 116 set nb(info) 0 117 set nb(ihm) 0 118 for {set j 1} {$j <= $nlu} {incr j} { 119 #astkrc_version : pas utilisé ici 120 if { $mots($j) == "astkrc_version" } { 121 if { $vale($j) != "$ashare::astkrc_version" } { 122 ashare::log "<ERROR> astkrc version incorrect : $fich" 123 return PB_astkrc_version 124 } 125 } else { 126 set iv [lsearch -exact $mots_cles $mots($j)] 127 if { $iv < 0 && [regexp {^[ ]*([0-9]+)[ ]*} $mots($j)] == 0 } { 128 ashare::log "<ERROR> Unknown keyword : $mots($j)" 129 incr nberr 130 } else { 131 set i [lsearch -exact $mots_smcf $mots($j)] 132 if { $i < 0 && [regexp {^[ ]*([0-9]+)[ ]*} $mots($j)] == 0 } { 133 if { $mots($j) == "langue" } { 134 set ashare::llang(lang,$ashare::llang(nb_lang)) $vale($j) 135 incr ashare::llang(nb_lang) 136 set lang $vale($j) 137 set lang_lue 1 138 } else { 139 set ashare::msg($mots($j)) $vale($j) 140 } 141 } elseif { $i >= 0 } { 142 if { [string length $lang] > 0 } { 143 set ashare::msg($lang,$mots($j),txt) $vale($j) 144 set typ $mots($j) 145 } 146 } else { 147 if { [string length $lang] > 0 && [string length $typ] > 0 } { 148 set ashare::msg($lang,$typ,$mots($j)) $vale($j) 149 incr nb($typ) 150 } 151 } 152 } 153 } 154 } 155 if { [string length $lang] == 0 || ! $lang_lue } { 156 ashare::log "<ERROR> Unknown language." 157 incr nberr 158 } else { 159 if { $nb(erreur) != [expr $ashare::msg(nb_err) * $ashare::llang(nb_lang)] } { 160 ashare::log "<ERROR> Number of ERROR messages incorrect." 161 incr nberr 162 } 163 if { $nb(info) != [expr $ashare::msg(nb_inf) * $ashare::llang(nb_lang)] } { 164 ashare::log "<ERROR> Number of INFO messages incorrect." 165 incr nberr 166 } 167 if { $nb(ihm) != [expr $ashare::msg(nb_ihm) * $ashare::llang(nb_lang)] } { 168 ashare::log "<ERROR> Number of GUI messages incorrect." 169 incr nberr 170 } 171 } 172 if { $nberr > 0 } { 173 ashare::log "<ERROR> Read of $fich failed." 174 ashare::my_exit 4 175 } 176# debug maxi 177 if { $ashare::dbg >= 5 } { 178 for {set i 1} {$i <= $ashare::msg(nb_err)} {incr i} { 179 ashare::log "ERR $i : $ashare::msg(erreur,$i)" } 180 for {set i 1} {$i <= $ashare::msg(nb_inf)} {incr i} { 181 ashare::log "INF $i : $ashare::msg(info,$i)" } 182 for {set i 1} {$i <= $ashare::msg(nb_ihm)} {incr i} { 183 ashare::log "IHM $i : [ashare::mess ihm $i]" } 184 } 185 return 0 186} 187 188# Affichage des messages dans une fenêtre de log + fenêtre 189################################################################# 190proc ashare::log { chaine } { 191 set fen $astk::ihm(log) 192 set wtxt $fen.txt.tx 193# si la fenetre des logs n'existe pas, on fait un puts sur stdout 194 if { $ashare::fen_log < 1 } { 195 puts $chaine 196 } else { 197 puts $ashare::pt_log $chaine 198 flush $ashare::pt_log 199 if { [winfo exists $fen] } { 200 $fen.txt.tx configure -state normal 201 $fen.txt.tx insert end $chaine 202 $fen.txt.tx insert end "\n" 203 $fen.txt.tx configure -state disabled 204 $fen.txt.tx see end 205 } 206 } 207} 208 209# ouverture du fichier des logs 210################################################################# 211proc ashare::init_log { fic } { 212 append ashare::fic_log $fic 213 set ashare::pt_log [open $ashare::fic_log w+] 214 set start [clock format [clock seconds] -format "%d/%m/%Y - %H:%M:%S"] 215 ashare::log "<INFO> Session started : $start (process id [pid])" 216} 217 218# fenetre des logs 219# fen_log = 0 : on ne veut pas de la fenetre 220# fen_log = 1 : en cours d'init, message erreur sur stdout 221# fen_log = 2 : init fini 222################################################################# 223proc ashare::affich_log { } { 224 if { $ashare::fen_log == 0 } { 225 return 226 } 227# ouverture du fichier 228 set fen $astk::ihm(log) 229 catch {destroy $fen} 230 toplevel $fen 231 set_icon $fen 232 # on cache la fenêtre en attendant la construction 233 wm withdraw $fen 234 wm title $fen "Messages" 235 wm protocol $fen WM_DELETE_WINDOW {$astk::ihm(log).valid.ok invoke} 236 bind $fen <Control-Key-w> "destroy $fen" 237 238# texte 239 pack [frame $fen.txt -relief solid -bd 0] -anchor c -fill both -expand yes 240 text $fen.txt.tx -xscrollcommand "$fen.txt.scrollx set" -yscrollcommand "$fen.txt.scrolly set" \ 241 -height 15 -width 100 -font $astk::ihm(font,txtfix) -bg $astk::ihm(couleur,entry_background) -wrap none 242 scrollbar $fen.txt.scrolly -command "$fen.txt.tx yview" 243 scrollbar $fen.txt.scrollx -command "$fen.txt.tx xview" -orient h 244 pack $fen.txt.scrolly -side right -fill y 245 pack $fen.txt.scrollx -side bottom -fill x 246 pack $fen.txt.tx -expand 1 -fill both 247 248# remplit le texte 249 set vol [file size $ashare::fic_log] 250 seek $ashare::pt_log 0 start 251 $fen.txt.tx configure -state normal 252 $fen.txt.tx insert end [read $ashare::pt_log] 253 $fen.txt.tx configure -state disabled 254 $fen.txt.tx see end 255 256# fermer 257 pack [frame $fen.valid -relief solid -bd 0] 258 button $fen.valid.ok -font $astk::ihm(font,labbout) -text "Ok" \ 259 -background $astk::ihm(couleur,valid) \ 260 -command "destroy $fen" 261 pack $fen.valid.ok -padx 10 -pady 3 262 wm deiconify $fen 263 ashare::trace_geom log $fen 264} 265