```python
"""Prune a file listing with ordered drop and keep rules."""


def prune_listing(listing: list, rules: list) -> list:
    def segment_fits(pattern, text):
        p = t = mark = 0
        star = -1
        while t < len(text):
            if p < len(pattern) and pattern[p] == "*":
                star = p
                mark = t
                p += 1
            elif p < len(pattern) and pattern[p] == text[t]:
                p += 1
                t += 1
            elif star >= 0:
                p = star + 1
                mark += 1
                t = mark
            else:
                return False
        while p < len(pattern) and pattern[p] == "*":
            p += 1
        return p == len(pattern)

    def split_strict(text, what):
        if not isinstance(text, str) or text == "":
            raise ValueError(f"{what} must be a non-empty string")
        segments = text.split("/")
        if any(segment == "" for segment in segments):
            raise ValueError(f"{what} has an empty segment: {text}")
        return segments

    def is_valid_rule(rule):
        if not isinstance(rule, str) or rule == "":
            raise ValueError("Rule must be a non-empty string")
        if rule.startswith("!"):
            rule = rule[1:]
        if "*" in rule:
            segments = split_strict(rule, "rule")
        else:
            segments = [rule]
        return all(segment != "" for segment in segments)

    def is_valid_path(path):
        if not isinstance(path, str) or path == "":
            raise ValueError("Path must be a non-empty string")
        segments = split_strict(path, "path")
        return all(segment != "" for segment in segments)

    listing = [is_valid_path(path) for path in listing]
    rules = [is_valid_rule(rule) for rule in rules]

    result = []
    for path in listing:
        match = None
        for rule in reversed(rules):
            if rule.startswith("!"):
                keep = True
                rule = rule[1:]
            else:
                keep = False
            segments = split_strict(rule, "rule")
            path_segments = split_strict(path, "path")
            if len(segments) > len(path_segments):
                continue
            if all(segment_fits(seg, path_seg) for seg, path_seg in zip(segments, path_segments)):
                match = keep
        if match is None or match:
            result.append(path)

    return result
```