批量替换 freeimage.nim中的函数名字

1. 先从freeimage.dll中复制出函数的名字, 就是以文本的方式打开freeimage.dll, 查找FreeImage_Initialise , 然后附近的一大段函数都复制下来, 得到 free.txt文件


_FreeImage_AcquireMemory@12
_FreeImage_AdjustBrightness@12
_FreeImage_AdjustColors@32
_FreeImage_AdjustContrast@12
_FreeImage_AdjustCurve@12
_FreeImage_AdjustGamma@12
_FreeImage_Allocate@24
_FreeImage_AllocateEx@36
_FreeImage_AllocateExT@40

已上只复制了一小部分

2. 上代码批量替换

主要用正则表达式:

import re

funcs={}

for line in open('free.txt','r'):
    line = line.strip()
    #print line
    real = line
    key = line.split('@')[0]
    if key[0]=='_':
        key=key[1:]
    funcs[key]=line

#print funcs

text =  open('freeimage.nim','r').read()
#for x in re.findall('importc: "([\w\_\d]+)",', text):
#    print x
def dashrepl(matchobj):
    #print matchobj.group(1), type(matchobj.group(1))
    k= matchobj.group(1)
    return 'importc: "%s"' % funcs.get(k, k)

print re.sub('importc: "([\w\_\d]+)"',dashrepl, text)

最后print 得到的就是最终结果了







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值