<commit_before>#!/usr/bin/perl
use strict;
use warnings;

use Getopt::Long;
use File::Spec::Functions qw/rel2abs splitpath/;
use File::Path;
use File::Temp qw/tempdir/;
use File::Copy;

Getopt::Long::Configure("gnu_getopt");

sub usage {
	print STDERR <<END;
Usage: $0 [options] files ...
Pack some files into a library usable from C

  --prefix=PREFIX           Prefix symbols with this string
  --output=libfoo.[so|a]    The static or dynamic library to produce
  --header=foo.h            The header file to create
  --templatedir=...         The location of our template files
  --cc=gcc                  The path to your gcc
  --ld=ld                   The path to your ld
  --align=N                 Align all files to N bytes (where N is a power
                            of two)
  --static                  Produce a static library (has bugs)
  --help                    What you're reading now

Report bugs to <<EMAIL>>
END
	exit 1;
}

my $tempdir;

END {
	if (defined $tempdir) {
		rmtree($tempdir);
	}
}

my $prefix = "earc_";
my $output = undef;
my $header = "earc.h";
my $template = rel2abs(".");
my $cc = 'gcc';
my $ld = 'ld';
my $align = 8;
my @cargs;
my $static = 0;

sub subst_file_into {
	my ($src, $dest) = @_;
	open my $in, "<", $src or die "Can't open $src for read: $!";
	open my $out, ">", $dest or die "Can't open $dest for write: $!";

	my $headermangle = $header;
	$headermangle =~ s/[^A-Za-z0-9]/_/g;

	while (<$in>) {
		s/##HEADERNAME##/$headermangle/g;
		s/##PREFIX##/$prefix/g;
		print $out $_;
	}
	close $out;
	close $in;
}

my $result = GetOptions(
	"prefix=s" => \$prefix,
	"output=s" => \$output,
	"header=s" => \$header,
	"templatedir=s" => \$template,
	"cc=s" => \$cc,
	"ld=s" => \$ld,
	"align=i" => \$align,
	"static" => \$static,
	"help" => \&usage
);
usage() unless $result;

if (!defined $output) {
	$output = $static ? "libearc.a" : "libearc.so";
}

$output = rel2abs $output;
$header = rel2abs $header;

my %fhash = map { ( (splitpath($_))[2], rel2abs $_ ) } @ARGV;<commit_msg>rel2abs the template directory /after/ getting options<commit_after>#!/usr/bin/perl
use strict;
use warnings;

use Getopt::Long;
use File::Spec::Functions qw/rel2abs splitpath/;
use File::Path;
use File::Temp qw/tempdir/;
use File::Copy;

Getopt::Long::Configure("gnu_getopt");

sub usage {
	print STDERR <<END;
Usage: $0 [options] files ...
Pack some files into a library usable from C

  --prefix=PREFIX           Prefix symbols with this string
  --output=libfoo.[so|a]    The static or dynamic library to produce
  --header=foo.h            The header file to create
  --templatedir=...         The location of our template files
  --cc=gcc                  The path to your gcc
  --ld=ld                   The path to your ld
  --align=N                 Align all files to N bytes (where N is a power
                            of two)
  --static                  Produce a static library (has bugs)
  --help                    What you're reading now

Report bugs to <<EMAIL>>
END
	exit 1;
}

my $tempdir;

END {
	if (defined $tempdir) {
		rmtree($tempdir);
	}
}

my $prefix = "earc_";
my $output = undef;
my $header = "earc.h";
my $template = ".";
my $cc = 'gcc';
my $ld = 'ld';
my $align = 8;
my @cargs;
my $static = 0;

sub subst_file_into {
	my ($src, $dest) = @_;
	open my $in, "<", $src or die "Can't open $src for read: $!";
	open my $out, ">", $dest or die "Can't open $dest for write: $!";

	my $headermangle = $header;
	$headermangle =~ s/[^A-Za-z0-9]/_/g;

	while (<$in>) {
		s/##HEADERNAME##/$headermangle/g;
		s/##PREFIX##/$prefix/g;
		print $out $_;
	}
	close $out;
	close $in;
}

my $result = GetOptions(
	"prefix=s" => \$prefix,
	"output=s" => \$output,
	"header=s" => \$header,
	"templatedir=s" => \$template,
	"cc=s" => \$cc,
	"ld=s" => \$ld,
	"align=i" => \$align,
	"static" => \$static,
	"help" => \&usage
);
usage() unless $result;

if (!defined $output) {
	$output = $static ? "libearc.a" : "libearc.so";
}

$output = rel2abs $output;
$header = rel2abs $header;
$template = rel2abs $template;

my %fhash = map { ( (splitpath($_))[2], rel2abs $_ ) } @ARGV;
{'fraction_non_alphanumeric': 0.1753958587088916, 'fraction_numerical': 0.0060901339829476245, 'mean_word_length': 2.7091237579042455, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '6087947', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1514, 'n_words': 461}