summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-09-18 10:51:05 -0400
committerNick Mathewson <nickm@torproject.org>2019-09-23 08:48:53 -0400
commit16890839d35e9ac270e32934a232b45de9e8544b (patch)
treef38e6b0faf3cde913960286ab2688ec932f4dea6 /scripts
parentf36e743e5de92cecee81a64d2e78ce5ca3070f98 (diff)
downloadtor-16890839d35e9ac270e32934a232b45de9e8544b.tar.gz
tor-16890839d35e9ac270e32934a232b45de9e8544b.zip
annotate_ifdef_directives: obey an 80-column line-limit
If we would add a comment making a line longer than 80 columns, instead truncate the variable portion of the comment until it just fits into 80 columns, with an ellipsis.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/maint/annotate_ifdef_directives25
1 files changed, 22 insertions, 3 deletions
diff --git a/scripts/maint/annotate_ifdef_directives b/scripts/maint/annotate_ifdef_directives
index fcd96aeb38..b784ca71ba 100755
--- a/scripts/maint/annotate_ifdef_directives
+++ b/scripts/maint/annotate_ifdef_directives
@@ -26,14 +26,33 @@ import re
# Any block with fewer than this many lines does not need annotations.
LINE_OBVIOUSNESS_LIMIT = 4
+# Maximum line width.
+LINE_WIDTH=80
+
class Problem(Exception):
pass
-def commented_line(fmt, argument):
+def commented_line(fmt, argument, maxwidth=LINE_WIDTH):
"""
- Return fmt%argument, for use as a commented line.
+ Return fmt%argument, for use as a commented line. If the line would
+ be longer than maxwidth, truncate argument.
+
+ Requires that fmt%"..." will fit into maxwidth characters.
"""
- return fmt % argument
+ result = fmt % argument
+ if len(result) <= maxwidth:
+ return result
+ else:
+ # figure out how much we need to truncate by to fit the argument,
+ # plus an ellipsis.
+ ellipsis = "..."
+ result = fmt % (argument + ellipsis)
+ overrun = len(result) - maxwidth
+ truncated_argument = argument[:-overrun] + ellipsis
+
+ result = fmt % truncated_argument
+ assert len(result) <= maxwidth
+ return result
def uncomment(s):
"""