SEE ALSO

MarpaX::ESLIF::BNF, MarpaX::ESLIF::Tutorial::Calculator, PCRE2, jpcre2.

NOTES

The perl interface is using an all-in-one version of the underlying marpaESLIF C library. This mean that character conversion relies on libiconv to do character translation if needed. TRAILER close(INTRO) || warn "Cannot close $dst, $!";

exit(EXIT_SUCCESS);

# # Well, I have a problem on Windows because path is greater than MAX_PATH...! # This private implementation of _dircopy is doing the job... # Even if I would use Win32::LongPath, dzil would fail afterwards -; # sub _dircopy { my ($srcdir, $dstdir) = @_;

  if (! -d $srcdir) {
      die "$srcdir is not a directory";
  }
  if (! -d $dstdir) {
      print "... Creating directory $dstdir\n",
      die "Failed to create $dstdir directory, $!" unless mkdir $dstdir;
  }

  my $workdir = cwd;

  my $basedir = basename($srcdir);
  my $reducedLength = 0;

  my $stats = _readdir($srcdir);
  foreach (sort keys %{$stats}) {
      next if $_ eq $updir;
      next if $_ eq $curdir;
      #
      # Do not copy known garbage
      #
      next if $_ eq 'cmake_install.cmake';
      next if $_ eq 'Makefile';
      next if $_ eq 'CMakeFiles';
      next if $_ eq 'output';
      next if $_ eq 'CTestTestfile.cmake';
      next if $_ eq '.gitignore';
      next if $_ eq '.gitattributes';
      #
      # Do not copy known stuff we can skip
      #
      next if $_ eq 'Makefile';
      next if $_ eq 'cmake';
      next if $_ eq 'cmake-utils';
      next if $_ eq 'test';
      next if $_ eq 'blog';
      next if $_ eq 't';
      next if $_ eq 'html';
      next if $_ eq 'inc';
      next if $_ eq 'lib';
      next if $_ eq 'm4';
      next if $_ eq 'pod';
      next if $_ eq 'etc';
      next if $_ eq 'xs';
      next if $_ eq 'author.t';
      next if $_ eq '.travis.yml';
      next if $_ eq 'visual-studio';
      next if $_ =~ /\..?sh$/;
      next if $_ =~ /\.3$/;
      next if $_ =~ /\.3\.gz$/;
      next if $_ =~ /\.o(?:bj)?$/;
      next if $_ =~ /\.pdb$/;
      next if $_ =~ /\.tlog$/;
      next if $_ =~ /\.vcxproj$/;
      next if $_ =~ /\.vcxproj\.filters$/;
      next if $_ =~ /\.vcxproj\.user$/;
      next if $_ =~ /\.opensdf$/;
      next if $_ =~ /\.sln$/;
      next if $_ =~ /\.suo$/;
      next if $_ =~ /\.sdf$/;
      next if $_ =~ /\.dir$/;
      next if $_ =~ /\.psess$/;
      next if $_ =~ /\.vsp$/;
      next if $_ eq 'Testing';
      next if $_ eq 'Win32';
      next if $_ eq 'ipch';
      next if $_ eq 'patchit';
      next if $_ eq 'pcre2-10.22';
      next if $_ eq 'pcre2-10.22.tar.gz';
      next if $_ eq 'pcre2-10.23';
      next if $_ eq 'pcre2-10.23.patchdir';
      next if $_ eq 'pcre2-10.23.tar.gz';
      next if $_ =~ /~$/;

      my $mode = $stats->{$_}->[2];

      if (S_ISDIR($mode)) {
          # if ($basedir eq 'github') {
          #     _dircopy(File::Spec->catdir($srcdir, $_), File::Spec->catdir($dstdir, $reducedLength++));
          # } else {
              _dircopy(File::Spec->catdir($srcdir, $_), File::Spec->catdir($dstdir, $_));
          # }
      } else {
          my $file = File::Spec->catfile($srcdir, $_);
          print "... Copying file $file to $dstdir\n";
          _copy($srcdir, $dstdir, $_);
      }
  }
}

sub _chdir { my ($dir) = @_;

my ($volume, $directories, $file) = File::Spec->splitpath($dir, 1);
my @dirs = File::Spec->splitdir($directories);
my @donedirs = ();
my $donedirs = '';
foreach (@dirs) {
    push(@donedirs, $_);
    $donedirs = File::Spec->catdir(@donedirs);
    chdir($_) || die "Cannot chdir to $donedirs, $!";
}
}

sub _readdir { my ($dir) = @_;

my $workdir = cwd;

_chdir($dir);

my $dh;
opendir($dh, $curdir) || die "Failed to opendir $dir, $!";
my %stats = ();
while (readdir($dh)) {
    my @stat = stat($_);
    if (! @stat) {
        warn "Failed to stat entry in $dir: $_";
    } else {
        $stats{$_} = \@stat;
    }
}
closedir($dh) || warn "Failed to closedir $dir, $!";

chdir($workdir) || die "Failed to chdir to $workdir, $!";
return \%stats;
}

sub _copy { my ($srcdir, $dstdir, $entry) = @_;

my $srcfile = File::Spec->catfile($srcdir, $entry);
my $dstfile = File::Spec->catfile($dstdir, $entry);

#
# All files I copy are short -;
#
my $workdir = cwd;
_chdir($srcdir);
open(my $in, '<', $entry) || die "Cannot open $srcfile, $!";
binmode($in) || die "Failed to set binary mode on $srcfile, $!";

chdir($workdir) || die "Failed to chdir to $workdir, $!";
_chdir($dstdir);

open(my $out, '>', $entry) || die "Cannot open $dstfile, $!";
binmode($out) || die "Failed to set binary mode on $dstfile, $!";
chdir($workdir) || die "Failed to chdir to $workdir, $!";

#
#
my $data = do { local $/; <$in> };
print $out $data;
close($in) || warn "Failed to close $srcfile, $!";
close($out) || warn "Failed to close $dstfile, $!";
}