#! /usr/bin/perl # Extract source text files from NASM listing files # by E. C. Masloch, 2025 # # Usage of the works is permitted provided that this # instrument is retained with the works, so that any entity # that uses the works is notified of this instrument. # # DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. use warnings; use strict; use Getopt::Long; Getopt::Long::Configure("no_auto_abbrev"); my $include; GetOptions( 'filter-include=s' => \$include, ) or die; my $includelevel = -1; my $priorlevel = -1; while (<<>>) { if (/^.{0,39}$/) { next; } if (/^.{0,20}\*{18}\s+/) { next; } my $level = 0; if (/^.{30,36}\<([0-9]+)\>\s+/) { $level = int($1); } if (not defined $include and $level != 0) { next; } if (defined $include and /^.{40}\s*\%include\s+['"]*$include['"]*\s*(;.*)?$/i) { $priorlevel = $level; $includelevel = $level + 1; } elsif (defined $include and $level != $includelevel) { if ($level <= $priorlevel) { last; } next; } if (defined $include and $level != $includelevel) { next; } s/^.{40}//; print; }