Listing du fichier ldphp.pl
00001# (gH) -_- ldphp.pl ; TimeStamp (unix) : 08 Janvier 2008 vers 13:05
00002
00003 ############################################################################
00004 #
00005 # ldphp.pl : liste des fonctions d'un module Php ; (gH) 2008
00006 #
00007 ############################################################################
00008
00009 $version_ldphp = 1.3 ;
00010
00011 use lib $ENV{"PERL_MACROS"} ; # répertoire qui contient mes macros
00012 use strFuncs ;
00013
00014 #
00015 # on détecte : include
00016 # include_once
00017 # require_once
00018 # function
00019 #
00020
00021 if ($ARGV[0] eq "") {
00022 print "\n" ;
00023 print " syntaxe : ldphp nom_de_fichier.php \n" ;
00024 print "\n" ;
00025 exit(-1) ;
00026 } ; # fin de test sur les arguments
00027
00028 $fs = "ldphp.sor" ; # fichier de sortie
00029 open( FS ,">$fs") || die "\n impossible d'écrire dans le fichier $fs\n\n" ;
00030
00031 $nomp = $ARGV[0] ; # nom du programme
00032 if (! ( (-e $nomp) && (-r $nomp) ) ) { die "\n Impossible de lire dans le fichier $nomp\n\n" ; } ;
00033
00034 print "\n" ;
00035 $msg = "Analyse du fichier $nomp" ;
00036 print " $msg \n" ;
00037 print FS " $msg \n" ;
00038 print FS " ".("=" x length($msg))."\n" ;
00039 print FS " ".&dateEtHeure()."\n\n" ;
00040
00041 print FS " Liste des fichiers inclus \n" ;
00042 print FS " ------------------------- \n" ;
00043 print FS " (format : nom du fichier et nombre de lignes dans le fichier) \n\n" ;
00044
00045 # on passe en revue le fichier et on cherche les inclusions
00046 # puis les fonctions
00047
00048 @tdmar = split(" ","include( include_once( require_once(") ; # tableau des mots à rechercher
00049 $lstFicTmp = " $nomp " ; # liste des fichiers
00050 $lstFonc = " " ; # liste des fonctions
00051 $lstFicVus = " $nomp " ; # fichiers déjà vus
00052
00053 while (&nbMots($lstFicTmp)>0) {
00054
00055 $nomf = &premierMot($lstFicTmp) ;
00056 $nomf = trim($nomf) ;
00057 if (length($nomf)>0) {
00058 #print " FICHIER $nomf\n" ;
00059 $lstFicTmp = &phraseSansPremierMot($lstFicTmp) ;
00060 $lstFic .= $nomf." " ;
00061 open(FC,"<$nomf") || die "\n impossible de lire dans le fichier $nomf\n\n\n" ;
00062 $nblc = 0 ;
00063 while ($lig=<FC>) {
00064 $nblc++ ;
00065
00066 # 1. recherche d'inclusion
00067
00068 foreach $mac (@tdmar) {
00069 $pdi = index($lig,$mac) ; # position de include ou assimilé
00070 if ($pdi>-1) {
00071 $ll = substr($lig,0,index($lig,')')) ; #
00072 $dl = substr($ll,1+index($ll,'"')) ; # début de ligne
00073 $nn = substr($dl,0,index($dl,'"')) ; # nom de fichier
00074 $nn = &trim($nn) ;
00075 #print " $nn \n" ;
00076 if ($nn ne "once(") {
00077 if (index(" $lstFicTmp "," $nn ")==-1) { # ajout éventuel
00078 if (index(" $lstFicVus "," $nn ")==-1) { # ajout éventuel
00079 $lstFicTmp .= " $nn" ;
00080 $lstFicVus .= " $nn" ;
00081 } ; # fin de si
00082 } ; # fin de si
00083 } ; # fin de si
00084 } ; # fin si on a vu le mot à chercher
00085 } ; # fin pour chaque
00086
00087 # 2. recherche du mot function
00088
00089 $mac = "function" ;
00090 $pdf = index($lig,$mac) ; # position de function
00091 if (($pdf>-1) && (&premierMot($lig) eq $mac)) {
00092 $dl = substr($lig,length($mac)+1) ; # début de ligne
00093 $nf = substr($dl,0,index($dl,'(')) ; # nom de fichier
00094 $nf = &trim($nf) ;
00095 if (index(" $lstFonc "," $nf ")==-1) { # ajout éventuel
00096 $lstFonc .= " $nf " ;
00097 $fdnbl{$nf} = $nblc ;
00098 $sdnbl{$nf} = $nomf ;
00099 } ; # fin de si
00100 } ; # fin si on a vu le mot function
00101 } ; # fin de tant que non fin de fichier sur FC
00102 $tdnbl{$nomf} = $nblc ;
00103 close(FC) ;
00104 }
00105 } ; # fin de tant que sur lstFic
00106
00107 # affichage des fichiers
00108
00109 @tabfic = sort split(" ",$lstFic) ;
00110 print "\n" ;
00111 $numf = 0 ; # nombre de fichiers
00112 $nbl_t = 0 ; # nombre de lignes en tout
00113 foreach $fic (@tabfic) {
00114 $numf++ ;
00115 $ls = " ".sprintf("%3d",$numf).". " ;
00116 if ($fic eq $nomp) { $ls .= "*" ; } else { $ls .= " " ; } ;
00117 $ls .= " ".surncarg($fic,20).sprintf("%6d",$tdnbl{$fic})."\n" ;
00118 $nbl_t += $tdnbl{$fic} ;
00119 print $ls ;
00120 print FS $ls ;
00121 } ; # fin pour chaque
00122 print " total ".sprintf("%6d",$nbl_t)." lignes\n" ;
00123 print FS " total ".sprintf("%6d",$nbl_t)." lignes\n" ;
00124 print FS "\n" ;
00125
00126 # affichage des fonctions
00127
00128 print FS " Liste des fonctions (et position dans le fichier)\n" ;
00129 print FS " --------------------\n\n" ;
00130
00131 $numf = 0 ;
00132 foreach $fonc (sort split(" ",$lstFonc)) {
00133 $numf++ ;
00134 $ls = " ".sprintf("%3d",$numf).". " ;
00135 $ls .= " ".surncarg($fonc,30) ;
00136 $ls .= " ".surncarg($sdnbl{$fonc},30) ;
00137 $ls .= " ".sprintf("%6d",$fdnbl{$fonc})."\n" ;
00138 print FS $ls ;
00139 } ; # fin pour chaque
00140 print FS "\n" ;
00141
00142 # fonctions par fichier
00143
00144 foreach $fic (@tabfic) {
00145 $ls = "Fonction(s) du fichier $fic" ;
00146 print FS " $ls (et position dans le fichier)\n" ;
00147 print FS " ".("-" x length($ls))."\n" ;
00148 $numf = 0 ;
00149 foreach $fonc (sort split(" ",$lstFonc)) {
00150 if ($sdnbl{$fonc} eq $fic) {
00151 $numf++ ;
00152 $ls = " ".sprintf("%3d",$numf).". " ;
00153 $ls .= " ".surncarg($fonc,30) ;
00154 $ls .= " ".sprintf("%6d",$fdnbl{$fonc})."\n" ;
00155 print FS $ls ;
00156 } ; # fin de si
00157 } ; # fin pour chaque
00158 if ($numf==0) {
00159 print FS " aucune fonction.\n" ;
00160 } ; # fin de si
00161 print FS "\n" ;
00162 } ; # fin pour chaque
00163
00164
00165 # affichages de fin
00166
00167 print "\n ... vous pouvez consulter $fs\n\n" ;
00168 print FS "\n" ;
00169 close(NP) ;
00170 close(FS) ;
00171
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)