Listing du fichier listefnsV2.php
00001<?php
00002 # # (gH) -_- listefnsV2.php ; TimeStamp (unix) : 22 Novembre 2017 vers 15:59
00003
00004 error_reporting(E_ALL | E_NOTICE | E_STRICT ) ;
00005
00006 include("listefnsV2-inc.php") ;
00007
00008 ## 1. vérification des paramètres
00009
00010 if ($argc<2) {
00011
00012 echo "\n" ;
00013 echo "Appel incorrect du programme. Il faut donner un nom de fichier PHP à analyser.\n " ;
00014 echo "Exemple : php listefnsV1.php index.php\n\n" ;
00015 exit(-1) ;
00016
00017 } ; # fin de si
00018
00019 $nomFic = $argv[1] ;
00020
00021 if (!file_exists($nomFic)) {
00022
00023 echo "\n" ;
00024 echo "Exécution impossible, le fichier indiqué, soit $nomFic n'est pas vu.\n " ;
00025 exit(-2) ;
00026
00027 } ; # fin de si
00028
00029 echo "\n" ;
00030 $msg = "Analyse du fichier $nomFic" ;
00031 echo " ".$msg." dans ".getcwd()."\n" ;
00032 echo " ".souligne($msg,"=")."\n" ;
00033 echo " ".dateEtHeure()."\n\n" ;
00034
00035 ## on cherche les noms de fichiers via les fonctions include_once() et require_once()
00036
00037 $tdmar = [ "include(","include_once(","require(","require_once("] ; # tableau des mots à rechercher
00038 $lstFicTmp = $nomFic ; # liste des fichiers à traiter
00039 $lstFonc = " " ; # liste des fonctions
00040 $lstFicVus = $nomFic ; # liste des fichiers déjà vus
00041
00042 while (nbMots($lstFicTmp)>0) {
00043 $nomf = trim(mot($lstFicTmp,1)) ;
00044 if (strlen($nomf)>0) {
00045 $fh = fopen($nomf,"r") or die("\n impossible de lire dans le fichier $nomf\n\n\n") ;
00046 # recherche d'inclusion
00047 while ($lig=fgets($fh)) {
00048 foreach ($tdmar as $mac) {
00049 $pdi = strpos($lig,$mac) ; # position de include ou assimilé
00050 if ($pdi>-1) {
00051 $ll = substr($lig,0,strpos($lig,')')) ; #
00052 $dl = substr($ll,1+strpos($ll,'"')) ; # début de ligne
00053 $nn = substr($dl,0,strpos($dl,'"')) ; # nom de fichier
00054 $nn = trim($nn) ;
00055 if (positionDans($nn,$lstFicTmp)==0) { # ajout éventuel de ce nom de fichier
00056 $lstFicTmp .= " $nn" ;
00057 if (positionDans($nn,$lstFicVus)==0) { # ajout éventuel
00058 $lstFicVus .= " $nn" ;
00059 } ; # fin de si
00060 } ; # fin de si
00061 } ; # fin si on a vu le mot à chercher
00062 } ; # fin pour chaque
00063 } ; # fin de lecture
00064 fclose($fh) ;
00065 $lstFicTmp = phraseSansPremierMot($lstFicTmp) ;
00066 } ; # fin de si sur strlen($nomf)>0
00067 } ; # fin de tant que sur lstFic
00068
00069 # affichage numéroté des fichiers à lister avec nombre de lignes
00070
00071 $msg = "Liste des fichiers inclus" ;
00072 echo " ".$msg."\n" ;
00073 echo " ".souligne($msg,"-")."\n" ;
00074
00075 # tri de la liste via explode/sort/implode
00076
00077 $tdf = explode(" ",$lstFicVus) ;
00078 sort($tdf) ;
00079 $lstFicVus = implode(" ",$tdf) ;
00080
00081 $nbLigTot = 0 ;
00082
00083 $nbm = nbMots($lstFicVus) ;
00084 for ($idf=1;$idf<=$nbm;$idf++) {
00085 echo sprintf(" %3d",$idf) ;
00086 $motc = mot($lstFicVus,$idf) ;
00087 if ($motc==$nomFic) {
00088 echo " * " ;
00089 } else {
00090 echo " " ;
00091 } ; # fin si
00092 echo sprintf("%-20s",$motc) ;
00093 $nbl = nbLignes($motc) ;
00094 $nbLigTot += $nbl ;
00095 echo sprintf("%6d",$nbl) ;
00096 echo "\n" ;
00097 } ; # fin pour chaque
00098
00099 echo "\n total ".sprintf("%18d",$nbLigTot)," lignes\n\n" ;
00100
00101 ?>
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)