2121import argparse
2222import signal
2323import threading
24+ import html
2425
2526def main ():
2627 # Set up argument parser
2728 parser = argparse .ArgumentParser (description = "Runs the doxygen comment viewer HTTP server." )
2829 parser .add_argument ('--port' , type = int , default = 8000 , help = 'Port number to run the server on' )
2930 parser .add_argument ('--doxygen' , type = str , default = 'doxygen' , help = 'Path to doxygen executable' )
3031 parser .add_argument ('--doxyfile' , type = str , default = 'Doxyfile' , help = 'Path to Doxyfile to use' )
31- parser .add_argument ('--debug' , action = "store_true" , help = 'Display warnings' )
32- parser .add_argument ('--version' , action = "store_true" , help = 'Display doxygen version used' )
3332 args = parser .parse_args ()
3433
3534 PORT = args .port
3635 DOXYGEN = args .doxygen
3736 DOXYFILE = args .doxyfile
38- DEBUG = args .debug
39- VERSION = args .version
40-
41- if VERSION :
42- VERSION_STR = subprocess .run ([DOXYGEN , '-v' ], \
43- capture_output = True , text = True , encoding = "utf-8" )
37+ VERSION_STR = subprocess .run ([DOXYGEN , '-v' ], capture_output = True , text = True , encoding = "utf-8" ).stdout
4438
4539 class RequestHandler (http .server .SimpleHTTPRequestHandler ):
4640 def do_POST (self ):
@@ -50,22 +44,21 @@ def do_POST(self):
5044 data = json .loads (post_data )
5145 input_text = data ['input' ]
5246
53- # Run doxygen in single comment mode, reading from stdin and writing to stdout
47+ # Run doxygen in single comment mode, reading from stdin and writing to stdout and stderr
5448 result = subprocess .run ([DOXYGEN , '-c' , '-' , DOXYFILE ], \
5549 input = input_text , capture_output = True , text = True , encoding = "utf-8" )
5650
57- # Insert CSS link tag into the HTML output
51+ # Prepare the response
52+ response = json .dumps ({
53+ 'html_output' : result .stdout ,
54+ 'error_output' : "<b>Doxygen version " + html .escape (VERSION_STR )+ "</b><pre>" + html .escape (result .stderr )+ "</pre>"
55+ })
56+
57+ # Send the result to the requesting HTML page
5858 self .send_response (200 )
5959 self .send_header ('Content-type' , 'text/html' )
6060 self .end_headers ()
61- if VERSION :
62- self .wfile .write (VERSION_STR .stdout .encode ())
63- self .wfile .write ("<hr>" .encode ())
64- self .wfile .write (result .stdout .encode ())
65- if DEBUG :
66- self .wfile .write ("<hr>\n <pre>" .encode ())
67- self .wfile .write (result .stderr .replace ('&' ,'&' ).replace ("'" ,"'" ).replace ('<' ,'<' ).replace ('>' ,'>' ).encode ())
68- self .wfile .write ("</pre>" .encode ())
61+ self .wfile .write (response .encode ())
6962
7063 httpd = socketserver .TCPServer (("" , PORT ), RequestHandler )
7164
0 commit comments