#!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 "