OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ Generator for C style prototypes and definitions """ | 6 """ Generator for C style prototypes and definitions """ |
7 | 7 |
8 import glob | 8 import glob |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 return CommentLines(lines) | 599 return CommentLines(lines) |
600 | 600 |
601 | 601 |
602 def Indent(self, data, tabs=0): | 602 def Indent(self, data, tabs=0): |
603 """Handles indentation and 80-column line wrapping.""" | 603 """Handles indentation and 80-column line wrapping.""" |
604 tab = ' ' * tabs | 604 tab = ' ' * tabs |
605 lines = [] | 605 lines = [] |
606 for line in data.split('\n'): | 606 for line in data.split('\n'): |
607 # Add indentation | 607 # Add indentation |
608 line = tab + line | 608 line = tab + line |
609 if len(line) <= 80: | 609 space_break = line.rfind(' ', 0, 80) |
| 610 if len(line) <= 80 or 'http' in line: |
| 611 # Ignore normal line and URLs permitted by the style guide. |
610 lines.append(line.rstrip()) | 612 lines.append(line.rstrip()) |
| 613 elif not '(' in line and space_break >= 0: |
| 614 # Break long typedefs on nearest space. |
| 615 lines.append(line[0:space_break]) |
| 616 lines.append(' ' + line[space_break + 1:]) |
611 else: | 617 else: |
612 left = line.rfind('(') + 1 | 618 left = line.rfind('(') + 1 |
613 args = line[left:].split(',') | 619 args = line[left:].split(',') |
614 orig_args = args | 620 orig_args = args |
615 orig_left = left | 621 orig_left = left |
616 # Try to split on '(arg1)' or '(arg1, arg2)', not '()' | 622 # Try to split on '(arg1)' or '(arg1, arg2)', not '()' |
617 while args[0][0] == ')': | 623 while args[0][0] == ')': |
618 left = line.rfind('(', 0, left - 1) + 1 | 624 left = line.rfind('(', 0, left - 1) + 1 |
619 if left == 0: # No more parens, take the original option | 625 if left == 0: # No more parens, take the original option |
620 args = orig_args | 626 args = orig_args |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 if f.GetProperty('ERRORS') > 0: | 743 if f.GetProperty('ERRORS') > 0: |
738 print 'Skipping %s' % f.GetName() | 744 print 'Skipping %s' % f.GetName() |
739 continue | 745 continue |
740 for node in f.GetChildren()[2:]: | 746 for node in f.GetChildren()[2:]: |
741 print cgen.Define(node, comment=True, prefix='tst_') | 747 print cgen.Define(node, comment=True, prefix='tst_') |
742 | 748 |
743 | 749 |
744 if __name__ == '__main__': | 750 if __name__ == '__main__': |
745 sys.exit(main(sys.argv[1:])) | 751 sys.exit(main(sys.argv[1:])) |
746 | 752 |
OLD | NEW |