split.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. """This script splits httplib.h into .h and .cc parts."""
  3. import argparse
  4. import os
  5. import sys
  6. border = '// ----------------------------------------------------------------------------'
  7. args_parser = argparse.ArgumentParser(description=__doc__)
  8. args_parser.add_argument(
  9. "-e", "--extension", help="extension of the implementation file (default: cc)",
  10. default="cc"
  11. )
  12. args_parser.add_argument(
  13. "-o", "--out", help="where to write the files (default: out)", default="out"
  14. )
  15. args = args_parser.parse_args()
  16. cur_dir = os.path.dirname(sys.argv[0])
  17. with open(cur_dir + '/httplib.h') as f:
  18. lines = f.readlines()
  19. python_version = sys.version_info[0]
  20. if python_version < 3:
  21. os.makedirs(args.out)
  22. else:
  23. os.makedirs(args.out, exist_ok=True)
  24. in_implementation = False
  25. h_out = args.out + '/httplib.h'
  26. cc_out = args.out + '/httplib.' + args.extension
  27. with open(h_out, 'w') as fh, open(cc_out, 'w') as fc:
  28. fc.write('#include "httplib.h"\n')
  29. fc.write('namespace httplib {\n')
  30. for line in lines:
  31. is_border_line = border in line
  32. if is_border_line:
  33. in_implementation = not in_implementation
  34. elif in_implementation:
  35. fc.write(line.replace('inline ', ''))
  36. else:
  37. fh.write(line)
  38. fc.write('} // namespace httplib\n')
  39. print("Wrote {} and {}".format(h_out, cc_out))