Skip to content

Commit

Permalink
Add .editorconfig, make Perl indent size 2 spaces
Browse files Browse the repository at this point in the history
Just tooling. No binary changes.
  • Loading branch information
inexorabletash committed May 18, 2024
1 parent e74b1a3 commit 393b2c2
Show file tree
Hide file tree
Showing 16 changed files with 689 additions and 681 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://editorconfig.org/

# Perl
[*.pl]
indent_size = 2
indent_style = space
insert_final_newline = true
charset = utf-8
182 changes: 91 additions & 91 deletions bin/asmfmt.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
use warnings;

sub nospace($) {
my ($s) = @_;
$s =~ s/\s//g;
return $s;
my ($s) = @_;
$s =~ s/\s//g;
return $s;
}

sub respace_comment($) {
my ($s) = @_;
$s =~ s/^(;+)\s+(.*)/$1 $2/g;
return $s;
my ($s) = @_;
$s =~ s/^(;+)\s+(.*)/$1 $2/g;
return $s;
}

sub max ($$) { $_[$_[0] < $_[1]] }
Expand All @@ -28,129 +28,129 @@ ($)
# TODO: sigils to disable/enable formatting around blocks

while (<STDIN>) {
chomp;
my $orig = $_;
$_ =~ s/^\s+|\s+$//g;
chomp;
my $orig = $_;
$_ =~ s/^\s+|\s+$//g;

if (m/^$/) {
# empty line - ignore
$tabstop = 0;
if (m/^$/) {
# empty line - ignore
$tabstop = 0;

} elsif (m/^(;;;.*)/) {
} elsif (m/^(;;;.*)/) {

# full line comment - flush left
$_ = respace_comment($1);
$tabstop = 0;
# full line comment - flush left
$_ = respace_comment($1);
$tabstop = 0;

} elsif (m/^(;;.*)/) {
} elsif (m/^(;;.*)/) {

# indented comment - one tab stop
$_ = (' ' x $tab) . respace_comment($1);
$tabstop = 0;
# indented comment - one tab stop
$_ = (' ' x $tab) . respace_comment($1);
$tabstop = 0;

} else {
} else {

my $comment = '';
if (m/^(.*?)(;.*)$/) {
$_ = $1;
$comment = respace_comment($2);
}
my $comment = '';
if (m/^(.*?)(;.*)$/) {
$_ = $1;
$comment = respace_comment($2);
}

if (m/^(\w+)\s*:=\s*(.*)$/) {
if (m/^(\w+)\s*:=\s*(.*)$/) {

# equate - flush left (!!), spaced out
my ($identifier, $expression) = ($1 // '', $2 // '', $3 // '');
# equate - flush left (!!), spaced out
my ($identifier, $expression) = ($1 // '', $2 // '', $3 // '');

$_ = '';
$_ .= $identifier . ' ';
$_ .= ' ' while length($_) % $tab;
$_ = '';
$_ .= $identifier . ' ';
$_ .= ' ' while length($_) % $tab;

$tabstop = max($tabstop, length($_));
$_ .= ' ' while length($_) < $tabstop;
$tabstop = max($tabstop, length($_));
$_ .= ' ' while length($_) < $tabstop;

$_ .= ':= ' . $expression . ' ';
$_ .= ':= ' . $expression . ' ';

} elsif (m/^(\w+)\s*=\s*(.*)$/) {
} elsif (m/^(\w+)\s*=\s*(.*)$/) {

# symbol - flush left (!!), spaced out
my ($identifier, $expression) = ($1 // '', $2 // '', $3 // '');
# symbol - flush left (!!), spaced out
my ($identifier, $expression) = ($1 // '', $2 // '', $3 // '');

$_ = '';
$_ .= $identifier . ' ';
$_ .= ' ' while length($_) % $tab;
$_ = '';
$_ .= $identifier . ' ';
$_ .= ' ' while length($_) % $tab;

$tabstop = max($tabstop, length($_));
$_ .= ' ' while length($_) < $tabstop;
$tabstop = max($tabstop, length($_));
$_ .= ' ' while length($_) < $tabstop;

$_ .= '= ' . $expression . ' ';
$_ .= '= ' . $expression . ' ';

} elsif (m/^(\.(?:end)?(?:proc|scope|macro|struct|enum|params)\b)\s*(.*)$/ ||
m/^(\b(?:END_)?(?:PROC_AT)\b)\s*(.*)$/) {
} elsif (m/^(\.(?:end)?(?:proc|scope|macro|struct|enum|params)\b)\s*(.*)$/ ||
m/^(\b(?:END_)?(?:PROC_AT)\b)\s*(.*)$/) {

# scope - flush left
my ($opcode, $arguments) = ($1 // '', $2 // '');
$tabstop = 0;
# scope - flush left
my ($opcode, $arguments) = ($1 // '', $2 // '');
$tabstop = 0;

$_ = $opcode . ' ' . $arguments;
$_ = $opcode . ' ' . $arguments;

} elsif (m/^(\.(?:if\w*|elseif|else|endif)\b)\s*(.*)$/) {
} elsif (m/^(\.(?:if\w*|elseif|else|endif)\b)\s*(.*)$/) {

# conditional - flush left
my ($opcode, $arguments) = ($1 // '', $2 // '');
$tabstop = 0;
# conditional - flush left
my ($opcode, $arguments) = ($1 // '', $2 // '');
$tabstop = 0;

$_ = $opcode . ' ' . $arguments;
$_ = $opcode . ' ' . $arguments;

} elsif (m/^(\b(?:IF_\w+|ELSE|END_IF|DO|WHILE_\w+)\b)\s*(.*)$/) {
} elsif (m/^(\b(?:IF_\w+|ELSE|END_IF|DO|WHILE_\w+)\b)\s*(.*)$/) {

# conditional macros - dynamic indent
my ($opcode, $arguments) = ($1 // '', $2 // '');
$tabstop = 0;
# conditional macros - dynamic indent
my ($opcode, $arguments) = ($1 // '', $2 // '');
$tabstop = 0;

if ($opcode =~ m/^(ELSE|END_IF|WHILE_\w+)$/) {
$flow_indent -= 2;
}
if ($opcode =~ m/^(ELSE|END_IF|WHILE_\w+)$/) {
$flow_indent -= 2;
}

$_ = ' ' x $flow_indent;
$_ .= $opcode . ' ' . $arguments;
$_ = ' ' x $flow_indent;
$_ .= $opcode . ' ' . $arguments;

if ($opcode =~ m/^(IF_\w+|ELSE|DO)$/) {
$flow_indent += 2;
}
if ($opcode =~ m/^(IF_\w+|ELSE|DO)$/) {
$flow_indent += 2;
}

} elsif (m/^(@?\w*:)?\s*(\S+)?\s*(.*?)\s*(;.*)?$/) {
} elsif (m/^(@?\w*:)?\s*(\S+)?\s*(.*?)\s*(;.*)?$/) {

# label / opcode / arguments / comment
my ($label, $opcode, $arguments, $comment) = ($1 // '', $2 // '', $3 // '', $4 // '');
# label / opcode / arguments / comment
my ($label, $opcode, $arguments, $comment) = ($1 // '', $2 // '', $3 // '', $4 // '');

$_ = '';
$_ .= $label . ' ';
$tabstop = 0 unless $label;
$_ = '';
$_ .= $label . ' ';
$tabstop = 0 unless $label;

$_ .= ' ' while length($_) % $tab;
$_ .= ' ' while length($_) % $tab;

$tabstop = max($tabstop, length($_));
$_ .= ' ' while length($_) < $tabstop;
$tabstop = max($tabstop, length($_));
$_ .= ' ' while length($_) < $tabstop;

$_ .= $opcode . ' ';
if ($opcode =~ m/^([a-z]{3}\w*)$|^(\.(byte|word|addr|res))$/) {
$_ .= ' ' while length($_) % $tab;
}
$_ .= $arguments . ' ';
$_ .= $opcode . ' ';
if ($opcode =~ m/^([a-z]{3}\w*)$|^(\.(byte|word|addr|res))$/) {
$_ .= ' ' while length($_) % $tab;
}
$_ .= $arguments . ' ';

} else {
die "Unexpected line: $_\n";
}
} else {
die "Unexpected line: $_\n";
}

if ($comment ) {
$_ .= ' ' while length($_) < $comment_column;
$_ .= $comment;
}
if ($comment ) {
$_ .= ' ' while length($_) < $comment_column;
$_ .= $comment;
}
}

$_ =~ s/\s+$//; # trim right
$_ =~ s/\s+$//; # trim right

die "Mismatch:\n> $orig\n<$_\n"unless nospace($_) eq nospace($orig);
die "Mismatch:\n> $orig\n<$_\n"unless nospace($_) eq nospace($orig);

print $_, "\n";
print $_, "\n";
}
10 changes: 5 additions & 5 deletions bin/build_fonts_from_latin1.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ ($)
open SRC, '<' . $src or die $!;
binmode(SRC);
sub getbyte {
my $b;
read(SRC, $b, 1);
return ord($b);
my $b;
read(SRC, $b, 1);
return ord($b);
}
my $type = getbyte();
die "Only type 0x00 supported\n" unless $type == 0x00;
Expand All @@ -51,11 +51,11 @@ sub getbyte {

my @chars;
for (my $i = 0; $i < $num; ++$i) {
$chars[$i] = [];
$chars[$i] = [];
}
my @widths;
for (my $i = 0; $i < $num; ++$i) {
push @widths, getbyte();
push @widths, getbyte();
}

for (my $row = 0; $row < $height; ++$row) {
Expand Down
Loading

0 comments on commit 393b2c2

Please sign in to comment.