71 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
| #!/usr/bin/perl
 | |
| 
 | |
| use strict;
 | |
| use File::Basename qw/basename dirname/;
 | |
| 
 | |
| 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.
 | |
|  */
 | |
| 
 | |
| #include "picrin.h"
 | |
| #include "picrin/error.h"
 | |
| 
 | |
| EOL
 | |
| 
 | |
| foreach my $file (@ARGV) {
 | |
|     my $var = &escape_v($file);
 | |
|     print "static const char *$var =\n";
 | |
| 
 | |
|     open IN, $file;
 | |
|     while (<IN>) {
 | |
|         chomp;
 | |
|         s/\\/\\\\/g;
 | |
|         s/"/\\"/g;
 | |
|         print "\"$_\\n\"\n";
 | |
|     }
 | |
|     print ";\n\n";
 | |
| }
 | |
| close IN;
 | |
| 
 | |
| print <<EOL;
 | |
| void
 | |
| pic_load_piclib(pic_state *pic)
 | |
| {
 | |
| EOL
 | |
| 
 | |
| foreach my $file (@ARGV) {
 | |
|     print "  pic_try {\n";
 | |
|     my $var = &escape_v($file);
 | |
|     my $basename = basename($file);
 | |
|     my $dirname = basename(dirname($file));
 | |
|     print "    pic_load_cstr(pic, $var);\n";
 | |
|     print<<EOL
 | |
|   }
 | |
|   pic_catch {
 | |
|     /* error! */
 | |
|     fputs("fatal error: failure in loading $dirname/$basename\\n", stderr);
 | |
|     fputs(pic_errmsg(pic), stderr);
 | |
|     abort();
 | |
|   }
 | |
| EOL
 | |
| }
 | |
| 
 | |
| print <<EOL;
 | |
| 
 | |
| #if DEBUG
 | |
|   puts("successfully loaded stdlib");
 | |
| #endif
 | |
| }
 | |
| EOL
 | |
| 
 | |
| sub escape_v {
 | |
|     ($_) = @_;
 | |
|     s/\.scm$//g;
 | |
|     s/[^[A-Za-z0-9_]/_/g;
 | |
|     "piclib_src_" . $_;
 | |
| }
 |