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;
|
2014-06-17 20:53:53 -04:00
|
|
|
/**
|
|
|
|
* !!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"
|
2016-02-20 10:58:58 -05:00
|
|
|
#include "picrin/extra.h"
|
2014-05-18 19:40:22 -04:00
|
|
|
|
2017-04-03 11:52:59 -04:00
|
|
|
void
|
|
|
|
pic_eval_native(pic_state *pic, const char *str)
|
|
|
|
{
|
|
|
|
pic_value port = pic_fmemopen(pic, str, strlen(str), "r"), e;
|
|
|
|
|
|
|
|
pic_try {
|
|
|
|
size_t ai = pic_enter(pic);
|
|
|
|
|
2017-04-15 02:45:28 -04:00
|
|
|
while (1) {
|
|
|
|
pic_value form = pic_funcall(pic, "read", 1, port);
|
|
|
|
if (pic_eof_p(pic, form))
|
|
|
|
break;
|
2017-04-03 11:52:59 -04:00
|
|
|
pic_funcall(pic, "eval", 1, form);
|
|
|
|
pic_leave(pic, ai);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pic_catch (e) {
|
|
|
|
pic_fclose(pic, port);
|
|
|
|
pic_raise(pic, e);
|
|
|
|
}
|
|
|
|
pic_fclose(pic, port);
|
|
|
|
}
|
|
|
|
|
2014-05-18 19:40:22 -04:00
|
|
|
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)
|
|
|
|
{
|
2016-02-25 06:52:38 -05:00
|
|
|
pic_value e;
|
|
|
|
|
2014-05-18 19:40:22 -04:00
|
|
|
EOL
|
|
|
|
|
2014-05-19 00:39:28 -04:00
|
|
|
foreach my $file (@ARGV) {
|
2015-06-26 00:20:49 -04:00
|
|
|
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));
|
2017-04-03 11:52:59 -04:00
|
|
|
print " pic_eval_native(pic, &${var}[0][0]);\n";
|
2014-08-10 22:12:32 -04:00
|
|
|
print<<EOL
|
2014-05-18 19:40:22 -04:00
|
|
|
}
|
2016-02-25 06:52:38 -05:00
|
|
|
pic_catch(e) {
|
2014-05-18 19:40:22 -04:00
|
|
|
/* error! */
|
2016-06-19 15:49:01 -04:00
|
|
|
pic_fputs(pic, "fatal error: failure in loading $dirname/$basename\\n", pic_stderr(pic));
|
2016-02-25 06:52:38 -05:00
|
|
|
pic_raise(pic, e);
|
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
|
|
|
}
|
|
|
|
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;
|
2014-05-20 11:29:13 -04:00
|
|
|
"piclib_src_" . $_;
|
2014-05-18 19:40:22 -04:00
|
|
|
}
|