import sys, zipfile, re
for path in sys.argv[1:]:
    z = zipfile.ZipFile(path)
    names = z.namelist()
    settings = z.read('word/settings.xml').decode() if 'word/settings.xml' in names else ''
    doc = z.read('word/document.xml').decode()
    upd = 'updateFields w:val="true"' in settings or 'updateFields w:val="1"' in settings or ('<w:updateFields' in settings and 'false' not in settings.split('<w:updateFields')[1][:40])
    sdt = 'docPartGallery w:val="Table of Contents"' in doc
    # cached TOC content: text between the TOC instrText's separate and end fldChar
    m = re.search(r'instrText[^>]*>\s*TOC[^<]*<.*?fldCharType="separate"/>(.*?)fldCharType="end"', doc, re.S)
    cached = re.sub(r'<[^>]+>', '', m.group(1)) if m else None
    if cached is not None: cached = cached.strip()[:120]
    m2 = re.findall(r'<w:instrText[^>]*>([^<]*TOC[^<]*)<', doc)
    styles = z.read('word/styles.xml').decode() if 'word/styles.xml' in names else ''
    has_heading1 = 'w:styleId="Heading1"' in styles
    title_style = 'w:styleId="Title"' in styles
    print(f"{path}: updateFields={upd} sdtTOC={sdt} tocInstr={m2[:1]} cached={cached!r} Heading1style={has_heading1}")
