1: get_file.sh
#!/bin/sh
code_path="/root/utHash"
files_name="file_path.cfg"
cfg_file_path="./${files_name}"
if [ -e $cfg_file_path ]
then
rm $cfg_file_path
fi
find $code_path -depth -name "*.c" > $cfg_file_path
find $code_path -depth -name "*.h" >> $cfg_file_path
2:
import re
import os
struct_vals = []
cfg_file_name = 'file_path.cfg'
struct_file_name = 'struct.c'
rex = '(struct\s+(\w+)\s+\{(?:\s+(?:struct\s+)?\w+\s+\w+;)+\s+\})'
#rex = 'struct\s+(\w+)\s+{(\s+\w+\s+\w+;\s+)+\s+}'
def output_c_file(struct_val_list):
with open(struct_file_name, 'w') as fd_struct:
for i in struct_val_list:
fd_struct.write('/* struct ' + i[1] + ' */\n')
fd_struct.write(i[0])
fd_struct.write('\n')
with open(cfg_file_name, 'r') as fd_path:
file_path = fd_path.readline()
while file_path <> "":
with open(file_path.replace("\n", ""), 'r') as fd_file:
buf = fd_file.read()
match_result = re.findall(rex, buf)
if match_result <> []:
print(match_result)
for i in match_result:
print(i)
if i not in struct_vals:
struct_vals.append(i)
file_path = fd_path.readline()
output_c_file(struct_vals)
print(struct_vals)
所有评论(0)