magicada_1.0.1_32af2d9a/examples/src/examples.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
with Ada.Text_IO;
with Ada.Command_Line;
with Ada.Directories;
with Magic.Manager;
procedure Examples is
   package AC renames Ada.Command_Line;

   Mgr : Magic.Manager.Magic_Manager;
begin
   Mgr.Initialize (Magic.MAGIC_MIME, Magic.DEFAULT_PATH);
   for I in 1 .. AC.Argument_Count loop
      declare
         Path : constant String := AC.Argument (I);
      begin
         if Ada.Directories.Exists (Path) then
            Ada.Text_IO.Put (Path);
            Ada.Text_IO.Put (": ");
            Ada.Text_IO.Put_Line (Mgr.Identify (Path));
         else
            Ada.Text_IO.Put (Path);
            Ada.Text_IO.Put_Line (": is not a file");
         end if;
      end;
   end loop;
end Examples;