Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01e40a9

Browse files
author
H. Peter Anvin
committed
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) <[email protected]>
1 parent 959644a commit 01e40a9

File tree

7 files changed

+148
-59
lines changed

7 files changed

+148
-59
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ TAGS
7878
/doc/pptok.src
7979
/doc/fontpath
8080
/doc/Fontmap
81+
/editors/nasmtok.el
8182
/include/warnings.h
8283
/macros/macros.c
83-
/misc/nasmtok.el
8484
/misc/omfdump
8585
/misc/Makefile
8686
/nasm

Makefile.in

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exec_prefix = @exec_prefix@
1515
bindir = @bindir@
1616
mandir = @mandir@
1717
datarootdir = @datarootdir@
18+
datadir = @datadir@
1819

1920
CC = @CC@
2021
CFLAGS = @CFLAGS@
@@ -94,7 +95,7 @@ endif
9495

9596
.PHONY: all doc misc install clean distclean cleaner spotless test
9697
.PHONY: install_doc everything install_everything strip perlreq dist tags TAGS
97-
.PHONY: nothing manpages nsis
98+
.PHONY: nothing manpages nsis editors
9899

99100
.c.$(O):
100101
$(CC) -c $(ALL_CFLAGS) -o $@ $<
@@ -212,8 +213,11 @@ ALLOBJ_W = $(NASM) $(LIBOBJ_W)
212213
ALLOBJ = $(PROGOBJ) $(LIBOBJ)
213214
SUBDIRS = stdlib nasmlib include config output asm disasm x86 \
214215
common zlib macros misc
215-
XSUBDIRS = nsis win test doc
216+
XSUBDIRS = nsis win test doc editors
216217
DEPDIRS = . $(SUBDIRS)
218+
219+
EDITORS = editors/nasmtok.el
220+
217221
#-- End File Lists --#
218222

219223
all: $(PROGS)
@@ -264,7 +268,6 @@ PERLREQ_CLEANABLE = \
264268
macros/macros.c \
265269
asm/pptok.ph asm/directbl.c asm/directiv.h \
266270
$(WARNFILES) \
267-
misc/nasmtok.el \
268271
version.h version.mac version.mak nsis/version.nsh
269272

270273
PERLREQ = $(PERLREQ_CLEANABLE)
@@ -376,9 +379,12 @@ asm/directbl.c: asm/directiv.dat nasmlib/perfhash.pl perllib/phash.ph
376379
$(srcdir)/asm/directiv.dat asm/directbl.c
377380

378381
# Emacs token files
379-
misc/nasmtok.el: misc/emacstbl.pl asm/tokhash.c asm/pptok.c \
380-
asm/directiv.dat version
381-
$(RUNPERL) $(srcdir)/misc/emacstbl.pl $@ $(srcdir) $(objdir)
382+
editors/nasmtok.el: editors/nasmtok.pl asm/tokhash.c asm/pptok.c \
383+
asm/directiv.dat macros/macros.c editors/builtin.mac \
384+
version.mak
385+
$(RUNPERL) $(srcdir)/editors/nasmtok.pl -el $@ $(srcdir) $(objdir)
386+
387+
editors: $(EDITORS)
382388

383389
#-- End Generated File Rules --#
384390

@@ -461,6 +467,10 @@ install: $(PROGS)
461467
$(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1
462468
$(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1
463469

470+
install_editors: $(EDITORS)
471+
$(MKDIR_P) $(DESTDIR)$(datadir)
472+
$(INSTALL_DATA) $(EDITORS) $(DESTDIR)$(datadir)
473+
464474
clean:
465475
for d in . $(SUBDIRS) $(XSUBDIRS); do \
466476
$(RM_F) "$$d"/*.$(O) "$$d"/*.s "$$d"/*.i "$$d"/*.$(A) ; \
@@ -481,7 +491,7 @@ distclean: clean
481491
-$(SHELL) autoconf/clean.sh || $(SHELL) $(srcdir)/autoconf/clean.sh
482492

483493
cleaner:
484-
$(RM_F) $(PERLREQ_CL) *.1 nasm.spec
494+
$(RM_F) $(PERLREQ_CL) $(EDITORS) *.1 nasm.spec
485495
$(MAKE) -C doc clean
486496
$(MAKE) -C misc clean
487497
$(MAKE) distclean
@@ -529,7 +539,7 @@ always_everything: $(DIRS)
529539
everything: always_everything
530540
$(MAKE) $(MANPAGES) $(NSIS) nothing
531541

532-
install_everything: everything install install_doc
542+
install_everything: everything install install_doc install_editors
533543

534544
dist:
535545
$(MAKE) alldeps
File renamed without changes.
File renamed without changes.

misc/emacstbl.pl renamed to editors/nasmtok.pl

Lines changed: 119 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@
88
use File::Spec;
99
use File::Find;
1010

11+
my $format = 'el';
12+
13+
if ($ARGV[0] =~ /^-(\S+)$/) {
14+
$format = $1;
15+
shift @ARGV;
16+
}
17+
1118
my($outfile, $srcdir, $objdir) = @ARGV;
1219

1320
if (!defined($outfile)) {
14-
die "Usage: $0 outfile srcdir objdir\n";
21+
die "Usage: $0 [-format] outfile srcdir objdir\n";
1522
}
1623

17-
$srcdir = File::Spec->curdir() unless (defined($srcdir));
18-
$objdir = $srcdir unless (defined($objdir));
24+
my @vpath;
25+
26+
$srcdir = $srcdir || File::Spec->curdir();
27+
$objdir = $objdir || $srcdir;
28+
push(@vpath, $objdir) if ($objdir ne $srcdir);
29+
push(@vpath, $srcdir);
1930

2031
my %tokens = (); # Token lists per category
2132
my %token_category = (); # Tokens to category map
@@ -27,6 +38,32 @@ ($@)
2738
return push(@$$ref, @_);
2839
}
2940

41+
# Search for a file, and return a file handle if successfully opened
42+
sub open_vpath($$) {
43+
my($mode, $file) = @_;
44+
my %tried;
45+
46+
# For simplicity, allow filenames to be specified
47+
# with Unix / syntax internally
48+
$file = File::Spec->catfile(split(/\//, $file));
49+
50+
foreach my $d (@vpath) {
51+
my $fn = File::Spec->catfile($d, $file);
52+
next if ($tried{$fn});
53+
$tried{$fn}++;
54+
my $fh;
55+
return $fh if (open($fh, $mode, $fn));
56+
}
57+
return undef;
58+
}
59+
60+
sub must_open($) {
61+
my($file) = @_;
62+
my $fh = open_vpath('<', $file);
63+
return $fh if (defined($fh));
64+
die "$0:$file: $!\n";
65+
}
66+
3067
# Combine some specific token types
3168
my %override = (
3269
'brcconst' => 'special-constant',
@@ -54,8 +91,7 @@ ($$)
5491
sub read_tokhash_c($) {
5592
my($tokhash_c) = @_;
5693

57-
open(my $th, '<', $tokhash_c)
58-
or die "$0:$tokhash_c: $!\n";
94+
my $th = must_open($tokhash_c);
5995

6096
my $l;
6197
my $tokendata = 0;
@@ -97,8 +133,7 @@ ($)
97133
sub read_pptok_c($) {
98134
my($pptok_c) = @_;
99135

100-
open(my $pt, '<', $pptok_c)
101-
or die "$0:$pptok_c: $!\n";
136+
my $pt = must_open($pptok_c);
102137

103138
my $l;
104139
my $pp_dir = 0;
@@ -123,8 +158,7 @@ ($)
123158
sub read_directiv_dat($) {
124159
my($directiv_dat) = @_;
125160

126-
open(my $dd, '<', $directiv_dat)
127-
or die "$0:$directiv_dat: $!\n";
161+
my $dd = must_open($directiv_dat);
128162

129163
my $l;
130164
my $directiv = 0;
@@ -145,22 +179,25 @@ ($)
145179
close($dd);
146180
}
147181

148-
my $version;
182+
my %version;
149183
sub read_version($) {
150184
my($vfile) = @_;
151-
open(my $v, '<', $vfile)
152-
or die "$0:$vfile: $!\n";
153-
154-
$version = <$v>;
155-
chomp $version;
185+
my $v = must_open($vfile);
156186

187+
while (defined(my $vl = <$v>)) {
188+
if ($vl =~ /^NASM_(\w+)=(\S+)\s*$/) {
189+
$version{lc($1)} = $2;
190+
}
191+
}
157192
close($v);
158193
}
159194

195+
# This is called from the directory search in read_macros(), so
196+
# don't use must_open() here.
160197
sub read_macro_file($) {
161198
my($file) = @_;
162199

163-
open(my $fh, '<', $file) or die;
200+
open(my $fh, '<', $file) or die "$0:$file: $!\n";
164201
while (defined(my $l = <$fh>)) {
165202
next unless ($l =~ /^\s*\%/);
166203
my @f = split(/\s+/, $l);
@@ -177,21 +214,20 @@ ($)
177214
close($fh);
178215
}
179216

180-
sub read_macros($$) {
181-
my($srcdir, $objdir) = @_;
182-
my @dirs;
183-
push(@dirs, $objdir);
184-
push(@dirs, File::Spec->catdir($srcdir, 'macros'));
185-
push(@dirs, File::Spec->catdir($srcdir, 'output'));
217+
sub read_macros(@) {
218+
my %visited;
219+
my @dirs = (File::Spec->curdir(), qw(macros output editors));
220+
@dirs = map { my $od = $_; map { File::Spec->catdir($od, $_) } @dirs } @_;
186221
foreach my $dir (@dirs) {
187-
opendir(my $dh, $dir) or die;
222+
next if ($visited{$dir});
223+
$visited{$dir}++;
224+
next unless opendir(my $dh, $dir);
188225
while (defined(my $fn = readdir($dh))) {
189-
next unless ($fn =~ /\.mac$/);
190-
read_macro_file(File::Spec->catdir($dir, $fn));
226+
next unless ($fn =~ /\.mac$/i);
227+
read_macro_file(File::Spec->catfile($dir, $fn));
191228
}
229+
closedir($dh);
192230
}
193-
# Don't read the whole misc directory!
194-
read_macro_file(File::Spec->catdir($srcdir, 'misc/builtin.mac'));
195231
}
196232

197233
sub make_lines($$@) {
@@ -235,18 +271,15 @@ (@)
235271
return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_;
236272
}
237273

238-
sub write_output($) {
239-
my($outfile) = @_;
240-
241-
open(my $out, '>', $outfile)
242-
or die "$0:$outfile: $!\n";
243-
244-
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
274+
# Emacs LISP
275+
sub write_output_el {
276+
my($out, $outfile, $file) = @_;
277+
my $whoami = 'NASM '.$version{'ver'};
245278

246279
print $out ";;; ${file} --- lists of NASM assembler tokens\n\n";
247280
print $out ";;; Commentary:\n\n";
248281
print $out ";; This file contains list of tokens from the NASM x86\n";
249-
print $out ";; assembler, automatically extracted from NASM ${version}.\n";
282+
print $out ";; assembler, automatically extracted from ${whoami}.\n";
250283
print $out ";;\n";
251284
print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n";
252285
print $out ";; major mode definition.\n";
@@ -268,28 +301,69 @@ ($)
268301

269302
print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}}));
270303
print $out ")\n";
271-
print $out " \"NASM ${version} ${type} tokens for `nasm-mode\'.\")\n";
304+
print $out " \"${whoami} ${type} tokens for `nasm-mode\'.\")\n";
272305
}
273306

274307
# Generate a list of all the token type lists.
275308
print $out "\n(defconst nasm-token-lists\n";
276309
print $out " \'(";
277310
print $out make_lines(78, 4, map { "'nasm-$_" } sort keys(%tokens));
278311
print $out ")\n";
279-
print $out " \"List of all NASM token type lists.\")\n";
280-
312+
print $out " \"List of all ${whoami} token type lists.\")\n";
313+
314+
# The NASM token extracted version
315+
printf $out "\n(defconst nasm-token-version %s\n",
316+
quote_for_emacs($version{'ver'});
317+
print $out " \"Version of NASM from which tokens were extracted,\n";
318+
print $out "as a human-readable string.\")\n";
319+
320+
printf $out "\n(defconst nasm-token-version-id #x%08x\n",
321+
$version{'version_id'};
322+
print $out " \"Version of NASM from which tokens were extracted,\n";
323+
print $out "as numeric identifier, for comparisons. Equivalent to the\n";
324+
print $out "__?NASM_VERSION_ID?__ NASM macro value.\")\n";
325+
326+
printf $out "\n(defconst nasm-token-version-snapshot %s\n",
327+
$version{'snapshot'} || 'nil';
328+
print $out " \"Daily NASM snapshot build from which tokens were extracted,\n";
329+
print $out "as a decimal number in YYYYMMDD format, or nil if not a\n";
330+
print $out "daily snapshot build.\")\n";
281331

282332
# Footer
283333
print $out "\n(provide 'nasmtok)\n";
284334
print $out ";;; nasmtok.el ends here\n";
285335

286-
close($out);
336+
return 0;
287337
}
288338

289-
read_tokhash_c(File::Spec->catfile($objdir, 'asm', 'tokhash.c'));
290-
read_pptok_c(File::Spec->catfile($objdir, 'asm', 'pptok.c'));
291-
read_directiv_dat(File::Spec->catfile($srcdir, 'asm', 'directiv.dat'));
292-
read_version(File::Spec->catfile($srcdir, 'version'));
293-
read_macros($srcdir, $objdir);
339+
sub write_output($$) {
340+
my($format, $outfile) = @_;
341+
my %formats = (
342+
'el' => \&write_output_el
343+
);
344+
345+
my $outfunc = $formats{$format};
346+
if (!defined($outfunc)) {
347+
die "$0: unknown output format: $format\n";
348+
}
349+
350+
open(my $out, '>', $outfile)
351+
or die "$0:$outfile: $!\n";
352+
353+
my($vol,$dir,$file) = File::Spec->splitpath($outfile);
354+
355+
my $err = $outfunc->($out, $outfile, $file);
356+
close($out);
357+
358+
if ($err) {
359+
unlink($outfile);
360+
die "$0:$outfile: error writing output\n";
361+
}
362+
}
294363

295-
write_output($outfile);
364+
read_tokhash_c('asm/tokhash.c');
365+
read_pptok_c('asm/pptok.c');
366+
read_directiv_dat('asm/directiv.dat');
367+
read_version('version.mak');
368+
read_macros(@vpath);
369+
write_output($format, $outfile);

misc/Makefile.in

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CP_F = cp -f
5151
CP_UF = cp -uf
5252

5353
PROGS = omfdump$(X)
54-
GENDATA = nasmtok.el
54+
GENDATA =
5555
SRCDATA = README \
5656
c16.mac c32.mac exebin.mac exebin2.mac \
5757
myC32.mac scitech.mac \
@@ -85,9 +85,6 @@ all: $(PROGS) $(GENDATA)
8585
omfdump$(X): omfdump.$(O)
8686
$(CC) $(ALL_LDFLAGS) -o $@ $< $(LIBS)
8787

88-
nasmtok.el:
89-
$(MAKE) -C ..
90-
9188
install-prog: $(PROGS)
9289
$(MKDIR_P) $(DESTDIR)$(bindir)
9390
$(INSTALL_PROGRAM) $(PROGS) $(DESTDIR)$(bindir)/

0 commit comments

Comments
 (0)