Back to... Zip-Ada

Source file : comp_zip.adb



   1  ------------------------------------------------------------------------------
   2  --  File:            Comp_Zip.adb
   3  --  Description:     A zip comparison tool using Zip-Ada lib.
   4  --                   Core moved to Comp_Zip_Prc (22-Sep-2009)
   5  --  Author:          Gautier de Montmollin
   6  ------------------------------------------------------------------------------
   7  
   8  with Zip, UnZip, Comp_Zip_Prc;
   9  with Show_License;
  10  
  11  with Ada.Calendar,
  12       Ada.Command_Line,
  13       Ada.Strings.Unbounded,
  14       Ada.Text_IO;
  15  
  16  procedure Comp_Zip is
  17    z : array (1 .. 2) of Zip.Zip_Info;
  18  
  19    function Try_with_zip (zip_name : String) return String is
  20    begin
  21      if Zip.Exists (zip_name) then
  22        return zip_name;
  23      else
  24        return zip_name & ".zip";
  25        --  Maybe the file doesn't exist, but we tried our best...
  26      end if;
  27    end Try_with_zip;
  28  
  29    use Ada.Text_IO;
  30  
  31    procedure Blurb is
  32    begin
  33      Put_Line ("Comp_Zip * compare two zip archive files, including their contents");
  34      Put_Line ("Demo for the Zip-Ada library, by G. de Montmollin");
  35      Put_Line ("Library version " & Zip.version & " dated " & Zip.reference);
  36      Put_Line ("URL: " & Zip.web);
  37      Show_License (Current_Output, "zip.ads");
  38    end Blurb;
  39  
  40    use Ada.Calendar, Ada.Command_Line, Ada.Strings.Unbounded;
  41  
  42    quiet    : Natural := 0;
  43    password : Unbounded_String;
  44    total_differences : Natural;
  45    T0, T1, T2 : Time;
  46  
  47  begin
  48    if Argument_Count < 2 then
  49      Blurb;
  50      Put_Line ("Usage: comp_zip archive1[.zip] archive2[.zip] [options]");
  51      New_Line;
  52      Put_Line ("Options: -q1   : (quieter level 1): summary only");
  53      Put_Line ("         -q2   : (quieter level 2): shorter summary only");
  54      Put_Line ("         -q3   : (quieter level 3): 1 line per archive");
  55      Put_Line ("         -q4   : (quieter level 4): no console output, only exit code");
  56      Put_Line ("         -pPwd : define a password for decryption (e.g. ""Pwd"")");
  57      New_Line;
  58      Put_Line ("The exit code is the number of mismatching entries:");
  59      Put_Line ("  - entry name is in both archives, but contents are different (+1)");
  60      Put_Line ("  - entry name is only in one archive but absent in the other one (+1)");
  61      Put_Line ("The exit code 0 means that both archives have identical contents.");
  62      New_Line;
  63      Put ("Press Return");
  64      Skip_Line;
  65      return;
  66    end if;
  67    T0 := Clock;
  68    for i in 1 .. 2 loop
  69      declare
  70        n : constant String := Try_with_zip (Argument (i));
  71      begin
  72        Zip.Load (z (i), n);
  73      exception
  74        when Zip.Archive_open_error =>
  75          Put ("Can't open archive [" & n & ']'); raise;
  76        when UnZip.Wrong_password      =>
  77          Put ("Archive has a password"); raise;
  78      end;
  79    end loop;
  80    for a in 3 .. Argument_Count loop
  81      declare
  82        arg : String renames Argument (a);
  83      begin
  84        if arg'Length > 2 and then arg (arg'First .. arg'First + 1) = "-q" then
  85          quiet := Natural'Value (arg (arg'First + 2 .. arg'Last));
  86        elsif arg'Length > 2 and then arg (arg'First .. arg'First + 1) = "-p" then
  87          password := To_Unbounded_String (arg (arg'First + 2 .. arg'Last));
  88        end if;
  89      end;
  90    end loop;
  91    --
  92    if quiet = 0 then
  93      Blurb;
  94    end if;
  95    T1 := Clock;
  96    Comp_Zip_Prc (z (1), z (2), quiet, To_String (password), total_differences);
  97    T2 := Clock;
  98    if quiet < 3 then
  99      Put_Line
 100        ("Time elapsed :" & Duration'Image (T2 - T0) &
 101         " seconds (loading catalogues: " & Duration'Image (T1 - T0) & ").");
 102    end if;
 103    Set_Exit_Status (Exit_Status (total_differences));
 104    --
 105  end Comp_Zip;

Web view of Ada source code generated by GNATHTML, project: ALI_Parse version 1.0.
Zip-Ada: Ada library for zip archive files (.zip). Ada programming.
Some news about Zip-Ada and other Ada projects on Gautier's blog.