#!perl #------------------------------------------------------------------------ # Copyright (C) 1995, 1996 University of Southern California (USC) and # USC Information Sciences Institute (USC/ISI). # # File : navigate-graph # Description: Navigation through graphical description of the system # Author : Rogelio Adobbati, based on Ali Erdem's old version # Language : Perl 4.0 #------------------------------------------------------------------------ require "idoc-utils.pl"; #------------------------------------------------------------------------ # Get HTTP request. #------------------------------------------------------------------------ sub get_request { if ($ENV{'REQUEST_METHOD'} eq "GET") { &init_sys_vars(); $command = $av{"command"}; &send_page(); } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { &init_sys_vars(); $command = $av{"command"}; &send_page(); } else { &send_error("Unknown REQUEST_METHOD given. GET or POST expected."); } } #------------------------------------------------------------------------ # Write MAP file and invoke Diagram Generator for display. #------------------------------------------------------------------------ sub send_page { &print_html_header("Dynamic Documentation: Graphical Navigation"); &print_header(); if (!&is_refine_system($system)) { print "

Note:This version of the graph tool only works for Refine/Ada systems.
\n"; return(); } # Create the transmission log. if (&send_to_refine() == 0) { print "

Error: could not get edges from Refine/Ada, please check server.
\n"; return(); } # Get edge list for map creation. local($line, $beginedges); foreach (@transmission_log) { if (/\[Start of all-edges list\]\s*(.*)/) { $line = $1; break; } } # Display a header and the applet call. print <<"EndOfPage";

Graphical representation of $system components


EndOfPage $javafile = "$IDOC_DIR/htdocs/diagen/development/demo/ampse-test.map"; $javafileold = "$javafile.old"; if (-e $javafile) { if (-r $javafile) { if (($status = rename($javafile, $javafileold)) == 1) { if (open(JAVAOUT, ">$javafile")) { &create_mapfile($line); close ($javafile); } else { &send_error("Can't [write] open $javafile"); } } else { &send_error("Can't rename $javafile: $!\n"); } } else { &send_error("Can't read $javafile\n"); } } else { &send_error("Can't find $javafile\n"); } } #------------------------------------------------------------------------ # Create the map file that the applet reads. #------------------------------------------------------------------------ sub create_mapfile { local($line) = @_; local(@edges,$edge,$edge_list,$debug,$count_edge,$count_anchor,%nodes); @edges = split(/,/,$line); $edge_list = ""; $debug = ""; $count_edge = 0; $count_anchor = 0; %nodes = (); foreach $edge (@edges) { if (&strip($edge,"\s")) { $_ = $edge; # Get the node names and node types /(.*)\/(.*)\/(.*)\/(.*)\/(.*)==(.*)\/(.*)\/(.*)\/(.*)\/(.*)/; $from = &trim($1); $from_type = &trim($2); $from_ver = &trim($3); $from_id = &trim($4); $from_prefix = &trim($5); $to = &trim($6); $to_type = &trim($7); $to_ver = &trim($8); $to_id = &trim($9); $to_prefix = &trim($10); #Now clean from (Refine duplicates 'type' in the name) $_ = $from; s/ *$from_type *//i; s/ /_/g; $from = $_; #Clean to $_ = $to; s/ *$to_type *//i; s/ /_/g; $to = $_; if ($from_type eq "MODULE") { $from_type = "Module"; } if ($to_type eq "MODULE") { $to_type = "Module"; } if ($from_type ne "PRAGMA" && $to_type ne "PRAGMA") { $edge_list = "from=$from_prefix.$from to=$to_prefix.$to/$to_type,"; $_=$edge_list; s/-/_/g; s/==/-/g; $line=$_; if (!$nodes{$from}) { $nodes{$from}= 1; printf(JAVAOUT "\n"); } if (!$nodes{$to}) { $nodes{$to}= 1; printf(JAVAOUT "\n"); } printf(JAVAOUT "\n"); $count_edge++; } $debug .= "Before=$edge\nAfter =$from=$from_type=$from_ver=$from_id=$to=$to_type=$to_ver=$to_id=\n\n"; } } print "\n"; } #------------------------------------------------------------------------ # Get all edges from Refine and store in transmission log #------------------------------------------------------------------------ sub send_to_refine { local($signal,$child); if (!&open_repository_connection($REFINE_PORT,$REFINE_HOST)) { return(0); } @transmission_log = (); pipe( SEND_READ, SEND_WRITE); if($child = fork) { close SEND_READ; select (SEND_WRITE); $| = 1; select (STDOUT); while () { #print "line=$_
\n"; s/type=MODULE/type=Module/; push(transmission_log, ($_)); if (/End of transmission/) { print SEND_WRITE "OK\n"; return(1); } elsif (/error/i) { print SEND_WRITE "ERROR\n"; return(0); } } close REPOSITORY; close SEND_WRITE; } else { close SEND_WRITE; print REPOSITORY "(format t \"Start of transmission\")\n"; print REPOSITORY "(in-package \"IDOC\")\n"; print REPOSITORY "(get-all-edges \"$system\")\n"; print REPOSITORY "(format t \"End of transmission\")\n"; $signal = ; if ($signal =~ /ERROR/i) { print REPOSITORY ":pop\n"; sleep 1; }; close REPOSITORY; close SEND_READ; exit; } } #------------------------------------------------------------------------ # Process GET/POST request. #------------------------------------------------------------------------ sub print_URL { if (!$duplicate_flag{"$from_prefix.$from"}) { $duplicate_flag{"$from_prefix.$from"} = 1; printf("\n",$count_anchor); $count_anchor++; } if (!$duplicate_flag{"$to_prefix.$to"}) { $duplicate_flag{"$to_prefix.$to"} = 1; printf("\n",$count_anchor); $count_anchor++; } } #------------------------------------------------------------------------ # Main processing. #------------------------------------------------------------------------ &get_request();