picrin/etc/mkloader.pl

75 lines
1.3 KiB
Perl
Raw Normal View History

2014-05-18 19:40:22 -04:00
#!/usr/bin/perl
2014-05-18 23:58:19 -04:00
use strict;
2014-08-10 22:12:32 -04:00
use File::Basename qw/basename dirname/;
2014-05-18 23:58:19 -04:00
2014-05-18 19:40:22 -04:00
print <<EOL;
/**
* !!NOTICE!!
* This file was automatically generated by mkloader.pl, and includes all of
* the prelude files required by Picrin. PLEASE DO NOT EDIT THIS FILE, changes
* will be overwritten the next time the script runs.
*/
2014-05-18 19:40:22 -04:00
#include "picrin.h"
EOL
2014-05-19 00:39:28 -04:00
foreach my $file (@ARGV) {
2014-05-18 19:40:22 -04:00
my $var = &escape_v($file);
2015-01-31 07:14:14 -05:00
print "static const char ${var}[][80] = {\n";
2014-05-18 19:40:22 -04:00
open IN, $file;
2015-01-31 07:14:14 -05:00
local $/ = undef;
my $src = <IN>;
close IN;
my @lines = $src =~ /.{0,80}/gs;
foreach (@lines) {
2014-05-18 19:40:22 -04:00
s/\\/\\\\/g;
s/"/\\"/g;
2015-01-31 07:14:14 -05:00
s/\n/\\n/g;
print "\"$_\",\n";
2014-05-18 19:40:22 -04:00
}
2015-01-31 07:14:14 -05:00
print "};\n\n";
2014-05-18 19:40:22 -04:00
}
print <<EOL;
void
pic_load_piclib(pic_state *pic)
{
EOL
2014-05-19 00:39:28 -04:00
foreach my $file (@ARGV) {
print <<EOL;
pic_try {
EOL
2014-05-18 19:40:22 -04:00
my $var = &escape_v($file);
2014-08-10 22:12:32 -04:00
my $basename = basename($file);
my $dirname = basename(dirname($file));
2015-01-31 07:14:14 -05:00
print " pic_load_cstr(pic, &${var}[0][0]);\n";
2014-08-10 22:12:32 -04:00
print<<EOL
2014-05-18 19:40:22 -04:00
}
pic_catch {
/* error! */
2015-06-18 16:13:57 -04:00
xfputs(pic, "fatal error: failure in loading $dirname/$basename\\n", xstderr);
pic_raise(pic, pic->err);
2014-05-18 19:40:22 -04:00
}
2014-08-10 22:12:32 -04:00
EOL
}
print <<EOL;
2014-05-18 19:40:22 -04:00
#if DEBUG
puts("successfully loaded stdlib");
#endif
}
EOL
sub escape_v {
2014-05-18 23:58:11 -04:00
($_) = @_;
2014-05-18 19:40:22 -04:00
s/\.scm$//g;
2014-05-19 00:39:28 -04:00
s/[^[A-Za-z0-9_]/_/g;
"piclib_src_" . $_;
2014-05-18 19:40:22 -04:00
}