NASM 0.98.09
[nasm.git] / macros.pl
blobe1d9ed0f6cba0b23d6b0eea70bdf75cf3cf5862e
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 licence given in the file "Licence"
8 # distributed in the NASM archive.
9 use strict;
11 my $fname;
12 my $line = 0;
13 my $index = 0;
15 $fname = "standard.mac" unless $fname = $ARGV[0];
16 open INPUT,$fname || die "unable to open $fname\n";
17 open OUTPUT,">macros.c" || die "unable to open macros.c\n";
19 print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
20 " - don't edit it */\n\nstatic char *stdmac[] = {\n";
22 while (<INPUT>) {
23 $line++;
24 chomp;
25 if (m/^\s*((\s*([^"';\s]+|"[^"]*"|'[^']*'))*)\s*(;.*)?$/) {
26 $_ = $1;
27 s/\\/\\\\/g;
28 s/"/\\"/g;
29 if (length > 0) {
30 print OUTPUT " \"$_\",\n";
31 if ($index >= 0) {
32 if (m/__NASM_MAJOR__/) {
33 $index = -$index;
34 } else {
35 $index++;
39 } else {
40 die "$fname:$line: error unterminated quote";
43 $index = -$index;
44 print OUTPUT " NULL\n};\n#define TASM_MACRO_COUNT $index\n"