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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if len(line) <= 80: |
610 lines.append(line.rstrip()) | 610 lines.append(line.rstrip()) |
611 else: | 611 else: |
612 # URLs are permitted to be over 80 chars by the style guide. | |
613 if 'http' in line: | |
ddorwin
2013/09/07 04:31:43
minor issue: Should we create a new line if 'http'
ddorwin
2013/09/07 04:31:43
Should we combine this if with the one above?
If
DaleCurtis
2013/09/09 20:49:14
There are a lot of cases here that aren't handled;
DaleCurtis
2013/09/09 20:49:14
Done; though now space_break is always computed.
| |
614 lines.append(line) | |
615 continue | |
616 | |
617 # Break long typedefs on nearest space. | |
618 space_break = line.rfind(' ', 0, 80) | |
619 if not '(' in line and space_break >= 0: | |
620 lines.append(line[0:space_break]) | |
621 lines.append(' ' + line[space_break + 1:]) | |
622 continue | |
623 | |
612 left = line.rfind('(') + 1 | 624 left = line.rfind('(') + 1 |
613 args = line[left:].split(',') | 625 args = line[left:].split(',') |
614 orig_args = args | 626 orig_args = args |
615 orig_left = left | 627 orig_left = left |
616 # Try to split on '(arg1)' or '(arg1, arg2)', not '()' | 628 # Try to split on '(arg1)' or '(arg1, arg2)', not '()' |
617 while args[0][0] == ')': | 629 while args[0][0] == ')': |
618 left = line.rfind('(', 0, left - 1) + 1 | 630 left = line.rfind('(', 0, left - 1) + 1 |
619 if left == 0: # No more parens, take the original option | 631 if left == 0: # No more parens, take the original option |
620 args = orig_args | 632 args = orig_args |
621 left = orig_left | 633 left = orig_left |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 if f.GetProperty('ERRORS') > 0: | 749 if f.GetProperty('ERRORS') > 0: |
738 print 'Skipping %s' % f.GetName() | 750 print 'Skipping %s' % f.GetName() |
739 continue | 751 continue |
740 for node in f.GetChildren()[2:]: | 752 for node in f.GetChildren()[2:]: |
741 print cgen.Define(node, comment=True, prefix='tst_') | 753 print cgen.Define(node, comment=True, prefix='tst_') |
742 | 754 |
743 | 755 |
744 if __name__ == '__main__': | 756 if __name__ == '__main__': |
745 sys.exit(main(sys.argv[1:])) | 757 sys.exit(main(sys.argv[1:])) |
746 | 758 |
OLD | NEW |