forked from analogdevicesinc/no-OS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These code delimiters are useless and we've decided not to use them in future code. However, many contributors use existing files as templates and they keep creeping up in new code. So the only solution is to remove them completely. Here's the command and python script I used to do this: $ find . -name "*.c" -o -name "*.h" -print0 | xargs -0 python code-delimiters.py $ cat code-delimiters.py import sys import re import os import chardet def remove_include_comments(filenames): # Regex for comments with leading/trailing blank lines (replace with single newline) comment_pattern_with_blanks = re.compile(r"\n/\*+\/\n(?:/\*+[^\n]*\n){1}/\*+\/\n\s*\n", re.DOTALL) # Regex for comments without leading/trailing blank lines (replace with nothing) comment_pattern_no_blanks = re.compile(r"/\*+\/\n(?:/\*+[^\n]*\n){1}/\*+\/\n", re.DOTALL) for filename in filenames: try: with open(filename, 'rb') as f: # Open in binary mode first raw_content = f.read() encoding_result = chardet.detect(raw_content) # Detect the encoding encoding = encoding_result['encoding'] if encoding is None: print(f"Could not detect encoding for {filename}. Skipping.") continue # Skip the file if encoding cannot be detected try: content = raw_content.decode(encoding) # Decode with detected encoding except UnicodeDecodeError: print(f"Decoding error with {filename} using {encoding}. Skipping.") continue # Skip the file if decoding fails # First pass: Remove comments with leading/trailing blanks new_content = comment_pattern_with_blanks.sub("\n", content) # Second pass: Remove comments without leading/trailing blanks new_content = comment_pattern_no_blanks.sub("", new_content) # Operate on the modified content if new_content != content: with open(filename, 'w', newline='') as f: f.write(new_content) print(f"Modified: {filename}") else: print(f"No changes: {filename}") except FileNotFoundError: print(f"File not found: {filename}") except Exception as e: print(f"Error processing {filename}: {e}") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python script.py <file1> <file2> ...") sys.exit(1) filenames = sys.argv[1:] remove_include_comments(filenames) Signed-off-by: Darius Berghe <[email protected]>
- Loading branch information
Showing
560 changed files
with
0 additions
and
4,896 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.