"Fossies" - the Fresh Open Source Software Archive

Member "cppcheck-1.89/tools/astyle_client.py" (1 Sep 2019, 1241 Bytes) of package /windows/misc/cppcheck-1.89.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "astyle_client.py" see the Fossies "Dox" file reference documentation.

    1 import os
    2 import socket
    3 import sys
    4 import time
    5 
    6 def receive_data(conn):
    7     data = ''
    8     for t in range(1000):
    9         d = conn.recv(8196)
   10         if d:
   11             data += d
   12             if data.endswith('\nDONE'):
   13                 return data[:-5]
   14         time.sleep(0.01)
   15     return ''
   16 
   17 
   18 def astyle(server_address, code):
   19     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   20     try:
   21         sock.connect(server_address)
   22         sock.sendall(code + '\nDONE')
   23         return receive_data(sock)
   24     except socket.error as err:
   25         print('Network error: ' + str(err))
   26     sock.close()
   27     return None
   28 
   29 if __name__ == "__main__":
   30     server_address = ('cppcheck.osuosl.org', 18000)
   31 
   32     for filename in sorted(sys.argv[1:]):
   33         if not (filename.endswith('.cpp') or filename.endswith('.h')):
   34             continue
   35 
   36         f = open(filename, 'rt')
   37         code = f.read()
   38         f.close()
   39         formatted_code = astyle(server_address, code)
   40         if formatted_code is None:
   41             break
   42         if code != formatted_code:
   43             print('Changed: ' + filename)
   44             f = open(filename, 'wt')
   45             f.write(formatted_code)
   46             f.close()
   47         else:
   48             print('Unchanged: ' + filename)
   49