Skip to content

Commit

Permalink
mandb: support the formats of the man pages of "awk" and "sed"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 6, 2021
1 parent 231dc39 commit 6932018
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -131,6 +131,7 @@
- mandb: fix an infinite loop by a leak variable (reported by rlanore, riblo) `#D1550` 0efcb65
- mandb: work around old groff in macOS (reported by killermoehre) `#D1551` d4f816b
- mandb: use `manpath` and `man -w`, and read `/etc/man_db.conf` and `~/.manpath` `#D1637` 2365e09
- mandb: support the formats of the man pages of `awk` and `sed` (reported by bbyfacekiller) `#D1687` 0000000
- edit: work around the wrong job information of Bash in trap handlers (reported by 3ximus) `#D1435` `#D1436` bc4735e
- edit (command-help): work around the Bash bug that tempenv vanishes with `builtin eval` `#D1438` 8379d4a
- global: suppress missing locale errors (reported by 3ximus) `#D1440` 4d3c595
Expand Down
73 changes: 54 additions & 19 deletions lib/core-complete.sh
Expand Up @@ -3379,48 +3379,83 @@ function ble/complete/mandb/.generate-cache {
g_desc = "";
}
mode == "key1" {
register_key($0);
mode = "desc";
# Comment: [.ig \n comments \n ..]
/^\.ig/ { mode = "ignore"; next; }
mode == "ignore" {
if (/^\.\.[[:space:]]*/) mode = "none";
next;
}
mode == "keyc" {
g_current_key = g_current_key "\n" $0;
if (/^\.Xc/) {
register_key(g_current_key);
mode = "desc";
}
next;
}
/^\.(S[Ss]|S[Hh]|P[Pp])([^_[:alnum:]]|$)/ { flush_topic(); next; }
type == "man" && /^\.TP([^_[:alnum:]]|$)/ {
#--------------------------------------------------------------------------
# Format #3: [.HP \n keys \n .IP \n desc]
# GNU sed seems to use this format.
/^\.HP[[:space:]]*$/ {
if (g_keys_count && g_desc != "") flush_topic();
mode = "key1";
mode = "fmt3_key";
}
mode == "fmt3_key" {
if (/^\.TP[[:space:]]*/) { flush_topic(); mode = "none"; next; }
if (/^\.PD([^_[:alnum:]]|$)/) next;
if (/^\.IP/) { mode = "fmt3_desc"; next; }
register_key($0);
next;
}
mode == "fmt3_desc" {
if (/^\.TP[[:space:]]*/) { flush_topic(); mode = "none"; next; }
if (/^\.PD([^_[:alnum:]]|$)/) next;
#% # mdoc でも man でもあった
if (g_desc != "") g_desc = g_desc "\n";
g_desc = g_desc $0;
next;
}
#--------------------------------------------------------------------------
# Format #2: [.It Fl key \n desc] or [.It Fl Xo \n key \n .Xc desc]
# This form was found in both "mdoc" and "man"
/^\.It Fl([^_[:alnum:]]|$)/ {
if (g_keys_count && g_desc != "") flush_topic();
sub(/^\.It Fl/, ".Fl");
if ($0 ~ / Xo$/) {
g_current_key = $0;
mode = "keyc"
mode = "fmt2_keyc"
} else {
register_key($0);
mode = "desc";
}
next;
}
/^\.(S[Ss]|S[Hh]|P[Pp])([^_[:alnum:]]|$)/ { flush_topic(); next; }
/^\.PD([^_[:alnum:]]|$)/ { next; }
mode == "fmt2_keyc" {
if (/^\.PD[[:space:]]*([0-9]+[[:space:]]*)?$/) next;
g_current_key = g_current_key "\n" $0;
if (/^\.Xc/) {
register_key(g_current_key);
mode = "desc";
}
next;
}
#--------------------------------------------------------------------------
# Format #1: [.TP \n key \n desc]
# This is the typical format in "man".
type == "man" && /^\.TP([^_[:alnum:]]|$)/ {
if (g_keys_count && g_desc != "") flush_topic();
mode = "key1";
next;
}
mode == "key1" {
if (/^\.PD[[:space:]]*([0-9]+[[:space:]]*)?$/) next;
register_key($0);
mode = "desc";
next;
}
mode == "desc" {
if (/^\.PD([^_[:alnum:]]|$)/) next;
if (g_desc != "") g_desc = g_desc "\n";
g_desc = g_desc $0;
}
#--------------------------------------------------------------------------
END { flush_topic(); }
' | ble/complete/mandb/convert-mandoc 2>/dev/null | ble/bin/awk '
Expand Down
15 changes: 14 additions & 1 deletion note.txt
Expand Up @@ -1599,12 +1599,15 @@ bash_tips
* return without arguments in trap handlers. これは結局強い理由がないと変更さ
れない雰囲気になっている。


@todo
*******************************************************************************
ToDo
-------------------------------------------------------------------------------

2021-12-06

* mandb: 空文字列の時にも mandb に基づくオプション生成を実行するべき

2021-11-23

* kitty shell-integration (requested by kovidgoyal)
Expand Down Expand Up @@ -5541,6 +5544,16 @@ bash_tips

2021-12-06

* mandb: awk, sed の man ページからの抽出に失敗している (reported by bbyfacekiller) [#D1687]
https://github.com/akinomyoga/ble.sh/issues/152

当初は bash-completion との integration の問題かとも思ったが、それ以前に
mandb での抽出に於いて awk, sed でそれぞれ異なる形で失敗していた。両方につ
いて対応した。

更に、awk の man page の中にある ".ig ... .." はコメントセクションの様だ。
古いオプションや文章が含まれているらしい。

* 2021-09-06 menu: fish の様に twocolumn 形式で表示する desc を作っても良いのではないか (motivated by Shahabaz-Bagwan) [#D1686]
https://www.youtube.com/watch?v=YS1vxEhd2Pc
https://github.com/akinomyoga/ble.sh/issues/132
Expand Down

0 comments on commit 6932018

Please sign in to comment.