Search one manpage for tokens in the attributes table.
(manpage)
| 49 | |
| 50 | |
| 51 | def man_search(manpage): |
| 52 | """Search one manpage for tokens in the attributes table.""" |
| 53 | vprint(1, '-- %s --' % (manpage)) |
| 54 | |
| 55 | try: |
| 56 | if manpage.endswith('.gz'): |
| 57 | MANPAGE = gzip.open(manpage, 'r') |
| 58 | else: |
| 59 | MANPAGE = open(manpage, 'r') |
| 60 | except OSError as filename: |
| 61 | print('cannot open %s' % filename, file=sys.stderr) |
| 62 | return # None, None |
| 63 | |
| 64 | vprint(1, '%s opened' % (manpage)) |
| 65 | |
| 66 | TSmatch = None |
| 67 | for lineread in MANPAGE: |
| 68 | vprint(4, 'type %s', type(lineread)) |
| 69 | lineread = str(lineread) |
| 70 | vprint(3, '--%s' % lineread) |
| 71 | # TSmatch = lineread.startswith('.TS') |
| 72 | TSmatch = re.search('\\.TS', lineread) |
| 73 | if TSmatch: |
| 74 | dprint(1, '%s:\treached .TS' % (manpage)) |
| 75 | break |
| 76 | |
| 77 | # dprint(2, '%s', lineread) |
| 78 | |
| 79 | if not TSmatch: |
| 80 | dprint(1, '.TS not found in %s' % manpage) |
| 81 | return # None, None |
| 82 | |
| 83 | vprint(1, 'Started reading the attribute table') |
| 84 | |
| 85 | apis = set() |
| 86 | for lineread in MANPAGE: |
| 87 | lineread = str(lineread) |
| 88 | dprint(2, '%s' % (lineread)) |
| 89 | if 'MT-Safe' in lineread: |
| 90 | vprint(1, 'clearing MT-Safe %s', lineread) |
| 91 | apis.clear() |
| 92 | |
| 93 | res = re.search(r'\.BR\s+(\w+)\s', lineread) |
| 94 | # vprint(1, '%s for %s' % (res, lineread)) |
| 95 | if res: |
| 96 | apis.add(res.group(1)) |
| 97 | dprint(1, 'found api %s in %s' % (res.group(1), lineread)) |
| 98 | continue |
| 99 | |
| 100 | if 'MT-Unsafe' in lineread: |
| 101 | resUnsafe = re.search("MT-Unsafe\\s+(.*)(\\n\'|$)", lineread) |
| 102 | |
| 103 | if resUnsafe: |
| 104 | values = resUnsafe.group(1) |
| 105 | dprint(1, 'a %s' % values) |
| 106 | values = re.sub(r'\\n\'$', '', values) |
| 107 | # |
| 108 | values = values.split(' ') |