#!/usr/bin/env python
#this is a script to extract given named nodes from a dot file, with
#the associated edges. An edge is kept iff for edge x -> y
# x and y are both nodes specified to be kept.
#known issues: if a line contains '->' and is not an edge line
#problems will occur. If node labels do not begin with
#Node this also will not work. Since this is designed to work
#on DSA dot output and not general dot files this is ok.
#If you want to use this on other files rename the node labels
#to Node[.*] with a script or something. This also relies on
#the length of a node name being 13 characters (as it is in all
#DSA dot output files)
#Note that the name of the node can be any substring of the actual
#name in the dot file. Thus if you say specify COLLAPSED
#as a parameter this script will pull out all COLLAPSED
#nodes in the file
#Specifying escape characters in the name like \n also will not work,
#as Python
#will make it \\n, I'm not really sure how to fix this
#currently the script prints the names it is searching for
#to STDOUT, so you can check to see if they are what you intend
#open the input file
=
#construct a set of node names
=
|=
#construct a list of compiled regular expressions from the
#node_name_set
=
#used to see what kind of line we are on
=
#used to check to see if the current line is an edge line
=
=
#read the file one line at a time
=
#filter out the unnecessary checks on all the edge lines
#check to see if this is a node we are looking for
#if this name is for the current node, add the dot variable name
#for the node (it will be Node(hex number)) to our set of nodes
|=
break
=
#test code
#print '\n'
#print node_set
#open the output file
=
#start the second pass over the file
=
=
#there are three types of lines we are looking for
#1) node lines, 2) edge lines 3) support lines (like page size, etc)
#is this an edge line?
#note that this is no completely robust, if a none edge line
#for some reason contains -> it will be missidentified
#hand edit the file if this happens
#check to make sure that both nodes are in the node list
#if they are print this to output
=
=
=
: #this is a node line
=
#this is a support line
=