strip-license.py 788 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. import sys
  3. def main ():
  4. if len(sys.argv) < 2:
  5. return
  6. for filepath in sys.argv[1:]:
  7. process_file(filepath)
  8. def process_file (filepath):
  9. file_in = open(filepath, "rb")
  10. content = file_in.read()
  11. file_in.close()
  12. if content[0] != '/' or content[1] != '*':
  13. return
  14. # Find the position of "*/".
  15. n = len(content)
  16. has_star = False
  17. for i in xrange(2, n):
  18. c = content[i]
  19. if has_star and c == '/':
  20. # Dump all after this position.
  21. if i == n-2:
  22. return
  23. file_out = open(filepath, "wb")
  24. file_out.write(content[i+2:])
  25. file_out.close()
  26. return
  27. has_star = c == '*'
  28. if __name__ == '__main__':
  29. main()