package auto_doc; # $Id: auto_doc.pm 1375 2011-02-01 23:32:36Z wwoodard $ # Note: # Firefox 3 fails to process XSLT files if they are on the local hard drive plus # outside of the current XML file's path (or descendant paths). Users may need # to edit $HOME/.mozilla/firefox/*.default/prefs.js and add a new URI setting: # - user_pref("security.fileuri.strict_origin_policy", false); # OR # - type about:config in the address bar # - change security.fileuri.strict_origin_policy to false use Exporter(); @ISA = qw(Exporter); @EXPORT = qw(print_xml_CP print_xml_mis print_xml_icg); use File::Basename; use Text::Balanced qw ( extract_bracketed ); use strict; use gte; my(%default_data_files, %object_jobs, @object_names, %jobs, %object_structs, $vt_ref); sub print_xml_CP($) { my($sim_ref) = @_; my $title; # Get the title of the sim from the file "Title" if (open TITLE, "Title") { $title = ; chomp $title; } else { $title = "No Title Specified"; } open XML_FILE, ">S_document.xml" or die "Could not open S_document.xml\n"; # Start the xml code print_xml_xml_header("$ENV{TRICK_HOME}/docs/trick_s_define.xsl"); print XML_FILE "<s_define>\n"; print XML_FILE " " x 4, "<title>$title\n"; # Given an array of simulation objects, sort array by 'objname' values # foreach my $o (sort { ${$a}{objname} cmp ${$b}{objname} } @{$$sim_ref{objs}}) { # # print XML_FILE " " x 4, "\n"; # # print XML_FILE " " x 8, # "$$o{objname}\n\n"; # # # printout the structures found in each object # print XML_FILE " " x 8, "\n"; # # Given an array of structures per sim_object, sort array by 'strname' values # foreach my $s (sort { ${$a}{strname} cmp ${$b}{strname} } @{$$o{structs}}) { # print XML_FILE " " x 12, "\n"; # print XML_FILE " " x 16, "$$s{strname}\n"; # $$sim_ref{icg_types}{$$s{strname}}{files}{$$s{file}}{xml} =~ s/^TRICK_HOME\//$ENV{TRICK_HOME}\// ; # print XML_FILE " " x 16, "$$sim_ref{icg_types}{$$s{strname}}{files}{$$s{file}}{xml}\n"; # print XML_FILE " " x 16, "\n"; # foreach my $d (sort @{$$s{def_data}}) { # print XML_FILE " " x 20, "$d\n"; # } # print XML_FILE " " x 16, "\n"; # print XML_FILE " " x 12, "\n"; # } # print XML_FILE " " x 8, "\n\n"; # # # print out each job found in this object # print XML_FILE " " x 8, "\n"; # # Given an array of jobs per sim_object, sort array by 'jobname' values # foreach my $j (sort { ${$a}{jobname} cmp ${$b}{jobname} } @{$$o{jobs}}) { # my ($file_name, $model_dir, $suffix) = # fileparse( $$j{file}, ("\.h" , "\.hh" , "\.c" , "\.f", "\.cpp" , "\.cxx" , "\.C" , "\.cc" , "\.c\\+\\+" )); # ($model_dir = $$j{file}) =~ s/(\/src)?\/([^\/]+)$// ; # if ($model_dir =~ m/\/include$/ ){ # $model_dir =~ s/(\/include)?\/([^\/]+)$// ; # } # print XML_FILE " " x 12, "\n"; # print XML_FILE " " x 16, "$$j{jobname}\n"; # print XML_FILE " " x 16, "${model_dir}/xml/${file_name}${suffix}.xml\n"; # print XML_FILE " " x 12, "\n"; # } # print XML_FILE " " x 8, "\n"; # print XML_FILE " " x 4, "\n\n"; # } print XML_FILE "\n"; close XML_FILE ; } sub print_xml_mis ($$$$) { my ($curr_file , $entries , $header_ptr, $includes) = @_ ; my ($out_file_basename , $name , $path , $suffix, $file_path_dir ) ; my %header = %$header_ptr ; my ($xml_file , $xml_dir , $file_version ) ; my ($subme , @inc_paths ) ; my $i ; $out_file_basename = $curr_file ; ($name, $path, $suffix) = fileparse( $curr_file, ("\.h" , "\.hh" , "\.c" , "\.f", "\.cpp" , "\.cxx" , "\.C" , "\.cc" , "\.c\\+\\+" )); $file_path_dir = dirname($curr_file) ; if ($file_path_dir eq ".") { $file_path_dir = cwd(); } $file_path_dir =~ s/\/+$// ; # remove trailing slash $path =~ s/\/+$// ; # remove trailing slash if ($file_path_dir !~ /sim_services\/include/ and $file_path_dir =~ s/\/src$// ) { $xml_file = $file_path_dir . "/xml/" . $name . $suffix . ".xml" ; $xml_dir = $file_path_dir . "/xml" ; } else { $xml_file = $path . "/xml/" . $name . $suffix . ".xml" ; $xml_dir = $path . "/xml" ; } if ( ! -e $xml_dir ) { mkdir $xml_dir, 0775 ; } $file_version = $file_path_dir ; foreach $subme (@inc_paths) { if ($file_version =~ s,^$subme/,, ) { # if found break out last ; } } open XML_FILE ,">$xml_file" or die "Couldn't open file for writing $xml_file\n" ; print_xml_xml_header( "$ENV{TRICK_HOME}/docs/trick_module.xsl") ; print_xml_body_header(); print_xml_trick_header($curr_file, \%header); print XML_FILE " " x 4 , "\n" ; foreach my $entry (@$entries) { if ( !exists $$entry{valid} ) { next ; } print XML_FILE " " x 8 , "\n" ; print_xml_child("job_name", $$entry{name}, 12); print_xml_child("return_type", $$entry{return_type}, 12); print_xml_child("units", $$entry{units}, 12); print_xml_child("comment", $$entry{desc}, 12); print XML_FILE " " x 12 , "\n" ; foreach my $arg ( @{$$entry{arg_list}} ) { print XML_FILE " " x 16 , "\n" ; print_xml_child("arg_name", $$arg{name}, 20); print_xml_child("type", $$arg{type}, 20); print_xml_child("dims", "$$arg{pointers} $$arg{array}", 20); print_xml_child("inout", ucfirst lc $$arg{inout}, 20); print_xml_child("units", $$arg{unit}, 20); print_xml_child("comment", $$arg{desc}, 20); print XML_FILE " " x 16 , "\n" ; } print XML_FILE " " x 12 , "\n" ; print XML_FILE " " x 8 , "\n" ; } print XML_FILE " " x 4 , "\n" ; print XML_FILE " " x 4 , "\n" ; foreach (@$includes) { s//>/g; s/"/"/g; print XML_FILE " " x 8 , "$_\n"; } print XML_FILE " " x 4 , "\n" ; print_xml_body_footer(); close XML_FILE ; } sub print_xml_icg ($$$$$) { my ($file_name, $xml_file, $header, $enums_info, $structs_info) = @_ ; open XML_FILE ,">$xml_file" or die "Couldn't open file for writing $xml_file\n" ; print_xml_xml_header( "$ENV{TRICK_HOME}/docs/trick_struct.xsl") ; print_xml_body_header(); print_xml_trick_header( $file_name, $header) ; # print the enums print XML_FILE " " x 4 , "\n" ; foreach my $pe_ret ( @$enums_info ) { foreach my $enum ( @{$$pe_ret{enum_names}} ) { print XML_FILE " " x 8 , "\n" ; print XML_FILE " " x 12 , "$enum\n" ; foreach my $name_val ( @{$$pe_ret{enums}} ) { print XML_FILE " " x 12 , "\n" ; print XML_FILE " " x 16 , "$$name_val{name}\n" ; print XML_FILE " " x 16 , "$$name_val{value}\n" ; $$name_val{comment} =~ s/&/&/g ; $$name_val{comment} =~ s/\\?"/"/g ; $$name_val{comment} =~ s//>/g ; print XML_FILE " " x 16 , "$$name_val{comment}\n" ; print XML_FILE " " x 12 , "\n" ; } print XML_FILE " " x 8 , "\n" ; } } print XML_FILE " " x 4 , "\n\n" ; # print the structs print XML_FILE " " x 4 , "\n" ; foreach my $ps_ret ( @$structs_info ) { foreach my $str ( @{$$ps_ret{struct_names}} ) { print XML_FILE " " x 8 , "\n" ; print XML_FILE " " x 12 , "$str\n" ; foreach my $param ( @{$$ps_ret{param_info}} ) { print XML_FILE " " x 12 , "\n" ; print XML_FILE " " x 16 , "$$param{p_name}\n" ; print XML_FILE " " x 16 , "$$param{p_type}\n" ; if ( $$param{p_link} ne "" ) { $$param{p_link} =~ s/^TRICK_HOME\//$ENV{TRICK_HOME}\// ; print XML_FILE " " x 16 , "$$param{p_link}\n" ; } if ( $$param{p_is_enum} ) { print XML_FILE " " x 16 , "$$param{p_is_enum}\n" ; } print XML_FILE " " x 16 , "$$param{p_dim_xml}\n" ; print XML_FILE " " x 16 , "$$param{p_unit}\n" ; $$param{p_desc} =~ s/&/&/g ; $$param{p_desc} =~ s/\\?"/"/g ; $$param{p_desc} =~ s//>/g ; print XML_FILE " " x 16 , "$$param{p_desc}\n" ; print XML_FILE " " x 12 , "\n" ; } print XML_FILE " " x 8 , "\n\n" ; } } print XML_FILE " " x 4 , "\n\n" ; print_xml_body_footer(); close XML_FILE ; } sub print_xml_xml_header($) { my ($xsl_file) = @_ ; print XML_FILE "\n" ; print XML_FILE "\n"; print XML_FILE "\n" ; print XML_FILE "\n" ; print XML_FILE "\n" ; } sub print_xml_body_header() { print XML_FILE "\n" ; } sub print_xml_body_footer() { print XML_FILE "\n" ; } sub print_xml_trick_header($$) { my ($full_file_name, $header) = @_ ; my ($tail_name, $path, $suffix) = fileparse( $full_file_name, ("\.h" , "\.hh" , "\.c" , "\.f", "\.cpp" , "\.cxx" , "\.C" , "\.cc" , "\.c\\+\\+" )); print_xml_child("file_name", "$tail_name$suffix", 4); print_xml_child("full_path_file_name", $full_file_name, 4); print XML_FILE " " x 4 , "\n" ; print_xml_references($header); print_xml_parent_children($header, "assumptions", "assumption", "assumptions and limitations"); print_xml_parent_children($header, "requirements", "requirement", "requirements"); print_xml_parent_children($header, "library_dependencies", "library_dependency", "libdep"); print_xml_parent_children($header, "purpose", "", "purpose"); print_xml_parent_children($header, "class", "", "class"); print_xml_programmers($header, "programmers", "programmer", "programmers"); print XML_FILE " " x 4 , "\n\n" ; } sub print_xml_parent_children($$$$) { # # Print: # # # my ($header_ptr, $xml_parent_name, $xml_child_name, $trick_name) = @_ ; my %header = %$header_ptr ; print XML_FILE " " x 8 , "<$xml_parent_name>" ; if ( $xml_child_name ne "" ) { print XML_FILE "\n" ; } foreach my $h ( keys %header ) { my @list ; @list = split /\)[ \t\n]*\(/ , $header{$h} ; foreach my $ll ( @list ) { if ( $h eq $trick_name ) { print_xml_child($xml_child_name, $ll, 12); } } } if ( $xml_child_name ne "" ) { print XML_FILE " " x 8 , "\n" ; } else { print XML_FILE "\n" ; } } sub print_xml_child($$$) { # Print a child xml node # # value # my ($xml_name, $value, $indent_level) = @_ ; $value =~ s/\(|\)//g ; $value =~ s/&/&/g ; $value =~ s/\\?"/"/g ; $value =~ s//>/g ; $value =~ s/\n/ /g ; $value =~ s/[ ]+/ /g ; $value =~ s/\s\s+/ /g ; if ( $xml_name ne "" ) { print XML_FILE " " x $indent_level , "<$xml_name>" ; } print XML_FILE " $value " ; if ( $xml_name ne "" ) { print XML_FILE "\n" ; } } sub print_xml_references($) { my ($header_ptr) = @_ ; my %header = %$header_ptr ; my $idx = 0 ; print XML_FILE " " x 8 , "\n" ; my @list ; my ($temp , $ref) ; $temp = $header{"reference"} ; $temp =~ s/^\(// ; do { ($ref, $temp) = extract_bracketed($temp,"()"); if ( $ref ne "" ) { @list = split /\)[ \t\n]*\(/ , $ref ; print XML_FILE " " x 12 , "\n" ; print_xml_child("author", @list[0], 16) ; print_xml_child("source", @list[1], 16) ; print_xml_child("ident", @list[2], 16) ; print_xml_child("location", @list[3], 16) ; print_xml_child("date", @list[4], 16) ; print_xml_child("notes", @list[5], 16) ; print XML_FILE " " x 12 , "\n" ; $idx = $idx + 6 ; } } while ( $ref ne "" ) ; print XML_FILE " " x 8 , "\n" ; } sub print_xml_programmers($) { my ($header_ptr) = @_ ; my %header = %$header_ptr ; my $idx = 0 ; print XML_FILE " " x 8 , "\n" ; foreach my $h ( keys %header ) { my @list ; @list = split /\)[ \t\n]*\(/ , $header{$h} ; if ( $h eq "programmers" ) { while ( $idx <= $#list ) { print XML_FILE " " x 12 , "\n" ; print_xml_child("programmer", @list[$idx + 0], 16) ; print_xml_child("employer", @list[$idx + 1], 16) ; print_xml_child("date", @list[$idx + 2], 16) ; print_xml_child("ident", @list[$idx + 3], 16) ; print_xml_child("notes", @list[$idx + 4], 16) ; print XML_FILE " " x 12 , "\n" ; $idx = $idx + 5 ; } } } print XML_FILE " " x 8 , "\n" ; } 1;