"""Q14: the club URL format strings and their builders.

Q6 found 'type=%s' at 0x180224c7a and 0x180224ff9 with no direct xref, which means
each is the TAIL of a longer literal whose start is what the code references. Dump
every C string in 0x180224a00..0x180225300 and 0x18021e200..0x18021e800 with xrefs,
so the club request builder can be identified and decompiled.

Also dump 0x180228400..0x18022b200 for the transfermarket/club parameter strings.

CONTROL: '&cat=%s' at 0x1802285b8 is already known to be referenced by
FUN_180162c90; it must show that xref here too.
"""
import traceback


def dump(lo, hi, tag):
    print("=== %s %#x..%#x ===" % (tag, lo, hi))
    p = lo
    while p < hi:
        try:
            b = mem.getByte(addr(p)) & 0xFF
        except Exception:
            p += 1
            continue
        if 0x20 <= b < 0x7F:
            s = rd_str(p, 160)
            if len(s) >= 3:
                who = ",".join(sorted({"%s(%#x)" % (fn, ent)
                                       for _f, _t, fn, ent in xrefs_to(p)}))
                print("  %#x %-66r %s" % (p, s, who))
            p += max(1, len(s)) + 1
        else:
            p += 1


try:
    dump(0x180224A00, 0x180225300, "club/url block")
    dump(0x18021E200, 0x18021E800, "route table")
    dump(0x180228400, 0x180229000, "params block")
except Exception:
    traceback.print_exc()
