删除根目录遗留的一次性乱码修复脚本(6 个)
fix_chinese_all/final/generic.py、fix_remaining.py、 dump_all_corruptions.py、git_compare.py 均为历史 U+FFFD 乱码事故的一次性修复脚本: - 硬编码旧路径 D:\Code\DTU 程序\ 已失效 - 补丁字典针对的损坏文件早已修复 - 乱码防护已由 no-mojibake 钩子承担
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
import sys, os
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
||||||
rep = chr(0xfffd)
|
|
||||||
base = 'D:\\Code\\DTU 程序\\STM32F4-Base\\'
|
|
||||||
|
|
||||||
files = [
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f.c',
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f_test.c',
|
|
||||||
'Drivers\\BSP\\NET\\net_select.c',
|
|
||||||
'Drivers\\BSP\\GD5F2GQ5UE\\gd5f2gq5ue.c',
|
|
||||||
'Drivers\\BSP\\SD2506\\sd2506.c',
|
|
||||||
'Drivers\\BSP\\TPAFE5160\\tpafe5160.c',
|
|
||||||
]
|
|
||||||
|
|
||||||
for fname in files:
|
|
||||||
path = base + fname
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
raw = f.read()
|
|
||||||
text = raw.decode('utf-8', errors='replace')
|
|
||||||
lines = text.split(chr(10))
|
|
||||||
count = text.count(rep)
|
|
||||||
if count == 0:
|
|
||||||
continue
|
|
||||||
print('\\n=== {} ({} remaining) ==='.format(fname, count))
|
|
||||||
for i, line in enumerate(lines, 1):
|
|
||||||
if rep in line:
|
|
||||||
idx = line.index(rep)
|
|
||||||
left = line[max(0,idx-30):idx]
|
|
||||||
right = line[idx+2:idx+30]
|
|
||||||
ctx = left + '[?]' + right
|
|
||||||
print('L{}: |{}|'.format(i, ctx))
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
import sys, os
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
||||||
rep = chr(0xfffd)
|
|
||||||
base = 'D:\\Code\\DTU 程序\\STM32F4-Base\\'
|
|
||||||
|
|
||||||
pair = {
|
|
||||||
'\u51fd':'\u6570', '\u8bf4':'\u660e', '\u529f':'\u80fd', '\u53c2':'\u6570',
|
|
||||||
'\u72b6':'\u6001', '\u521d':'\u59cb', '\u7f13':'\u51b2', '\u56de':'\u503c',
|
|
||||||
'\u7b49':')', '\u8bbe':'\u7f6e', '\u5f00':'\u542f', '\u5173':'\u95ed',
|
|
||||||
'\u83b7':'\u53d6', '\u53d1':'\u9001', '\u63a5':'\u6536', '\u8bfb':'\u53d6',
|
|
||||||
'\u5199':'\u5165', '\u64e6':'\u9664', '\u5b57':'\u8282', '\u8282':'\u6570',
|
|
||||||
'\u957f':'\u5ea6', '\u7aef':'\u53e3', '\u534f':'\u8bae', '\u7c7b':'\u578b',
|
|
||||||
'\u6a21':'\u5f0f', '\u670d':'\u52a1', '\u5730':'\u5740', '\u7f51':'\u5173',
|
|
||||||
'\u63a9':'\u7801', '\u4f7f':'\u80fd', '\u54cd':'\u5e94', '\u5bc4':'\u5b58',
|
|
||||||
'\u5b58':'\u5668', '\u547d':'\u4ee4', '\u4e8b':'\u4ef6', '\u8c03':'\u7528',
|
|
||||||
'\u58f0':'\u660e', '\u5b9e':'\u73b0', '\u8fd4':'\u56de', '\u6307':'\u9488',
|
|
||||||
'\u6570':'\u636e', '\u8fde':'\u63a5', '\u9519':'\u8bef', '\u65f6':'\u95f4',
|
|
||||||
'\u6b21':'\u6570', '\u603b':'\u5bb9', '\u5bb9':'\u91cf', '\u5757':'\u5927',
|
|
||||||
'\u5927':'\u5c0f', '\u91cd':'\u4f20', '\u4f20':'\u6b21',
|
|
||||||
'\u63a2':'\u6d4b', '\u9694':'\uff1a', '\u59cb':'\u5316',
|
|
||||||
'\u8bdd':'\u65f6', '\u5316':'\uff1a', '\u52a1':'\u5668', '\u6237':'\u7aef',
|
|
||||||
'\u76ee':'\u6807', '\u6807':'\u7aef', '\u672c':'\u5730',
|
|
||||||
'\u542b':'\u957f', '\u5305':'\u542b', '\u5c5e':'\u6027',
|
|
||||||
'\u6536':'\u6570', '\u53ca':'\u65f6', '\u7cfb':'\u7edf', '\u7edf':'\u521d',
|
|
||||||
'\u5145':'\u7535', '\u95f9':'\u949f',
|
|
||||||
'\u5199':'\u4fdd', '\u4fdd':'\u62a4',
|
|
||||||
'\u8f6c':'\uff0c',
|
|
||||||
'\u65f6':'\u5236',
|
|
||||||
'\u6e05':'\u96f6',
|
|
||||||
'\u5143':'\uff1a',
|
|
||||||
'\u884c':'\uff1a',
|
|
||||||
'\u6574':'\u4e00',
|
|
||||||
}
|
|
||||||
|
|
||||||
files = [
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f.c',
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f_test.c',
|
|
||||||
'Drivers\\BSP\\NET\\net_select.c',
|
|
||||||
'Drivers\\BSP\\GD5F2GQ5UE\\gd5f2gq5ue.c',
|
|
||||||
'Drivers\\BSP\\SD2506\\sd2506.c',
|
|
||||||
'Drivers\\BSP\\TPAFE5160\\tpafe5160.c',
|
|
||||||
]
|
|
||||||
|
|
||||||
# Manual patterns that don't follow the pair rule
|
|
||||||
manual = [
|
|
||||||
# ch395f.c
|
|
||||||
('\u521d\u59cb\u5316' + rep + '?', '\u521d\u59cb\u5316\uff09'),
|
|
||||||
('\u4fee\u6539\u8bb0\u5f55' + rep + '?', '\u4fee\u6539\u8bb0\u5f55\uff1a'),
|
|
||||||
('\u738b\u5efa' + rep + '? \u6539', '\u738b\u5efa\u950b \u6539'),
|
|
||||||
('\u6d4b\u8bd5\u5b57' + rep + '?*/', '\u6d4b\u8bd5\u5b57\u8282 */'),
|
|
||||||
('\u79c1\u6709\u53d8\u91cf' + rep + '?', '\u79c1\u6709\u53d8\u91cf\u533a'),
|
|
||||||
('\u63a5\u6536\u7f13\u51b2' + rep + '?*/', '\u63a5\u6536\u7f13\u51b2\u533a */'),
|
|
||||||
('\u51fd\u6570\u58f0\u660e' + rep + '?', '\u51fd\u6570\u58f0\u660e\u533a'),
|
|
||||||
('\u51fd\u6570\u5b9e\u73b0' + rep + '?', '\u51fd\u6570\u5b9e\u73b0\u533a'),
|
|
||||||
('\u53d1\u9001\u7f13\u51b2' + rep + '?*/', '\u53d1\u9001\u7f13\u51b2\u533a */'),
|
|
||||||
('\u8bfb\u53d6\u6307\u5b9a' + rep + '?\u5b58' + rep + '?\u5185' + rep + '? */', '\u8bfb\u53d6\u6307\u5b9a\u5bc4\u5b58\u5668\u5185\u5bb9 */'),
|
|
||||||
('\u6210\u529f' + rep + '?\u5931' + rep + '?', '\u6210\u529f\u5931\u8d25'),
|
|
||||||
('\u53d1\u9001\u5b57\u8282' + rep + '?*/', '\u53d1\u9001\u5b57\u8282\u6570 */'),
|
|
||||||
('\u63a5\u6536\u5b57\u8282' + rep + '?*/', '\u63a5\u6536\u5b57\u8282\u6570 */'),
|
|
||||||
('\u5f00' + rep + '?SPI', '\u5f00\u542f SPI'),
|
|
||||||
('\u7ed3' + rep + '?SPI', '\u7ed3\u675f SPI'),
|
|
||||||
('\u53d1\u9001\u83b7\u53d6\u8fdc' + rep + '?IP', '\u53d1\u9001\u83b7\u53d6\u8fdc\u7aef IP'),
|
|
||||||
# net_select.c
|
|
||||||
('\u53ef\u8bfb\u4e8b' + rep + '?*/', '\u53ef\u8bfb\u4e8b\u4ef6 */'),
|
|
||||||
('\u53ef\u5199\u4e8b' + rep + '?*/', '\u53ef\u5199\u4e8b\u4ef6 */'),
|
|
||||||
('\u5f02\u5e38\u4e8b' + rep + '?*/', '\u5f02\u5e38\u4e8b\u4ef6 */'),
|
|
||||||
('\u8d85\u65f6\u68c0' + rep + '?*/', '\u8d85\u65f6\u68c0\u67e5 */'),
|
|
||||||
('\u65b0\u8fde\u63a5\u65f6\u53ef' + rep + '?*/', '\u65b0\u8fde\u63a5\u65f6\u53ef\u8bfb */'),
|
|
||||||
# tpafe5160.c
|
|
||||||
('16' + rep + '?\u901a\u9053', '16\u4f4d 8\u901a\u9053'),
|
|
||||||
('t10 (RD \u4f4e\u8109' + rep + '?)', 't10 (RD \u4f4e\u8109\u51b2)'),
|
|
||||||
('\u5e8f\u5173\u952e' + rep + '?(', '\u5e8f\u5173\u952e\u70b9('),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e\uff1a\u4ea7' + rep + '?CONVST', '\u51fd\u6570\u8bf4\u660e\uff1a\u4ea7\u751f CONVST'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e\uff1a\u8f6e' + rep + '?BUSY', '\u51fd\u6570\u8bf4\u660e\uff1a\u8f6e\u8be2 BUSY'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e\uff1a\u6bcf' + rep + '?RD', '\u51fd\u6570\u8bf4\u660e\uff1a\u6bcf\u4e2a RD'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e\uff1a' + rep + 'V\u91cf\u7a0b', '\u51fd\u6570\u8bf4\u660e\uff1a5V\u91cf\u7a0b'),
|
|
||||||
# sd2506.c
|
|
||||||
('\u5341\u8fdb\u5236' + rep + '?BCD ', '\u5341\u8fdb\u5236\u8f6c BCD '),
|
|
||||||
('\u6210\u529f' + rep + '?2 - I2C', '\u6210\u529f\uff0c-2 - I2C'),
|
|
||||||
('00H: ' + rep + '?*/', '00H: \u79d2 */'),
|
|
||||||
('01H: ' + rep + '?*/', '01H: \u5206 */'),
|
|
||||||
('02H: ' + rep + '?', '02H: \u65f6'),
|
|
||||||
('04H: ' + rep + '?*/', '04H: \u65e5 */'),
|
|
||||||
('05H: ' + rep + '?*/', '05H: \u6708 */'),
|
|
||||||
('06H: ' + rep + '?*/', '06H: \u5e74 */'),
|
|
||||||
('07H: \u79d2\u62a5' + rep + '?*/', '07H: \u79d2\u62a5\u8b66 */'),
|
|
||||||
('08H: \u5206\u62a5' + rep + '?*/', '08H: \u5206\u62a5\u8b66 */'),
|
|
||||||
('09H: \u65f6\u62a5' + rep + '?', '09H: \u65f6\u62a5\u8b66'),
|
|
||||||
('0BH: \u65e5\u62a5' + rep + '?*/', '0BH: \u65e5\u62a5\u8b66 */'),
|
|
||||||
('0CH: \u6708\u62a5' + rep + '?*/', '0CH: \u6708\u62a5\u8b66 */'),
|
|
||||||
('0DH: \u5e74\u62a5' + rep + '?*/', '0DH: \u5e74\u62a5\u8b66 */'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e' + rep + '?. \u5148\u5f00\u5199\u4fdd', '\u51fd\u6570\u8bf4\u660e\uff1a1. \u5148\u5f00\u5199\u4fdd\u62a4'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e' + rep + '?. \u5199\u4f7f', '\u51fd\u6570\u8bf4\u660e\uff1a2. \u5199\u4f7f\u80fd'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e' + rep + '?. \u542f\u52a8\u8f6c\u6362', '\u51fd\u6570\u8bf4\u660e\uff1a3. \u542f\u52a8\u8f6c\u6362'),
|
|
||||||
# ch395f
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u590d\u4f4d\u82af' + rep + '?', '\u51fd\u6570\u529f\u80fd\uff1a\u590d\u4f4d\u82af\u7247'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u68c0' + rep + '?CH395', '\u51fd\u6570\u529f\u80fd\uff1a\u68c0\u67e5 CH395'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u83b7\u53d6\u8fdc' + rep + '?IP', '\u51fd\u6570\u529f\u80fd\uff1a\u83b7\u53d6\u8fdc\u7aef IP'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u8f6f\u4ef6\u590d' + rep + '?CH395', '\u51fd\u6570\u529f\u80fd\uff1a\u8f6f\u4ef6\u590d\u4f4d CH395'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u542f' + rep + '?TCP \u76d1\u542c', '\u51fd\u6570\u529f\u80fd\uff1a\u542f\u52a8 TCP \u76d1\u542c'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u542f' + rep + '?TCP \u8fde\u63a5', '\u51fd\u6570\u529f\u80fd\uff1a\u542f\u52a8 TCP \u8fde\u63a5'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u542f' + rep + '?\u7981\u7528 DHCP', '\u51fd\u6570\u529f\u80fd\uff1a\u542f\u7528\u7981\u7528 DHCP'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u542f' + rep + '?\u7981\u7528\u6307\u5b9a S', '\u51fd\u6570\u529f\u80fd\uff1a\u542f\u7528\u7981\u7528\u6307\u5b9a S'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u8bfb\u53d6\u5168' + rep + '?\u901a\u9053\u8f6c\u6362\u7ed3\u679c', '\u51fd\u6570\u529f\u80fd\uff1a\u8bfb\u53d6\u5168\u90e8\u901a\u9053\u8f6c\u6362\u7ed3\u679c'),
|
|
||||||
('\u51fd\u6570\u529f\u80fd\uff1a\u8bfb\u53d6\u82af' + rep + '?ID', '\u51fd\u6570\u529f\u80fd\uff1a\u8bfb\u53d6\u82af\u7247 ID'),
|
|
||||||
# ch395f_test.c
|
|
||||||
('NET ' + rep + '?TCP Ec', 'NET \u7684 TCP Ec'),
|
|
||||||
('NET ' + rep + '?UDP Ec', 'NET \u7684 UDP Ec'),
|
|
||||||
# gd5f2gq5ue.c
|
|
||||||
('\u7f16\u7a0b\u5b8c\u6210\u540e\u68c0' + rep + '?P_FAIL', '\u7f16\u7a0b\u5b8c\u6210\u540e\u68c0\u67e5 P_FAIL'),
|
|
||||||
('\u64e6\u9664\u5b8c\u6210\u540e\u68c0' + rep + '?E_FAIL', '\u64e6\u9664\u5b8c\u6210\u540e\u68c0\u67e5 E_FAIL'),
|
|
||||||
# generic patterns
|
|
||||||
('\u9650\u5b9a\u6761\u4ef6\uff1a\u5e94' + rep + '?ch395f', '\u9650\u5b9a\u6761\u4ef6\uff1a\u5e94\u5148\u8c03\u7528 ch395f'),
|
|
||||||
('\u9650\u5b9a\u6761\u4ef6\uff1a\u9700' + rep + '?ch395f', '\u9650\u5b9a\u6761\u4ef6\uff1a\u9700\u5148\u8c03\u7528 ch395f'),
|
|
||||||
('\u9650\u5b9a\u6761\u4ef6\uff1a\u6307\u9488\u975e' + rep + '? */', '\u9650\u5b9a\u6761\u4ef6\uff1a\u6307\u9488\u975e\u7a7a */'),
|
|
||||||
('\u6570\u636e\u540c\u6b65\u5c4f\u969c\uff1a\u786e' + rep + '?memcpy', '\u6570\u636e\u540c\u6b65\u5c4f\u969c\uff1a\u786e\u4fdd memcpy'),
|
|
||||||
('\u68c0\u67e5\u8f93\u5165\u53c2\u6570\u5408\u6cd5' + rep + '?*/', '\u68c0\u67e5\u8f93\u5165\u53c2\u6570\u5408\u6cd5\u6027 */'),
|
|
||||||
('\u8bfb\u53d6\u5168\u5c40\u4e2d\u65ad\uff08\u5237' + rep + '?socket', '\u8bfb\u53d6\u5168\u5c40\u4e2d\u65ad\uff08\u5237\u65b0 socket'),
|
|
||||||
('Socket \u6709\u6570\u636e\u53ef' + rep + '?*/', 'Socket \u6709\u6570\u636e\u53ef\u8bfb */'),
|
|
||||||
('IP \u5730\u5740\uff08\u4f4e\u5b57\u8282\u5728\u524d' + rep + '?', 'IP \u5730\u5740\uff08\u4f4e\u5b57\u8282\u5728\u524d\uff09'),
|
|
||||||
('\u8fd4\u56de\u503c\uff1a\u547d\u4ee4\u7801\u56de\u663e' + rep + '? uint8', '\u8fd4\u56de\u503c\uff1a\u547d\u4ee4\u7801\u56de\u663e\u503c uint8'),
|
|
||||||
('\u8fd4\u56de\u503c\uff1a\u6570\u636e\u56de\u663e' + rep + '? uint8', '\u8fd4\u56de\u503c\uff1a\u6570\u636e\u56de\u663e\u503c uint8'),
|
|
||||||
('GET_IP_INF ' + rep + '?9 ', 'GET_IP_INF \u7b49 9 '),
|
|
||||||
# tpafe
|
|
||||||
('RANGE ' + rep + '?GND', 'RANGE \u63a5 GND'),
|
|
||||||
('\u62f7\u8d1d\u7528\u6237\u6570\u636e' + rep + '?DMA', '\u62f7\u8d1d\u7528\u6237\u6570\u636e\u5230 DMA'),
|
|
||||||
('\u7ec4\u5408 9 ' + rep + '? bit8', '\u7ec4\u5408 9 \u548c bit8'),
|
|
||||||
('ttl - TTL ' + rep + '? uint8', 'ttl - TTL \u503c uint8'),
|
|
||||||
('(BAT8_VAL) ' + rep + '?1BH', '(BAT8_VAL) \u4e3a 1BH'),
|
|
||||||
('\u6b63\u6e29' + rep + '?*/', '\u6b63\u6e29\u5ea6 */'),
|
|
||||||
('\u8d1f\u6e29' + rep + '? \u53d6\u8865', '\u8d1f\u6e29\u5ea6 \u53d6\u8865\u7801'),
|
|
||||||
# tpafe
|
|
||||||
('\u51fd\u6570\u8bf4\u660e\uff1a\u542f' + rep + '?DHCP', '\u51fd\u6570\u8bf4\u660e\uff1a\u542f\u52a8 DHCP'),
|
|
||||||
('\u51fd\u6570\u8bf4\u660e\uff1a' + rep + '?V\u91cf\u7a0b', '\u51fd\u6570\u8bf4\u660e\uff1a\u00b15V\u91cf\u7a0b'),
|
|
||||||
# generic pair leftovers
|
|
||||||
(rep + '?' + rep + '?\u503c\uff1a', '\u8fd4\u56de\u503c\uff1a'),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Apply pair mapping
|
|
||||||
for fname in files:
|
|
||||||
path = base + fname
|
|
||||||
if not os.path.exists(path):
|
|
||||||
print(f'*** {fname}: NOT FOUND')
|
|
||||||
continue
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
raw = f.read()
|
|
||||||
text = raw.decode('utf-8', errors='replace')
|
|
||||||
before = text.count(rep)
|
|
||||||
if before == 0:
|
|
||||||
print(f'{fname}: clean')
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Strategy 1: pair mapping [char][REP]?
|
|
||||||
for first, second in pair.items():
|
|
||||||
pattern = first + rep + '?'
|
|
||||||
replacement = first + second
|
|
||||||
text = text.replace(pattern, replacement)
|
|
||||||
|
|
||||||
# Strategy 2: manual patterns
|
|
||||||
for old, new in manual:
|
|
||||||
text = text.replace(old, new)
|
|
||||||
|
|
||||||
# Strategy 3: common multi-char patterns
|
|
||||||
text = text.replace(rep + '?' + rep + '?\u503c\uff1a', '\u8fd4\u56de\u503c\uff1a')
|
|
||||||
text = text.replace(rep + '?' + rep + '?\u503c\uff1a', '\u8fd4\u56de\u503c\uff1a')
|
|
||||||
|
|
||||||
# Strategy 4: for remaining [REP]?\u503c\uff1a -> '\u8fd4\u56de\u503c\uff1a'
|
|
||||||
# These are cases where the full '\u8fd4' was also corrupted
|
|
||||||
import re as regex
|
|
||||||
text = regex.sub(rep + r'\?' + rep + r'\?\u503c\uff1a', '\u8fd4\u56de\u503c\uff1a', text)
|
|
||||||
|
|
||||||
after = text.count(rep)
|
|
||||||
fixed = before - after
|
|
||||||
|
|
||||||
with open(path, 'wb') as f:
|
|
||||||
f.write(text.encode('utf-8'))
|
|
||||||
|
|
||||||
if after > 0:
|
|
||||||
print(f'{fname}: fixed {fixed}/{before}, {after} remaining')
|
|
||||||
# Show first remaining
|
|
||||||
for i, line in enumerate(text.split(chr(10)), 1):
|
|
||||||
if rep in line:
|
|
||||||
idx = line.index(rep)
|
|
||||||
ctx = line[max(0,idx-10):idx+6]
|
|
||||||
printable = ctx.replace(rep, '[?]')
|
|
||||||
print(f' eg L{i}: ...{printable}...')
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print(f'{fname}: CLEAN ({fixed} fixed)')
|
|
||||||
|
|
||||||
print('Done')
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
import sys, os
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
||||||
rep = chr(0xfffd)
|
|
||||||
base = 'D:\\Code\\DTU 程序\\STM32F4-Base\\'
|
|
||||||
|
|
||||||
fixes = {
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f.c': [
|
|
||||||
# Author name
|
|
||||||
('王建' + rep + '? * 创建', '王建锋 * 创建'),
|
|
||||||
# Closing parens and punctuation
|
|
||||||
('手册要' + rep + '?SPI', '手册要求 SPI'),
|
|
||||||
('rx_buf[' + rep + '? *', 'rx_buf] *'),
|
|
||||||
('SPI 驱动' + rep + '?DMA TX+RX', 'SPI 驱动) DMA TX+RX'),
|
|
||||||
('SPI 驱动' + rep + '?DMA 传输', 'SPI 驱动) DMA 传输'),
|
|
||||||
('begin() ' + rep + '?ch395f_spi_end', 'begin() 到 ch395f_spi_end'),
|
|
||||||
('begin() ' + rep + '?ch395f_spi_end', 'begin() 到 ch395f_spi_end'),
|
|
||||||
('begin() ' + rep + '?ch395f_spi_end', 'begin() 到 ch395f_spi_end'),
|
|
||||||
('0x57' + rep + '? *', '0x57) *'),
|
|
||||||
('exist() 检' + rep + '? */', 'exist() 检查) */'),
|
|
||||||
('在前,' + rep + '? */', '在前,) */'),
|
|
||||||
('默认' + rep + '?' + rep + '? *', '默认值) *'),
|
|
||||||
('SUCCESS ' + rep + '?CH395F_CMD_RET', 'SUCCESS 或 CH395F_CMD_RET'),
|
|
||||||
('4s' + rep + '? */', '4s) */'),
|
|
||||||
('EEPROM' + rep + '? * 入口参数', 'EEPROM) * 入口参数'),
|
|
||||||
('TE5' + rep + '? */', 'TE5) */'),
|
|
||||||
('手' + rep + '?5.37', '手册 5.37'),
|
|
||||||
('发送启' + rep + '?禁用', '发送启禁用'),
|
|
||||||
('时钟)' + rep + '? *', '时钟), *'),
|
|
||||||
(rep + '?DMA 接收缓冲区偏移', '从 DMA 接收缓冲区偏移'),
|
|
||||||
('0~7' + rep + '? * 返回值', '0~7) * 返回值'),
|
|
||||||
('100ms' + rep + '?=默认', '100ms)=默认'),
|
|
||||||
('次' + rep + '?=默认', '次数=默认'),
|
|
||||||
('最' + rep + '?128', '最大 128'),
|
|
||||||
('+IP' + rep + '? * 限定条件', '+IP) * 限定条件'),
|
|
||||||
],
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f_test.c': [
|
|
||||||
('默' + rep + '?192.168.1.2:8081' + rep + '?', '认 192.168.1.2:8081)'),
|
|
||||||
('默' + rep + '?192.168.1.2:8082' + rep + '?', '认 192.168.1.2:8082)'),
|
|
||||||
('version) ' + rep + '?read-clear', 'version) 即 read-clear'),
|
|
||||||
('创建' + rep + '?UDP', '创建 UDP'),
|
|
||||||
('DHCP ' + rep + '?轮询等待', 'DHCP 并轮询等待'),
|
|
||||||
('= 60000' + rep + '?*/', '= 60000)*/'),
|
|
||||||
],
|
|
||||||
'Drivers\\BSP\\GD5F2GQ5UE\\gd5f2gq5ue.c': [
|
|
||||||
('再拉' + rep + '? */', '再拉高 */'),
|
|
||||||
('P_FAIL ' + rep + '? */', 'P_FAIL 位 */'),
|
|
||||||
('E_FAIL ' + rep + '? */', 'E_FAIL 位 */'),
|
|
||||||
('128KB' + rep + '? * 入口参数', '128KB) * 入口参数'),
|
|
||||||
],
|
|
||||||
'Drivers\\BSP\\NET\\net_select.c': [
|
|
||||||
('不可' + rep + '? */', '不可写 */'),
|
|
||||||
('可' + rep + '?*/', '可写*/'),
|
|
||||||
],
|
|
||||||
'Drivers\\BSP\\SD2506\\sd2506.c': [
|
|
||||||
('BCD ' + rep + '? * 入口参数', 'BCD 码 * 入口参数'),
|
|
||||||
('编码' + rep + '? * 限定条件', '编码) * 限定条件'),
|
|
||||||
(rep + '?1AH=80H', '(1AH=80H'),
|
|
||||||
('毫' + rep + '?(raw', '毫秒 (raw'),
|
|
||||||
('SRAM ' + rep + '?2CH~71H', 'SRAM 区 2CH~71H'),
|
|
||||||
('始终' + rep + '?])', '始终为0])'),
|
|
||||||
('CTR2 ' + rep + '?INTAE=1', 'CTR2 的 INTAE=1'),
|
|
||||||
],
|
|
||||||
'Drivers\\BSP\\TPAFE5160\\tpafe5160.c': [
|
|
||||||
('ZGT6,并' + rep + '?6位', 'ZGT6,并行 6位'),
|
|
||||||
('驱动' + rep + '?TPAFE5160' + rep + '?', '驱动适配 TPAFE5160'),
|
|
||||||
# Fix multiple specific cases
|
|
||||||
('脉冲 ' + rep + '?22ns', '脉冲 约 22ns'),
|
|
||||||
('~6ns)' + rep + '? * 加上', '~6ns),* 加上'),
|
|
||||||
('已完' + rep + '?GPIO', '已完成 GPIO'),
|
|
||||||
# 设置过采样
|
|
||||||
('过采样' + rep + '? * 入口参数', '过采样率 * 入口参数'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:GPIO', '返回值:无 * 限定条件:GPIO'),
|
|
||||||
# 下一 - this is tricky, let me look at full context
|
|
||||||
('样本' + rep + '?BUSY', '样本 BUSY'),
|
|
||||||
('下一' + rep + '?BUSY', '下一次 BUSY'),
|
|
||||||
# wait conversion
|
|
||||||
('转换完' + rep + '? * 入口参数', '转换完成 * 入口参数'),
|
|
||||||
('转换完' + rep + '? * 返回值', '转换完成 * 返回值'), # if this pattern exists
|
|
||||||
('转换完成' + rep + '?2 - 超时', '转换完成,2 - 超时'),
|
|
||||||
('下降' + rep + '? */', '下降沿 */'),
|
|
||||||
('空闲' + rep + '?*/', '空闲)*/'),
|
|
||||||
('转换' + rep + '?1 -', '转换中 1 -'),
|
|
||||||
# 读取指定通道的转换结果
|
|
||||||
('转换结' + rep + '? * 入口参数', '转换结果 * 入口参数'),
|
|
||||||
('转电压' + rep + '? * 入口参数', '转电压 * 入口参数'),
|
|
||||||
('量程' + rep + '?LSB', '量程,LSB'),
|
|
||||||
('量程' + rep + '?LSB', '量程,LSB'),
|
|
||||||
('引脚' + rep + '?GND', '引脚接 GND'),
|
|
||||||
('RANGE 接 GND ' + rep + '?±5V', 'RANGE 接 GND,±5V'),
|
|
||||||
('转换' + rep + '? * 入口参数', '转换)* 入口参数'),
|
|
||||||
('RD 为低' + rep + '?CS', 'RD 为低,CS'),
|
|
||||||
('通道' + rep + '? uint8_t', '通道数 uint8_t'),
|
|
||||||
('缓冲' + rep + '? int16_t', '缓冲区 int16_t'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:转换', '返回值:无 * 限定条件:转换'),
|
|
||||||
('主频)' + rep + '? *', '主频),*'),
|
|
||||||
('数据' + rep + '?DB[15:0]', '数据到 DB[15:0]'),
|
|
||||||
('ISR ' + rep + '?s_buf_b', 'ISR 写 s_buf_b'),
|
|
||||||
('0 = ' + rep + '?B / ' + rep + '?A, 1 = ' + rep + '?A / ' + rep + '?B',
|
|
||||||
'0 = 写 B / 读 A, 1 = 写 A / 读 B'),
|
|
||||||
('使能用' + rep + '? * 入口参数', '使能)* 入口参数'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:CubeMX', '返回值:无 * 限定条件:CubeMX'),
|
|
||||||
('仅' + rep + '?irq_disable()', '仅当 irq_disable()'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:已调用', '返回值:无 * 限定条件:已调用'),
|
|
||||||
('启动转换(中断模式' + rep + '? * 入口参数', '启动转换(中断模式)* 入口参数'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:已调用 tpafe5', '返回值:无 * 限定条件:已调用 tpafe5'),
|
|
||||||
('完成后' + rep + '?EXTI 中断', '完成后触发 EXTI 中断'),
|
|
||||||
('数据就绪' + rep + '? - 无新数据', '数据就绪,0 - 无新数据'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:中断', '返回值:无 * 限定条件:中断'),
|
|
||||||
('缓冲' + rep + '? */', '缓冲区 */'),
|
|
||||||
('下降' + rep + '?EXTI', '下降沿 EXTI'),
|
|
||||||
('返回值:' + rep + '? * 限定条件:BUSY', '返回值:无 * 限定条件:BUSY'),
|
|
||||||
# Additional tpafe5160 patterns
|
|
||||||
('并' + rep + '?位数据', '并行 16位数据'),
|
|
||||||
('本驱动' + rep + '?AD7606', '本驱动适配 AD7606'),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
total_fixed = 0
|
|
||||||
for fname, file_fixes in fixes.items():
|
|
||||||
path = base + fname
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
raw = f.read()
|
|
||||||
text = raw.decode('utf-8', errors='replace')
|
|
||||||
before = text.count(rep)
|
|
||||||
|
|
||||||
for needle, replacement in file_fixes:
|
|
||||||
while needle in text:
|
|
||||||
text = text.replace(needle, replacement)
|
|
||||||
|
|
||||||
after = text.count(rep)
|
|
||||||
fixed = before - after
|
|
||||||
total_fixed += fixed
|
|
||||||
print('{}: fixed {} ({} -> {})'.format(fname, fixed, before, after))
|
|
||||||
|
|
||||||
with open(path, 'wb') as f:
|
|
||||||
f.write(text.encode('utf-8'))
|
|
||||||
|
|
||||||
print('\nTotal fixed this pass: {}'.format(total_fixed))
|
|
||||||
|
|
||||||
# Show remaining
|
|
||||||
print('\n=== REMAINING ===')
|
|
||||||
for fname in fixes:
|
|
||||||
path = base + fname
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
text = f.read().decode('utf-8', errors='replace')
|
|
||||||
remaining = text.count(rep)
|
|
||||||
if remaining > 0:
|
|
||||||
print('\n--- {} remaining in {} ---'.format(remaining, fname))
|
|
||||||
for i, line in enumerate(text.split(chr(10)), 1):
|
|
||||||
if rep in line:
|
|
||||||
idx = line.index(rep)
|
|
||||||
left = line[max(0,idx-30):idx]
|
|
||||||
right = line[idx+2:idx+20]
|
|
||||||
print('L{}: ...{}[?]{}...'.format(i, left, right))
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
import sys, os, re
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
||||||
rep = chr(0xfffd)
|
|
||||||
base = 'D:\\Code\\DTU 程序\\STM32F4-Base\\'
|
|
||||||
|
|
||||||
files = [
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f.c',
|
|
||||||
'Drivers\\BSP\\CH395F\\ch395f_test.c',
|
|
||||||
'Drivers\\BSP\\GD5F2GQ5UE\\gd5f2gq5ue.c',
|
|
||||||
'Drivers\\BSP\\SD2506\\sd2506.c',
|
|
||||||
'Drivers\\BSP\\TPAFE5160\\tpafe5160.c',
|
|
||||||
]
|
|
||||||
|
|
||||||
# Generic patterns - these work across comment blocks
|
|
||||||
generic_fixes = []
|
|
||||||
|
|
||||||
# 1. [?] followed by */ -> ) */
|
|
||||||
generic_fixes.append((rep + r'\? \*/', u') */'))
|
|
||||||
|
|
||||||
# 2. [?] followed by * and 入口参数/函数说明/etc -> ) * xxx
|
|
||||||
comment_keywords = [
|
|
||||||
u'入口参数', u'函数功能', u'函数说明', u'限定条件', u'返回值',
|
|
||||||
u'适用平台', u'作者', u'创建日期', u'修改记录', u'模块名称',
|
|
||||||
u'模块功能', u'函数说明', u'头文件', u'私有宏', u'私有变量',
|
|
||||||
u'私有函数', u'外部变量', u'作者',
|
|
||||||
]
|
|
||||||
for kw in comment_keywords:
|
|
||||||
# [?] * X -> ) * X
|
|
||||||
generic_fixes.append((rep + r'\? \* ' + kw, u') * ' + kw))
|
|
||||||
|
|
||||||
# 3. Various suffix patterns
|
|
||||||
generic_fixes.append((rep + r'\?\)', u'))'))
|
|
||||||
generic_fixes.append((u')' + rep + r'\?', u'))'))
|
|
||||||
|
|
||||||
# 4. [?]\n at end of line (before comment continuation)
|
|
||||||
# This is hard to do with simple string matching, use regex
|
|
||||||
|
|
||||||
# 5. Specific contexts that appear across files
|
|
||||||
generic_fixes.append((rep + r'\?,', u'),'))
|
|
||||||
generic_fixes.append((rep + r'\?。', u')。'))
|
|
||||||
|
|
||||||
# 6. Numbers or units followed by [?]
|
|
||||||
# e.g. "范围[?] * 函数" -> "范围)* 函数"
|
|
||||||
# e.g. "128KB[?] * 入口" -> "128KB)* 入口"
|
|
||||||
|
|
||||||
total_fixed = 0
|
|
||||||
for fname in files:
|
|
||||||
path = base + fname
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
raw = f.read()
|
|
||||||
text = raw.decode('utf-8', errors='replace')
|
|
||||||
before = text.count(rep)
|
|
||||||
if before == 0:
|
|
||||||
print('{}: clean'.format(fname))
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Apply generic pattern fixes
|
|
||||||
for pattern, replacement in generic_fixes:
|
|
||||||
text = re.sub(pattern, replacement, text)
|
|
||||||
|
|
||||||
# Manual patterns for each file
|
|
||||||
if 'ch395f.c' in fname:
|
|
||||||
text = text.replace(rep + '?' + u'DMA 接收缓冲区偏移', u'从 DMA 接收缓冲区偏移')
|
|
||||||
text = text.replace(u'创建日期' + rep + '?', u'创建日期:')
|
|
||||||
text = text.replace(u'要' + rep + '? */', u'要求 */')
|
|
||||||
text = text.replace(u'rx_buf[' + rep + '?', u'rx_buf]')
|
|
||||||
text = text.replace(u'取反' + rep + '?', u'取反为')
|
|
||||||
text = text.replace(u'在前' + rep + '? */', u'在前)*/')
|
|
||||||
text = text.replace(u'_ABORT' + rep + '? *', u'_ABORT)*')
|
|
||||||
text = text.replace(u'一' + rep + '?SPI', u'一次 SPI')
|
|
||||||
text = text.replace(u'缓冲' + rep + '?*/', u'缓冲区)*/')
|
|
||||||
text = text.replace(u'~7 + DHCPv6' + rep + '? *', u'~7 + DHCPv6)*')
|
|
||||||
text = text.replace(u'100ms)=默认' + rep + '?', u'100ms)=默认值')
|
|
||||||
text = text.replace(u'次数据=默认' + rep + '?', u'次数=默认值')
|
|
||||||
text = text.replace(u'最' + rep + '?128', u'最大 128')
|
|
||||||
|
|
||||||
if 'ch395f_test.c' in fname:
|
|
||||||
text = text.replace(u':8081' + rep + '? *', u':8081)*')
|
|
||||||
text = text.replace(u':8082' + rep + '? *', u':8082)*')
|
|
||||||
text = text.replace(u'创建' + rep + '?UDP', u'创建 UDP')
|
|
||||||
text = text.replace(u'IP ' + rep + '?打印', u'IP,打印')
|
|
||||||
text = text.replace(u'(1-byte version) ' + rep + '?read-clear', u'(1-byte version),read-clear')
|
|
||||||
|
|
||||||
if 'gd5f2gq5ue.c' in fname:
|
|
||||||
text = text.replace(u'对齐' + rep + '? *', u'对齐)*')
|
|
||||||
|
|
||||||
if 'sd2506.c' in fname:
|
|
||||||
text = text.replace(u'范围' + rep + '? *', u'范围)*')
|
|
||||||
text = text.replace(u'始终' + rep + '?])', u'始终为0])')
|
|
||||||
text = text.replace(u'(周期' + rep + '? */', u'(周期中断) */')
|
|
||||||
|
|
||||||
if 'tpafe5160.c' in fname:
|
|
||||||
text = text.replace(u'16位数据总线' + rep + '?GPIOG', u'16位数据总线(GPIOG')
|
|
||||||
text = text.replace(u'驱动' + rep + '?TPAFE5160', u'驱动适配 TPAFE5160')
|
|
||||||
text = text.replace(u'滞后' + rep + '?18-24ns', u'滞后约 18-24ns')
|
|
||||||
text = text.replace(u'说明' + rep + '?.', u'说明:')
|
|
||||||
text = text.replace(u'枚举' + rep + '? tpafe5160_os_t', u'枚举值 tpafe5160_os_t')
|
|
||||||
text = text.replace(u'锁存生' + rep + '? */', u'锁存生效 */')
|
|
||||||
text = text.replace(u'转换' + rep + '? - 空闲', u'转换中 - 空闲')
|
|
||||||
text = text.replace(u'原始化 int16_t', u'原始值 int16_t')
|
|
||||||
text = text.replace(u'有符号补' + rep + '? *', u'有符号补码 *')
|
|
||||||
text = text.replace(u'65536 ' + rep + '?152.59', u'65536 ≈ 152.59')
|
|
||||||
text = text.replace(u'65536 ' + rep + '?305.18', u'65536 ≈ 305.18')
|
|
||||||
text = text.replace(u'默' + rep + '?±5V', u'默认 ±5V')
|
|
||||||
text = text.replace(u'CS ' + rep + '?RD', u'CS 和 RD')
|
|
||||||
text = text.replace(u'写操' + rep + '?~6ns', u'写操作 ~6ns')
|
|
||||||
text = text.replace(u'主循环' + rep + '?s_buf_a', u'主循环读 s_buf_a')
|
|
||||||
text = text.replace(u'GPIO ' + rep + '?NVIC', u'GPIO 和 NVIC')
|
|
||||||
text = text.replace(u'调用' + rep + '? * 入口参数', u'调用)* 入口参数')
|
|
||||||
|
|
||||||
after = text.count(rep)
|
|
||||||
fixed = before - after
|
|
||||||
total_fixed += fixed
|
|
||||||
|
|
||||||
with open(path, 'wb') as f:
|
|
||||||
f.write(text.encode('utf-8'))
|
|
||||||
|
|
||||||
print('{}: fixed {} ({} -> {})'.format(fname, fixed, before, after))
|
|
||||||
|
|
||||||
print('\nTotal fixed: {}'.format(total_fixed))
|
|
||||||
|
|
||||||
# Show remaining
|
|
||||||
print('\n=== REMAINING ===')
|
|
||||||
for fname in files:
|
|
||||||
path = base + fname
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
text = f.read().decode('utf-8', errors='replace')
|
|
||||||
remaining = text.count(rep)
|
|
||||||
if remaining > 0:
|
|
||||||
print('\n--- {} remaining in {} ---'.format(remaining, fname))
|
|
||||||
for i, line in enumerate(text.split(chr(10)), 1):
|
|
||||||
if rep in line:
|
|
||||||
idx = line.index(rep)
|
|
||||||
left = line[max(0,idx-35):idx]
|
|
||||||
right = line[idx+2:idx+35]
|
|
||||||
ctx_u = left.encode('unicode-escape').decode()
|
|
||||||
ctx_v = right.encode('unicode-escape').decode()
|
|
||||||
print('L{}: ...{}[?]{}...'.format(i, left, right))
|
|
||||||
print(' ...{} [?] {}...'.format(ctx_u, ctx_v))
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
import sys, os
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
||||||
rep = chr(0xfffd)
|
|
||||||
base = 'D:\\Code\\DTU 程序\\STM32F4-Base\\'
|
|
||||||
|
|
||||||
all_fixes = [
|
|
||||||
# (filename, pattern_to_match, replacement_full_line_fragment)
|
|
||||||
|
|
||||||
# ch395f.c
|
|
||||||
('ch395f.c', 'rx_buf[' + rep + '? * 阻塞', 'rx_buf] * 阻塞'),
|
|
||||||
('ch395f.c', '默认值10' + rep + '?秒)', '默认值10 秒)'),
|
|
||||||
('ch395f.c', '默认值3' + rep + '? uint8_t', '默认值3 uint8_t'),
|
|
||||||
|
|
||||||
# ch395f_test.c
|
|
||||||
('ch395f_test.c', '回显' + rep + '? \ufffd?PING', '回显,PING'),
|
|
||||||
('ch395f_test.c', '创建' + rep + '? UDP', '创建 UDP'),
|
|
||||||
('ch395f_test.c', 'IP,打印结果 ' + rep + '?广播', 'IP,打印结果,广播'),
|
|
||||||
|
|
||||||
# gd5f2gq5ue.c
|
|
||||||
('gd5f2gq5ue.c', '块对' + rep + '? * size', '块对齐 * size'),
|
|
||||||
|
|
||||||
# sd2506.c
|
|
||||||
('sd2506.c', '个位存入' + rep + '4 )', '个位存入低 4 )'),
|
|
||||||
|
|
||||||
# tpafe5160.c
|
|
||||||
('tpafe5160.c', '6位数据总线' + rep + '?GPIOG', '16位数据总线(GPIOG'),
|
|
||||||
('tpafe5160.c', '滞后约 18-24ns' + rep + '? *', '滞后约 18-24ns,*'),
|
|
||||||
('tpafe5160.c', '电压' + rep + '? float', '电压值 float'),
|
|
||||||
('tpafe5160.c', 'IDR ' + rep + '?6位', 'IDR 16位'),
|
|
||||||
('tpafe5160.c', '~18ns ' + rep + '?RD 引脚', '~18ns,RD 引脚'),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Additional generic cleanups for things our fixes missed
|
|
||||||
# These handle cases where ? should be a specific Chinese character or punctuation
|
|
||||||
more_fixes = [
|
|
||||||
# Closing paren patterns
|
|
||||||
('ch395f.c', rep + '?\ufffd?' + u'10\ufffd?' + u'\u79d2', ' '),
|
|
||||||
('tpafe5160.c', u'\ufffd?' + u'HELLO', ''),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Remaining problematic patterns from output
|
|
||||||
specific = [
|
|
||||||
# ch395f_test.c - the ?HELLO issue
|
|
||||||
('Drivers\\BSP\\CH395F\\ch395f_test.c', u'结果 ' + rep + '?' + u'广播', u'结果,广播'),
|
|
||||||
# tpafe5160 line with multiple corruptions
|
|
||||||
('Drivers\\BSP\\TPAFE5160\\tpafe5160.c', u'总线' + rep + '?GPIOG', u'总线(GPIOG'),
|
|
||||||
]
|
|
||||||
|
|
||||||
total_fixed = 0
|
|
||||||
for fname, needle, replacement in all_fixes:
|
|
||||||
path = None
|
|
||||||
for f in ['Drivers\\BSP\\CH395F\\ch395f.c', 'Drivers\\BSP\\CH395F\\ch395f_test.c',
|
|
||||||
'Drivers\\BSP\\GD5F2GQ5UE\\gd5f2gq5ue.c', 'Drivers\\BSP\\NET\\net_select.c',
|
|
||||||
'Drivers\\BSP\\SD2506\\sd2506.c', 'Drivers\\BSP\\TPAFE5160\\tpafe5160.c']:
|
|
||||||
if fname in f:
|
|
||||||
path = base + f
|
|
||||||
break
|
|
||||||
if path is None:
|
|
||||||
continue
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
raw = f.read()
|
|
||||||
text = raw.decode('utf-8', errors='replace')
|
|
||||||
before = text.count(rep)
|
|
||||||
|
|
||||||
if needle in text:
|
|
||||||
text = text.replace(needle, replacement)
|
|
||||||
after = text.count(rep)
|
|
||||||
fixed = before - after
|
|
||||||
total_fixed += fixed
|
|
||||||
print('{}: fixed ({} -> {})'.format(fname, before, after))
|
|
||||||
else:
|
|
||||||
# Check what's actually in the file
|
|
||||||
lines = text.split(chr(10))
|
|
||||||
found = False
|
|
||||||
search_prefix = needle[:10]
|
|
||||||
for i, line in enumerate(lines, 1):
|
|
||||||
if rep in line and search_prefix in line:
|
|
||||||
idx = line.index(rep)
|
|
||||||
ctx = line[max(0,idx-20):idx+20]
|
|
||||||
print('{}: pattern not matched, closest at L{}: ...{}...'.format(fname, i, ctx))
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
print('{}: pattern not found at all'.format(fname))
|
|
||||||
|
|
||||||
with open(path, 'wb') as f:
|
|
||||||
f.write(text.encode('utf-8'))
|
|
||||||
|
|
||||||
print('\nTotal fixed this pass: {}'.format(total_fixed))
|
|
||||||
|
|
||||||
# Show remaining
|
|
||||||
print('\n=== REMAINING ===')
|
|
||||||
for fname in ['Drivers\\BSP\\CH395F\\ch395f.c', 'Drivers\\BSP\\CH395F\\ch395f_test.c',
|
|
||||||
'Drivers\\BSP\\GD5F2GQ5UE\\gd5f2gq5ue.c', 'Drivers\\BSP\\NET\\net_select.c',
|
|
||||||
'Drivers\\BSP\\SD2506\\sd2506.c', 'Drivers\\BSP\\TPAFE5160\\tpafe5160.c']:
|
|
||||||
path = base + fname
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
text = f.read().decode('utf-8', errors='replace')
|
|
||||||
remaining = text.count(rep)
|
|
||||||
if remaining > 0:
|
|
||||||
print('\n--- {} remaining in {} ---'.format(remaining, fname))
|
|
||||||
for i, line in enumerate(text.split(chr(10)), 1):
|
|
||||||
if rep in line:
|
|
||||||
idx = line.index(rep)
|
|
||||||
left = line[max(0,idx-40):idx]
|
|
||||||
right = line[idx+2:idx+40]
|
|
||||||
print('L{}: ...{}[?]{}...'.format(i, left, right))
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import subprocess, os, sys
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
||||||
base = 'D:\\Code\\DTU 程序\\STM32F4-Base\\'
|
|
||||||
|
|
||||||
result = subprocess.run(
|
|
||||||
['C:\\Program Files\\Git\\bin\\git.exe', 'show', '3466c4c:Drivers/BSP/CH395F/ch395f.c'],
|
|
||||||
capture_output=True,
|
|
||||||
cwd=base
|
|
||||||
)
|
|
||||||
git_text = result.stdout.decode('utf-8', errors='replace')
|
|
||||||
|
|
||||||
with open(os.path.join(base, 'Drivers\\BSP\\CH395F\\ch395f.c'), 'rb') as f:
|
|
||||||
wt_text = f.read().decode('utf-8', errors='replace')
|
|
||||||
|
|
||||||
rep = chr(0xfffd)
|
|
||||||
print('Git version: {} FFFD chars'.format(git_text.count(rep)))
|
|
||||||
print('Working tree: {} FFFD chars'.format(wt_text.count(rep)))
|
|
||||||
|
|
||||||
git_lines = git_text.split(chr(10))
|
|
||||||
wt_lines = wt_text.split(chr(10))
|
|
||||||
for i in range(min(len(git_lines), len(wt_lines))):
|
|
||||||
if git_lines[i] != wt_lines[i]:
|
|
||||||
print('\nFirst diff at line {}:'.format(i+1))
|
|
||||||
print(' GIT: {}'.format(git_lines[i][:120]))
|
|
||||||
print(' WT: {}'.format(wt_lines[i][:120]))
|
|
||||||
hex_g = git_lines[i].encode('utf-8').hex()[:40]
|
|
||||||
hex_w = wt_lines[i].encode('utf-8').hex()[:40]
|
|
||||||
print(' GIT hex: {}'.format(hex_g))
|
|
||||||
print(' WT hex: {}'.format(hex_w))
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('Files are identical')
|
|
||||||
Reference in New Issue
Block a user