mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-03-02 09:56:31 +00:00
ar: move --print-armap support code to archive library
This commit is contained in:
@@ -439,7 +439,7 @@ ar_print_armap(ArchiveFile) ->
|
||||
case archive:read(ArchiveFile) of
|
||||
{ok, {FP, Archive}} ->
|
||||
try
|
||||
ar_print_armap_1(Archive)
|
||||
archive:print_armap(Archive)
|
||||
after
|
||||
pdp10_stdio:fclose(FP)
|
||||
end;
|
||||
@@ -447,29 +447,6 @@ ar_print_armap(ArchiveFile) ->
|
||||
escript_runtime:fatal("failed to read ~s: ~p\n", [ArchiveFile, Reason])
|
||||
end.
|
||||
|
||||
ar_print_armap_1(Archive) ->
|
||||
#archive{symtab = SymTab, members = Members} = Archive,
|
||||
case SymTab of
|
||||
false ->
|
||||
io:format(standard_io, "No archive index\n", []);
|
||||
_ ->
|
||||
io:format(standard_io, "Archive index:\n", []),
|
||||
OffsetToNameMap =
|
||||
maps:from_list(
|
||||
lists:map(
|
||||
fun(#member{location = Offset, arhdr = #arhdr{ar_name = Name}}) ->
|
||||
{Offset, Name}
|
||||
end, Members)),
|
||||
lists:foreach(
|
||||
fun({Symbol, Offset}) ->
|
||||
ar_print_armap(Symbol, Offset, OffsetToNameMap)
|
||||
end, SymTab)
|
||||
end.
|
||||
|
||||
ar_print_armap(Symbol, Offset, OffsetToNameMap) ->
|
||||
Name = maps:get(Offset, OffsetToNameMap, "<unknown>"),
|
||||
io:format(standard_io, "~s in ~s at ~p\n", [Symbol, Name, Offset]).
|
||||
|
||||
%% labelled archives ===========================================================
|
||||
%%
|
||||
%% - members are ordered as stored in the archive
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
-export([ iocpy/4
|
||||
, new/0
|
||||
, print_armap/1
|
||||
, read/1
|
||||
, write/4
|
||||
]).
|
||||
@@ -38,6 +39,32 @@ new() ->
|
||||
{ok, Archive} = make_archive(_SymTab = [], _Members = []),
|
||||
Archive.
|
||||
|
||||
%% print the symbol table ======================================================
|
||||
|
||||
-spec print_armap(#archive{}) -> ok.
|
||||
print_armap(Archive) ->
|
||||
#archive{symtab = SymTab, members = Members} = Archive,
|
||||
case SymTab of
|
||||
false ->
|
||||
io:format(standard_io, "No archive index\n", []);
|
||||
_ ->
|
||||
io:format(standard_io, "Archive index:\n", []),
|
||||
OffsetToNameMap =
|
||||
maps:from_list(
|
||||
lists:map(
|
||||
fun(#member{location = Offset, arhdr = #arhdr{ar_name = Name}}) ->
|
||||
{Offset, Name}
|
||||
end, Members)),
|
||||
lists:foreach(
|
||||
fun({Symbol, Offset}) ->
|
||||
print_armap(Symbol, Offset, OffsetToNameMap)
|
||||
end, SymTab)
|
||||
end.
|
||||
|
||||
print_armap(Symbol, Offset, OffsetToNameMap) ->
|
||||
Name = maps:get(Offset, OffsetToNameMap, "<unknown>"),
|
||||
io:format(standard_io, "~s in ~s at ~p\n", [Symbol, Name, Offset]).
|
||||
|
||||
%% archive output ==============================================================
|
||||
|
||||
-spec write(boolean(), string(), file() | false, #archive{}) -> ok | {error, any()}.
|
||||
|
||||
Reference in New Issue
Block a user