picrin/etc/mkloader.pl

71 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"
#include "picrin/error.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);
2014-05-20 11:28:54 -04:00
print "static const char *$var =\n";
2014-05-18 19:40:22 -04:00
open IN, $file;
while (<IN>) {
chomp;
s/\\/\\\\/g;
s/"/\\"/g;
2014-05-18 20:00:51 -04:00
print "\"$_\\n\"\n";
2014-05-18 19:40:22 -04:00
}
print ";\n\n";
}
close IN;
print <<EOL;
void
pic_load_piclib(pic_state *pic)
{
EOL
2014-05-19 00:39:28 -04:00
foreach my $file (@ARGV) {
2014-08-10 22:12:32 -04:00
print " pic_try {\n";
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));
2014-05-18 19:40:22 -04:00
print " pic_load_cstr(pic, $var);\n";
2014-08-10 22:12:32 -04:00
print<<EOL
2014-05-18 19:40:22 -04:00
}
pic_catch {
/* error! */
2014-08-10 22:12:32 -04:00
fputs("fatal error: failure in loading $dirname/$basename\\n", stderr);
2014-05-18 19:40:22 -04:00
fputs(pic_errmsg(pic), stderr);
abort();
}
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
}