Rough python script to dump structs from header files to .html.
Endless room to improve, no ego on the part of the developer.
#!/usr/bin/python """Version: 0.1
-
Script to descend selected paths in source tree and dump structure definitions to single HTML page. We rely heavily on properly formatted code, and appreciate the effort spent keeping the codebase tidy, so that these regular expressions can be trivial.
Edit the output file path. Obviously these will become command-line
Execute script, open output file in web browser (even lynx!).
With all three paths below, there are ~2300 structs. So there
It would be nice to format the output a little more consistently,
It would also be cool to detect when structs embed each other, and
License: GPL v2 Copyright 2006, Christopher L. Smith, smitty1elkml@gmail.com
#Edit the desired list of structs to this list.
all_your_paths.append( root + 'arch/i386' )
#all_your_paths.append( root + 'fs/ext3' )
#all_your_paths.append( root + 'include/linux' )
output = open( "/mnt/dmz/proj/allstructs.htm", "w" )
FAT_TAB = " " # "
re_h = re.compile("\.h$" ) #a header file
re_s = re.compile("^(struct)\s*([\w|_]*)(.*{$)") #a structure
re_c = re.compile("^}.*;$") #end of a struct
struct_names = {} #index builder
def print_struct( file_handle, i ):
def scan_file( path_name, file_handle, i ):
"""Walk FILE_HANDLE, dumping structures to TMP_FILE.
def descend_path( start_here ):
"""START_HERE is the root of the tree descent to look for structures.
for root, dirs, files in os.walk( start_here ):
def format_struct_names( key_list, long_name ):
"""After all of the processing is done, we take the list of keys,
structs_per_col = len(key_list) // COLUMN_COUNT
overflow_cols = len(key_list) % COLUMN_COUNT
output.write( "<table><tr valign='top'><td>" )
for col_counter in range( 0, COLUMN_COUNT ):
column_chunk = structs_per_col
if ( col_counter < overflow_cols ):
for index in range( 0, column_chunk ):
running_total = running_total + index + 1
output.write( "</td></tr></table><br>" )
[descend_path( this_path ) for this_path in all_your_paths]
output.write( "<html><body>" )
key_list = struct_names.keys()
output.write( "list length: %s<br>" % len(key_list) )
format_struct_names( key_list, long_name )
output.write( str(tmp_file).replace("', '", "") ) #spurious and
output.write( "</body></html>" )
