-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfixHeader.py
114 lines (101 loc) · 4.94 KB
/
fixHeader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# ---------------------------------------------------------------------------
# Copyright (C) 2020-2030, [email protected]
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and / or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions :
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# ---------------------------------------------------------------------------
import GPS
from os.path import *
import string
HEADER = \
"""##############################################################################
## MIT License ##
## 0MQ Ada-binding ##
%(name)s
## ##
%(ext)s
## ##
## Copyright (c) 2021 [email protected] ##
## ##
## Permission is hereby granted, free of charge, to any person obtaining a ##
## copy of this software and associated documentation files ##
## (the "Software"), to deal in the Software without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of the Software, and to ##
## permit persons to whom the Software is furnished to do so, subject to ##
## the following conditions: ##
## ##
## The above copyright notice and this permission notice shall be included ##
## in all copies or substantial portions of the Software. ##
## ##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ##
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ##
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ##
## IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY ##
## CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ##
## TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ##
## SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ##
##############################################################################
"""
def to80Comment(s):
if len(s) > 76:
s = s.replace(" ", "")
if len(s) > 76:
s = s[:-76]
n = 76 - len(s)
n = n/2
ret = "##" + (" " * n) + s
ret = ret + (" " * (76 - len(ret))) + "##"
return ret
def getHeader(f):
name, ext = splitext(basename(f.name()))
name = name.upper().replace("-", ".")
name = to80Comment(string.join(name, " "))
if ext == ".ads":
ext = to80Comment("S p e c")
return(HEADER % {"name": name, "ext": ext}).replace("#", "-")
elif ext == ".adb":
ext = to80Comment("B o d y")
return (HEADER % {"name": name, "ext": ext}).replace("#", "-")
elif ext == ".gpr":
ext = to80Comment("P r o j e c t")
return (HEADER % {"name": name, "ext": ext}).replace("#", "-")
else:
ext = to80Comment("")
return HEADER % {"name": name, "ext": ext}
def fixFile(f, of):
name, ext = splitext(basename(f.name()))
ed = GPS.EditorBuffer.get(f)
begin = ed.beginning_of_buffer()
if (ext not in [".gpr", ".adb", ".ads",
".c", ".cpp", ".h", ".hh", ".idl"]):
begin = begin.forward_line(1)
last = ed.beginning_of_buffer().search(r"\n\n", regexp=True)
of.write("%s\n" % ( 80 * "/"))
of.write("%s\n" % (f.name()))
of.write("%s\n" % (30 * "<"))
of.write("%s\n" % (ed.get_chars(begin, last[0])))
of.write("%s\n" % (30 * "<"))
of.write("%s\n" % (getHeader(f)))
of.write("%s\n" % (80 * "/"))
with file("temp.out", "w") as of:
for i in GPS.Project("zmq").sources():
fixFile(i, of)