Last active
November 9, 2023 01:45
-
-
Save evnu/f1da2ae067423bbe760a28936deee716 to your computer and use it in GitHub Desktop.
Find all documented Erlang NIF functions and when they were introduced
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/escript | |
%%% | |
%%% Output NIF functions and since when they are supported | |
%%% | |
%%% Usage: | |
%%% | |
%%% Run `funcs.escript` without any arguments to output all NIF functions. | |
%%% To filter NIFs by a specific version of OTP, use `funcs.escript <version>`, | |
%%% where matching versions must have the same prefix as the one supplied on | |
%%% the command line. | |
%%% | |
-include_lib("xmerl/include/xmerl.hrl"). | |
main(Args) -> | |
FetchPaths = filelib:wildcard("lib/erl_docgen/priv/*"), | |
{ParseResult, _} = xmerl_scan:file("erts/doc/src/erl_nif.xml", [{fetch_path, FetchPaths}]), | |
Funcs = xmerl_xpath:string("/cref/funcs/func/name", ParseResult), | |
Pairs = [ | |
begin | |
Inner = Func#xmlElement.content, | |
[NameText] = [ NameText || NameText = #xmlElement{name = nametext} <- Inner ], | |
[Name] = [ prettify_name(Name#xmlText.value) || Name = #xmlText{} <- NameText#xmlElement.content ], | |
[Since] = [ prettify_since(Attr#xmlAttribute.value) || Attr = #xmlAttribute{} <- Func#xmlElement.attributes ], | |
{Since, Name} | |
end | |
|| Func <- Funcs | |
], | |
FilteredPairs = case Args of | |
[] -> Pairs; | |
[VersionPrefix] -> filter(Pairs, VersionPrefix) | |
end, | |
output(FilteredPairs). | |
prettify_name(Str) -> | |
[Name | _] = string:tokens(Str, "("), | |
Name. | |
prettify_since("") -> "UNKNOWN "; | |
prettify_since(Since) -> Since. | |
filter(Pairs, VersionPrefix) -> | |
[ | |
{Since, Name} || {Since, Name} <- Pairs, string:find(Since, VersionPrefix) /= nomatch | |
]. | |
output(Pairs) -> | |
[ | |
io:format("~10.s ~20.s ~s~n", [Since, Name, url(Name)]) || {Since, Name} <- Pairs | |
]. | |
url(Name) -> | |
io_lib:format("http://erlang.org/doc/man/erl_nif.html#~s", [Name]). | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment