```ts

/** Prune a file listing with ordered drop and keep rules. */

function segmentFits(pattern: string, text: string): boolean {
  let p = 0;
  let t = 0;
  let star = -1;
  let mark = 0;
  while (t < text.length) {
    if (p < pattern.length && pattern[p] === "*") {
      star = p;
      mark = t;
      p += 1;
    } else if (p < pattern.length && pattern[p] === text[t]) {
      p += 1;
      t += 1;
    } else if (star >= 0) {
      p = star + 1;
      mark += 1;
      t = mark;
    } else {
      return false;
    }
  }
  while (p < pattern.length && pattern[p] === "*") {
    p += 1;
  }
  return p === pattern.length;
}

function splitStrict(text: string, what: string): string[] {
  if (typeof text !== "string" || text === "") {
    throw new Error(`${what} must be a non-empty string`);
  }
  const segments = text.split("/");
  if (segments.some((segment) => segment === "")) {
    throw new Error(`${what} has an empty segment: ${text}`);
  }
  return segments;
}

export function pruneListing(listing: string[], rules: string[]): string[] {
  for (const rule of rules) {
    if (rule === "") throw new Error("rules must be non-empty strings");
    if (!segmentFits(rule, "")) throw new Error("rules may not hold an empty segment left by a leading, trailing or doubled slash");
  }
  for (const path of listing) {
    if (path === "" || !splitStrict(path, "paths").every((segment) => segment !== "")) throw new Error("paths must be non-empty strings with no bare slashes");
  }

  return listing.filter((path) => {
    let keep = false;
    for (const rule of rules) {
      const negate = rule.startsWith("!");
      const pattern = negate ? rule.slice(1) : rule;
      if (segmentFits(pattern, path)) {
        keep = !negate;
        break;
      }
    }
    return keep;
  });
}
```