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


def prune_listing(listing: list, rules: list) -> list:
    def segment_fits(pattern: str, text: str) -> bool:
        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: str, what: str) -> list:
        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

    # Validate every rule and path with split_strict, then keep each
    # path the last matching rule allows; a path no rule matches survives.
    valid_listing = []
    valid_rules = []

    for path in listing:
        try:
            valid_listing.append(split_strict(path, "path"))
        except ValueError as e:
            print(f"Invalid path: {e}")

    for rule in rules:
        try:
            valid_rules.append(split_strict(rule, "rule"))
        except ValueError as e:
            print(f"Invalid rule: {e}")

    surviving_paths = []
    for path in valid_listing:
        last_matching_rule = None
        for rule in reversed(valid_rules):
            if segment_fits(rule, "/".join(path)):
                last_matching_rule = rule
                break
        if last_matching_rule is not None and last_matching_rule[0] != "!":
            surviving_paths.append("/".join(path))

    return surviving_paths
```