#!/usr/bin/env python3"""This script splits httplib.h into .h and .cc parts."""import argparseimport osimport sysborder = '// ----------------------------------------------------------------------------'args_parser = argparse.ArgumentParser(description=__doc__)args_parser.add_argument("-e", "--extension", help="extension of the implementation file (default: cc)",default="cc")args_parser.add_argument("-o", "--out", help="where to write the files (default: out)", default="out")args = args_parser.parse_args()cur_dir = os.path.dirname(sys.argv[0])lib_name = 'httplib'header_name = '/' + lib_name + '.h'source_name = '/' + lib_name + '.' + args.extension# get the input filein_file = cur_dir + header_name# get the output fileh_out = args.out + header_namecc_out = args.out + source_name# if the modification time of the out file is after the in file,# don't split (as it is already finished)do_split = Trueif os.path.exists(h_out):in_time = os.path.getmtime(in_file)out_time = os.path.getmtime(h_out)do_split = in_time > out_timeif do_split:with open(in_file) as f:lines = f.readlines()python_version = sys.version_info[0]if python_version < 3:os.makedirs(args.out)else:os.makedirs(args.out, exist_ok=True)in_implementation = Falsecc_out = args.out + source_namewith open(h_out, 'w') as fh, open(cc_out, 'w') as fc:fc.write('#include "httplib.h"\n')fc.write('namespace httplib {\n')for line in lines:is_border_line = border in lineif is_border_line:in_implementation = not in_implementationelif in_implementation:fc.write(line.replace('inline ', ''))else:fh.write(line)fc.write('} // namespace httplib\n')print("Wrote {} and {}".format(h_out, cc_out))else:print("{} and {} are up to date".format(h_out, cc_out))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。