AutoIt脚本的反编译和代码格式化问题分析(lua脚本反编译工具手机版)新鲜出炉

随心笔谈3年前发布 admin
189 0 0

文章摘要

这篇文章介绍了一种自动生成格式化注释的Python脚本。该脚本通过定义两个函数`au3formater`和`main`,实现对输入注释文件的处理。`au3formater`函数根据注释语句调整缩进和换行符,`main`函数则读取输入文件并将其格式化后的注释写入输出文件。该脚本主要用于自动调整注释格式,提升代码的可读性和一致性。


#!/usr/bin/env python2.7
#-*- coding: utf-8 -*-

_AU3=’;https://www.jb51.net/article/sample.au3′;
_AU3_OUT=’;https://www.jb51.net/article/format.au3′;
_INDENT=’; ‘; * 4

def au3formater(line, indent):
line=line.strip().lower()

next_indent=indent
if (line.startswith(‘;end’;) or
line.startswith(‘;until’;) or
line in (‘;next’;, ‘;wend’;)):
indent -=1
next_indent -=1
elif line.startswith(‘;if’;) and line.endswith(‘;then’;):
next_indent +=1
elif (line.startswith(‘;func’;) or
line.startswith(‘;for’;) or
line.startswith(‘;select’;) or
line.startswith(‘;switch’;) or
line.startswith(‘;while’;) or
line==’;do’;):
next_indent +=1
elif line.startswith(‘;else’;) or line.startswith(‘;case’;):
indent -=1
new_line=_INDENT * indent + line

return new_line, next_indent

def main():
with open(_AU3, ‘;r’;) as fp:
with open(_AU3_OUT, ‘;w’;) as fpw:
indent=0
line=fp.readline()
while line:
new_line, indent=au3formater(line, indent)
fpw.write(‘;%s\n’; % new_line)
line=fp.readline()

if __name__==’;__main__’;:
main()

© 版权声明

相关文章