summaryrefslogtreecommitdiff
path: root/overload.pl
diff options
context:
space:
mode:
Diffstat (limited to 'overload.pl')
-rw-r--r--overload.pl37
1 files changed, 25 insertions, 12 deletions
diff --git a/overload.pl b/overload.pl
index 295c837102..9def29f429 100644
--- a/overload.pl
+++ b/overload.pl
@@ -21,14 +21,18 @@ while (<DATA>) {
push @names, $name;
}
-safer_unlink 'overload.h';
+safer_unlink ('overload.h', 'overload.c');
+die "overload.h: $!" unless open(C, ">overload.c");
+binmode C;
die "overload.h: $!" unless open(H, ">overload.h");
binmode H;
-select H;
-print <<'EOF';
+
+sub print_header {
+ my $file = shift;
+ print <<"EOF";
/* -*- buffer-read-only: t -*-
*
- * overload.h
+ * $file
*
* Copyright (C) 1997, 1998, 2000, 2001, 2005, 2006, 2007 by Larry Wall
* and others
@@ -39,6 +43,15 @@ print <<'EOF';
* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
* This file is built by overload.pl
*/
+EOF
+}
+
+select C;
+print_header('overload.c');
+
+select H;
+print_header('overload.h');
+print <<'EOF';
enum {
EOF
@@ -50,12 +63,15 @@ print <<'EOF';
/* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */
};
-
#define NofAMmeth max_amg_code
+
+EOF
+
+print C <<'EOF';
+
#define AMG_id2name(id) (PL_AMG_names[id]+1)
-#ifdef DOINIT
-EXTCONST char * const PL_AMG_names[NofAMmeth] = {
+char * const PL_AMG_names[NofAMmeth] = {
/* Names kept in the symbol table. fallback => "()", the rest has
"(" prepended. The only other place in perl which knows about
this convention is AMG_id2name (used for debugging output and
@@ -64,14 +80,11 @@ EXTCONST char * const PL_AMG_names[NofAMmeth] = {
EOF
my $last = pop @names;
-print " \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
+print C " \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
-print <<"EOT";
+print C <<"EOT";
"$last"
};
-#else
-EXTCONST char * PL_AMG_names[NofAMmeth];
-#endif /* def INITAMAGIC */
EOT
close H or die $!;