      subroutine gsquestion(ix,iy,nbchamps,nbchoix,ial,question,longq
     &                     ,iqpos,facpos,cretour,longr,iretour,rretour
     &                     ,cinit,longi,iinit,rinit,ctitre,ltitre,iapply
     &                     ,blablabla,lblablabla,iexcl,ieps,eps,irc)
      INCLUDE 'Parametres.f'
      parameter(nbzonesmax=30)
c
      dimension rretour(*),rinit(*),eps(*)
      integer ial(*),longq(*),iqpos(*),longr(*),iretour(*)
     &       ,longi(*),iinit(*),iexcl(*),ieps(*)
      integer ixzone(2,nbzonesmax),iyzone(2,nbzonesmax)
     &       ,itypzone(nbzonesmax),iselzone(nbzonesmax)
     &       ,longc(nbzonesmax),ialpha(nbzonesmax)
     &       ,ipos(nbzonesmax),ixs(nbzonesmax),iys(nbzonesmax),inum(256)
      character*132 question(*),cretour(*),cinit(*),ctitre
      character*132 chaine(nbzonesmax),chainesav,string
      character*512 blablabla
      common / lesboules / icboul,irboul,ixboul
c
c mettre plein de commentaires
c ialpha = 0 : chaine de caracteres
c ialpha = 1 : entier
c ialpha = 2 : reel
c
c iqpos = 0 a gauche
c iqpos = 1 au dessus
c
c caracteres alphanumeriques
c
      do i=1,256
        inum(i) = 0
      enddo
      inum(43) = 1
      inum(45) = 1
      inum(46) = 1
      do i=48,57
        inum(i) = 1
      enddo
      inum(68) = 1
      inum(69) = 1
      inum(100) = 1
      inum(101) = 1
c
      if (irc.eq.-2) then
        inew = 1
      else
        inew = 0
      endif
      call okcancel(ix,iy,iynew,ixzone,iyzone,itypzone,iselzone,iapply
     &             ,inew)
c
      nb  = min(nbchamps+nbchoix,nbzonesmax-nokcancel)
      nbq = min(nbchamps,nbzonesmax-nokcancel)
      nbc = max(nb-nbq,0)
      nzones = nb+nokcancel
c
      ligne  = nint(2.5*real(ibordpop))
      ligne2 = 5*ibordpop
      ligne3 = 2*ibordpop
      llii = nint(0.4*real(ibordpop))
      call gslss(7)
      iyc = 2*ibordpop
      iz = nokcancel
      ix2 = ix/2
      ixp = nint(facpos*real(ix))
      if (ltitre.gt.0) then
        call x11loadcolor(3)
        z = 0.
        call x11txtsrnrot3(ctitre(1:ltitre)//char(0),ltitre
     &                    ,ix2,iyc,8,z,8,-1)        
        iyc = iyc + ligne
      endif
      call x11loadcolor(0)
c
      if (lblablabla.gt.0) then
        call gslss(0)
        nblignebla = 1
        do i=1,lblablabla
          if (ichar(blablabla(i:i)).eq.10) nblignebla = nblignebla+1
        enddo
        z = 0.
        iii = iyc + nint(real((nblignebla-1)*ligne)*0.5)
        call x11txtsrnrot3(blablabla(1:lblablabla)//char(0),lblablabla
     &                    ,ibordpop,iii,8,z,7,-1)        
        iyc = iyc + nint(real(ligne*nblignebla)*0.6)
        call gslss(7)
      endif
c
c questions avec valeurs numeriques
c
      if (nbq.gt.0) then
        do i=1,nbq
          call x11txtsrn(question(i),longq(i),ibordpop,iyc)
          iz = iz + 1
          itypzone(iz) = 7
          ialpha(iz)= ial(i)
          iselzone(iz) = 0
          if (ial(i).eq.0) then
            if (longi(i).gt.0) then
              chaine(iz) = cinit(i)(1:longi(i))//char(0)
            else
              chaine(iz) = ' '//char(0)
            endif
            longc(iz) = longi(i)
          elseif(ial(i).eq.1) then
            call encodeentier(iinit(i),chaine(iz),longc(iz))
          else
            call reduitreel1(rinit(i),chaine(iz),longc(iz),0)
          endif
          ipos(iz) = longc(iz)
          ixzone(2,iz) = ix-ibordpop
          if (iqpos(i).eq.0) then
            ixzone(1,iz) = ixp
            iyzone(1,iz) = iyc - ibordpop - llii
            iyc = iyc + ligne
          else
            ixzone(1,iz) = ibordpop
            iyzone(1,iz) = iyc + ibordpop
            iyc = iyc + ligne2
          endif
          iyzone(2,iz) = iyzone(1,iz) + ligne3
          ixs(iz) = ixzone(1,iz) + ibordpop/2
          iys(iz) = (iyzone(1,iz) + iyzone(2,iz))/2
        enddo
c
        do i=1,nbq
          iz = i + nokcancel
          call metstring(ixzone(1,iz),iyzone(1,iz),chaine(iz)
     &                  ,longc(iz),ixs(iz),iys(iz),ipos(iz),0)
        enddo
c        if (irc.eq.-2) then
c          call x11setcurs((ixzone(1,3)+ixzone(2,3))/2
c     &                   ,(iyzone(1,3)+iyzone(2,3))/2)
c        else
          call x11setcurs((ixzone(1,iz)+ixzone(2,iz))/2
     &                   ,(iyzone(1,iz)+iyzone(2,iz))/2)
c        endif
      endif
c
c cases a cocher
c
      icboul = 1
      ixboul = ix-ligne
      irboul = ibordpop
      if (nbc.gt.0) then
        call gslss(7)
        iyc = iyc + ibordpop
        ideja = 0
        do j=1,nbc
          i = nbchamps+j
          i1 = iexcl(i)/1000
          i2 = mod(iexcl(i),1000)
          if (i1.eq.i.and.j.gt.1.and.ideja.eq.0) then
            iyc = iyc - ibordpop
            call idoubleligne(0,ix,iyc,ibordpop,15,7,1)
            iyc = iyc + 2*ibordpop
          endif
          call x11loadcolor(0)
          call x11txtsrn(question(i),longq(i),ibordpop,iyc)
          iz = iz + 1
          itypzone(iz) = 10
          ialpha(iz)= ial(i)
          iselzone(iz) = 0
          ixzone(2,iz) = ix-ibordpop
          ixzone(1,iz) = ixp
          iyzone(1,iz) = iyc - ibordpop - llii
          iyzone(2,iz) = iyzone(1,iz) + ligne3
          ixs(iz) = ixzone(1,iz) + ibordpop/2
          iys(iz) = (iyzone(1,iz) + iyzone(2,iz))/2
          iyboul = (iyzone(1,iz) + iyzone(2,iz))/2
          call affichelaboule(iinit(i),ixboul,iyboul,irboul,icboul)
          iretour(i) = iinit(i)
          if (i2.eq.i.and.j.lt.nbc) then
            iyc = iyc + ibordpop
            call idoubleligne(0,ix,iyc,ibordpop,15,7,1)
            ideja = 1
          else
            ideja = 0
          endif
          iyc = iyc + ligne3
        enddo
      endif
c
      leretour = 0
      call recupevents(nzones,ixzone,iyzone,itypzone,iselzone
     &                ,ialpha,ipos,ixs,iys,chaine,question,0
     &                ,chainesav,longq,longc,lfichiers,idir,inum,0
     &                ,iretour,iexcl,ieps,eps,leretour)
c
      irc = leretour
      if (irc.eq.0.or.irc.eq.-2) then
        do i=1,nb
          iz = i+nokcancel
          if (ial(i).eq.0) then
            if (longc(iz).gt.0) then
              cretour(i) = chaine(iz)(1:longc(iz))
            else
              cretour(i) = ' '
            endif
            longr(i) = longc(iz)
          elseif(ial(i).eq.1) then
            if (longc(iz).gt.0) then
              read(chaine(iz)(1:longc(iz)),*) iretour(i)
            else
              iretour(i) = iinit(i)
            endif
          elseif(ial(i).eq.2) then
            if (longc(iz).gt.0) then
              read(chaine(iz)(1:longc(iz)),*) rretour(i)
            else
              rretour(i) = rinit(i)
            endif
          endif
        enddo
      endif
      end
c-----------------------------------------------------------------------
      subroutine gspopup(ix,iy,iretour)
      INCLUDE 'Parametres.f'
      parameter(nbzonesmax=10)
c
      integer ixzone(2,nbzonesmax),iyzone(2,nbzonesmax)
     &       ,itypzone(nbzonesmax),iselzone(nbzonesmax)
     &       ,longq(nbzonesmax),longc(nbzonesmax),ialpha(nbzonesmax)
     &       ,ipos(nbzonesmax),ixs(nbzonesmax),iys(nbzonesmax),inum(256)
cc      character*32 string
      character*132 chaine(nbzonesmax),question(nbzonesmax),chainesav
c
c mettre plein de commentaires
c ialpha = 0 : chaine de caracteres
c ialpha = 1 : entier
c ialpha = 2 : reel
c
c caracteres alphanumeriques
c
      do i=1,256
        inum(i)=0
      enddo
      inum(43) = 1
      inum(45) = 1
      inum(46) = 1
      do i=48,57
        inum(i)=1
      enddo
      inum(68) = 1
      inum(69) = 1
      inum(100) = 1
      inum(101) = 1
c
      call okcancel(ix,iy,iynew,ixzone,iyzone,itypzone,iselzone,0,0)
c
      question(1) = 'Essai de question ?'//char(0)
      longq(1) = 19
      call x11loadcolor(0)
      call gslss(7)
      call x11txtsrn(question(1),longq(1),ibordpop,2*ibordpop)
      ixzone(1,3) = ibordpop
      ixzone(2,3) = ix-ibordpop
      iyzone(1,3) = 3*ibordpop
      iyzone(2,3) = 5*ibordpop
      itypzone(3) = 7
      ialpha(3)   = 0
      iselzone(3) = 0
      chaine(3) = 'Chaine initiale'//char(0)
      longc(3) = 15
      ipos(3) = longc(3)
      ixs(3) = ixzone(1,3)+ibordpop/2
      iys(3) = (iyzone(1,3)+iyzone(2,3))/2
      izone = 3
      call metstring(ixzone(1,izone),iyzone(1,izone),chaine(izone)
     &              ,longc(izone),ixs(izone),iys(izone),ipos(izone),0)
c
      question(4) = 'Autre question ?'//char(0)
      longq(4) = 16
      call x11loadcolor(0)
      call gslss(7)
      call x11txtsrn(question(4),longq(4),ibordpop,7*ibordpop)
      ixzone(1,4) = ibordpop
      ixzone(2,4) = ix-ibordpop
      iyzone(1,4) = 8*ibordpop
      iyzone(2,4) = 10*ibordpop
      itypzone(4) = 7
Cfj      ialpha(4)   = 1
      ialpha(4)   = 2
      iselzone(4) = 0
Cfj      iii = 123456
Cfj      write(chaine(4),'(i6)') iii
      xxx = 1234.5
      write(chaine(4),'(f6.1)') xxx
      longc(4) = 6
      chaine(4)(longc(4)+1:longc(4)+1) = char(0)
Cfj      chaine(4) = 'Autre Chaine initiale'//char(0)
Cfj      longc(4) = 21
      ipos(4) = longc(4)
      ixs(4) = ixzone(1,4)+ibordpop/2
      iys(4) = (iyzone(1,4)+iyzone(2,4))/2
      izone = 4
      call metstring(ixzone(1,izone),iyzone(1,izone),chaine(izone)
     &              ,longc(izone),ixs(izone),iys(izone),ipos(izone),0)
c
      nzones=4
      leretour = 0
c
      call recupevents(nzones,ixzone,iyzone,itypzone,iselzone
     &                ,ialpha,ipos,ixs,iys,chaine,question,0
     &                ,chainesav,longq,longc,lfichiers,idir,inum,0
     &                ,ibid,ibid,ieps,eps,leretour)
c
      do i=1,4
        print*,i,longc(i),'"'//chaine(i)(1:longc(i))
      enddo
      iretour = leretour
      end
c-----------------------------------------------------------------------
      subroutine metstring(ixzone,iyzone,chaine,longc,ixs,iys,ipos,iopt)
c
      INCLUDE 'Parametres.f'
      integer ixzone(2),iyzone(2)
      character*132 chaine,bidon
c
      ilar = ixzone(2)-ixzone(1)
      ihau = iyzone(2)-iyzone(1)
      call x11loadcolor(icoul_questions)
      call x11facette2(ixzone,iyzone,ilar,ihau)
      call x11bord(ixzone(1),iyzone(2),ixzone(2),iyzone(1)
     &            ,bidon,0,2,15,7,8,0)
      ipos2 = ipos
      if (longc.gt.0) then
        call x11loadcolor(7)
        call gslss(0)
        if (longc.lt.ilarstrfen) then
          call x11txtsrnrot3(chaine(1:longc)//char(0),longc
     &         ,ixs,iys,icoul_questions,zero,4,1)
        else
          call x11txtsrnrot3(chaine(longc-ilarstrfen+2:longc)//char(0)
     &                      ,ilarstrfen-1,ixs,iys,icoul_questions
     &                      ,zero,4,1)
          ipos2 = ipos-longc+ilarstrfen-1
        endif
      endif
      if (iopt.ne.0) call metcurstring(iyzone,ixs,iys,ipos2,isizecar0,1)
      end
c-----------------------------------------------------------------------
      subroutine metcurstring(iyzone,ixs,iys,ipos,isizecar0,ic)
      integer iyzone(2)
c
      call x11loadcolor(ic)
      ih = (iyzone(2)-iyzone(1))*.4
      ixcu = ixs+isizecar0*ipos-1
      iycu1 = iys+ih
      iycu2 = iys-ih
      call x11linsrn(ixcu,iycu1,ixcu,iycu2)
      end
c-----------------------------------------------------------------------
      subroutine checknumeric(chaine,long,ialpha,icheck)
      character*32 chaine
c
      icheck = 0
      if (ialpha.eq.1) then
        read(chaine(1:long),fmt=*,err=1000) iii 
cc        print*,'passe entier',iii
        return
 1000   icheck = 1
      else
        read(chaine(1:long),fmt=*,err=2000) xxx
cc        print*,'passe reel',xxx
        return
 2000   icheck = 2
      endif
c
      end
c-----------------------------------------------------------------------
      subroutine clearallzones(ixzone,iyzone,itypzone,iselzone,ixs,iys
     &                        ,ipos,chaine,longc,isizecar0,nzones)
      integer ixzone(2,*),iyzone(2,*),itypzone(*),iselzone(*)
     &       ,ixs(*),iys(*),ipos(*),longc(*)
      character*132 chaine(*)
c
      do i=1,nzones
        if (itypzone(i).ne.0) then
          if (iselzone(i).ne.0) then
            iselzone(i) = 0
            call bordzone(ixzone(1,i),iyzone(1,i),8)
            if (itypzone(i).eq.7) then
              call metcurstring(iyzone(1,i),ixs(i),iys(i),ipos(i)
     &                         ,isizecar0,0)
              call metstring(ixzone(1,i),iyzone(1,i),chaine(i),longc(i)
     &                      ,ixs(i),iys(i),ipos(i),0)
            endif
          endif
        endif
      enddo
      end
c-----------------------------------------------------------------------
      subroutine bordzone(ixzone,iyzone,icoul)
      integer ixzone(2),iyzone(2)
      call x11loadcolor(icoul)
      ix1=ixzone(1)-1
      ix2=ixzone(2)+1
      iy1=iyzone(1)-1
      iy2=iyzone(2)+1
      call x11linsrn(ix1,iy1,ix1,iy2)
      call x11linsrn(ix1,iy2,ix2,iy2)
      call x11linsrn(ix2,iy2,ix2,iy1)
      call x11linsrn(ix2,iy1,ix1,iy1)
      end
c-----------------------------------------------------------------------
      subroutine browsfich(quest,lq,fi,lfi,chaine_retour,lchaine_ret
     &                    ,iretour)
      INCLUDE 'Parametres.f'
      parameter(nbzonesmax=10,nfichmax=4000)
      integer ixzone(2,nbzonesmax),iyzone(2,nbzonesmax)
     &       ,itypzone(nbzonesmax),iselzone(nbzonesmax)
     &       ,longq(nbzonesmax),longc(nbzonesmax),ialpha(nbzonesmax)
     &       ,ipos(nbzonesmax),ixs(nbzonesmax),iys(nbzonesmax)
     &       ,lfichiers(nfichmax),idir(nfichmax)
      character*132 chaine(nfichmax),fichiers(nfichmax)
     &             ,question(nfichmax),bidon
      character*(*) chaine_retour,quest,fi
c
      ilarstrfen = 65
      ix = ilarstrfen*isizecar0 + 2*ibordpop
      iy = ihautcar0*80
c
      if (lfi.le.0) then
        filtre = ' '
        lfiltre = 1
        ioptliste = 0
Cfj        filtre = '*theta*'
Cfj        lfiltre = 7
Cfj        ioptliste = 1
      else
        filtre(1:lfi) = fi(1:lfi)
        lfiltre = lfi
        ioptliste = 1
      endif
      pathrelatif = ' '
      longpath = 1
      call cree_la_liste(fichiers,lfichiers,idir,nfich,nfichmax
     &                  ,ioptliste)
c
      if (nfich.gt.0) then
        call okcancel(ix,iy,iynew,ixzone,iyzone,itypzone,iselzone,0,0)
c
Cfj        question(1) = 'Fichier ?'//char(0)
Cfj        longq(1) = 19
        question(1) = quest(1:lq)//char(0)
        longq(1) = lq
        call x11loadcolor(0)
        call gslss(7)
        call x11txtsrn(question(1),longq(1),ibordpop,2*ibordpop)
        izzz = 3
        ixzone(1,izzz) = ibordpop
        ixzone(2,izzz) = ix-ibordpop
        iyzone(1,izzz) = 3*ibordpop
        iyzone(2,izzz) = 5*ibordpop
        itypzone(izzz) = 7
        ialpha(izzz)   = 0
        iselzone(izzz) = 0
c
        izzz = izzz+1
        idfleche = ibordpop/2
        ixzone(1,izzz) = ibordpop
        ixzone(2,izzz) = ix-ibordpop-idfleche*3
        iyzone(1,izzz) = iyzone(2,izzz-1)+ibordpop
        iyzone(2,izzz) = iynew
        ihau = iyzone(2,izzz)-iyzone(1,izzz)
        ihaubrow = ihau-ibordbrow*2
        ilonglistey = ihaubrow/idyliste
        ihaubrow = ilonglistey*idyliste+ibordbrow*2
        ititi = (iyzone(1,izzz)+iyzone(2,izzz))/2
        iyzone(1,izzz) = ititi - ihaubrow/2
        iyzone(2,izzz) = iyzone(1,izzz) + ihaubrow
        itypzone(izzz) = 9
        ialpha(izzz) = 0
        call x11bord(ixzone(1,izzz),iyzone(2,izzz),ixzone(2,izzz)
     &       ,iyzone(1,izzz),bidon,0,ibordbrow,0,7,8,0)
        call bordzone(ixzone(1,izzz),iyzone(1,izzz),1)
        iselzone(izzz) = 1
c
        ixbrow = ixzone(1,izzz)+ibordbrow
        iybrow = iyzone(1,izzz)+ibordbrow
        ilarbrow = ixzone(2,izzz)-ixzone(1,izzz)-ibordbrow*2
        ihaubrow = iyzone(2,izzz)-iyzone(1,izzz)-ibordbrow*2
c
        izzz = izzz+1
        ixzone(2,izzz) = ix-ibordpop
        ixzone(1,izzz) = ixzone(2,izzz)-idfleche*2
        iyzone(1,izzz) = iyzone(1,izzz-1)
        iyzone(2,izzz) = iyzone(2,izzz-1)
        itypzone(izzz) = 0
        ixfleche = (ixzone(1,izzz)+ixzone(2,izzz))/2
        iyfleche1 = iyzone(1,izzz)+idfleche
        iyfleche2 = iyzone(2,izzz)-idfleche
        iyascen1 = iyfleche1+idfleche+ibordbrow*3
        iyascen2 = iyfleche2-idfleche-ibordbrow*3
Cfj        call gsitriangle(2,ixfleche,iyfleche1,idfleche,idfleche,-1)
Cfj        call gsitriangle(-2,ixfleche,iyfleche2,idfleche,idfleche,-1)
        call gsitriangle(ibordbrow,ixfleche,iyfleche1,idfleche,idfleche
     &                  ,1)
        call gsitriangle(-ibordbrow,ixfleche,iyfleche2,idfleche,idfleche
     &                  ,1)
        call x11bord(ixzone(1,izzz)-ibordbrow,iyascen2+ibordbrow
     &              ,ixzone(2,izzz)+ibordbrow,iyascen1-ibordbrow
     &              ,bidon,0,ibordbrow,15,7,8,0)
        nbfaffiche = 1 +
     &    (iyzone(2,izzz)-iyzone(1,izzz)-idyliste/2-ibordbrow)/idyliste
        nbaffichebrow = 1+(ilarbrow-ibordbrow*2)/isizecar0
c
c
        if (lchaine_ret.gt.0) then
          chaine(3) = chaine_retour(1:lchaine_ret)//char(0)
          longc(3) = lchaine_ret
          if (chaine(3)(1:1).eq.'|'
     &   .and.chaine(3)(longc(3):longc(3)).eq.'|') then
            longc(3) = lchaine_ret-2
            chaine(3) = chaine_retour(2:lchaine_ret-1)//char(0)
          endif
          ishi = 0
          ii = 0
          iok = 0
          do i=1,longc(3)
            if (chaine(3)(i:i).eq.'/') ii = i
          enddo
          do i=1,nfich
            if (fichiers(i)(1:lfichiers(i))
     &           .lt.chaine(3)(ii+1:longc(3))) ishi = i
            if (fichiers(i)(1:lfichiers(i))
     &           .eq.chaine(3)(ii+1:longc(3))) iok = i
          enddo
          if (iok.eq.0) then
            ishiftliste = ishi
          else
            ishiftliste = iok-ilonglistey/2
            ialpha(4) = iok
          endif
          if ((ishiftliste+ilonglistey).gt.nfich)
     &         ishiftliste = nfich-ilonglistey
          ishiftliste = max(0,ishiftliste)
        else
          chaine(3) = ' '
          longc(3) = 0
        endif
        ipos(3) = longc(3)
        ixs(3) = ixzone(1,3)+ibordpop/2
        iys(3) = (iyzone(1,3)+iyzone(2,3))/2
        izone = 3
        call metstring(ixzone(1,izone),iyzone(1,izone),chaine(izone)
     &                ,longc(izone),ixs(izone),iys(izone)
     &                ,ipos(izone),0)
c
        call affiche_liste(ixzone(1,4),iyzone(1,4),nfich,0
     &                    ,idir,fichiers,lfichiers,ialpha(4))
c
        nzones = izzz
        leretour = 3
        lebrowser = .true.
c
        call recupevents(nzones,ixzone,iyzone,itypzone,iselzone
     &                  ,ialpha,ipos,ixs,iys,chaine,question,nfich
     &                  ,fichiers,longq,longc,lfichiers,idir,inum
     &                  ,nfichmax,ibid,ibid,ieps,eps,leretour)
        lebrowser = .false.
        if (leretour.gt.0) then
          chaine_retour = chaine(leretour)
          lchaine_ret = longc(leretour)
          iretour = 0
        else
          iretour = -1
        endif
      else
        iretour = -9999
      endif
c
      end
c-----------------------------------------------------------------------
      subroutine affiche_liste(ixzone,iyzone,nfich,ifich,idir
     &                        ,fichiers,lfichiers,imarque)
      INCLUDE 'Parametres.f'
      integer ixzone(2,2),iyzone(2,2),idir(*),lfichiers(*)
      character*132 fichiers(*),bidon
c
      call gslss(0)
      ixst = ixzone(1,1) + ibordpop/2
      iyst = iyzone(1,1) + idyliste/2+ibordbrow
      if (nfich.gt.nbfaffiche) then
        propaffiche = real(nbfaffiche)/real(nfich)
        ipropaffiche = max(2*ibordbrow,
     &       int(real(iyascen2-iyascen1)*propaffiche))
      else
        ipropaffiche = 0
      endif
      call gsprogre(1)
      if (ifich.eq.0) then
        call x11loadcolor(15)
        call x11facette2(ixbrow,iybrow,ilarbrow,ihaubrow)
        call x11loadcolor(8)
        call x11facette2(ixzone(1,2),iyascen1
     &       ,ixzone(2,2)-ixzone(1,2),iyascen2-iyascen1)
        if (ipropaffiche.eq.0) then
          iyascen3 = iyascen1
          iyascen4 = iyascen2
        else
          iyascen3 = iyascen1+int(real(ishiftliste*(iyascen2-iyascen1))
     &       /real(nfich))
          iyascen4 = iyascen3+ipropaffiche
        endif
        call x11bord(ixzone(1,2),iyascen4
     &              ,ixzone(2,2),iyascen3
     &              ,bidon,0,ibordbrow,7,15,8,0)
      endif
      nnn = min(nfich,ishiftliste+nbfaffiche)
      do i=ishiftliste+1,nnn
        lfi = min(nbaffichebrow,lfichiers(i))
        if (ifich.eq.0) then
          if (idir(i).eq.0) then
            ifonfon = 7
          elseif(idir(i).eq.1) then
            ifonfon = 4
          else
            ifonfon = 5
          endif
          if (imarque.ne.i) then
            call x11loadcolor(ifonfon)
            ifonfon =  15
          else
            call x11loadcolor(ifonfon)
            call x11facette2(ixbrow,iyst-idyliste/2,ilarbrow,idyliste)
            call x11loadcolor(0)
          endif
          call x11txtsrnrot3(fichiers(i)(1:lfi)//char(0),lfi,ixst,iyst
     &                      ,ifonfon,zero,4,1)
        elseif(i.eq.iabs(ifich)) then
          if (ifich.gt.0) then
            ifonfon = 15
          else
            if (idir(i).eq.0) then
              ifonfon = 7
            elseif(idir(i).eq.1) then
              ifonfon = 4
            else
              ifonfon = 5
            endif
          endif
          call x11loadcolor(ifonfon)
          call x11facette2(ixbrow,iyst-idyliste/2,ilarbrow,idyliste)
          if (ifich.gt.0) then
            if (idir(i).eq.0) then
              call x11loadcolor(7)
            elseif(idir(i).eq.1) then
              call x11loadcolor(4)
            else
              call x11loadcolor(5)
            endif
          else
            call x11loadcolor(0)
          endif
          call x11txtsrnrot3(fichiers(i)(1:lfi)//char(0),lfi,ixst,iyst
     &                      ,ifonfon,zero,4,1)
        endif
        iyst = iyst+idyliste
      enddo
      call gsprogre(0)
      CALL x11metrect2(ixbrow,iybrow,ilarbrow,ihaubrow,ixbrow,iybrow)
      CALL x11metrect2(ixzone(1,2),iyascen1,ixzone(2,2)-ixzone(1,2)
     &                ,iyascen2-iyascen1,ixzone(1,2),iyascen1)
      end
c-----------------------------------------------------------------------
      subroutine recupevents(nzones,ixzone,iyzone,itypzone,iselzone
     &                      ,ialpha,ipos,ixs,iys,chaine,question,nfich
     &                      ,fichiers,longq,longc,lfichiers,idir,inum
     &                      ,nfichmax,icoche,iexcl,ieps,eps,leretour)
      INCLUDE 'Parametres.f'
      integer ixzone(2,*),iyzone(2,*),itypzone(*),iselzone(*)
     &       ,longq(*),longc(*),ialpha(*),ipos(*),ixs(*),iys(*)
     &       ,lfichiers(*),idir(*),inum(*),icoche(*),iexcl(*),ieps(*)
      dimension eps(*)
      character*132 fichiers(*),chaine(*),question(*),chainesav,string
      logical la
      common / lesboules / icboul,irboul,ixboul
      titi = 0.1
c
      call mybackingsave2()
 1    call ASREAD3(nzones,ixzone,iyzone,itypzone,izone,ipf)
ccccccc      if (ipf.ne.-9999) print*,'***',ipf,izone,nzones
c
c souris a roulette <=> fleches
c
      if (ipf.eq.-264.or.ipf.eq.-265) then
        ishiftelem = 3
        if (ipf.eq.-264) then
          ipf = 1098
        else
          ipf = 1104
        endif
      else
        ishiftelem = 1
        if (ipf.eq.-254) then
          ipf = 1098
        elseif(ipf.eq.-255) then
          ipf = 1104
        endif
      endif
c
      if (ipf.gt.0) then
c
c return = OK, esc = cancel
c
        if (ipf.eq.13.or.ipf.eq.27) then
          if (ipf.eq.13) then
            izone = 2
          else
            izone = 1
            leretour = -1
          endif
          call x11bord(ixzone(1,izone),iyzone(2,izone)
     &                ,ixzone(2,izone),iyzone(1,izone)
     &                ,string,0,2,15,7,8,0)
          call viderbuff2()
          if (leretour.gt.0) then
            call remetfullpath(chaine(leretour),longc(leretour))
            inquire(file=chaine(leretour)(1:longc(leretour)),exist=la)
            if (.not.la) then
              call fsalrm
              call perddutemps(titi)
              call x11bord(ixzone(1,izone),iyzone(2,izone)
     &                    ,ixzone(2,izone),iyzone(1,izone)
     &                    ,string,0,2,7,15,8,0)
              goto 1
            endif
          endif
          call perddutemps(titi)
          goto 3
c
c autres touches (fleches, pf, pgdown, ctrl...)
c
c 1098 ^
c 1099 pgup
c 1100 <
c 1102 >
c 1103 end
c 1104 v
c 1105 pgdown
c
        elseif(ipf.gt.1000) then
          if (ipf.eq.1098.or.ipf.eq.1104.or.ipf.eq.1100
     &    .or.ipf.eq.1099.or.ipf.eq.1105.or.ipf.eq.1102) then
            if (izone.ne.0) then
              if (itypzone(izone).eq.9.and.ipropaffiche.gt.0) then
                izone = izone+1
                itienlebien = 0
                if (ipf.eq.1104) then
                  ifleche = 2
                  goto 110
                elseif(ipf.eq.1098) then
                  ifleche = 1
                  goto 110
                elseif(ipf.eq.1099) then
                  ifleche = 3
                  goto 110
                elseif(ipf.eq.1105) then
                  ifleche = 4
                  goto 110
                endif
              elseif(itypzone(izone).eq.7) then
                if (ipf.eq.1100) then
                  if (ipos(izone).gt.0) then
                    call metcurstring(iyzone(1,izone)
     &                               ,ixs(izone),iys(izone)
     &                               ,ipos(izone),isizecar0,0)
                    ipos(izone) = ipos(izone)-1
                    call metstring(ixzone(1,izone),iyzone(1,izone)
     &                            ,chaine(izone)
     &                            ,longc(izone),ixs(izone),iys(izone)
     &                            ,ipos(izone),1)
                  else
                    call fsalrm
                  endif
                elseif(ipf.eq.1102) then
                  if (ipos(izone).lt.longc(izone)) then
                    call metcurstring(iyzone(1,izone)
     &                               ,ixs(izone),iys(izone)
     &                               ,ipos(izone),isizecar0,0)
                    ipos(izone) = ipos(izone)+1
                    call metstring(ixzone(1,izone),iyzone(1,izone)
     &                            ,chaine(izone)
     &                            ,longc(izone),ixs(izone),iys(izone)
     &                            ,ipos(izone),1)
                  else
                    call fsalrm
                  endif
                elseif(ipf.eq.1098) then
                  iep = ieps(izone-nokcancel)
                  ep = eps(izone-nokcancel)
                  if (ialpha(izone).eq.1.and.iep.gt.0) then
                    read(chaine(izone)(1:longc(izone)),*) iii
                    iii = iii+iep
                    call encodeentier(iii,chaine(izone),longc(izone))
                    call metstring(ixzone(1,izone),iyzone(1,izone)
     &                            ,chaine(izone)
     &                            ,longc(izone),ixs(izone),iys(izone)
     &                            ,ipos(izone),1)
                  elseif(ialpha(izone).eq.2.and.ep.gt.0.) then
                    read(chaine(izone)(1:longc(izone)),*) rrr
                    iii = nint(rrr/ep)
                    rrr2 = real(iii)*ep
                    if (abs(rrr-rrr2).lt.ep*0.01) then
                      rrr = real(iii+1)*ep
                    elseif(rrr2.lt.rrr) then
                      rrr = real(iii+1)*ep
                    else
                      rrr = rrr2
                    endif
                    call reduitreel1(rrr,chaine(izone),longc(izone),0)
                    call metstring(ixzone(1,izone),iyzone(1,izone)
     &                            ,chaine(izone)
     &                            ,longc(izone),ixs(izone),iys(izone)
     &                            ,ipos(izone),1)
                  else
                    iz = izone-1
                    if (iz.gt.0) then
                      if (itypzone(iz).eq.7) then
                        call x11setcurs((ixzone(1,iz)+ixzone(2,iz))/2
     &                                 ,(iyzone(1,iz)+iyzone(2,iz))/2)
                        izone = iz
                      endif
                    endif
                  endif
                elseif(ipf.eq.1104) then
                  iep = ieps(izone-nokcancel)
                  ep = eps(izone-nokcancel)
                  if (ialpha(izone).eq.1.and.iep.gt.0) then
                    read(chaine(izone)(1:longc(izone)),*) iii
                    iii = iii-iep
                    call encodeentier(iii,chaine(izone),longc(izone))
                    call metstring(ixzone(1,izone),iyzone(1,izone)
     &                            ,chaine(izone)
     &                            ,longc(izone),ixs(izone),iys(izone)
     &                            ,ipos(izone),1)
                  elseif(ialpha(izone).eq.2.and.ep.gt.0.) then
                    read(chaine(izone)(1:longc(izone)),*) rrr
                    iii = nint(rrr/ep)
                    rrr2 = real(iii)*ep
                    if (abs(rrr-rrr2).lt.ep*0.01) then
                      rrr = real(iii-1)*ep
                    elseif(rrr2.lt.rrr) then
                      rrr = rrr2
                    else
                      rrr = real(iii-1)*ep
                    endif
                    call reduitreel1(rrr,chaine(izone),longc(izone),0)
                    call metstring(ixzone(1,izone),iyzone(1,izone)
     &                            ,chaine(izone)
     &                            ,longc(izone),ixs(izone),iys(izone)
     &                            ,ipos(izone),1)
                  else
                    iz = izone+1
                    if (iz.le.nzones) then
                      if (itypzone(iz).eq.7) then
                        call x11setcurs((ixzone(1,iz)+ixzone(2,iz))/2
     &                                 ,(iyzone(1,iz)+iyzone(2,iz))/2)
                        izone = iz
                      endif
                    endif
                  endif
                endif
              endif
            endif
          endif
c          if (ipf.eq.1102) then
c          endif
          goto 1
c
c 8 backspace, 9 tab, 127 del
c
        else
          if (lebrowser) izone = 3
c
c tab <=> apply
c
          if (nokcancel.eq.3.and.ipf.eq.9) then
            izone = 3
            call x11bord(ixzone(1,izone),iyzone(2,izone)
     &                  ,ixzone(2,izone),iyzone(1,izone)
     &                  ,string,0,2,15,7,8,0)
            call viderbuff2()
            leretour = -2
            goto 3
          endif
          if (izone.ne.0) then
            if (itypzone(izone).eq.7) then
              if (ipf.eq.8) then
                if (ipos(izone).gt.0) then
                  do i=ipos(izone)+1,longc(izone)
                    chaine(izone)(i-1:i-1) = chaine(izone)(i:i)
                  enddo
                  chaine(izone)(longc(izone):longc(izone)) = char(0)
                  longc(izone) = longc(izone)-1
                  ipos(izone) = ipos(izone)-1
                  call metstring(ixzone(1,izone),iyzone(1,izone)
     &                          ,chaine(izone)
     &                          ,longc(izone),ixs(izone),iys(izone)
     &                          ,ipos(izone),1)
                else
                  call fsalrm
                endif
              elseif(ipf.eq.9) then
                call caexiste(chaine(izone)(1:longc(izone))
     &                       ,longc(izone),1,iok)
                call reduitpath(chaine(izone),longc(izone))
                if (iok.ge.0) then
                  call fsalrm
                else
                  ipos(izone) = longc(izone)
                  call metstring(ixzone(1,izone),iyzone(1,izone)
     &                          ,chaine(izone),longc(izone)
     &                          ,ixs(izone),iys(izone),ipos(izone),1)
                endif
              elseif(ipf.eq.127) then
                if (ipos(izone).lt.longc(izone)) then
                  do i=ipos(izone)+1,longc(izone)
                    chaine(izone)(i:i) = chaine(izone)(i+1:i+1)
                  enddo
                  chaine(izone)(longc(izone):longc(izone)) = char(0)
                  longc(izone) = longc(izone)-1
                  call metstring(ixzone(1,izone),iyzone(1,izone)
     &                          ,chaine(izone),longc(izone)
     &                          ,ixs(izone),iys(izone),ipos(izone),1)
                else
                  call fsalrm
                endif
              else
                if (ialpha(izone).eq.1) then
                  if (((ipf.lt.48.or.ipf.gt.57).and.ipf.ne.45)
     &           .or.longc(izone).eq.11) then
                    call fsalrm
                    goto 1
                  endif
                elseif(ialpha(izone).eq.2) then
                  if (inum(ipf).eq.0.or.longc(izone).eq.32) then
                    call fsalrm
                    goto 1
                  endif
                endif
                if (ialpha(izone).gt.0)
     &     chainesav(1:longc(izone)) = chaine(izone)(1:longc(izone))
                ipos(izone) = ipos(izone)+1
                if (ipos(izone).le.longc(izone)) then
                  do i=longc(izone),ipos(izone),-1
                    chaine(izone)(i+1:i+1) = chaine(izone)(i:i)
                  enddo
                endif
                chaine(izone)(ipos(izone):ipos(izone)) = char(ipf)
                longc(izone) = longc(izone)+1
                chaine(izone)(longc(izone)+1:longc(izone)+1) = char(0)
                if (ialpha(izone).ne.0) then
                  call checknumeric(chaine(izone),longc(izone)
     &                             ,ialpha(izone),icheck)
Cfj                  print*,ialpha(izone),icheck
Cfj     &                 ,' '//chaine(izone)(1:longc(izone))
                  if (icheck.ne.0) then
                    chaine(izone)(longc(izone):longc(izone)) = char(0)
                    longc(izone) = longc(izone)-1
                    ipos(izone) = ipos(izone)-1
                    chaine(izone)(i:longc(izone)) =
     &                   chainesav(i:longc(izone))
Cfj                    print*,chaine(izone)(1:longc(izone))
                    call fsalrm
                    goto 1
                  endif
                endif
                call metstring(ixzone(1,izone),iyzone(1,izone)
     &                        ,chaine(izone),longc(izone)
     &                        ,ixs(izone),iys(izone),ipos(izone),1)
              endif
            endif
          endif
          if (nzones.gt.izone) then
            if (itypzone(izone+1).eq.9) then
              if (longc(izone).gt.1
     &    .and.chaine(izone)(longc(izone):longc(izone)).eq.'/') then
                call caexiste(chaine(izone),longc(izone),0,iok)
                if (iok.le.0) then
                  pathrelatif = chaine(izone)(1:longc(izone))
                  longpath = longc(izone)
                  call cree_la_liste(fichiers,lfichiers,idir
     &                              ,nfich,nfichmax,ioptliste)
                  call affiche_liste(ixzone(1,izone+1),iyzone(1,izone+1)
     &                              ,nfich,0,idir,fichiers,lfichiers,0)
                else
                  call fsalrm
                endif
              else
                if (longc(izone).gt.0) then
                  ishi = 0
                  ii = 0
                  do i=1,longc(izone)
                    if (chaine(izone)(i:i).eq.'/') ii = i
                  enddo
                  do i=1,nfich
                    if (fichiers(i)(1:lfichiers(i))
     &                   .lt.chaine(izone)(ii+1:longc(izone))) ishi=i-1
                  enddo
                else
                  ishi = 0
                endif
                ishiftliste0 = ishiftliste
                ishiftliste = ishi
                if ((ishiftliste+ilonglistey).gt.nfich)
     &               ishiftliste = max(0,nfich-ilonglistey)
                if (ishiftliste.ne.ishiftliste0)
     &            call affiche_liste(ixzone(1,izone+1),iyzone(1,izone+1)
     &                              ,nfich,0,idir,fichiers,lfichiers,0)
              endif
            endif
          endif
          goto 1
        endif
c
c click
c
      elseif(ipf.ge.-253.and.ipf.le.-251) then
        if (izone.ne.0) then
          if (itypzone(izone).eq.2) then
 9901       call x11bord(ixzone(1,izone),iyzone(2,izone)
     &                  ,ixzone(2,izone),iyzone(1,izone)
     &                  ,string,0,2,15,7,8,0)
            call viderbuff2()
c
c cancel
c
            if (izone.eq.1) then
              leretour = -1
            elseif(leretour.gt.0) then
              call remetfullpath(chaine(leretour),longc(leretour))
              inquire(file=chaine(leretour)(1:longc(leretour)),exist=la)
              if (.not.la) then
                call fsalrm
                call perddutemps(titi)
                call x11bord(ixzone(1,izone),iyzone(2,izone)
     &                      ,ixzone(2,izone),iyzone(1,izone)
     &                      ,string,0,2,7,15,8,0)
                goto 1
              endif
            endif
            call perddutemps(titi)
c
c apply
c
            if (izone.eq.3) leretour = -2
          elseif(itypzone(izone).eq.9) then
            laposition = nint(.5+real(iyposcurs-iyzone(1,izone))
     &           /real(idyliste)) + ishiftliste
            if (ialpha(izone).ne.0)
     &           call affiche_liste(ixzone(1,izone),iyzone(1,izone)
     &                             ,nfich,ialpha(izone),idir
     &                             ,fichiers,lfichiers,ialpha(izone))
            ialpha(izone) = laposition
            ll = -laposition
            call affiche_liste(ixzone(1,izone),iyzone(1,izone)
     &                        ,nfich,ll,idir,fichiers,lfichiers
     &                        ,ialpha(izone))
            if (idir(laposition).ne.1) then
              if (pathrelatif(1:1).eq.' ') then
                chaine(izone-1) = fichiers(laposition)
                longc(izone-1) = lfichiers(laposition)
              else
                chaine(izone-1) = pathrelatif(1:longpath)
     &               //fichiers(laposition)(1:lfichiers(laposition))
     &               //char(0)
                longc(izone-1) = longpath+lfichiers(laposition)
              endif
              ipos(izone-1) = longc(izone-1)
            endif
            call metstring(ixzone(1,izone-1),iyzone(1,izone-1)
     &                    ,chaine(izone-1),longc(izone-1)
     &                    ,ixs(izone-1),iys(izone-1),ipos(izone-1),0)
            goto 1
C
C Ascenseur
C
          elseif(itypzone(izone).eq.0.and.izone.gt.2) then
            if (itypzone(izone-1).eq.9
     &     .and.ipropaffiche.gt.0) then
              itienlebien = 0
              iretour = 0
              if (iyposcurs.le.(iyzone(1,5)+2*idfleche)) then
                ifleche = 1
              elseif(iyposcurs.ge.(iyzone(2,5)-2*idfleche)) then
                ishiftliste = ishiftliste+1
                ifleche = 2
              elseif(iyposcurs.ge.iyascen1
     &          .and.iyposcurs.le.iyascen2) then
                if (iyposcurs.lt.iyascen3) then
                  ifleche = 3
                elseif(iyposcurs.gt.iyascen4) then
                  ifleche = 4
                else
                  ifleche = 5
                  call change_curs(10)
                endif
              else
                goto 1
              endif
 110          dyy = real((iyascen2-iyascen1)-ipropaffiche)
     &             /real(nfich-nbfaffiche)
 10           ishiftliste0 = ishiftliste
              if (ifleche.eq.1) then
                ishiftliste = ishiftliste-ishiftelem
              elseif(ifleche.eq.2) then
                ishiftliste = ishiftliste+ishiftelem
              else
                if (ifleche.ne.5) then
                  iretour = 1
                  if (ipf.eq.-252) then
                    iii = iyposcurs-(iyascen4-iyascen3)/2
                    ishiftliste = int(real((iii-iyascen1)*nfich)
     &                   /real(iyascen2-iyascen1))
                  else
                    if (ifleche.eq.3) then
                      ishiftliste = ishiftliste-nbfaffiche
                    else
                      ishiftliste = ishiftliste+nbfaffiche
                    endif
                  endif
                endif
              endif
              if (ishiftliste.lt.0) then
                ishiftliste = 0
                iretour = 1
              elseif((ishiftliste+ilonglistey).gt.nfich) then
                ishiftliste = nfich-ilonglistey
                iretour = 1
              endif
              if (ishiftliste.ne.ishiftliste0.or.ifleche.eq.5) then
 4              call affiche_liste(ixzone(1,izone-1),iyzone(1,izone-1)
     &               ,nfich,0,idir,fichiers,lfichiers,ialpha(izone-1))
                if (itienlebien.eq.0) then
                  ttt = 0.1
                  if (ifleche.eq.1) then
                    call gsitriangle(ibordbrow,ixfleche,iyfleche1
     &                              ,idfleche,idfleche,-1)
                  elseif(ifleche.eq.2) then
                    call gsitriangle(-ibordbrow,ixfleche,iyfleche2
     &                              ,idfleche,idfleche,-1)
                  endif
                else
                  ttt = 0.005
                endif
                call viderbuff2()
                if (iretour.eq.0) then
                  if (ifleche.eq.5) then
 5                  call getxycx11b(ibutton,ix,iy,ixroot,iyroot)
                    if (ibutton.eq.0) then
                      ishiftliste00 = ishiftliste
                      ishiftliste = ishiftliste0
     &                     +nint(real(iy-iyposcurs)/dyy)
                      if (ishiftliste.eq.ishiftliste00) then
                        goto 5
                      else
                        if (ishiftliste.lt.0) then
                          ishiftliste = 0
                        elseif((ishiftliste+ilonglistey).gt.nfich) then
                          ishiftliste = nfich-ilonglistey
                        endif
                        goto 4
                      endif
                    else
                      call change_curs(12)
                      goto 1
                    endif
                  else
                    call perddutemps(ttt)
                    call getbuttonrelease(iretour)
                    itienlebien = itienlebien+1
                    if (iretour.eq.0) goto 10
                  endif
                endif
              endif
              if (ifleche.eq.1) then
                call gsitriangle(ibordbrow,ixfleche,iyfleche1,idfleche
     &                          ,idfleche,1)
              elseif(ifleche.eq.2) then
                call gsitriangle(-ibordbrow,ixfleche,iyfleche2,idfleche
     &                          ,idfleche,1)
              endif
            endif
            goto 1
c
c case a cocher
c
          elseif(itypzone(izone).eq.10) then
            iz = izone-nokcancel
            itouch = 1
            i1 = iexcl(iz)/1000
            i2 = mod(iexcl(iz),1000)
            if (icoche(iz).eq.0) then
              icoche(iz) = 1
              if (i1.gt.0.and.i2.gt.0) then
                do i=i1,i2
                  if (i.ne.iz) icoche(i) = 0
                enddo
              endif
            else
              if (iz.ge.i1.and.iz.le.i2) then
                itouch = 0
              else
                icoche(iz) = 0
              endif
            endif
            if (itouch.ne.0) then
              iyboul = (iyzone(1,izone) + iyzone(2,izone))/2
              call affichelaboule(icoche(iz),ixboul,iyboul,irboul
     &                           ,icboul)
              if (i1.gt.0) then
                do i=i1,i2
                  if (i.ne.iz) then
                    ii = i+nokcancel
                    iyboul = (iyzone(1,ii) + iyzone(2,ii))/2
                    call affichelaboule(icoche(i),ixboul,iyboul,irboul
     &                                 ,icboul)
                  endif
                enddo
              endif
            endif
            goto 1
          else
            call metcurstring(iyzone(1,izone),ixs(izone),iys(izone)
     &                       ,ipos(izone),isizecar0,0)
            ii = nint(real(ixposcurs-ixs(izone))/real(isizecar0))
            ipos(izone) = max(0,min(ii,longc(izone)))
Cfj            call metcurstring(iyzone(1,izone),ixs(izone),iys(izone)
Cfj     &                       ,ipos(izone),isizecar0,1)
            call metstring(ixzone(1,izone),iyzone(1,izone),chaine(izone)
     &                    ,longc(izone),ixs(izone),iys(izone)
     &                    ,ipos(izone),1)
            iselzone(izone) = 1
            goto 1
          endif
        else
          goto 1
        endif
c
c double click
c
      elseif(ipf.eq.-7777) then
        if (izone.ne.0) then
          if (itypzone(izone).eq.9) then
            laposition = nint(.5+real(iyposcurs-iyzone(1,izone))
     &           /real(idyliste)) + ishiftliste
            if (idir(laposition).eq.1) then
              if (pathrelatif(1:1).eq.' ') then
                pathrelatif = fichiers(laposition)
                longpath = lfichiers(laposition)
              else
                ll = lfichiers(laposition)
c
                call exec('cd '//pathrelatif(1:longpath)
     &                         //fichiers(laposition)(1:ll)
     &                         //' 2> '//fichtmp(1:lftmp)//'E'
     &                         //' ; pwd > '//fichtmp(1:lftmp))
                call premier_libre(ifichtmp)
                open(ifichtmp,file=fichtmp(1:lftmp)//'E')
                iok = 0
                read(ifichtmp,'(a)',end=999,err=999) string
                call enleve_tous_blancs(string,l,132)
                if (l.eq.0) then
                  iok = 0
                else
                  iok = 1
                endif
 999            close(ifichtmp)
                call exec('/bin/rm -f '//fichtmp(1:lftmp)//'E')
                if (iok.ne.0) then
                  call fsalrm
                  goto 1
                endif
                open(ifichtmp,file=fichtmp(1:lftmp))
                read(ifichtmp,'(a)') string
                call enleve_tous_blancs(string,l,132)
                close(ifichtmp)
                call exec('/bin/rm -f '//fichtmp(1:lftmp)//'E')
                pathrelatif = string(1:l)//'/'
                longpath = l+1
              endif
              call reduitpath(pathrelatif,longpath)
              call cree_la_liste(fichiers,lfichiers,idir,nfich,nfichmax
     &                          ,ioptliste)
              call affiche_liste(ixzone(1,izone),iyzone(1,izone),nfich,0
     &                          ,idir,fichiers,lfichiers,ialpha(izone))
              chaine(izone-1) = pathrelatif(1:longpath)//char(0)
              longc(izone-1) = longpath
              ipos(izone-1) = longpath
              call metstring(ixzone(1,izone-1),iyzone(1,izone-1)
     &                      ,chaine(izone-1),longc(izone-1)
     &                      ,ixs(izone-1),iys(izone-1),ipos(izone-1),0)
              goto 1
            else
              goto 9901
            endif
          else
            goto 1
          endif
        else
          goto 1
        endif
      else
c
c bouge la souris
c
        if (izone.eq.0) then
          call clearallzones(ixzone,iyzone,itypzone,iselzone,ixs,iys
     &                      ,ipos,chaine,longc,isizecar0,nzones)
        else
          if (itypzone(izone).ne.0.and.itypzone(izone).ne.10) then
cc          if (itypzone(izone).ne.2.and.itypzone(izone).ne.0) then
            if (iselzone(izone).eq.0) then
              call clearallzones(ixzone,iyzone,itypzone,iselzone,ixs,iys
     &                          ,ipos,chaine,longc,isizecar0,nzones)
              iselzone(izone) = 1
              call bordzone(ixzone(1,izone),iyzone(1,izone),1)
              if (itypzone(izone).eq.7)
     &          call metcurstring(iyzone(1,izone),ixs(izone),iys(izone)
     &                           ,ipos(izone),isizecar0,1)
            endif
          else
            call clearallzones(ixzone,iyzone,itypzone,iselzone,ixs,iys
     &                        ,ipos,chaine,longc,isizecar0,nzones)
          endif
        endif
        goto 1
      endif
c
      iclicb1 = ichar(mouse(1)(1:1))
 2    call asread2(nseg,ipf,1)
      if (ipf.ne.iclicb1) goto 2
c      
 3    continue
C
      if (leretour.eq.-2) then
        call x11setcurs(0,0)
        call x11detruitpop(1)
        call getxycx11c(iev,ixposcurs,iyposcurs
     &                 ,ixposcurs_root,iyposcurs_root)
        ixpos = ixposcurs_root-ixposcurs
        iypos = iyposcurs_root-iyposcurs
        if (ibordx.eq.0.and.ibordy.eq.0) then
          napply = napply+1
          if (napply.eq.1) then
            ixpos1 = ixpos
            iypos1 = iypos
          else
            ixpos2 = ixpos
            iypos2 = iypos
            ibx1 = ixpos2-ixpos1
            iby1 = iypos2-iypos1
            ibx0 = ixpos1-ixpos0
            iby0 = iypos1-iypos0
            if (ibx0.eq.ibx1.and.iby0.eq.iby1) then
              print*,'Window manager borders =',ibx1,iby1
              ibordx = ibx1
              ibordy = iby1
            else
              ixpos0 = ixpos1
              iypos0 = iypos1
              ixpos1 = ixpos2
              iypos1 = iypos2
            endif
          endif
        endif
      else
        call x11detruitpop(0)
        call change_curs(1)
      endif
c
      call gslss(ifonte_sav)
      call x11loadcolor(icoul_courante)
      call viderbuff3()
      end
c-----------------------------------------------------------------------
      subroutine okcancel(ix,iy,iynew,ixzone,iyzone,itypzone,iselzone
     &                   ,iapply,inew)
      integer ixzone(2,*),iyzone(2,*),itypzone(*),iselzone(*)
      character*32 string
      INCLUDE 'Parametres.f'
c
      if (inew.eq.0) then
        ixpos = max(0,ixposcurs_root-ix/2)
        iypos = max(0,iyposcurs_root-iy/2)
        if (ixpos+ix.gt.nbpixx-ibordpop) ixpos = nbpixx-ibordpop-ix
        if (iypos+iy.gt.nbpixy-ibordpop) iypos = nbpixy-ibordpop-iy
        call x11popup(ix,iy,ixpos,iypos
     &               ,nomprogramme(1:lprogcourt)//' dialog'//char(0))
        napply = 0
        ixpos0 = ixpos
        iypos0 = iypos
      else
        call viderbuff2()
Cfj        call x11pop(1)
Cfj        call selgraphix11()
        ixposbor = ixpos-ibordx
        iyposbor = iypos-ibordy
        call x11popup(ix,iy,ixposbor,iyposbor
     &               ,nomprogramme(1:lprogcourt)//' dialog'//char(0))
      endif
c pour lui laisser le temps de mapper
cc      tempsaperdre = 0.1
      tempsaperdre = 0.25
      call perddutemps(tempsaperdre)
c
      call change_curs(2)
      call x11loadcolor(8)
      call x11facette2(0,0,ix,iy)
cc      if (ix.le.isizecar0*32) then
      if (ix.le.isizecar0*64) then
        ibp = ibordpop
      else
        if (iapply.eq.0) then
          ibp = ix/6
        else
          ibp = ix/8
        endif
      endif
      if (iapply.eq.0) then
        nokcancel = 2
      else
        nokcancel = 3
      endif
      ilar = (ix-(nokcancel+1)*ibp)/nokcancel
      ihau = nint(real(ibordpop)*2.2)
c
c zone cancel
c
      ixzone(2,1) = ix-ibp
      ixzone(1,1) = ixzone(2,1)-ilar
      iyzone(1,1) = iy-ibordpop-ihau
      iyzone(2,1) = iy-ibordpop
      itypzone(1) = 2
      iselzone(1) = 0
      string = 'Cancel'//char(0)
      lstr = 5
      ifonte_sav = ifonte_courante
      call gslss(7)
      call x11bord(ixzone(1,1),iyzone(2,1),ixzone(2,1),iyzone(1,1)
     &            ,string,lstr,2,7,15,8,0)
c
c zone ok
c
      ixzone(1,2) = ibp
      ixzone(2,2) = ixzone(1,2)+ilar
      iyzone(1,2) = iy-ibordpop-ihau
      iyzone(2,2) = iy-ibordpop
      itypzone(2) = 2
      iselzone(2) = 0
      string = 'OK'//char(0)
      lstr = 2
      call x11bord(ixzone(1,2),iyzone(2,2),ixzone(2,2),iyzone(1,2)
     &            ,string,lstr,2,7,15,8,0)
c
c zone apply
c
      if (iapply.ne.0) then
        ixzone(1,3) = ixzone(2,2)+ibp
        ixzone(2,3) = ixzone(1,1)-ibp
        iyzone(1,3) = iy-ibordpop-ihau
        iyzone(2,3) = iy-ibordpop
        itypzone(3) = 2
        iselzone(3) = 0
        string = 'Apply'//char(0)
        lstr = 5
        call x11bord(ixzone(1,3),iyzone(2,3),ixzone(2,3),iyzone(1,3)
     &              ,string,lstr,2,7,15,8,0)
      endif
c
      iynew = iyzone(1,1)-ibordpop
      end
c-----------------------------------------------------------------------
      subroutine oktoutseul(ix,iy,iynew,ixzone,iyzone,itypzone,iselzone)
      integer ixzone(2,*),iyzone(2,*),itypzone(*),iselzone(*)
      character*32 string
      INCLUDE 'Parametres.f'
c
      ixpos = max(0,ixposcurs_root-ix/2)
      iypos = max(0,iyposcurs_root-iy/2)
      if (ixpos+ix.gt.nbpixx-ibordpop) ixpos = nbpixx-ibordpop-ix
      if (iypos+iy.gt.nbpixy-ibordpop) iypos = nbpixy-ibordpop-iy
c
      call x11popup(ix,iy,ixpos,iypos
     &     ,nomprogramme(1:lprogcourt)//' dialog'//char(0))
c pour lui laisser le temps de mapper
cc      tempsaperdre = 0.1
      tempsaperdre = 0.25
      call perddutemps(tempsaperdre)
c
      call change_curs(2)
      call x11loadcolor(8)
      call x11facette2(0,0,ix,iy)
cc      if (ix.le.isizecar0*32) then
      if (ix.le.isizecar0*64) then
        ibp = ibordpop
      else
        ibp = ix/6
      endif
      ihau = nint(real(ibordpop)*2.2)
c
c zone ok
c
      ixzone(2,1) = ix-ibp
      ixzone(1,1) = ibp
      iyzone(1,1) = iy-ibordpop-ihau
      iyzone(2,1) = iy-ibordpop
      itypzone(1) = 2
      iselzone(1) = 0
      string = 'OK'//char(0)
      lstr = 2
      ifonte_sav = ifonte_courante
      call gslss(7)
      call x11bord(ixzone(1,1),iyzone(2,1),ixzone(2,1),iyzone(1,1)
     &            ,string,lstr,2,7,15,8,0)
c
      iynew = iyzone(1,1)-ibordpop
      end
c-----------------------------------------------------------------------
      subroutine cree_la_liste(fichiers,lfichiers,idir,nfich,nfichmax
     &                        ,iopt)
c
c iopt=0 liste alphabetique
c iopt=1 les directory au debut
c
      INCLUDE 'Parametres.f'
      character*132 fichiers(*)
      integer idir(*),lfichiers(*)
      parameter(numext=41)
      character*12 ext(numext)
      integer     lext(numext)
      data ext / '.bit','.charge','.def_max','.def_min'
     a          ,'.defor11','.defor22','.defor33'
     b          ,'.defor23','.defor31','.defor12','.depcont','.depimp'
     c          ,'.depl','.depmod','.effcontact','.en','.enp'
     d          ,'.errcont','.errdep','.for','.force','.forces'
     e          ,'.maxmises','.maxmisesp','.mises','.misesp','.mode'
     f          ,'.psi','.second','.solu'
     g          ,'.stres11','.stres22','.stres33'
     h          ,'.stres23','.stres31','.stres12'
     i          ,'.str_max','.theta','.thetap','.v','.xd3d' /
      data lext / 4,7,8,8
     a          , 8,8,8
     b          , 8,8,8,8,8
     c          , 5,7,11,3,4   
     d          , 8,7,4,6,7 
     e          , 9,10,6,7,5
     f          , 4,7,5
     g          , 8,8,8
     h          , 8,8,8
     i          , 8,6,7,2,5 /
c
      ishiftliste = 0
      nfich = 0
      call premier_libre(ifichtmp)
      if (iopt.eq.1) then
        call exec('/bin/ls -ap '//pathrelatif(1:longpath)
     &       //'|grep /> '//fichtmp(1:lftmp))
        open(ifichtmp,file=fichtmp(1:lftmp))
        do i=1,nfichmax
          nfich = nfich+1
          read(ifichtmp,'(a)',end=1000,err=1000) fichiers(nfich)
          call enleve_tous_blancs(fichiers(nfich),lfichiers(nfich),132)
          if (lfichiers(nfich).eq.2
     &   .and.fichiers(nfich)(1:2).eq.'./') then
            nfich = nfich-1
          else
            idir(nfich) = 1
          endif
        enddo
 1000   close(ifichtmp)
        nfich = nfich-1
      endif
      call exec('/bin/ls -ap '
     &     //pathrelatif(1:longpath)//filtre(1:lfiltre)//
     &    ' 1> '//fichtmp(1:lftmp)//' 2> /dev/null')
      open(ifichtmp,file=fichtmp(1:lftmp))
      do i=1,nfichmax
        nfich = nfich+1
        read(ifichtmp,'(a)',end=1001,err=1001) fichiers(nfich)
        call enleve_tous_blancs(fichiers(nfich),l,132)
C
C On traite les liens commes des fichiers...
C
        if (fichiers(nfich)(l:l).eq.'@') l = l-1
        if (fichiers(nfich)(l:l).eq.'/') then
ccc     &  .or.fichiers(nfich)(l:l).eq.'@') then
          if (iopt.eq.1) then
            nfich = nfich-1
          else
            if (l.eq.2.and.fichiers(nfich)(1:2).eq.'./') then
              nfich = nfich-1
            else
              lfichiers(nfich) = l
              idir(nfich) = 1
            endif
          endif
        else
          if (pathrelatif(1:1).eq.' ') then
            lfichiers(nfich) = l
          else
            lslash = 0
            do k=l,1,-1
              if (fichiers(nfich)(k:k).eq.'/') then
                lslash = k
                goto 2000
              endif
            enddo
 2000       if (lslash.gt.0)
     &           fichiers(nfich) = fichiers(nfich)(lslash+1:l)
            lfichiers(nfich) = l-lslash
          endif
C
C idir(n) = 0  fichier quelconque
C idir(n) = 1  directory ou lien
C idir(n) = 2  fichier specialement repere (.theta, .depl,...)
C
          l = lfichiers(nfich)
          idir(nfich) = 0
          do k=1,numext
            j = lext(k)
            if (l.ge.j.and.fichiers(nfich)(l-j+1:l).eq.ext(k)(1:j))
     &           idir(nfich) = 2
          enddo
        endif
      enddo
 1001 close(ifichtmp)
      nfich = nfich-1
      call exec('/bin/rm -f '//fichtmp(1:lftmp))
      if (nfich.le.0) call fsalrm
      if (nfich.lt.50) then
        do i=nfich+1,50
          lfichiers(i) = 0
        enddo
      endif
      end
c-----------------------------------------------------------------------
      subroutine caexiste(chaine,longc,iopt,iok)
c
      INCLUDE 'Parametres.f'
      parameter (nmax=100)
      integer ll(nmax)
      character*132 chaine,string,ctmp(nmax)
c
      if (iopt.eq.0) then
        call exec('/bin/ls -ad '
     &       //chaine(1:longc)
     &       //' 1> /dev/null'
     &       //' 2> '//fichtmp(1:lftmp)//'E')
      else
        call exec('/bin/ls -adp '
     &       //chaine(1:longc)//'*'
     &       //' 1> '//fichtmp(1:lftmp)
     &       //' 2> '//fichtmp(1:lftmp)//'E')
      endif
      call premier_libre(ifichtmp)
      open(ifichtmp,file=fichtmp(1:lftmp)//'E')
      iok = 0
      read(ifichtmp,'(a)',end=1999,err=1999) string
      call enleve_tous_blancs(string,l,132)
      if (l.gt.0) iok=1
 1999 close(ifichtmp)
      call exec('/bin/rm -f '//fichtmp(1:lftmp)//'E')
      if (iopt.ne.0.and.iok.eq.0) then
        call exec('wc '//fichtmp(1:lftmp)//'> '//fichtmp(1:lftmp)//'E')
        open(ifichtmp,file=fichtmp(1:lftmp)//'E')
        read(ifichtmp,*) ii
        close(ifichtmp)
        call exec('/bin/rm -f '//fichtmp(1:lftmp)//'E')
        ii = min(nmax,ii)
        iok = -ii
        open(ifichtmp,file=fichtmp(1:lftmp))
        if (ii.eq.1) then
          read(ifichtmp,'(a)') string
          call enleve_tous_blancs(string,l,132)
          call reduitpath(string,l)
          chaine(1:l) = string(1:l)
          chaine(l+1:l+1) = char(0)
          longc = l
        else
          lmin = 133
          do i=1,ii
            read(ifichtmp,'(a)') ctmp(i)
            call enleve_tous_blancs(ctmp(i),ll(i),132)
            call reduitpath(ctmp(i),ll(i))
            lmin = min(lmin,ll(i))
          enddo
          if (lmin.gt.longc) then
            iflag = 0
            l = lmin
            do n=longc+1,lmin
              do i=2,ii
                if (ctmp(i)(n:n).ne.ctmp(1)(n:n)) iflag=1
              enddo
              if (iflag.ne.0) then
                l = n-1
                goto 10
              endif
            enddo
 10         chaine(longc+1:l) = ctmp(1)(longc+1:l)
            chaine(l+1:l+1) = char(0)
            longc = l
          endif
          call fsalrm()
        endif
        close(ifichtmp)
        call exec('/bin/rm -f '//fichtmp(1:lftmp))
      endif
      end
c-----------------------------------------------------------------------
      subroutine reduitpath(string,l)
c
      INCLUDE 'Parametres.f'
      character*(*) string
c
      if (l.eq.2.and.string(1:2).eq.'//') then
        l = 1
        string(2:2) = ' '
      elseif(lhomedir.gt.1) then
        if (chomedir(1:lhomedir)//'/'.eq.string(1:lhomedir+1)) then
          string(1:l+1-lhomedir) = '~'//string(lhomedir+1:l)
          l = l+1-lhomedir
        elseif(string(1:1).eq.'|') then
          if (chomedir(1:lhomedir)//'/'.eq.string(2:lhomedir+2)) then
            string(2:l+1-lhomedir) = '~'//string(lhomedir+2:l)
            l = l+1-lhomedir
          endif
        endif
      endif
      end
c-----------------------------------------------------------------------
      subroutine remetfullpath(string,l)
c
      INCLUDE 'Parametres.f'
      character*(*) string
c
      if (string(1:1).eq.'~'.and.l.gt.1) then
        string(1:l+lhomedir-1) = chomedir(1:lhomedir)//string(2:l)
        l = l-1+lhomedir
      endif
      end
c-----------------------------------------------------------------------
      subroutine encodeentier(n,c,l)
      character*12 c
c
      write(c,'(i12)') n
      i0 = 0
      do i=1,12
        if (i0.eq.0.and.c(i:i).ne.' ') i0 = i
      enddo
      c = c(i0:12)//char(0)
      l = 13-i0
      end
