summaryrefslogtreecommitdiffstats
path: root/apps/prime.c
AgeCommit message (Expand)Author
2015-11-21Fix "primarility" typoMichal Bozon
2015-10-12Centralise loading default apps config fileMatt Caswell
2015-09-28RT4053: Typo in error messageMichal Bozon
2015-05-29Restore module loadingRichard Levitte
2015-04-24Big apps cleanup (option-parsing, etc)Rich Salz
2015-01-22Run util/openssl-format-source -v -c .Matt Caswell
2005-08-23Generate primes, too.Ben Laurie
2005-07-16makeNils Larsch
2005-05-01Add prototype.Ben Laurie
2005-04-26Port prime utility across from stable branch.Dr. Stephen Henson
td>
# FIPS assembly language preprocessor
# Renames all symbols in the file to
# their modified fips versions.


my @ARGS = @ARGV;

my $top = shift @ARGS;
my $target = shift @ARGS;

my $runasm = 1;

if ($ARGS[0] eq "norunasm")
	{
	$runasm = 0;
	shift @ARGS;
	}

my $enabled = 0;

$enabled = 1 if $ENV{FIPSCANISTERINTERNAL} eq "y";

if ($enabled == 0 && $runasm)
	{
	system @ARGS;
	exit $?
	}


# Open symbol rename file.
open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";

# Skip to assembler symbols
while (<IN>)
	{
	last if (/assembler/)
	}

# Store all renames.
while (<IN>)
	{
	if (/^#define\s+(\w+)\s+(\w+)\b/)
		{
		$edits{$1} = $2;
		}
	}

my ($from, $to);

#rename target temporarily
rename($target, "tmptarg.s") || die "Can't rename $target";

#edit target
open(IN,"tmptarg.s") || die "Can't open temporary file";
open(OUT, ">$target") || die "Can't open output file $target";

while (<IN>)
{
	while (($from, $to) = each %edits)
		{
		s/(\b_*)$from(\b)/$1$to$2/g;
		}
	print OUT $_;
}

close OUT;

if ($runasm)
	{
	# run assembler
	system @ARGS;

	my $rv = $?;

	# restore target
	unlink $target;
	rename "tmptarg.s", $target;

	die "Error executing assembler!" if $rv != 0;
	}
else
	{
	# Don't care about target
	unlink "tmptarg.s";
	}