zephyr/kernel
Lingao Meng 302422ad9d 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: Lingao Meng <menglingao@xiaomi.com>
2024-06-25 06:05:35 -04:00
..
include kernel: avoided increments/decrements with side effects 2024-06-14 19:19:29 +02:00
paging kernel: mm: rename z_num_pagefaults_get to k_mem_num_* 2024-06-12 21:13:26 -04:00
CMakeLists.txt
Kconfig everywhere: replace double words 2024-06-25 06:05:35 -04:00
Kconfig.device kernel: add CONFIG_DEVICE_DT_METADATA and helpers 2024-06-12 18:49:54 +02:00
Kconfig.mem_domain
Kconfig.obj_core
Kconfig.smp kernel: Add CONFIG_SCHED_IPI_CASCADE 2024-06-21 20:49:11 -04:00
Kconfig.vm kernel: mm: rename Z_MEM_PHYS/VIRT_ADDR to K_MEM_* 2024-06-12 21:13:26 -04:00
atomic_c.c
banner.c kernel: banner: Add option to clear screen on boot 2024-06-13 20:30:14 -04:00
busy_wait.c
compiler_stack_protect.c kernel: Unified type of stack protection canary __stack_chk_guard. 2024-06-14 19:26:27 +02:00
condvar.c
cpu_mask.c
device.c kernel: add CONFIG_DEVICE_DT_METADATA and helpers 2024-06-12 18:49:54 +02:00
dynamic.c
dynamic_disabled.c
errno.c
events.c
fatal.c
float.c
futex.c
idle.c
init.c tracing: trace sys_init calls 2024-06-18 14:39:05 -04:00
ipi.c
irq_offload.c
kheap.c
mailbox.c
main_weak.c
mem_domain.c
mem_slab.c kernel: mem_slab: only define slab_ptr_is_good with assert enabled 2024-06-10 17:46:10 +01:00
mempool.c kernel: avoided increments/decrements with side effects 2024-06-14 19:19:29 +02:00
mmu.c demand_paging: add frame tracking functions to eviction algorithms 2024-06-14 18:58:02 -04:00
msg_q.c
mutex.c
nothread.c
obj_core.c
pipes.c
poll.c
priority_queues.c
queue.c
sched.c kernel: Add CONFIG_SCHED_IPI_CASCADE 2024-06-21 20:49:11 -04:00
sem.c
smp.c
spinlock_validate.c
stack.c
system_work_q.c
thread.c kernel: mm: remove k_mem_phys_un/map() 2024-06-12 21:13:26 -04:00
thread_monitor.c
timeout.c
timer.c
timeslicing.c
usage.c
userspace.c everywhere: replace double words 2024-06-25 06:05:35 -04:00
userspace_handler.c
version.c
work.c
xip.c