Merge branch 'nasm-2.03.x'
[platform/upstream/nasm.git] / macros.pl
1 #!/usr/bin/perl -w
2 #
3 # macros.pl   produce macros.c from standard.mac
4 #
5 # The Netwide Assembler is copyright (C) 1996 Simon Tatham and
6 # Julian Hall. All rights reserved. The software is
7 # redistributable under the license given in the file "LICENSE"
8 # distributed in the NASM archive.
9
10 use strict;
11
12 my $fname;
13 my $line = 0;
14 my $index      = 0;
15 my $tasm_count;
16
17 undef $tasm_count;
18
19 open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
20
21 print OUTPUT "/*\n";
22 print OUTPUT " * Do not edit - this file auto-generated by macros.pl from:\n";
23 print OUTPUT " * ", join(' ', @ARGV), "\n";
24 print OUTPUT " */\n";
25 print OUTPUT "\n";
26 print OUTPUT "#include \"tables.h\"\n";
27 print OUTPUT "\n";
28 print OUTPUT "const char * const nasm_stdmac[] = {";
29
30 foreach $fname ( @ARGV ) {
31     open(INPUT,$fname) or die "unable to open $fname\n";
32     print OUTPUT "\n    /* From $fname */\n";
33     while (<INPUT>) {
34         $line++;
35         chomp;
36         if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
37             $tasm_count = $index;
38             print OUTPUT "    /* End of TASM macros */\n";
39         } elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
40             $_ = $1;
41             s/\\/\\\\/g;
42             s/"/\\"/g;
43             if (length > 0) {
44                 print OUTPUT "        \"$_\",\n";
45                 $index++;
46             }
47         } else {
48             die "$fname:$line:  error unterminated quote";
49         }
50     }
51     close(INPUT);
52 }
53 print OUTPUT "\n    NULL\n};\n\n";
54 $tasm_count = $index unless ( defined($tasm_count) );
55 print OUTPUT "const char * const * nasm_stdmac_after_tasm = ",
56     "&nasm_stdmac[$tasm_count];\n";
57 close(OUTPUT);