0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

Move editor help files to editors/, add NASM version number

Move the editor help files (currently nasmtok.el) to the editors/
subdirectory in anticipation of having more such files.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin
2025-10-02 13:47:20 -07:00
parent 959644a017
commit 01e40a9aeb
7 changed files with 147 additions and 58 deletions

2
.gitignore vendored
View File

@@ -78,9 +78,9 @@ TAGS
/doc/pptok.src /doc/pptok.src
/doc/fontpath /doc/fontpath
/doc/Fontmap /doc/Fontmap
/editors/nasmtok.el
/include/warnings.h /include/warnings.h
/macros/macros.c /macros/macros.c
/misc/nasmtok.el
/misc/omfdump /misc/omfdump
/misc/Makefile /misc/Makefile
/nasm /nasm

View File

@@ -15,6 +15,7 @@ exec_prefix = @exec_prefix@
bindir = @bindir@ bindir = @bindir@
mandir = @mandir@ mandir = @mandir@
datarootdir = @datarootdir@ datarootdir = @datarootdir@
datadir = @datadir@
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
@@ -94,7 +95,7 @@ endif
.PHONY: all doc misc install clean distclean cleaner spotless test .PHONY: all doc misc install clean distclean cleaner spotless test
.PHONY: install_doc everything install_everything strip perlreq dist tags TAGS .PHONY: install_doc everything install_everything strip perlreq dist tags TAGS
.PHONY: nothing manpages nsis .PHONY: nothing manpages nsis editors
.c.$(O): .c.$(O):
$(CC) -c $(ALL_CFLAGS) -o $@ $< $(CC) -c $(ALL_CFLAGS) -o $@ $<
@@ -212,8 +213,11 @@ ALLOBJ_W = $(NASM) $(LIBOBJ_W)
ALLOBJ = $(PROGOBJ) $(LIBOBJ) ALLOBJ = $(PROGOBJ) $(LIBOBJ)
SUBDIRS = stdlib nasmlib include config output asm disasm x86 \ SUBDIRS = stdlib nasmlib include config output asm disasm x86 \
common zlib macros misc common zlib macros misc
XSUBDIRS = nsis win test doc XSUBDIRS = nsis win test doc editors
DEPDIRS = . $(SUBDIRS) DEPDIRS = . $(SUBDIRS)
EDITORS = editors/nasmtok.el
#-- End File Lists --# #-- End File Lists --#
all: $(PROGS) all: $(PROGS)
@@ -264,7 +268,6 @@ PERLREQ_CLEANABLE = \
macros/macros.c \ macros/macros.c \
asm/pptok.ph asm/directbl.c asm/directiv.h \ asm/pptok.ph asm/directbl.c asm/directiv.h \
$(WARNFILES) \ $(WARNFILES) \
misc/nasmtok.el \
version.h version.mac version.mak nsis/version.nsh version.h version.mac version.mak nsis/version.nsh
PERLREQ = $(PERLREQ_CLEANABLE) PERLREQ = $(PERLREQ_CLEANABLE)
@@ -376,9 +379,12 @@ asm/directbl.c: asm/directiv.dat nasmlib/perfhash.pl perllib/phash.ph
$(srcdir)/asm/directiv.dat asm/directbl.c $(srcdir)/asm/directiv.dat asm/directbl.c
# Emacs token files # Emacs token files
misc/nasmtok.el: misc/emacstbl.pl asm/tokhash.c asm/pptok.c \ editors/nasmtok.el: editors/nasmtok.pl asm/tokhash.c asm/pptok.c \
asm/directiv.dat version asm/directiv.dat macros/macros.c editors/builtin.mac \
$(RUNPERL) $(srcdir)/misc/emacstbl.pl $@ $(srcdir) $(objdir) version.mak
$(RUNPERL) $(srcdir)/editors/nasmtok.pl -el $@ $(srcdir) $(objdir)
editors: $(EDITORS)
#-- End Generated File Rules --# #-- End Generated File Rules --#
@@ -461,6 +467,10 @@ install: $(PROGS)
$(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1 $(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1
$(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1 $(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1
install_editors: $(EDITORS)
$(MKDIR_P) $(DESTDIR)$(datadir)
$(INSTALL_DATA) $(EDITORS) $(DESTDIR)$(datadir)
clean: clean:
for d in . $(SUBDIRS) $(XSUBDIRS); do \ for d in . $(SUBDIRS) $(XSUBDIRS); do \
$(RM_F) "$$d"/*.$(O) "$$d"/*.s "$$d"/*.i "$$d"/*.$(A) ; \ $(RM_F) "$$d"/*.$(O) "$$d"/*.s "$$d"/*.i "$$d"/*.$(A) ; \
@@ -481,7 +491,7 @@ distclean: clean
-$(SHELL) autoconf/clean.sh || $(SHELL) $(srcdir)/autoconf/clean.sh -$(SHELL) autoconf/clean.sh || $(SHELL) $(srcdir)/autoconf/clean.sh
cleaner: cleaner:
$(RM_F) $(PERLREQ_CL) *.1 nasm.spec $(RM_F) $(PERLREQ_CL) $(EDITORS) *.1 nasm.spec
$(MAKE) -C doc clean $(MAKE) -C doc clean
$(MAKE) -C misc clean $(MAKE) -C misc clean
$(MAKE) distclean $(MAKE) distclean
@@ -529,7 +539,7 @@ always_everything: $(DIRS)
everything: always_everything everything: always_everything
$(MAKE) $(MANPAGES) $(NSIS) nothing $(MAKE) $(MANPAGES) $(NSIS) nothing
install_everything: everything install install_doc install_everything: everything install install_doc install_editors
dist: dist:
$(MAKE) alldeps $(MAKE) alldeps

View File

@@ -8,14 +8,25 @@ use strict;
use File::Spec; use File::Spec;
use File::Find; use File::Find;
my $format = 'el';
if ($ARGV[0] =~ /^-(\S+)$/) {
$format = $1;
shift @ARGV;
}
my($outfile, $srcdir, $objdir) = @ARGV; my($outfile, $srcdir, $objdir) = @ARGV;
if (!defined($outfile)) { if (!defined($outfile)) {
die "Usage: $0 outfile srcdir objdir\n"; die "Usage: $0 [-format] outfile srcdir objdir\n";
} }
$srcdir = File::Spec->curdir() unless (defined($srcdir)); my @vpath;
$objdir = $srcdir unless (defined($objdir));
$srcdir = $srcdir || File::Spec->curdir();
$objdir = $objdir || $srcdir;
push(@vpath, $objdir) if ($objdir ne $srcdir);
push(@vpath, $srcdir);
my %tokens = (); # Token lists per category my %tokens = (); # Token lists per category
my %token_category = (); # Tokens to category map my %token_category = (); # Tokens to category map
@@ -27,6 +38,32 @@ sub xpush($@) {
return push(@$$ref, @_); return push(@$$ref, @_);
} }
# Search for a file, and return a file handle if successfully opened
sub open_vpath($$) {
my($mode, $file) = @_;
my %tried;
# For simplicity, allow filenames to be specified
# with Unix / syntax internally
$file = File::Spec->catfile(split(/\//, $file));
foreach my $d (@vpath) {
my $fn = File::Spec->catfile($d, $file);
next if ($tried{$fn});
$tried{$fn}++;
my $fh;
return $fh if (open($fh, $mode, $fn));
}
return undef;
}
sub must_open($) {
my($file) = @_;
my $fh = open_vpath('<', $file);
return $fh if (defined($fh));
die "$0:$file: $!\n";
}
# Combine some specific token types # Combine some specific token types
my %override = ( my %override = (
'brcconst' => 'special-constant', 'brcconst' => 'special-constant',
@@ -54,8 +91,7 @@ sub addtoken($$) {
sub read_tokhash_c($) { sub read_tokhash_c($) {
my($tokhash_c) = @_; my($tokhash_c) = @_;
open(my $th, '<', $tokhash_c) my $th = must_open($tokhash_c);
or die "$0:$tokhash_c: $!\n";
my $l; my $l;
my $tokendata = 0; my $tokendata = 0;
@@ -97,8 +133,7 @@ sub read_tokhash_c($) {
sub read_pptok_c($) { sub read_pptok_c($) {
my($pptok_c) = @_; my($pptok_c) = @_;
open(my $pt, '<', $pptok_c) my $pt = must_open($pptok_c);
or die "$0:$pptok_c: $!\n";
my $l; my $l;
my $pp_dir = 0; my $pp_dir = 0;
@@ -123,8 +158,7 @@ sub read_pptok_c($) {
sub read_directiv_dat($) { sub read_directiv_dat($) {
my($directiv_dat) = @_; my($directiv_dat) = @_;
open(my $dd, '<', $directiv_dat) my $dd = must_open($directiv_dat);
or die "$0:$directiv_dat: $!\n";
my $l; my $l;
my $directiv = 0; my $directiv = 0;
@@ -145,22 +179,25 @@ sub read_directiv_dat($) {
close($dd); close($dd);
} }
my $version; my %version;
sub read_version($) { sub read_version($) {
my($vfile) = @_; my($vfile) = @_;
open(my $v, '<', $vfile) my $v = must_open($vfile);
or die "$0:$vfile: $!\n";
$version = <$v>;
chomp $version;
while (defined(my $vl = <$v>)) {
if ($vl =~ /^NASM_(\w+)=(\S+)\s*$/) {
$version{lc($1)} = $2;
}
}
close($v); close($v);
} }
# This is called from the directory search in read_macros(), so
# don't use must_open() here.
sub read_macro_file($) { sub read_macro_file($) {
my($file) = @_; my($file) = @_;
open(my $fh, '<', $file) or die; open(my $fh, '<', $file) or die "$0:$file: $!\n";
while (defined(my $l = <$fh>)) { while (defined(my $l = <$fh>)) {
next unless ($l =~ /^\s*\%/); next unless ($l =~ /^\s*\%/);
my @f = split(/\s+/, $l); my @f = split(/\s+/, $l);
@@ -177,21 +214,20 @@ sub read_macro_file($) {
close($fh); close($fh);
} }
sub read_macros($$) { sub read_macros(@) {
my($srcdir, $objdir) = @_; my %visited;
my @dirs; my @dirs = (File::Spec->curdir(), qw(macros output editors));
push(@dirs, $objdir); @dirs = map { my $od = $_; map { File::Spec->catdir($od, $_) } @dirs } @_;
push(@dirs, File::Spec->catdir($srcdir, 'macros'));
push(@dirs, File::Spec->catdir($srcdir, 'output'));
foreach my $dir (@dirs) { foreach my $dir (@dirs) {
opendir(my $dh, $dir) or die; next if ($visited{$dir});
$visited{$dir}++;
next unless opendir(my $dh, $dir);
while (defined(my $fn = readdir($dh))) { while (defined(my $fn = readdir($dh))) {
next unless ($fn =~ /\.mac$/); next unless ($fn =~ /\.mac$/i);
read_macro_file(File::Spec->catdir($dir, $fn)); read_macro_file(File::Spec->catfile($dir, $fn));
} }
closedir($dh);
} }
# Don't read the whole misc directory!
read_macro_file(File::Spec->catdir($srcdir, 'misc/builtin.mac'));
} }
sub make_lines($$@) { sub make_lines($$@) {
@@ -235,18 +271,15 @@ sub quote_for_emacs(@) {
return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_; return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_;
} }
sub write_output($) { # Emacs LISP
my($outfile) = @_; sub write_output_el {
my($out, $outfile, $file) = @_;
open(my $out, '>', $outfile) my $whoami = 'NASM '.$version{'ver'};
or die "$0:$outfile: $!\n";
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
print $out ";;; ${file} --- lists of NASM assembler tokens\n\n"; print $out ";;; ${file} --- lists of NASM assembler tokens\n\n";
print $out ";;; Commentary:\n\n"; print $out ";;; Commentary:\n\n";
print $out ";; This file contains list of tokens from the NASM x86\n"; print $out ";; This file contains list of tokens from the NASM x86\n";
print $out ";; assembler, automatically extracted from NASM ${version}.\n"; print $out ";; assembler, automatically extracted from ${whoami}.\n";
print $out ";;\n"; print $out ";;\n";
print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n"; print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n";
print $out ";; major mode definition.\n"; print $out ";; major mode definition.\n";
@@ -268,7 +301,7 @@ sub write_output($) {
print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}})); print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}}));
print $out ")\n"; print $out ")\n";
print $out " \"NASM ${version} ${type} tokens for `nasm-mode\'.\")\n"; print $out " \"${whoami} ${type} tokens for `nasm-mode\'.\")\n";
} }
# Generate a list of all the token type lists. # Generate a list of all the token type lists.
@@ -276,20 +309,61 @@ sub write_output($) {
print $out " \'("; print $out " \'(";
print $out make_lines(78, 4, map { "'nasm-$_" } sort keys(%tokens)); print $out make_lines(78, 4, map { "'nasm-$_" } sort keys(%tokens));
print $out ")\n"; print $out ")\n";
print $out " \"List of all NASM token type lists.\")\n"; print $out " \"List of all ${whoami} token type lists.\")\n";
# The NASM token extracted version
printf $out "\n(defconst nasm-token-version %s\n",
quote_for_emacs($version{'ver'});
print $out " \"Version of NASM from which tokens were extracted,\n";
print $out "as a human-readable string.\")\n";
printf $out "\n(defconst nasm-token-version-id #x%08x\n",
$version{'version_id'};
print $out " \"Version of NASM from which tokens were extracted,\n";
print $out "as numeric identifier, for comparisons. Equivalent to the\n";
print $out "__?NASM_VERSION_ID?__ NASM macro value.\")\n";
printf $out "\n(defconst nasm-token-version-snapshot %s\n",
$version{'snapshot'} || 'nil';
print $out " \"Daily NASM snapshot build from which tokens were extracted,\n";
print $out "as a decimal number in YYYYMMDD format, or nil if not a\n";
print $out "daily snapshot build.\")\n";
# Footer # Footer
print $out "\n(provide 'nasmtok)\n"; print $out "\n(provide 'nasmtok)\n";
print $out ";;; nasmtok.el ends here\n"; print $out ";;; nasmtok.el ends here\n";
close($out); return 0;
} }
read_tokhash_c(File::Spec->catfile($objdir, 'asm', 'tokhash.c')); sub write_output($$) {
read_pptok_c(File::Spec->catfile($objdir, 'asm', 'pptok.c')); my($format, $outfile) = @_;
read_directiv_dat(File::Spec->catfile($srcdir, 'asm', 'directiv.dat')); my %formats = (
read_version(File::Spec->catfile($srcdir, 'version')); 'el' => \&write_output_el
read_macros($srcdir, $objdir); );
write_output($outfile); my $outfunc = $formats{$format};
if (!defined($outfunc)) {
die "$0: unknown output format: $format\n";
}
open(my $out, '>', $outfile)
or die "$0:$outfile: $!\n";
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
my $err = $outfunc->($out, $outfile, $file);
close($out);
if ($err) {
unlink($outfile);
die "$0:$outfile: error writing output\n";
}
}
read_tokhash_c('asm/tokhash.c');
read_pptok_c('asm/pptok.c');
read_directiv_dat('asm/directiv.dat');
read_version('version.mak');
read_macros(@vpath);
write_output($format, $outfile);

View File

@@ -51,7 +51,7 @@ CP_F = cp -f
CP_UF = cp -uf CP_UF = cp -uf
PROGS = omfdump$(X) PROGS = omfdump$(X)
GENDATA = nasmtok.el GENDATA =
SRCDATA = README \ SRCDATA = README \
c16.mac c32.mac exebin.mac exebin2.mac \ c16.mac c32.mac exebin.mac exebin2.mac \
myC32.mac scitech.mac \ myC32.mac scitech.mac \
@@ -85,9 +85,6 @@ all: $(PROGS) $(GENDATA)
omfdump$(X): omfdump.$(O) omfdump$(X): omfdump.$(O)
$(CC) $(ALL_LDFLAGS) -o $@ $< $(LIBS) $(CC) $(ALL_LDFLAGS) -o $@ $< $(LIBS)
nasmtok.el:
$(MAKE) -C ..
install-prog: $(PROGS) install-prog: $(PROGS)
$(MKDIR_P) $(DESTDIR)$(bindir) $(MKDIR_P) $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) $(PROGS) $(DESTDIR)$(bindir)/ $(INSTALL_PROGRAM) $(PROGS) $(DESTDIR)$(bindir)/

View File

@@ -134,7 +134,7 @@ if ( $what eq 'h' ) {
printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl; printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id; printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id; printf "s/\@\@NASM_VERSION_XID\@\@/%08x/g\n", $nasm_id;
printf "s/\@\@NASM_VER\@\@/%s/g\n", $line; printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver; printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
} elsif ( $what eq 'make' ) { } elsif ( $what eq 'make' ) {
@@ -143,12 +143,20 @@ if ( $what eq 'h' ) {
printf "NASM_MINOR_VER=%d\n", $nmin; printf "NASM_MINOR_VER=%d\n", $nmin;
printf "NASM_SUBMINOR_VER=%d\n", $nsmin; printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl; printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
printf "NASM_VERSION_ID=%d\n", $nasm_id;
printf "NASM_VERSION_XID=%08x\n", $nasm_id;
if (defined($snapshot)) {
printf "NASM_SNAPSHOT=%d\n", $snapshot;
}
} elsif ( $what eq 'nsis' ) { } elsif ( $what eq 'nsis' ) {
printf "!define VERSION \"%s\"\n", $line; printf "!define VERSION \"%s\"\n", $line;
printf "!define MAJOR_VER %d\n", $nmin; printf "!define MAJOR_VER %d\n", $nmin;
printf "!define MINOR_VER %d\n", $nmin; printf "!define MINOR_VER %d\n", $nmin;
printf "!define SUBMINOR_VER %d\n", $nsmin; printf "!define SUBMINOR_VER %d\n", $nsmin;
printf "!define PATCHLEVEL_VER %d\n", $nplvl; printf "!define PATCHLEVEL_VER %d\n", $nplvl;
if (defined($snapshot)) {
printf "!define SNAPSHOT_VER=%d\n", $snapshot;
}
} elsif ( $what eq 'id' ) { } elsif ( $what eq 'id' ) {
print $nasm_id, "\n"; # Print ID in decimal print $nasm_id, "\n"; # Print ID in decimal
} elsif ( $what eq 'xid' ) { } elsif ( $what eq 'xid' ) {