Skip to content

Commit

Permalink
bplist: Harmonize ns_keyed_archive jq style a bit
Browse files Browse the repository at this point in the history
Let root arg be a lambda so torepr can be done once
  • Loading branch information
wader committed Dec 19, 2022
1 parent 6f354bb commit 8f39ef6
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions format/apple/bplist/ns_keyed_archiver.jq
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
def from_ns_keyed_archiver($root):
if _exttype == "decode_value" and format == "bplist" then _bplist_torepr end
| (
. as {
"$objects": $objects
}
def from_ns_keyed_archiver(root):
( if _is_decode_value and format == "bplist" then _bplist_torepr end
| ."$objects" as $objects
| def _f($id; $seen_ids):
def _r($id):
if $seen_ids | has("\($id)") then "cycle-\($id)"
else _f($id; $seen_ids | ."\($id)" = true)
end;
( $objects[$id]
| type as $type |
if $type == "string" and . == "$null" then null
( def _r($id):
if $seen_ids | has("\($id)") then "cycle-\($id)"
else _f($id; $seen_ids | ."\($id)" = true)
end;
$objects[$id]
| type as $type
| if $type == "string" and . == "$null" then null
elif $type |
. == "number"
or . == "boolean"
Expand All @@ -22,9 +19,9 @@ def from_ns_keyed_archiver($root):
( ."$class" as $class
| if $class == null then # TODO: what case is this?
with_entries(
if (.value | type == "object")
and (.value | has("cfuid"))
then .value |= _r(.cfuid) end
if .value | type == "object" and has("cfuid") then
.value |= _r(.cfuid)
end
)
else
( $objects[$class.cfuid]."$classname" as $cname
Expand Down Expand Up @@ -52,22 +49,22 @@ def from_ns_keyed_archiver($root):
elif $cname == "NSUUID" then ."NS.uuidbytes"
else
# replace class ID with classname, and dereference all cfuid values.
."$class" = $cname |
with_entries(
if (.value | type == "object")
and (.value | has("cfuid"))
then .value |= _r(.cfuid) end
( ."$class" = $cname
| with_entries(
if .value | type == "object" and has("cfuid") then
.value |= _r(.cfuid)
end
)
)
end
)
end
)
end
);
def _f($id): _f($id; {"\($id)": true});
_f($root)
root as $root
| _f($root; {"\($root)": true})
);

def from_ns_keyed_archiver:
if _exttype == "decode_value" and format == "bplist" then _bplist_torepr end
| from_ns_keyed_archiver(."$top"?.root?.cfuid // error("root node not found, must specify root ID"));
from_ns_keyed_archiver(."$top"?.root?.cfuid // error("root node not found, must specify root ID"));

0 comments on commit 8f39ef6

Please sign in to comment.