+ $demo .= $chr;
+ }
+ @demo = reverse $demo =~ m{.{1,$democols}}go;
+}
+
+parsefont();
+
+our $do_git; # contains may chars 'c' (count) and/or 'o' (object)
+our $do_git_untracked = 1;
+our $argcounter;
+
+our @forms;
+
+sub rjustt ($$;$) { # right justify and truncate (ie, pad and truncate at left)
+ # always includes prefix
+ my ($sz, $whole, $prefix) = @_;
+ $prefix //= '';
+ my $lw = length $whole;
+ my $spare = $sz - $lw - (length $prefix);
+ return
+ ($spare > 0 ? (' ' x $spare) : '').
+ $prefix.
+ substr($whole, ($spare < 0 ? -$spare : 0));
+}
+
+sub ljustt ($$;$) {
+ my ($sz, $whole, $suffix) = @_;
+ $suffix //= '';
+ $sz -= length $suffix;
+ return sprintf "%-${sz}.${sz}s%s", $whole, $suffix;
+}
+
+sub genform ($@) {
+ my ($form, @lines) = @_;
+ gentextmodule($form, @lines);
+ my $f = {
+ Form => $form,
+ Chars => (length join '', @lines),
+ Lines => (scalar @lines),
+ Ambiguous => ($form =~ m/Full/ && !grep { m/\W/ } @lines),
+ };
+ push @forms, $f;
+}
+
+sub genform_q ($$$) {
+ my ($form, $s, $lines) = @_;
+ $gtm_demo_j++;
+ my $l = length $s;
+ return if $l % $lines;
+ my $e = $l/$lines;
+ return if $e < 2;
+ $gtm_demo_j--;
+ genform($form, $s =~ m/.{$e}/g);
+}
+
+sub genform_plusq ($$) {
+ my ($form, $s) = @_;
+ genform($form, $s);
+ genform_q("${form}S", $s, 2);
+ genform_q("${form}T", $s, 3);
+}
+
+our @gcmd;
+
+sub gitrun_start () {
+ open F, "-|", @gcmd or die "$gcmd[0]: start: $!";
+}
+
+sub gitrun_done (;$) {
+ my ($errok) = @_;
+ $?=0; $!=0;
+ return if close F;
+ return if $errok;
+ die $! if $!;
+ die "@gcmd failed ($?)\n";
+}
+
+sub gitoutput (@) {
+ (@gcmd) = (qw(git), @_);
+ gitrun_start;
+ $_ = <F>;
+ gitrun_done;
+ defined or die "@gcmd produced no output";
+ chomp or die "@gcmd produced no final newline";
+ $_;
+}
+
+sub do_git () {
+ return unless $do_git;
+
+ @gcmd = qw(git status --porcelain);
+ push @gcmd, qw(--untracked=no) unless $do_git_untracked;
+
+ my $git_dirty = '';
+ gitrun_start;
+ while (<F>) {
+ if (m/^\?\?/ && $do_git_untracked) {
+ $git_dirty = '+';
+ next;
+ }
+ $git_dirty = '*';
+ last;
+ }
+ gitrun_done($git_dirty eq '*');
+
+ my $git_count;
+ my $git_object;
+
+ if ($do_git =~ m/c/) {
+ $git_count = gitoutput qw(rev-list --first-parent --count HEAD);
+ }
+ if ($do_git =~ m/o/) {
+ $git_object = gitoutput qw(rev-parse HEAD);
+ }
+
+ foreach my $sz (2..10) {
+ gentextmodule_demo_start_batch();
+
+ genform_plusq("Small$sz", rjustt($sz, $git_count, $git_dirty))
+ if defined $git_count;
+
+ genform_plusq("Git$sz", ljustt($sz, $git_object, $git_dirty))
+ if defined $git_object;
+
+ if (defined $git_count && defined $git_object) {
+ genform("Full".($sz*2),
+ ljustt($sz, $git_object),
+ rjustt($sz, $git_count, $git_dirty));
+
+ my $e = $sz;
+ genform("Full".($e*3)."T",
+ ljustt($e*2, $git_object, $git_dirty)
+ =~ m/.{$e}/g,
+ rjustt($e, $git_count));
+ }
+ }
+}
+
+sub do_some_best ($$) {
+ my ($modname, $formre) = @_;
+ p "module Commitid_$modname(max_sz) {\n";
+ foreach my $f (
+ sort {
+ $b->{Chars} <=> $a->{Chars} or
+ $a->{Lines} <=> $b->{Chars}
+ }
+ grep {
+ $_->{Form} =~ m/$formre/ &&
+ !$_->{Ambiguous}
+ }
+ @forms
+ ) {
+ p "// $f->{Form}\n";