#Copyright (c) 2025 Huawei Technologies Co., Ltd.
#This program is free software, you can redistribute it and/or modify it under the terms and conditions of
#CANN Open Software License Agreement Version 2.0 (the "License").
#Please refer to the License for details. You may not use this file except in compliance with the License.
#THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
#INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
#See LICENSE in the root of the software repository for the full text of the License.
import sys
sys.stdout.reconfigure(encoding='utf-8')
p = r'D:\AI\Vector_error_testing_angent\skills\ascendc-fuzz-cpp-gen\scripts\gen_error_cpp.py'
with open(p, 'rb') as f:
data = f.read()
# Approach: just globally replace ALL occurrences of the 3-byte sequence
# 0x5C 0x5C 0x6E (double-backslash + n) with 0x5C 0x6E (single-backslash + n)
# This works because:
# - In Python source strings, \\n means literal backslash-n (2 bytes in .py file)
# - In emit_raw, that becomes C++ output \n which is the newline escape - CORRECT
# - But we have \\\\n in some places (4 bytes in .py: \,\,n or actually 0x5C,0x5C,0x6E)
# Wait no. Let me just look at the actual bytes.
# Let me scan for the exact pattern that's wrong
count = 0
pos = 0
while True:
pos = data.find(b'\x5c\x5c\x6e', pos) # double-backslash + n
if pos < 0:
break
# Get context
ctx = data[max(0,pos-30):pos+20]
count += 1
pos += 3
print(f'Total double-backslash+n occurrences: {count}')
# Replace ALL of them
new_data = data.replace(b'\x5c\x5c\x6e', b'\x5c\x6e')
new_count = 0
pos = 0
while True:
pos = new_data.find(b'\x5c\x5c\x6e', pos)
if pos < 0:
break
new_count += 1
pos += 3
print(f'After replacement: {new_count}')
with open(p, 'wb') as f:
f.write(new_data)
print('Written successfully')