diff --git a/fact/GNUmakefile b/fact/GNUmakefile new file mode 100644 index 0000000..13d48f3 --- /dev/null +++ b/fact/GNUmakefile @@ -0,0 +1,30 @@ +include GNUmakevars + +CONFDIR=../../configure + +all: configure fact + +clean: + rm fact customize + +install: $(BINDIR) $(BINDIR)/fact + +%: %.pl customize + sh ./customize < $< > $@ + chmod +x $@ + +%: %.sh customize + sh ./customize < $< > $@ + chmod +x $@ + +customize: configure + sh ./configure + +configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish + cat $^ > $@ + +$(BINDIR): + mkdir -p $@ + +include GNUmakerules + diff --git a/fact/configure b/fact/configure new file mode 100644 index 0000000..6fea68e --- /dev/null +++ b/fact/configure @@ -0,0 +1,34 @@ +#!/bin/sh +# +echo "#!/bin/sh" > customize.$$ +echo "sed \\" > customize.$$ +chmod +x customize.$$ + +################################################################ +# find a working perl: +# +for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5 +do + if $i -e 'exit ($] < 5.000)' + then + echo $i works + perl="$i" + break + fi +done +if [ -z "$perl" ] +then + could not find a working perl command, sorry. + exit 1 +fi +echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$ + + +################################################################ +# finish +# Add trailing newline and rename temp file to final name +# +echo >> customize.$$ + +mv customize.$$ customize + diff --git a/fact/fact.pl b/fact/fact.pl new file mode 100644 index 0000000..ca83a85 --- /dev/null +++ b/fact/fact.pl @@ -0,0 +1,31 @@ +#!@@@perl@@@ -w +use strict; + +sub usage { + print STDERR "Usage: $0 number\n"; + exit(1); +} + +sub fact { + my ($n) = @_; + + my $d = 2; + + my @f = (); + + while ($d <= $n) { + if ($n % $d == 0) { + push (@f, $d); + $n /= $d; + } else { + $d++; + } + } + return @f; +} + +if (@ARGV != 1) { usage(); } +my @f = fact($ARGV[0]); +print "@f\n"; + +#vim:sw=4