/usr/share/pyshared/Traducteur/inseremocle.py is in eficas 6.4.0-1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | # -*- coding: utf-8 -*-
import logging
from parseur import FactNode
from dictErreurs import jdcSet
from dictErreurs import EcritErreur
import string
import regles
debug=0
#-----------------------------------
def insereMotCle(jdc,recepteur,texte):
#-----------------------------------
# appelle la methode selon la classe 
# du recepteur
    if recepteur.name  not in jdcSet : return
    if recepteur.__class__.__name__ == "Command" :
       if debug : print " Ajout de ", texte, "dans la commande : " ,recepteur.name 
       insereMotCleDansCommande(jdc,recepteur,texte)
       return
#--------------------------------------------
def insereMotCleDansCommande(jdc,command,texte):
#---------------------------------------------
# insere le texte comme 1er mot cle
# de la commande
    if command.name  not in jdcSet : return
    if debug : print "insereMotCle ", texte , " dans ", command.name
    numcol=chercheDebut1Mot(jdc,command)
    if numcol > 0 :
       jdc.splitLine(command.lineno,numcol)
    indice = -1
    while texte[indice] == " " or texte[indice] == "\n": 
       indice = indice -1
    if texte[indice] != "," : texte=texte+","
    texteinfo=texte
    texte=texte+'\n'
    jdc.addLine(texte,command.lineno) 
    logging.info("Insertion de : %s ligne %d", texteinfo,command.lineno)
    if numcol > 0 : 		# Les mots clefs etaient sur la même ligne
        jdc.joinLineandNext(command.lineno)
#---------------------------------------------
def insereMotCleDansFacteur(jdc,facteur,texte):
#-------------------------------------------------
    if debug : print "insereMotCle ", texte , " dans ", facteur.name
    if texte[-1] == "\n" : texte=texte[0:-1] 
    ancien=jdc.getLine(facteur.lineno)
    # On va chercher la derniere ) pour ajouter avant
    # on va verifier s il il y a un , avant
    # si le texte ne finit pas par une ","
    # on en met une
    indice = -1
    while texte[indice] == " " : 
       indice = indice -1
    if texte[indice] != "," : 
       texte=texte+","
    if (texte.find("#") > -1) and (texte.find("#") < texte.find(",")) :
          texte=texte+"\n,"
          
    texteinfo=texte
    texte=texte+"\n"
  
    ligneaCouper=facteur.lineno
    trouve=0
    trouveF=0
    trouveP=0
    while ligneaCouper < facteur.endline + 1 :
       indiceDeCoupe=0
       while  ancien.find("_F") > 0 :
          longueur=len(ancien)
          indice=ancien.find("_F")
          indiceParcours=0
          # pour ne pas tenir compte des autres noms 
          # Attention si 2 MCF sur la meme ligne (la 1ere)
          if trouveF == 0 :
            if ((ligneaCouper!=facteur.lineno) or ((ancien.find(facteur.name) < indice ) or (ancien.find(facteur.name) < 0))) :
               trouveF=1
               indiceParcours=indice + 2
          # attention pour regler DEFI_FONCTION .. 
            else :
               indiceDeCoupe=indiceDeCoupe+indice+2
               ancien=ancien[indice +2:]
               continue
          if trouveF == 1 :
             indiceDeCoupe=indiceDeCoupe+indice
    #         print "indice de Parcours" ,indiceParcours
    #         print ancien[indiceParcours] 
    #         print ancien[indiceParcours+1] 
    #         print ancien[indiceParcours+2] 
             while  indiceParcours < longueur :
               if ancien[indiceParcours] == "(" :
                trouveP=1
    #            print "trouve"
                break
               if ancien[indiceParcours] != " " :
                trouveP=0
    #            print "mouv"
                break
               indiceParcours = indiceParcours+1
          trouve = trouveP * trouveF
          if trouve : break
          ancien=ancien[indice+1:]
          
       trouve = trouveP * trouveF
       if trouve : break
       ligneaCouper=ligneaCouper+1
       ancien=jdc.getLine(ligneaCouper)
         
    if trouve :
       debut=indiceDeCoupe + 3
       jdc.splitLine(ligneaCouper,debut)
    else :
       print "Le traducteur ne sait pas faire"
       assert 0
    # enleve les blancs en debut de texte
    i = 0
    while i < len(texte) :
      if texte[i] != " " : break
      i = i +1
    jdc.addLine(texte,ligneaCouper)
    jdc.joinLineandNext(ligneaCouper)
    logging.info("Insertion de %s ligne %d", texteinfo,ligneaCouper)
    # Gestion du cas particulier du mot clef facteur vide
    if facteur.childNodes == []:
       jdc.joinLineandNext(facteur.lineno)
#-----------------------------------
def chercheDebut1Mot(jdc,command):
#-----------------------------------
# Retourne le numero de colonne si le 1er mot clef est 
# sur la meme ligne que le mot clef facteur
# -1 sinon
    assert (command.childNodes != [])
    debut=-1
    node1=command.childNodes[0]
    if hasattr(node1,"lineno"):
       if node1.lineno == command.lineno :
          debut=node1.colno
    else:
       debut=chercheDebutFacteur(jdc,command) 
    if debut == -1 and debug : print "attention!!! pb pour trouver le debut dans ", command
    return debut
#-----------------------------------
def chercheDebutFacteur(jdc,facteur):
#-----------------------------------
    debut=-1
    ligne=jdc.getLines()[facteur.lineno]
    debut=ligne.find("_F")
    if debut >  -1 : debut=debut + 3
    return debut
    
#-----------------------------------
def chercheAlignement(jdc,command):
#-----------------------------------
# Retourne le nb de blanc
# pour aligner sur le 1er mot clef fils
    assert (command.childNodes != []) 
    node1=command.childNodes[0]
    nbBlanc=node1.colno
    return " "*nbBlanc
#---------------------------------------------------------------------------------------------------------
def chercheOperInsereFacteur(jdc,nomcommande,nouveau,ensemble=regles.SansRegle, estunFacteur=1, erreur=0):
#--------------------------------------------------------------------------------------------------------
# Cherche l oper
# cree le texte
# appelle insereMotCle pour ajouter le texte
#
    boolChange=0
    if estunFacteur : 
      texte=nouveau+"=_F(),"
    else :
      texte=nouveau
    if nomcommande  not in jdcSet : return
    commands= jdc.root.childNodes[:]
    commands.reverse()
    for c in commands:
        if c.name != nomcommande:continue
        if ensemble.verif(c) == 0 : continue
        if erreur : EcritErreur((nomcommande,nouveau),c.lineno)
        boolChange=1
        insereMotCle(jdc,c,texte)
    if boolChange : jdc.reset(jdc.getSource())
#----------------------------------------------------------------------------------------
def chercheOperInsereFacteurSiRegle(jdc,nomcommande,nouveau,liste_regles, estunFacteur=1):
#----------------------------------------------------------------------------------------
# Cherche l oper
# cree le texte
# appelle insereMotCle pour ajouter le texte
#
    if nomcommande  not in jdcSet : return
    mesRegles=regles.ensembleRegles(liste_regles)
    chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur)
#----------------------------------------------------------------------------------------
def chercheOperInsereMotCleSiRegle(jdc,nomcommande,nouveau,liste_regles, estunFacteur=0):
#----------------------------------------------------------------------------------------
    if nomcommande  not in jdcSet : return
    mesRegles=regles.ensembleRegles(liste_regles)
    chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur)
    
#---------------------------------------------------------------------------------------------------------
def chercheOperInsereFacteurSiRegleAvecAvertissement(jdc,nomcommande,nouveau,liste_regles, estunFacteur=1):
#---------------------------------------------------------------------------------------------------------
    if nomcommande  not in jdcSet : return
    mesRegles=regles.ensembleRegles(liste_regles)
    chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur,erreur=1)
#-------------------------------------------------------------------------------------------------
def AjouteMotClefDansFacteur(jdc,commande,fact,nouveau,ensemble=regles.SansRegle, estunFacteur=0):
#-------------------------------------------------------------------------------------------------
# Cherche la commande
# Cherche le MCF
# cree le texte
# appelle insereMotCle pour ajouter le texte
#
    if commande  not in jdcSet : return
    if estunFacteur : 
      texte=nouveau+"=_F(),"
    else :
      texte=nouveau
    commands= jdc.root.childNodes[:]
    commands.reverse()
    boolChange=0
    for c in commands:
        if c.name != commande : continue
        for mcF in c.childNodes:
          if mcF.name != fact : continue
          if ensemble.verif(c) == 0 : continue
          l=mcF.childNodes[:]
          l.reverse()
          boolChange=1
          insereMotCleDansFacteur(jdc,mcF,texte)
    if boolChange : jdc.reset(jdc.getSource())
#-------------------------------------------------------------------------------------------
def AjouteMotClefDansFacteurSiRegle(jdc,commande,fact,nouveau,liste_regles,estunFacteur=0):
#-------------------------------------------------------------------------------------------
#
    if commande  not in jdcSet : return
    mesRegles=regles.ensembleRegles(liste_regles)
    AjouteMotClefDansFacteur(jdc,commande,fact,nouveau,mesRegles,estunFacteur)
#-------------------------------------------------------------------------------------------
def AjouteMotClefDansFacteurCourantSiRegle(jdc,commande,fact,nouveau,liste_regles):
#-------------------------------------------------------------------------------------------
#
    if commande  not in jdcSet : return
    ensemble=regles.ensembleRegles(liste_regles)
    commands= jdc.root.childNodes[:]
    commands.reverse()
    boolChange=0
    for c in commands:
        if c.name != commande : continue
        for mcF in c.childNodes:
          if mcF.name != fact : continue
          l=mcF.childNodes[:]
          l.reverse()
          for ll in l:
             if ensemble.verif(ll) == 0 : continue
             boolChange=1
             n=ll.childNodes[0]
             ligneaCouper=n.lineno-1
             numcol=n.colno
             jdc.splitLine(ligneaCouper+1,numcol)
             texte=nouveau+",\n"
             jdc.addLine(texte,ligneaCouper+1)
             logging.info("Insertion de %s dans %s : ligne %d", nouveau,c.name,ligneaCouper+1)
             if numcol > 0 :    
                 jdc.joinLineandNext(ligneaCouper+1)
    if boolChange : jdc.reset(jdc.getSource())
 |