xref: /petsc/lib/petsc/bin/extract.py (revision f748bf6bfc83f133d5068e6a5445afd45844ada1)
1#!/usr/bin/env python3
2
3import sys
4import re
5import codecs
6import os
7import subprocess
8
9encoding = 'utf8'
10
11def comment_finder(text):
12    pattern = re.compile( r'//.*?$|/\*.*?\*/', re.DOTALL | re.MULTILINE)
13    result = pattern.findall(text)
14    return result
15
16def print_command(filename):
17    codefile = codecs.open(filename, 'r', encoding)
18    lines = codefile.read()
19    codefile.close()
20    list_of_comments = comment_finder(lines)
21    for comment in list_of_comments:
22        if comment[0:2] == "//":
23                comment_to_write = comment[2:]
24        else:
25            comment_to_write = comment[2:-2]
26        if comment_to_write.endswith("\r"):
27            comment_to_write = comment_to_write[0:-1]
28        if len(comment_to_write) != 0:
29            print(comment_to_write)
30
31if __name__ == "__main__":
32    root = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).splitlines()
33    files = subprocess.check_output(["git", "ls-files", "--full-name", "../../.."]).splitlines()
34    for name in files:
35        decoded = os.path.join(root[0].decode("utf-8"), name.decode("utf-8"))
36        if decoded.endswith(('.c', '.h', '.cxx')):
37            print_command(decoded)
38