当前位置: 首页 > news >正文

对mozjpeg中的函数名进行替换

获取到mozjpeg中的所有函数名

import os
import redef process_files_in_directory(directory, pattern, output_file, valid_extensions):matches = []for root, _, files in os.walk(directory):for file_name in files:# 检查文件后缀if not any(file_name.endswith(ext) for ext in valid_extensions):continuefile_path = os.path.join(root, file_name)try:# 读取文件内容with open(file_path, 'r', encoding='utf-8') as file:content = file.read()# 查找匹配项,提取捕获组中的字符串file_matches = re.findall(pattern, content)matches.extend(file_matches)print(f"Processed {file_path}")except Exception as e:print(f"Error processing {file_path}: {e}")# 将所有匹配到的字符串写入到文件中if matches:with open(output_file, 'w', encoding='utf-8') as out_file:for match in matches:out_file.write(match + '\n')else:print("No matches found")# 示例调用
directory_to_search = r'Z:\\Variablereplace\\mozjpeg-master'
# 修改正则表达式,使用捕获组提取字符串
search_pattern = r"EXTERN\([^)]*\)\s+(\w+)"
output_file_path = 'output_file.txt'
# 指定需要处理的文件扩展名
valid_extensions = ['.c', '.h']process_files_in_directory(directory_to_search, search_pattern, output_file_path, valid_extensions)

获取到函数列表到指定文件后,删去simd相关的内容。

进行第一次替换,替换所有的函数名称。
第二次替换是替换def目录导出的函数

 import os
import redef replace_in_files(replace_dict, directory, extensions):""":param replace_dict: 进行替换的字典:param directory: 要搜索的目录:param extensions: 需要处理的文件后缀列表,例如 ['.txt', '.md']"""for root, _, files in os.walk(directory):for file_name in files:if any(file_name.endswith(ext) for ext in extensions):file_path = os.path.join(root, file_name)try:# 读取文件内容with open(file_path, 'r', encoding='utf-8') as file:content = file.read()# 进行替换for old_string, new_string in replace_dict.items():content = re.sub(r'\b' + re.escape(old_string) + r'\b', new_string, content)# 写回文件with open(file_path, 'w', encoding='utf-8') as file:file.write(content)print(f"Processed {file_path}")except Exception as e:print(f"Error processing {file_path}: {e}")def get_replacement_dict(file_path):replace_dict = {}try:with open(file_path, 'r', encoding='utf-8') as file:for line in file:line = line.strip()if line:  # 确保非空行replace_dict[line] = line + '_cjpeg'except Exception as e:print(f"Error reading replacement file {file_path}: {e}")return replace_dict# 示例调用
replacement_file_path = 'output_file.txt'
# directory_to_search = r'Z:\\Variablereplace\\mozjpeg-master'
# file_extensions = ['.c', '.h']  # 需要处理的文件后缀
directory_to_search = r"Z:\\Variablereplace\\mozjpeg-master\\win"
file_extensions = ['.def']  # 需要处理的文件后缀replace_dict = get_replacement_dict(replacement_file_path)
replace_in_files(replace_dict, directory_to_search, file_extensions) 

http://www.mrgr.cn/news/15798.html

相关文章:

  • 用矩阵乘法的底层原理来理解“特征融合”
  • Android强制设置所有应用显示方向,忽略应用本身的设置
  • 【面试题系列Vue06】Vue 单页应用与多页应用的区别
  • 损失函数、成本函数cost 、最大似然估计
  • 五,Spring Boot中的 Spring initializr 的使用
  • Runway删库跑路,真的run away了!
  • net6 core 接入nacos 实现服务注册入门使用,心跳检测和负载均衡
  • 从零开始:全面掌握C++ Qt开发框架基础
  • C#——扩展方法
  • 【2024 CCF编程能力等级认证(GESP)C++ 】一级大纲
  • pytorch view 函数介绍
  • 【大模型项目实战】练完这些项目,天下没有再难倒你的大模型
  • 集成电路学习:什么是DAC数模转换器
  • 从开题到答辩:ChatGPT超全提示词分享!(下)【建议收藏】
  • 【C++】智能指针
  • leetcode刷题-二叉树07
  • 咬破那片叶,看天
  • 企业需求管理好帮手:10款工具深度解析
  • 大学生学习python之后,就业迷茫怎么办?
  • 【练习1】数字统计