Constipate the stdmac[] array.
[nasm.git] / macros.pl
blobe4f60a4b821350b7578d5107ac42d496f67cd022
1 #!/usr/bin/perl -w
3 # macros.pl produce macros.c from standard.mac
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.
10 use strict;
12 my $fname;
13 my $line = 0;
14 my $index = 0;
15 my $tasm_count;
17 undef $tasm_count;
19 open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
21 print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
22 " - don't edit it */\n";
23 print OUTPUT "\n";
24 print OUTPUT "#include \"compiler.h\"\n";
25 print OUTPUT "\n";
26 print OUTPUT "static const char * const stdmac[] = {\n";
28 foreach $fname ( @ARGV ) {
29 open(INPUT,$fname) or die "unable to open $fname\n";
30 while (<INPUT>) {
31 $line++;
32 chomp;
33 if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
34 $tasm_count = $index;
35 } elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
36 $_ = $1;
37 s/\\/\\\\/g;
38 s/"/\\"/g;
39 if (length > 0) {
40 print OUTPUT " \"$_\",\n";
41 $index++;
43 } else {
44 die "$fname:$line: error unterminated quote";
47 close(INPUT);
49 print OUTPUT " NULL\n};\n";
50 $tasm_count = $index unless ( defined($tasm_count) );
51 print OUTPUT "#define TASM_MACRO_COUNT $tasm_count\n";
52 close(OUTPUT);