| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Given a filename as an argument, sort the #include/#imports in that file. | 6 """Given a filename as an argument, sort the #include/#imports in that file. |
| 7 | 7 |
| 8 Shows a diff and prompts for confirmation before doing the deed. | 8 Shows a diff and prompts for confirmation before doing the deed. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 """Sorting comparator key used for comparing two #include lines. | 35 """Sorting comparator key used for comparing two #include lines. |
| 36 Returns the filename without the #include/#import prefix. | 36 Returns the filename without the #include/#import prefix. |
| 37 """ | 37 """ |
| 38 for prefix in ('#include ', '#import '): | 38 for prefix in ('#include ', '#import '): |
| 39 if line.startswith(prefix): | 39 if line.startswith(prefix): |
| 40 line = line[len(prefix):] | 40 line = line[len(prefix):] |
| 41 break | 41 break |
| 42 # <windows.h> needs to be before other includes, so return a key | 42 # <windows.h> needs to be before other includes, so return a key |
| 43 # that's less than all other keys. | 43 # that's less than all other keys. |
| 44 if line.lstrip().startswith('<windows.h>'): | 44 if line.lstrip().startswith('<windows.h>'): |
| 45 return '' | 45 return ' 0' |
| 46 if line.lstrip().startswith('<unknwn.h>'): |
| 47 return ' 1' |
| 46 return line | 48 return line |
| 47 | 49 |
| 48 | 50 |
| 49 def IsInclude(line): | 51 def IsInclude(line): |
| 50 """Returns True if the line is an #include/#import line.""" | 52 """Returns True if the line is an #include/#import line.""" |
| 51 return line.startswith('#include ') or line.startswith('#import ') | 53 return line.startswith('#include ') or line.startswith('#import ') |
| 52 | 54 |
| 53 | 55 |
| 54 def SortHeader(infile, outfile): | 56 def SortHeader(infile, outfile): |
| 55 """Sorts the headers in infile, writing the sorted file to outfile.""" | 57 """Sorts the headers in infile, writing the sorted file to outfile.""" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 finally: | 95 finally: |
| 94 try: | 96 try: |
| 95 os.remove(fixfilename) | 97 os.remove(fixfilename) |
| 96 except OSError: | 98 except OSError: |
| 97 # If the file isn't there, we don't care. | 99 # If the file isn't there, we don't care. |
| 98 pass | 100 pass |
| 99 | 101 |
| 100 | 102 |
| 101 if __name__ == '__main__': | 103 if __name__ == '__main__': |
| 102 main() | 104 main() |
| OLD | NEW |