2002-05-01 05:01:08 +08:00
|
|
|
#!/usr/bin/perl -w
|
2007-10-20 05:42:29 +08:00
|
|
|
#
|
2002-05-01 04:52:26 +08:00
|
|
|
# macros.pl produce macros.c from standard.mac
|
|
|
|
#
|
|
|
|
# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
|
|
|
|
# Julian Hall. All rights reserved. The software is
|
|
|
|
# redistributable under the licence given in the file "Licence"
|
|
|
|
# distributed in the NASM archive.
|
2002-05-01 05:01:38 +08:00
|
|
|
|
2002-05-18 15:28:31 +08:00
|
|
|
use strict;
|
2002-05-01 05:01:08 +08:00
|
|
|
|
|
|
|
my $fname;
|
|
|
|
my $line = 0;
|
2002-05-04 11:57:52 +08:00
|
|
|
my $index = 0;
|
|
|
|
my $tasm_count;
|
2002-05-01 04:52:26 +08:00
|
|
|
|
2002-05-04 11:57:52 +08:00
|
|
|
undef $tasm_count;
|
2002-05-01 04:52:26 +08:00
|
|
|
|
2002-05-19 09:51:00 +08:00
|
|
|
open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
|
2007-10-20 05:42:29 +08:00
|
|
|
|
2002-05-01 04:52:26 +08:00
|
|
|
print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
|
2007-10-03 12:53:51 +08:00
|
|
|
" - don't edit it */\n\n#include \"compiler.h\"\n\nstatic const char *stdmac[] = {\n";
|
2007-10-20 05:42:29 +08:00
|
|
|
|
2002-05-04 11:57:52 +08:00
|
|
|
foreach $fname ( @ARGV ) {
|
2002-05-19 09:51:00 +08:00
|
|
|
open(INPUT,$fname) or die "unable to open $fname\n";
|
2002-05-04 11:57:52 +08:00
|
|
|
while (<INPUT>) {
|
2002-05-01 05:01:08 +08:00
|
|
|
$line++;
|
|
|
|
chomp;
|
2002-05-04 11:57:52 +08:00
|
|
|
if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
|
|
|
|
$tasm_count = $index;
|
|
|
|
} elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
|
|
|
|
$_ = $1;
|
|
|
|
s/\\/\\\\/g;
|
|
|
|
s/"/\\"/g;
|
|
|
|
if (length > 0) {
|
|
|
|
print OUTPUT " \"$_\",\n";
|
|
|
|
$index++;
|
2007-10-20 05:42:29 +08:00
|
|
|
}
|
2002-05-04 11:57:52 +08:00
|
|
|
} else {
|
|
|
|
die "$fname:$line: error unterminated quote";
|
2002-05-01 05:01:08 +08:00
|
|
|
}
|
2002-05-04 11:57:52 +08:00
|
|
|
}
|
|
|
|
close(INPUT);
|
2002-05-01 04:52:26 +08:00
|
|
|
}
|
2002-05-04 11:57:52 +08:00
|
|
|
print OUTPUT " NULL\n};\n";
|
|
|
|
$tasm_count = $index unless ( defined($tasm_count) );
|
|
|
|
print OUTPUT "#define TASM_MACRO_COUNT $tasm_count\n";
|
|
|
|
close(OUTPUT);
|