ocl: add try-catch for OpenCL device getter
[profile/ivi/opencv.git] / doc / reformat.py
1 #!/usr/bin/env python
2
3 import os, sys, re
4
5 finput=open(sys.argv[1], "rt")
6
7 # read the whole file content to s
8 s = "".join(finput.readlines())
9 finput.close()
10
11 # normalize line endings
12 s = re.sub(r"\r\n", "\n", s)
13
14 # remove trailing whitespaces
15 s = re.sub(r"[ \t]+\n", "\n", s)
16
17 # compress multiple empty lines
18 for i in range(5):
19     s = re.sub(r"\n\n\n", "\n\n", s)
20
21 # remove empty line before ".." that terminates a code block
22 s = re.sub(r"\n\n\.\.\n", "\n..\n", s)
23
24 # move :: starting a code block to the end of previous line
25 s = re.sub(r"\n\n::\n", " ::\n", s)
26
27 # remove extra line breaks before/after _ or ,
28 s = re.sub(r"\n[ \t]*([_,])\n", r"\1", s)
29
30 # remove extra line breaks after `
31 s = re.sub(r"`\n", "` ", s)
32
33 # remove extra line breaks before `
34 s = re.sub(r"\n[ \t]*`", " `", s)
35
36 # remove links to wiki
37 s = re.sub(r"\n[ \t]*`id=\d[^`]+`__\n", "", s)
38
39 # remove trailing whitespaces one more time
40 s = re.sub(r"[ \t]+\n", "\n", s)
41
42 foutput=open(sys.argv[2], "wt")
43 foutput.write(s)
44 foutput.close()