<commit_before>--  This file is covered by the Internet Software Consortium (ISC) License
--  Reference: ../License.txt

with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Exceptions;
with PortScan.Ops;
with PortScan.Packages;
with PortScan.Buildcycle;
with Signals;
with Unix;

package body PortScan.Pilot is

   package EX  renames Ada.Exceptions;
   package CLI renames Ada.Command_Line;
   package ASF renames Ada.Strings.Fixed;
   package OPS renames PortScan.Ops;
   package PKG renames PortScan.Packages;
   package CYC renames PortScan.Buildcycle;
   package SIG renames Signals;

   ---------------------
   --  store_origins  --
   ---------------------
   function store_origins return Boolean
   is
      function trimmed_catport (S : String) return String;
      function trimmed_catport (S : String) return String
      is
         last : constant Natural := S'Last;
      begin
         if S (last) = '/' then
            return S (S'First .. last - 1);
         else
            return S (S'First .. last);
         end if;
      end trimmed_catport;
   begin
      if CLI.Argument_Count <= 1 then
         return False;
      end if;
      portlist.Clear;
      if CLI.Argument_Count = 2 then
         --  Check if this is a file
         declare
            Arg2 : constant String := trimmed_catport (CLI.Argument (2));
         begin
            if AD.Exists (Arg2) then
               return valid_file (Arg2);
            end if;
            if valid_catport (catport => Arg2) then
               plinsert (Arg2, 2);
               return True;
            else
               TIO.Put_Line (badport & Arg2);
               return False;
            end if;
         end;
      end if;
      for k in 2 .. CLI.Argument_Count loop
         declare
            Argk : constant String := trimmed_catport (CLI.Argument (k));
         begin
            if valid_catport (catport => Argk) then
               plinsert (Argk, k);
            else
               TIO.Put_Line (badport & "'" & Argk & "'" & k'Img);
               return False;
            end if;
         end;
      end loop;
      return True;
   end store_origins;


   -------------------------------
   --  build_pkg8_as_necessary  --
   -------------------------------<commit_msg>Properly strip ports-mgmt/pkg from the ports list<commit_after>--  This file is covered by the Internet Software Consortium (ISC) License
--  Reference: ../License.txt

with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Exceptions;
with PortScan.Ops;
with PortScan.Packages;
with PortScan.Buildcycle;
with Signals;
with Unix;

package body PortScan.Pilot is

   package EX  renames Ada.Exceptions;
   package CLI renames Ada.Command_Line;
   package ASF renames Ada.Strings.Fixed;
   package OPS renames PortScan.Ops;
   package PKG renames PortScan.Packages;
   package CYC renames PortScan.Buildcycle;
   package SIG renames Signals;

   ---------------------
   --  store_origins  --
   ---------------------
   function store_origins return Boolean
   is
      function trimmed_catport (S : String) return String;
      function trimmed_catport (S : String) return String
      is
         last : constant Natural := S'Last;
      begin
         if S (last) = '/' then
            return S (S'First .. last - 1);
         else
            return S (S'First .. last);
         end if;
      end trimmed_catport;
   begin
      if CLI.Argument_Count <= 1 then
         return False;
      end if;
      portlist.Clear;
      if CLI.Argument_Count = 2 then
         --  Check if this is a file
         declare
            Arg2 : constant String := trimmed_catport (CLI.Argument (2));
         begin
            if AD.Exists (Arg2) then
               return valid_file (Arg2);
            end if;
            if valid_catport (catport => Arg2) then
               if Arg2 /= pkgng then
                  plinsert (Arg2, 2);
               end if;
               return True;
            else
               TIO.Put_Line (badport & Arg2);
               return False;
            end if;
         end;
      end if;
      for k in 2 .. CLI.Argument_Count loop
         declare
            Argk : constant String := trimmed_catport (CLI.Argument (k));
         begin
            if valid_catport (catport => Argk) then
               if Argk /= pkgng then
                  plinsert (Argk, k);
               end if;
            else
               TIO.Put_Line (badport & "'" & Argk & "'" & k'Img);
               return False;
            end if;
         end;
      end loop;
      return True;
   end store_origins;


   -------------------------------
   --  build_pkg8_as_necessary  --
   -------------------------------
{'fraction_non_alphanumeric': 0.11872340425531915, 'fraction_numerical': 0.00574468085106383, 'mean_word_length': 1.4755134281200633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1035944', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1287, 'n_words': 420}