add-modelines.py 668 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. import sys
  3. top_line = "/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */"
  4. bottom_line = "/* vim:set shiftwidth=4 softtabstop=4 expandtab: */"
  5. def main ():
  6. if len(sys.argv) < 2:
  7. return
  8. for filepath in sys.argv[1:]:
  9. process_file(filepath)
  10. def process_file (filepath):
  11. file_in = open(filepath, "rb")
  12. content = file_in.read()
  13. file_in.close()
  14. file_out = open(filepath, "wb")
  15. file_out.write(top_line)
  16. file_out.write("\n")
  17. file_out.write(content)
  18. file_out.write(bottom_line)
  19. file_out.write("\n")
  20. file_out.close()
  21. if __name__ == '__main__':
  22. main()