Formatting: kill off "stealth whitespace"
[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 licence given in the file "Licence"
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 "/* This file auto-generated from standard.mac by macros.pl" .
22 " - don't edit it */\n\n#include \"compiler.h\"\n\nstatic const char *stdmac[] = {\n";
23
24 foreach $fname ( @ARGV ) {
25     open(INPUT,$fname) or die "unable to open $fname\n";
26     while (<INPUT>) {
27         $line++;
28         chomp;
29         if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
30             $tasm_count = $index;
31         } elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
32             $_ = $1;
33             s/\\/\\\\/g;
34             s/"/\\"/g;
35             if (length > 0) {
36                 print OUTPUT "    \"$_\",\n";
37                 $index++;
38             }
39         } else {
40             die "$fname:$line:  error unterminated quote";
41         }
42     }
43     close(INPUT);
44 }
45 print OUTPUT "    NULL\n};\n";
46 $tasm_count = $index unless ( defined($tasm_count) );
47 print OUTPUT "#define TASM_MACRO_COUNT $tasm_count\n";
48 close(OUTPUT);