markdown-like

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@77 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-30 11:49:09 +00:00
parent 64534fe712
commit b09cdf23a9
2 changed files with 148 additions and 135 deletions

View File

@@ -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)

View File

@@ -9,7 +9,10 @@ our @notes = ("warning", "unsure", "note");
sub sentence {
my $str = $_[0];
$str =~ s/([^\.])$/\1./g;
$str =~ s/`([^`]+)`/<code>\1<\/code>/g;
$str =~ s/`(.+?)`/<code>\1<\/code>/g;
$str =~ s/\*\*\*(.+?)\*\*\*/<b><i>\1<\/i><\/b>/g;
$str =~ s/\*\*(.+?)\*\*/<b>\1<\/b>/g;
$str =~ s/\*(.+?)\*/<i>\1<\/i>/g;
return $str;
}
@@ -23,11 +26,12 @@ sub arguments {
my @arglist = split(/[ \t]*,[ \t]*/, $args);
$out = $out . " (\n";
foreach my $str (@arglist){
foreach my $str (@arglist) {
$out = $out . "\t$str";
if($str eq $arglist[0+@arglist - 1]){
if ($str eq $arglist[ 0 + @arglist - 1 ]) {
$out = $out . "\n";
}else{
}
else {
$out = $out . ",\n";
}
}
@@ -40,17 +44,18 @@ sub scan_dir {
my ($first, $path) = @_;
$path =~ s/\/+$//g;
if(opendir(my $dh, $path)){
if (opendir(my $dh, $path)) {
print(STDERR "Scanning $path\n");
my @paths = sort(readdir($dh));
foreach my $p (@paths){
if($p eq '.' || $p eq '..'){
foreach my $p (@paths) {
if ($p eq '.' || $p eq '..') {
next;
}
scan_dir($first, $path . "/" . $p);
}
closedir($dh);
}else{
}
else {
my $spaces = "";
my $in = 0;
my $out = 0;
@@ -62,36 +67,37 @@ sub scan_dir {
print(STDERR "$path is a file\n");
open(IN, "<", "$path");
while(my $l = <IN>){
while (my $l = <IN>) {
my $l2 = $l;
$l =~ s/[\r\n]+$//g;
$l2 =~ s/[\r\n \t]+//g;
if(length($l2) == 0){
if (length($l2) == 0) {
next;
}
if($out){
if ($out) {
my $para = "p";
my $brief = $kv{brief} or "";
$brief = sentence($brief);
$out = 0;
if(!$has_file){
print(STDERR "Warning: missing comment with %file, ignoring\n");
if (!$has_file) {
print(STDERR
"Warning: missing comment with %file, ignoring\n");
next;
}
if(!defined($kv{brief})){
if (!defined($kv{brief})) {
print(STDERR "Warning: comment missing %brief, ignoring\n");
next;
}
if(!$file && defined($kv{brief})){
if (!$file && defined($kv{brief})) {
$para = "dd";
$l =~ s/[ \t]*\\$//g;
$l =~ s/[ \t]*(?:;|\{.+)[ \t]*$/;/g;
if(!($l =~ /^#/)){
if (!($l =~ /^#/)) {
$l =~ s/\(([^\)]+)\)/arguments($1)/ge;
}
@@ -101,8 +107,8 @@ sub scan_dir {
out(" $brief");
out("</$para>");
foreach my $note (@notes){
if(defined($kv{$note})){
foreach my $note (@notes) {
if (defined($kv{$note})) {
out("<dt>");
out(" <img src=\"$note.gif\" alt=\"$note\">");
out("</dt>");
@@ -112,7 +118,7 @@ sub scan_dir {
}
}
foreach my $p (@paramlist){
foreach my $p (@paramlist) {
out("<dt>");
out(" Parameter <code>$p</code>");
out("</dt>");
@@ -121,7 +127,7 @@ sub scan_dir {
out("</dd>");
}
if(defined($kv{return})){
if (defined($kv{return})) {
out("<dt>");
out(" Returns");
out("</dt>");
@@ -130,26 +136,32 @@ sub scan_dir {
out("</dd>");
}
out("<hr>");
}elsif($l =~ /^([ \t]*)\/\*\!/){
}
elsif ($l =~ /^([ \t]*)\/\*\!/) {
$spaces = $1;
$in = 1;
$file = 0;
%kv = ();
%param = ();
@paramlist = ();
}elsif($in && ($l =~ /^$spaces \*\//)){
}
elsif ($in && ($l =~ /^$spaces \*\//)) {
$in = 0;
$out = 1;
}elsif($in && ($l =~ /^$spaces \*[ \t]+%([^ ]+)(?:[ \t]+(.+))?$/)){
}
elsif ($in
&& ($l =~ /^$spaces \*[ \t]+%([^ ]+)(?:[ \t]+(.+))?$/))
{
$kv{$1} = $2;
if($1 eq "file"){
if(!$has_file){
if ($1 eq "file") {
if (!$has_file) {
out("<h2 align=\"center\">$2</h2>");
}
$file = 1;
$has_file = 1;
}elsif($1 eq "param"){
}
elsif ($1 eq "param") {
my $p = $2;
$p =~ /^([^ ]+)(?:[ \t]+(.+))?$/;
@@ -171,7 +183,7 @@ out(" <body>");
out(" <h1 align=\"center\">$title</h1>");
out(" <hr>");
foreach my $f (@pathlist){
foreach my $f (@pathlist) {
scan_dir($f, $f);
}