zephyr/drivers
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
..
adc everywhere: replace double words 2024-06-25 06:05:35 -04:00
audio everywhere: replace double words 2024-06-25 06:05:35 -04:00
auxdisplay
bbram driver: bbram: npcx: fix the way to clear bbram status 2024-06-21 10:07:41 +02:00
bluetooth everywhere: replace double words 2024-06-25 06:05:35 -04:00
cache
can everywhere: replace double words 2024-06-22 05:40:22 -04:00
charger
clock_control everywhere: replace double words 2024-06-25 06:05:35 -04:00
console
coredump
counter drivers/smartbond: Fix PM device runtime support 2024-06-18 14:36:38 -04:00
crypto drivers/smartbond: Fix PM device runtime support 2024-06-18 14:36:38 -04:00
dac
dai everywhere: replace double words 2024-06-22 05:40:22 -04:00
disk drivers: disk: remove `sdmmc_sdhc.h` since no longer used 2024-06-14 18:50:47 -04:00
display drivers/smartbond: Fix PM device runtime support 2024-06-18 14:36:38 -04:00
dma everywhere: replace double words 2024-06-25 06:05:35 -04:00
dp
edac
eeprom everywhere: replace double words 2024-06-22 05:40:22 -04:00
entropy drivers/smartbond: Remove atomic flags from drivers 2024-06-21 08:45:10 -04:00
espi
ethernet everywhere: replace double words 2024-06-25 06:05:35 -04:00
flash drivers: flash: stm32 xspi driver supports the MemoryMapped mode 2024-06-24 12:45:34 -04:00
fpga
fuel_gauge
gnss
gpio everywhere: replace double words 2024-06-22 05:40:22 -04:00
hwinfo
hwspinlock
i2c drivers/smartbond: Remove atomic flags from drivers 2024-06-21 08:45:10 -04:00
i2s
i3c i3c: ccc: fix missing break in switch in _do__getcaps() 2024-06-24 22:25:57 -04:00
ieee802154 driver: ieee802154: remove deprecated Kconfigs 2024-06-18 14:33:58 -04:00
input everywhere: replace double words 2024-06-22 05:40:22 -04:00
interrupt_controller drivers: intc: esp32: fix kconfig visibility 2024-06-21 11:37:33 -04:00
ipm
kscan
led everywhere: replace double words 2024-06-22 05:40:22 -04:00
led_strip
lora drivers: lora: implement reyax lora driver 2024-06-14 17:12:49 -04:00
mbox drivers: mbox: nrf: Change VEVIFs and BELLBOARD nomenclature 2024-06-15 04:41:47 -04:00
mdio driver: eth_esp32: fix shared clock check 2024-06-24 14:49:16 -04:00
memc drivers: fix Kconfig.mspi for issue #74349 2024-06-18 19:55:35 -04:00
mfd
mipi_dbi drivers: mipi_dbi: smartbond: Unused symbol 2024-06-24 12:43:12 -04:00
mipi_dsi everywhere: replace double words 2024-06-22 05:40:22 -04:00
misc
mm
modem net: sockets: use z_finalize_typed_fd() to identify as sockets 2024-06-15 07:47:12 -04:00
mspi drivers: mspi: Add Ambiq apollo3p mspi controller 2024-06-14 21:07:00 -04:00
net net: sockets: use z_finalize_typed_fd() to identify as sockets 2024-06-15 07:47:12 -04:00
pcie
peci
pinctrl drivers: pinctrl_nrf: : Allow applying pins of disabled peripherals 2024-06-20 12:09:24 -04:00
pm_cpu_ops
power_domain
ps2
ptp_clock drivers: ptp_clock: ptp_enet: use MMIO mapped address 2024-06-14 19:21:18 +02:00
pwm drivers: ledc: Clock source update to support ESP32C6 2024-06-14 18:51:46 -04:00
regulator
reset
retained_mem
rtc drivers: rtc: rtc_ll_stm32: coverity 368806 fix 2024-06-24 14:48:15 -04:00
sdhc everywhere: replace double words 2024-06-25 06:05:35 -04:00
sensor everywhere: replace double words 2024-06-25 06:05:35 -04:00
serial everywhere: replace double words 2024-06-25 06:05:35 -04:00
sip_svc
smbus
spi everywhere: replace double words 2024-06-22 05:40:22 -04:00
syscon
timer everywhere: replace double words 2024-06-22 05:40:22 -04:00
usb drivers: usb: device: smartbond: Use DMA driver 2024-06-24 12:43:12 -04:00
usb_c
video
virtualization
w1
watchdog drivers: watchdog: Added support to C6 2024-06-14 18:51:46 -04:00
wifi drivers: wifi/airoc: update airoc_wifi_host_buffer_get 2024-06-18 15:55:19 +02:00
xen
CMakeLists.txt drivers: mspi: Add the new MSPI API 2024-06-14 21:07:00 -04:00
Kconfig drivers: mspi: Add the new MSPI API 2024-06-14 21:07:00 -04:00