123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- #!/usr/local/bin/perl -n
- #
- # This script converts graphs in GraphEd format to GraphEdPro Format.
- # Note: it relies heavily on the way GraphEd writes files !
- #
- # Note: this script needs perl version 5.
- #
- # (C) Michael Himsolt / Graphlet Project,
- # University of Passau, 1995-1996
- #
- BEGIN {
- $true= (42 == 42);
- $false= (42 != 42);
- $includegraphed=$false;
- $LastNodeId=-1;
- $GraphicsStarted=$false;
- }
- ##########################################
- #
- # Convert header line
- #
- ##########################################
- if (/^GRAPH\b\s*=*\s*(".*")/) {
- print "graph [\n";
- if ($1 ne "") {
- print "label $1\n";
- }
-
- if (/\bDIRECTED\b/) {
- print "directed 1\n";
- } elsif (/\bUNDIRECTED\b/) {
- print "directed 0\n";
- } else {
- print "directed 1\n";
- };
- }
- ##########################################
- #
- # Convert footer line (final END)
- #
- ##########################################
- if (/^END$/) {
- print "]\n";
- }
- ##########################################
- #
- # Cleanup operations ...
- #
- ##########################################
- #
- # remove all lines with just a ';' in them
- #
- if (/^\s*;\s*$/) {
- s/\s*;\s*//;
- }
- #
- # remove all lines with just a "{$" or "$}" in them
- # (thay are the delimeters for the graph attributes)
- #
- s/^\s*\{\$\s*$//;
- s/^\s*\$\}\s*$//;
- ##########################################
- #
- # Convert fonts, node- and edgetypes, node- and edgestyles
- #
- ##########################################
- #
- # Font
- #
- if (/^Font:\s*(\d+)\s*(".*")\s*(".*")/) {
- if ($includegraphed) {
- print "Font [\nid $1\ngraphedname $2\nexample $3\n]\n";
- }
- }
- #
- # Nodetype
- #
- if (/^nodetype\s*(\d+)\s*(".*")/) {
- if ($includegraphed) {
- print "Nodetype [\nid $1\nname $2\n]\n";
- }
- }
- #
- # Edgetype
- #
- if (/^edgetype\s*(\d+)\s*(".*")/) {
- if ($includegraphed) {
- print "Edgetype [\nid $1\nname $2\n]\n";
- }
- }
- #
- # Nodestyle
- #
- if (/^NSTYL\s*(".*")\s*\[/) {
- if ($includegraphed) {
- print "Nodestyle [\nlabel $1\n";
- }
- }
- #
- # Edgestyle
- #
- if (/^ESTYL\s*(".*")\s*\[/) {
- if ($includegraphed) {
- print "Edgestyle [\nlabel $1\n";
- }
- }
- ##########################################
- #
- # Convert the adjacency list structure
- #
- ##########################################
- #
- # Convert nodes
- #
- if (/^(\d+)\s*\{\$/) {
- print "node [\nid $1\n";
- $LastNodeId=$1;
- }
- #
- # Convert Edges
- #
- if (/^\s+(\d+)\s*\{\$/) {
- print "edge [\nsource $LastNodeId\ntarget $1\n";
- }
- ##########################################
- #
- # Convert standard attributes
- #
- ##########################################
- $GraphicsStarted=$false;
- # NS x y
- if (/\bNS\b\s+(\d+)\s+(\d+)/ && $LastNodeId > 0) {
- print "graphics [\n";
- $GraphicsStarted=$true;
- print "w $1.0\nh $2.0\n";
- }
- # NP x y
- if (/\bNP\b\s+(\d+)\s+(\d+)/ && $LastNodeId > 0) {
- print "x $1.0\ny $2.0\n";
- if ($GraphicsStarted == $true) {
- print "]\n";
- $GraphicsStarted =$false;
- }
- }
- # NTI nodetypeindex
- # NFI nodefontindex
- # NLP nodelabelplacement
- # NEI nodeedgeinterface
- # NLV bool
- if (/\bNTI\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Typeid $1\n";
- }
- };
- if (/\bNFI\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Fontid $1\n";
- }
- };
- if (/\bNLP\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Labelplacement $1\n";
- }
- };
- if (/\bNEI\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Nodeedgeinterface $1\n";
- }
- };
- if (/\bNLV\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Labelvisible $1\n";
- }
- }
- # ETI edgetypeid
- # EFI edgefontid
- # ELV bool
- # AL length AA angle
- if (/\bETI\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Typeid $1\n";
- }
- };
- if (/\bEFI\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Fontid $1\n";
- }
- };
- if (/\bELV\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Labelvisible $1\n";
- }
- };
- if (/\bAL\b\s+(\d+)\s+\bAA\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Arrow [\nlength $1.0\nangle $2.0\n]\n";
- }
- };
- # Col colorid
- if (/\bCOL\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Colorid $1\n";
- }
- };
- #
- # GraphEd's default graph parameters ...
- #
- # DIR defaultdirected
- # GRAGRA nr string string
- # GEMBED string
- # EMBMATCH boolean
- # ELS defaultedgelabelwidth defaultedgelabelheight
- # WA defaultworkingareawidth defaultworkingareaheight
- # WAWIN workingareawindowwidth tworkingareawindowheight
- # SC scrolloffsetx scrolloffsety
- # GR gridwidth
- if (/\bDIR\b\s+(\d+)/) {
- if ($includegraphed) {
- print "GraphedGraphStyle [\ndirected $1";
- }
- };
- if (/\bGRAGRA\b\s+(\d+)\s+(".*")\s*(".*")/) {
- if ($includegraphed) {
- print "Gragra [\nstyle $1\nterminals $2\nnonterminals $2\n";
- }
- };
- if (/\bGEMBED\b\s+(".*")/) {
- if ($includegraphed) {
- print "Embeddingidentifier $1\n";
- }
- };
- if (/\bEMBMATCH\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Embeddingmatch $1\n";
- }
- }
- if (/\bELS\b\s+(\d+)\s+(\d+)/) {
- if ($includegraphed) {
- print "Edgelabelsize [\nw $1.0\nh $2.0\n]\n";
- }
- }
- if (/\bWA\b\s+(\d+)\s+(\d+)/) {
- if ($includegraphed) {
- print "Workingarea [\nw $1.0\nh $2.0\n]\n";
- }
- }
- if (/\bWAWIN\b\s+(\d+)\s+(\d+)/) {
- if ($includegraphed) {
- print "Windowsize [\nw $1.0\nh $2.0\n]\n";
- }
- }
- if (/\bSC\b\s+(\d+)\s+(\d+)/) {
- if ($includegraphed) {
- print "Scrolloffset [\n x $1.0\ny $2.0\n]\n";
- }
- }
- if (/\bGR\b\s+(\d+)/) {
- if ($includegraphed) {
- print "Gridwidth $1.0\n]\n";
- }
- }
- # EL x y x y x ty ...
- if (/\bEL((\b\s+\d+\s+\d+)+)/) {
- if ($GraphicsStarted == $false) {
- print "graphics [\n";
- $GraphicsStarted=$true;
- }
- $coords = $1;
- $coords =~ s/\s+(\d+)\s+(\d+)/point [\nx $1.0\ny $2.0\n]\n/g;
- print "Line [\n$coords]\n";
- # Last in edge graphics
- if ($GraphicsStarted == $true) {
- print "]\n";
- $GraphicsStarted =$false;
- }
- };
- #
- # The next substitutions come here because they close the lists ...
- #
- #
- # Convert node/edge labels (one substitution fits all)
- #
- if (/\$\}\s*(".*")\s*$/) {
- print "\nlabel $1\n]\n";
- }
- #
- # Close node/edge styles
- #
- if (/]/) {
- if ($includegraphed) {
- print "]\n";
- }
- }
- #
- # clean up ...
- #
- s/^\s//;
- ##########################################
- #
- # Set emacs variables
- #
- ##########################################
- # ;;; Local Variables: ***
- # ;;; tab-width: 4 ***
- # ;;; tab-stop-list: (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72) ***
- # ;;; End: ***
|