Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Make Prelude.pm self-sufficient, and re-introduce file2c.pl (from P…

…AR::Packer).
commit 36d2ba8bdb239094aab057f9aca8d714c9dcaa2e 1 parent 27f1db4
@audreyt audreyt authored
Showing with 78 additions and 1 deletion.
  1. +2 −1  Pugs/src/perl6/Prelude.pm
  2. +76 −0 Pugs/utils/file2c.pl
View
3  Pugs/src/perl6/Prelude.pm
@@ -26,7 +26,8 @@ the `is builtin` trait.
=cut
-use Math::Basic :GLOBAL<pi>;
+#use Math::Basic :GLOBAL<pi>;
+sub pi() is export(:constants) {3.141592653589793}
class Process {
multi sub exec($prog, @args) returns Bool is builtin is primitive is unsafe {
View
76 Pugs/utils/file2c.pl
@@ -0,0 +1,76 @@
+#!/usr/bin/perl -w
+
+# Copyright (c) 2002 Mattia Barbon.
+# Copyright (c) 2002 Audrey Tang.
+# This package is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+
+use strict;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use File::Basename;
+use Getopt::Long;
+
+my $chunk_size = 0;
+my $strip_pod = 0;
+my $compress = 0;
+my $name;
+
+GetOptions(
+ "c|chunk-size=i" => \$chunk_size,
+ "s|strip" => \$strip_pod,
+ "z|compress" => \$compress,
+ "n|name=s" => \$name)
+ && @ARGV == 3
+ or die "Usage: $0 [-c CHUNK][-n NAME][-s][-z] file.pl file.c c_variable\n";
+my ($pl_file, $c_file, $c_var) = @ARGV;
+$name = basename($pl_file) unless defined $name;
+
+my $pl_text = do # a scalar reference
+{
+ open my $in, "<", $pl_file or die "open input file '$pl_file': $!";
+ binmode $in;
+ local $/ = undef;
+ my $slurp = <$in>;
+ close $in;
+ \$slurp;
+};
+
+open my $out, ">", $c_file or die "open output file '$c_file': $!";
+binmode $out;
+
+my $len = length($$pl_text);
+
+# add a NUL byte so that chunk_${c_var} may be used as C string
+print_chunk( $$pl_text, "" );
+
+print $out <<"...";
+const char * text_$c_var () { return((const char *)$c_var); }
+const int size_$c_var () { return $len; }
+...
+
+close $out;
+
+exit 0;
+
+
+sub print_chunk
+{
+ my ($chunk, $suffix) = @_;
+
+ my $len = length($chunk);
+ print $out <<"...";
+static unsigned char ${c_var}[] = {
+...
+
+ for (my $i = 0; $i < $len; $i++) {
+ printf $out "0x%02x,", ord(substr($chunk, $i, 1));
+ print $out "\n" if $i % 16 == 15;
+ }
+
+ print $out "};\n";
+}
+
+# local variables:
+# mode: cperl
+# end:
Please sign in to comment.
Something went wrong with that request. Please try again.