[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-wpkg/sources/www/bin/ -> rapports.awk (source)

   1  #!/usr/bin/gawk -f
   2  BEGIN { 
   3      print "<?xml version='1.0' encoding='iso-8859-1'?>" 
   4      print "<!-- Généré par SambaEdu. Ne pas modifier -->" 
   5      print "<rapports>" 
   6  }
   7  {   sub("\r", "");
   8      if ( FNR == 2 ) Ligne = $0;
   9      if ( FNR == 4 ) Ligne = "";
  10      # print "<!-- FNR = " FNR " Ligne=" Ligne " -->";
  11      if ( FNR == 1 ) {
  12          PC="id=\"" $3 "\" ";
  13          #DATET=substr($1, 7, 4) "-" substr($1, 4, 2) "-" substr($1, 1, 2) " " $2;
  14          DATET="datetime=\"" substr($1, 7, 4) "-" substr($1, 4, 2) "-" substr($1, 1, 2) " " $2 "\" "
  15          DATEDAY="date=\"" $1 "\" ";
  16          #DATEDAY=$1;
  17          HEURE="time=\"" $2 "\" ";
  18          TYPEWIN="typewin=\"" $NF "\" ";
  19          
  20          MAC="";
  21          for ( i = 4; i < NF; i++) {
  22              IPMASK=$(i+1);
  23              gsub("[)(]", "", IPMASK);
  24              # print "<!-- 0 = " $0 "\nNF=" NF " i = " i " IPMASK = " IPMASK " -->";
  25              if ( IPMASK ~ /^0.0.0.0/ ) {
  26                  while ( ( $(++i) !~ /.*)$/ ) && (i < NF)) ;
  27              } else{
  28                  MAC=$i;
  29                  i=NF;
  30              }
  31          }
  32          MAC="mac=\"" MAC "\" ";
  33          split(IPMASK, a, "/");
  34          IP="ip=\"" a[1] "\" ";
  35          if (a[2] != "") MASK="mask=\"" a[2] "\" ";
  36          else MASK="";
  37          gsub("/.*", "", IP);
  38          gsub(".*/", "", MASK);
  39          # print "  <!-- ARGIND=" ARGIND " -->";
  40          if ( InRapport == 1 ) {
  41              if ( Ligne != "" ) {
  42                  gsub("\"", "\\&#39;", Ligne);
  43                  print "<erreur str=\"" Ligne "\" />";
  44              }
  45              print "  </rapport>";
  46              InRapport = 0;
  47          }
  48          if ( (PC != "") && ( $5 != "") ) {
  49              LogFile=FILENAME;
  50              sub("\\.txt$", ".log", LogFile);
  51              
  52              if ( ! system ( "test -e " LogFile ) ) {
  53                  LogFile="logfile=\"" LogFile "\" ";
  54              } else {
  55                  LogFile="";
  56                  #print "  <rapport id=\"" PC "\" datetime=\"" DATET "\" date=\"" DATEDAY "\" time=\"" HEURE "\" mac=\"" MAC "\" ip=\"" IP "\" mask=\"" MASK "\" typewin=\"" TYPEWIN "\">";
  57              }
  58              print "  <rapport " PC DATET DATEDAY HEURE MAC IP MASK TYPEWIN LogFile ">";
  59              PC="";
  60              InRapport=1;
  61          } else {
  62              print "    <!-- Erreur Ligne 1 du rapport " FILENAME " non conforme -->";
  63              nextfile
  64          }
  65          nChamps=0;
  66          next;
  67      }
  68  }
  69  /^    .+: / {
  70      InPackage=1;
  71      nChamps++;
  72      if ( $1 == "ID:"       ) { ID       = valeur(); next }
  73      if ( $1 == "Revision:" ) { Revision = valeur(); next }
  74      if ( $1 == "Reboot:"   ) { Reboot   = valeur(); next }
  75      if ( $1 == "Status:"   ) { Status   = valeur(); next }
  76  }
  77  /^$/ {
  78      # print "  <!-- Ligne vide InPackage=" InPackage ", nChamp=" nChamp " -->";
  79      if ( InPackage == 1 ) {
  80          if ( nChamps == 4 ) {
  81              print "    <package id=\"" ID "\" revision=\"" Revision "\" reboot=\"" Reboot "\" status=\"" Status "\" />";
  82          } else {
  83              print "    <!-- Erreur nChamps=" nChamps " -->";
  84              nextfile
  85          }
  86          InPackage = 0;
  87          nChamps=0;
  88          next;
  89      }
  90  }
  91  END {
  92      # print "  <!-- END InRapport=" InRapport " -->";
  93      if ( InRapport == 1 ) {
  94          if ( Ligne != "" ) {
  95              gsub("\"", "\\&#39;", Ligne);
  96              print "<erreur str=\"" Ligne "\" />";
  97          }
  98          print "  </rapport>"
  99      }
 100  }
 101  function valeur() {
 102      if (NF >= 2) {
 103          $1="";
 104          sub("^ ", "");
 105          return $0;
 106      } else {
 107          return "";
 108      }
 109  }
 110  END { print "</rapports>" }


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1