#!/usr/local/bin/python # -*- coding: KOI8-R -*- import sys sections = [ '00', 'NAME', 'НАЗВАНИЕ', 'LIBRARY', 'БИБЛИОТЕКА', 'SYNOPSIS', 'СИНТАКСИС', 'DESCRIPTION', 'ОПИСАНИЕ', 'IMPLEMENTATION NOTES', 'ОСОБЕННОСТИ РЕАЛИЗАЦИИ', 'RETURN VALUES', 'ВОЗВРАЩАЕМЫЕ ЗНАЧЕНИЯ', 'ENVIRONMENT', 'ОКРУЖЕНИЕ', 'FILES', 'ФАЙЛЫ', 'EXIT STATUS', 'СТАТУС ЗАВЕРШЕНИЯ', 'EXAMPLES', 'ПРИМЕРЫ', 'DIAGNOSTICS', 'ДИАГНОСТИКА', 'COMPATIBILITY', 'СОВМЕСТИМОСТЬ', 'ERRORS', 'ОШИБКИ', 'SEE ALSO', 'СМОТРИ ТАКЖЕ', 'STANDARDS', 'СТАНДАРТЫ', 'HISTORY', 'ИСТОРИЯ', 'AUTHORS', 'АВТОРЫ', 'BUGS', 'ПРОБЛЕМЫ', ] def check_sections(manpage): lines = {} section = '00' last_idx = 0 lineno = 0 for line in file(manpage): lineno += 1 words = line.split() if len(words) > 0 and words[0] == '.Sh': sname = ' '.join(words[1:]) if (sname in sections): idx = sections.index(sname) if (idx < last_idx): warn("%s:%d: %s comes before %s" % (manpage, lineno, sname, sections[last_idx])) last_idx = idx section = sname if section not in lines: lines[section] = [] lines[section].append(line) for section in sections: if section in lines: for line in lines[section]: print line, def warn(msg): sys.stderr.write(msg + '\n') def main(): if len(sys.argv) > 1: for file in sys.argv[1:]: check_sections(file) else: check_sections("/dev/stdin") main()