Commit 302422ad authored by Lingao Meng's avatar Lingao Meng Committed by Anas Nashif
Browse files

everywhere: replace double words

import os
import re

common_words = set([
    'about', 'after', 'all', 'also', 'an', 'and',
     'any', 'are', 'as', 'at',
    'be', 'because', 'but', 'by', 'can', 'come',
    'could', 'day', 'do', 'even',
    'first', 'for', 'get', 'give', 'go', 'has',
    'have', 'he', 'her',
    'him', 'his', 'how', 'I', 'in', 'into', 'it',
    'its', 'just',
    'know', 'like', 'look', 'make', 'man', 'many',
    'me', 'more', 'my', 'new',
    'no', 'not', 'now', 'of', 'one', 'only', 'or',
    'other', 'our', 'out',
    'over', 'people', 'say', 'see', 'she', 'so',
    'some', 'take', 'tell', 'than',
    'their', 'them', 'then', 'there', 'these',
    'they', 'think',
    'this', 'time', 'two', 'up', 'use', 'very',
    'want', 'was', 'way',
    'we', 'well', 'what', 'when', 'which', 'who',
    'will', 'with', 'would',
    'year', 'you', 'your'
])

valid_extensions = set([
    'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
    'rst', 'dtsi',
    'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
    'soc', 'cfg'
])

def filter_repeated_words(text):
    # Split the text into lines
    lines = text.split('\n')

    # Combine lines into a single string with unique separator
    combined_text = '/*sep*/'.join(lines)

    # Replace repeated words within a line
    def replace_within_line(match):
        return match.group(1)

    # Regex for matching repeated words within a line
    within_line_pattern =
	re.compile(r'\b(' +
		'|'.join(map(re.escape, common_words)) +
		r')\b\s+\b\1\b')
    combined_text = within_line_pattern.
		sub(replace_within_line, combined_text)

    # Replace repeated words across line boundaries
    def replace_across_lines(match):
        return match.group(1) + match.group(2)

    # Regex for matching repeated words across line boundaries
    across_lines_pattern = re.
		compile(r'\b(' + '|'.join(
			map(re.escape, common_words)) +
			r')\b(\s*[*\/\n\s]*)\b\1\b')
    combined_text = across_lines_pattern.
		sub(replace_across_lines, combined_text)

    # Split the text back into lines
    filtered_text = combined_text.split('/*sep*/')

    return '\n'.join(filtered_text)

def process_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        text = file.read()

    new_text = filter_repeated_words(text)

    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_text)

def process_directory(directory_path):
    for root, dirs, files in os.walk(directory_path):
        dirs[:] = [d for d in dirs if not d.startswith('.')]
        for file in files:
            # Filter out hidden files
            if file.startswith('.'):
                continue
            file_extension = file.split('.')[-1]
            if
	file_extension in valid_extensions:  # 只处理指定后缀的文件
                file_path = os.path.join(root, file)
                print(f"Processed file: {file_path}")
                process_file(file_path)

directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)

Signed-off-by: default avatarLingao Meng <menglingao@xiaomi.com>
parent f3beebbc
Loading
Loading
Loading
Loading
+1 −1
Changes for arch/arc/core/mpu/arc_mpu_v2_internal.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ static inline bool _is_enabled_region(uint32_t r_index)
}

/**
 * This internal function check if the given buffer in in the region
 * This internal function check if the given buffer is in the region
 */
static inline bool _is_in_region(uint32_t r_index, uint32_t start, uint32_t size)
{
+1 −1
Changes for arch/arc/core/mpu/arc_mpu_v6_internal.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ static inline bool _is_enabled_region(uint32_t r_index)
}

/**
 * This internal function check if the given buffer in in the region
 * This internal function check if the given buffer is in the region
 */
static inline bool _is_in_region(uint32_t r_index, uint32_t start, uint32_t size)
{
+1 −1
Changes for arch/xtensa/core/README_MMU.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -254,7 +254,7 @@ of access variability. But it also means that the TLB entries end up
being stored twice in the same CPU, wasting transistors that could
presumably store other useful data.

But it it also important to note that the L1 data cache on Xtensa is
But it is also important to note that the L1 data cache on Xtensa is
incoherent!  The cache being used for refill reflects the last access
on the current CPU only, and not of the underlying memory being
mapped.  Page table changes in the data cache of one CPU will be
+1 −1
Changes for boards/native/native_posix/native_rtc.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ extern "C" {
uint64_t native_rtc_gettime_us(int clock_type);

/**
 * @brief Get the value of a clock split in in nsec and seconds
 * @brief Get the value of a clock split in nsec and seconds
 *
 * @param clock_type Which clock to measure from
 * @param nsec Pointer to store the nanoseconds
+1 −1
Changes for doc/connectivity/networking/api/http_server.rst: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ macro:

    HTTP_SERVICE_DEFINE(my_service, "0.0.0.0", &http_service_port, 1, 10, NULL);

Alternatively, an HTTPS service can be defined with with
Alternatively, an HTTPS service can be defined with
:c:macro:`HTTPS_SERVICE_DEFINE`:

.. code-block:: c
Loading