From b09cdf23a91a8264db0a6df0e50d82edceb2c32e Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 30 Sep 2025 11:49:09 +0000 Subject: [PATCH] markdown-like git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@77 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 1 + tools/doc.pl | 282 +++++++++++++++++++++++++++------------------------ 2 files changed, 148 insertions(+), 135 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 69ea856..f931abd 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -63,6 +63,7 @@ examples: $(EXAMPLES) format: clang-format --verbose -i $(shell find src include examples tools -name "*.c" -or -name "*.h") + perltidy -b -bext='/' --paren-tightness=2 $(shell find tools -name "*.pl") src/libMw$(SO): $(L_OBJS) $(CC) $(L_LDFLAGS) -shared -o $@ $^ $(L_LIBS) diff --git a/tools/doc.pl b/tools/doc.pl index 9487f6c..ff4503f 100755 --- a/tools/doc.pl +++ b/tools/doc.pl @@ -1,165 +1,177 @@ #!/usr/bin/env perl # $Id$ -our $html = ""; -our $title = "Milsko GUI Toolkit Documentation"; +our $html = ""; +our $title = "Milsko GUI Toolkit Documentation"; our @pathlist = ("include"); -our @notes = ("warning", "unsure", "note"); +our @notes = ("warning", "unsure", "note"); sub sentence { - my $str = $_[0]; - $str =~ s/([^\.])$/\1./g; - $str =~ s/`([^`]+)`/\1<\/code>/g; - return $str; + my $str = $_[0]; + $str =~ s/([^\.])$/\1./g; + $str =~ s/`(.+?)`/\1<\/code>/g; + $str =~ s/\*\*\*(.+?)\*\*\*/\1<\/i><\/b>/g; + $str =~ s/\*\*(.+?)\*\*/\1<\/b>/g; + $str =~ s/\*(.+?)\*/\1<\/i>/g; + return $str; } sub out { - $html = $html . "$_[0]\n"; + $html = $html . "$_[0]\n"; } sub arguments { - my ($args) = @_; - my $out = ""; - my @arglist = split(/[ \t]*,[ \t]*/, $args); + my ($args) = @_; + my $out = ""; + my @arglist = split(/[ \t]*,[ \t]*/, $args); - $out = $out . " (\n"; - foreach my $str (@arglist){ - $out = $out . "\t$str"; - if($str eq $arglist[0+@arglist - 1]){ - $out = $out . "\n"; - }else{ - $out = $out . ",\n"; - } - } - $out = $out . ")"; + $out = $out . " (\n"; + foreach my $str (@arglist) { + $out = $out . "\t$str"; + if ($str eq $arglist[ 0 + @arglist - 1 ]) { + $out = $out . "\n"; + } + else { + $out = $out . ",\n"; + } + } + $out = $out . ")"; - return $out; + return $out; } sub scan_dir { - my ($first, $path) = @_; - $path =~ s/\/+$//g; + my ($first, $path) = @_; + $path =~ s/\/+$//g; - if(opendir(my $dh, $path)){ - print(STDERR "Scanning $path\n"); - my @paths = sort(readdir($dh)); - foreach my $p (@paths){ - if($p eq '.' || $p eq '..'){ - next; - } - scan_dir($first, $path . "/" . $p); - } - closedir($dh); - }else{ - my $spaces = ""; - my $in = 0; - my $out = 0; - my $file = 0; - my $has_file = 0; - my %kv = (); - my %param = (); - my @paramlist = (); + if (opendir(my $dh, $path)) { + print(STDERR "Scanning $path\n"); + my @paths = sort(readdir($dh)); + foreach my $p (@paths) { + if ($p eq '.' || $p eq '..') { + next; + } + scan_dir($first, $path . "/" . $p); + } + closedir($dh); + } + else { + my $spaces = ""; + my $in = 0; + my $out = 0; + my $file = 0; + my $has_file = 0; + my %kv = (); + my %param = (); + my @paramlist = (); - print(STDERR "$path is a file\n"); - open(IN, "<", "$path"); - while(my $l = ){ - my $l2 = $l; - $l =~ s/[\r\n]+$//g; + print(STDERR "$path is a file\n"); + open(IN, "<", "$path"); + while (my $l = ) { + my $l2 = $l; + $l =~ s/[\r\n]+$//g; - $l2 =~ s/[\r\n \t]+//g; - if(length($l2) == 0){ - next; - } + $l2 =~ s/[\r\n \t]+//g; + if (length($l2) == 0) { + next; + } - if($out){ - my $para = "p"; - my $brief = $kv{brief} or ""; + if ($out) { + my $para = "p"; + my $brief = $kv{brief} or ""; - $brief = sentence($brief); + $brief = sentence($brief); - $out = 0; - if(!$has_file){ - print(STDERR "Warning: missing comment with %file, ignoring\n"); - next; - } - if(!defined($kv{brief})){ - print(STDERR "Warning: comment missing %brief, ignoring\n"); - next; - } - if(!$file && defined($kv{brief})){ - $para = "dd"; + $out = 0; + if (!$has_file) { + print(STDERR + "Warning: missing comment with %file, ignoring\n"); + next; + } + if (!defined($kv{brief})) { + print(STDERR "Warning: comment missing %brief, ignoring\n"); + next; + } + if (!$file && defined($kv{brief})) { + $para = "dd"; - $l =~ s/[ \t]*\\$//g; - $l =~ s/[ \t]*(?:;|\{.+)[ \t]*$/;/g; - if(!($l =~ /^#/)){ - $l =~ s/\(([^\)]+)\)/arguments($1)/ge; - } + $l =~ s/[ \t]*\\$//g; + $l =~ s/[ \t]*(?:;|\{.+)[ \t]*$/;/g; + if (!($l =~ /^#/)) { + $l =~ s/\(([^\)]+)\)/arguments($1)/ge; + } - out("
$l
"); - } - out("<$para>"); - out(" $brief"); - out(""); + out("
$l
"); + } + out("<$para>"); + out(" $brief"); + out(""); - foreach my $note (@notes){ - if(defined($kv{$note})){ - out("
"); - out(" \"$note\""); - out("
"); - out("
"); - out(" " . sentence($kv{$note})); - out("
"); - } - } + foreach my $note (@notes) { + if (defined($kv{$note})) { + out("
"); + out(" \"$note\""); + out("
"); + out("
"); + out(" " . sentence($kv{$note})); + out("
"); + } + } - foreach my $p (@paramlist){ - out("
"); - out(" Parameter $p"); - out("
"); - out("
"); - out(" " . sentence($param{$p})); - out("
"); - } - - if(defined($kv{return})){ - out("
"); - out(" Returns"); - out("
"); - out("
"); - out(" " . sentence($kv{return})); - out("
"); - } - out("
"); - }elsif($l =~ /^([ \t]*)\/\*\!/){ - $spaces = $1; - $in = 1; - $file = 0; - %kv = (); - %param = (); - @paramlist = (); - }elsif($in && ($l =~ /^$spaces \*\//)){ - $in = 0; - $out = 1; - }elsif($in && ($l =~ /^$spaces \*[ \t]+%([^ ]+)(?:[ \t]+(.+))?$/)){ - $kv{$1} = $2; - if($1 eq "file"){ - if(!$has_file){ - out("

$2

"); - } + foreach my $p (@paramlist) { + out("
"); + out(" Parameter $p"); + out("
"); + out("
"); + out(" " . sentence($param{$p})); + out("
"); + } - $file = 1; - $has_file = 1; - }elsif($1 eq "param"){ - my $p = $2; - $p =~ /^([^ ]+)(?:[ \t]+(.+))?$/; + if (defined($kv{return})) { + out("
"); + out(" Returns"); + out("
"); + out("
"); + out(" " . sentence($kv{return})); + out("
"); + } + out("
"); + } + elsif ($l =~ /^([ \t]*)\/\*\!/) { + $spaces = $1; + $in = 1; + $file = 0; + %kv = (); + %param = (); + @paramlist = (); + } + elsif ($in && ($l =~ /^$spaces \*\//)) { + $in = 0; + $out = 1; + } + elsif ($in + && ($l =~ /^$spaces \*[ \t]+%([^ ]+)(?:[ \t]+(.+))?$/)) + { + $kv{$1} = $2; + if ($1 eq "file") { + if (!$has_file) { + out("

$2

"); + } - $param{$1} = $2; - push(@paramlist, $1); - } - } - } - close(IN); - } + $file = 1; + $has_file = 1; + } + elsif ($1 eq "param") { + my $p = $2; + $p =~ /^([^ ]+)(?:[ \t]+(.+))?$/; + + $param{$1} = $2; + push(@paramlist, $1); + } + } + } + close(IN); + } } out(""); @@ -171,8 +183,8 @@ out(" "); out("

$title

"); out("
"); -foreach my $f (@pathlist){ - scan_dir($f, $f); +foreach my $f (@pathlist) { + scan_dir($f, $f); } out(" ");