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/fontpath
/doc/Fontmap
/editors/nasmtok.el
/include/warnings.h
/macros/macros.c
/misc/nasmtok.el
/misc/omfdump
/misc/Makefile
/nasm

View File

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

View File

@@ -8,14 +8,25 @@ use strict;
use File::Spec;
use File::Find;
my $format = 'el';
if ($ARGV[0] =~ /^-(\S+)$/) {
$format = $1;
shift @ARGV;
}
my($outfile, $srcdir, $objdir) = @ARGV;
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));
$objdir = $srcdir unless (defined($objdir));
my @vpath;
$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 %token_category = (); # Tokens to category map
@@ -27,6 +38,32 @@ sub xpush($@) {
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
my %override = (
'brcconst' => 'special-constant',
@@ -54,8 +91,7 @@ sub addtoken($$) {
sub read_tokhash_c($) {
my($tokhash_c) = @_;
open(my $th, '<', $tokhash_c)
or die "$0:$tokhash_c: $!\n";
my $th = must_open($tokhash_c);
my $l;
my $tokendata = 0;
@@ -97,8 +133,7 @@ sub read_tokhash_c($) {
sub read_pptok_c($) {
my($pptok_c) = @_;
open(my $pt, '<', $pptok_c)
or die "$0:$pptok_c: $!\n";
my $pt = must_open($pptok_c);
my $l;
my $pp_dir = 0;
@@ -123,8 +158,7 @@ sub read_pptok_c($) {
sub read_directiv_dat($) {
my($directiv_dat) = @_;
open(my $dd, '<', $directiv_dat)
or die "$0:$directiv_dat: $!\n";
my $dd = must_open($directiv_dat);
my $l;
my $directiv = 0;
@@ -145,22 +179,25 @@ sub read_directiv_dat($) {
close($dd);
}
my $version;
my %version;
sub read_version($) {
my($vfile) = @_;
open(my $v, '<', $vfile)
or die "$0:$vfile: $!\n";
$version = <$v>;
chomp $version;
my $v = must_open($vfile);
while (defined(my $vl = <$v>)) {
if ($vl =~ /^NASM_(\w+)=(\S+)\s*$/) {
$version{lc($1)} = $2;
}
}
close($v);
}
# This is called from the directory search in read_macros(), so
# don't use must_open() here.
sub read_macro_file($) {
my($file) = @_;
open(my $fh, '<', $file) or die;
open(my $fh, '<', $file) or die "$0:$file: $!\n";
while (defined(my $l = <$fh>)) {
next unless ($l =~ /^\s*\%/);
my @f = split(/\s+/, $l);
@@ -177,21 +214,20 @@ sub read_macro_file($) {
close($fh);
}
sub read_macros($$) {
my($srcdir, $objdir) = @_;
my @dirs;
push(@dirs, $objdir);
push(@dirs, File::Spec->catdir($srcdir, 'macros'));
push(@dirs, File::Spec->catdir($srcdir, 'output'));
sub read_macros(@) {
my %visited;
my @dirs = (File::Spec->curdir(), qw(macros output editors));
@dirs = map { my $od = $_; map { File::Spec->catdir($od, $_) } @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))) {
next unless ($fn =~ /\.mac$/);
read_macro_file(File::Spec->catdir($dir, $fn));
next unless ($fn =~ /\.mac$/i);
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($$@) {
@@ -235,18 +271,15 @@ sub quote_for_emacs(@) {
return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_;
}
sub write_output($) {
my($outfile) = @_;
open(my $out, '>', $outfile)
or die "$0:$outfile: $!\n";
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
# Emacs LISP
sub write_output_el {
my($out, $outfile, $file) = @_;
my $whoami = 'NASM '.$version{'ver'};
print $out ";;; ${file} --- lists of NASM assembler tokens\n\n";
print $out ";;; Commentary:\n\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 ";; This file is intended to be (require)d from a `nasm-mode\'\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 ")\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.
@@ -276,20 +309,61 @@ sub write_output($) {
print $out " \'(";
print $out make_lines(78, 4, map { "'nasm-$_" } sort keys(%tokens));
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
print $out "\n(provide 'nasmtok)\n";
print $out ";;; nasmtok.el ends here\n";
close($out);
return 0;
}
read_tokhash_c(File::Spec->catfile($objdir, 'asm', 'tokhash.c'));
read_pptok_c(File::Spec->catfile($objdir, 'asm', 'pptok.c'));
read_directiv_dat(File::Spec->catfile($srcdir, 'asm', 'directiv.dat'));
read_version(File::Spec->catfile($srcdir, 'version'));
read_macros($srcdir, $objdir);
sub write_output($$) {
my($format, $outfile) = @_;
my %formats = (
'el' => \&write_output_el
);
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
PROGS = omfdump$(X)
GENDATA = nasmtok.el
GENDATA =
SRCDATA = README \
c16.mac c32.mac exebin.mac exebin2.mac \
myC32.mac scitech.mac \
@@ -85,9 +85,6 @@ all: $(PROGS) $(GENDATA)
omfdump$(X): omfdump.$(O)
$(CC) $(ALL_LDFLAGS) -o $@ $< $(LIBS)
nasmtok.el:
$(MAKE) -C ..
install-prog: $(PROGS)
$(MKDIR_P) $(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_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
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_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
} elsif ( $what eq 'make' ) {
@@ -143,12 +143,20 @@ if ( $what eq 'h' ) {
printf "NASM_MINOR_VER=%d\n", $nmin;
printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
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' ) {
printf "!define VERSION \"%s\"\n", $line;
printf "!define MAJOR_VER %d\n", $nmin;
printf "!define MINOR_VER %d\n", $nmin;
printf "!define SUBMINOR_VER %d\n", $nsmin;
printf "!define PATCHLEVEL_VER %d\n", $nplvl;
if (defined($snapshot)) {
printf "!define SNAPSHOT_VER=%d\n", $snapshot;
}
} elsif ( $what eq 'id' ) {
print $nasm_id, "\n"; # Print ID in decimal
} elsif ( $what eq 'xid' ) {