A semantic search engine for source code https://bitshift.benkurtovic.com/
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import socket, sys, struct
  2. file_name = 'resources/<name>.c'
  3. server_socket_number = 5001
  4. recv_size = 8192
  5. if __name__ == '__main__':
  6. if len(sys.argv) == 1:
  7. print "Please input a parser to test."
  8. elif len(sys.argv) > 2:
  9. print "Too many arguments."
  10. else:
  11. if sys.argv[1] == 'c':
  12. pass
  13. elif sys.argv[1] == 'java':
  14. file_name = "resources/Matrix.java"
  15. server_socket_number = 5002
  16. elif sys.argv[1] == 'ruby':
  17. file_name = "resources/parser.rb"
  18. server_socket_number = 5065
  19. server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  20. server_socket.connect(("localhost", server_socket_number))
  21. with open(file_name, "r") as source_file:
  22. source = source_file.read()
  23. server_socket.send("%d\n%s" % (len(source), source));
  24. total_data = []; size_data = cur_data = ''
  25. total_size = 0; size = sys.maxint
  26. while total_size < size:
  27. cur_data = server_socket.recv(recv_size)
  28. if not total_data:
  29. if len(size_data) > 4:
  30. size_data += cur_data
  31. size = struct.unpack('>i', size_data[:4])[0]
  32. recv_size = size
  33. if recv_size > sys.maxint: recv_size = sys.maxint
  34. total_data.append(size_data[4:])
  35. else:
  36. size_data += cur_data
  37. else:
  38. total_data.append(cur_data)
  39. total_size = sum([len(s) for s in total_data])
  40. server_socket.close()
  41. print ''.join(total_data);