00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <unistd.h>
00027 #include <stdlib.h>
00028 #include <fcntl.h>
00029 #include <time.h>
00030 #include <errno.h>
00031 #include <math.h>
00032
00033 #include "../type.h"
00034 #include "../graph.h"
00035
00036 #include "opt.h"
00037
00038 static int _clipper(dglGraph_s * pgraphIn,
00039 dglGraph_s * pgraphOut,
00040 dglSpanClipInput_s * pArgIn,
00041 dglSpanClipOutput_s * pArgOut,
00042 void * pvArg)
00043 {
00044 return 0;
00045 }
00046
00047 int main( int argc , char ** argv )
00048 {
00049 dglGraph_s graph , graphOut;
00050 dglInt32_t nVertex;
00051 int nret , fd;
00052
00053
00054
00055 char * pszGraph;
00056 char * pszGraphOut;
00057 char * pszVertex;
00058
00059 GNO_BEGIN
00060 GNO_OPTION( "g", "graph", NULL , & pszGraph , "Input Graph file" )
00061 GNO_OPTION( "o", "graphout", NULL , & pszGraphOut , "Output Graph file" )
00062 GNO_OPTION( "v", "vertex", NULL , & pszVertex , "Vertex Node Id" )
00063 GNO_END
00064
00065
00066 if ( GNO_PARSE( argc , argv ) < 0 )
00067 {
00068 return 1;
00069 }
00070
00071
00072
00073
00074 if ( pszVertex == NULL ) {
00075 GNO_HELP("span usage");
00076 return 1;
00077 }
00078 nVertex = atol(pszVertex);
00079
00080 printf( "Graph read:\n" );
00081 if ( (fd = open( pszGraph , O_RDONLY )) < 0 )
00082 {
00083 perror( "open" ); return 1;
00084 }
00085 nret = dglRead( & graph , fd );
00086 if ( nret < 0 ) {
00087 fprintf( stderr , "dglRead error: %s\n", dglStrerror( & graph ) );
00088 return 1;
00089 }
00090 close( fd );
00091 printf( "Done.\n" );
00092
00093 printf( "Graph depth spanning:\n" );
00094 nret = dglDepthSpanning( & graph , & graphOut , nVertex , _clipper , NULL );
00095 if ( nret < 0 ) {
00096 fprintf( stderr , "dglDepthSpanning error: %s\n", dglStrerror( & graph ) );
00097 return 1;
00098 }
00099 printf( "Done.\n" );
00100
00101
00102 printf( "Graph flatten:\n" );
00103 nret = dglFlatten( & graphOut );
00104 printf( "Done.\n" );
00105
00106 if ( dglGet_EdgeCount( & graphOut ) > 0 ) {
00107
00108
00109 if ( pszGraphOut ) {
00110 printf( "Graph write:\n" );
00111 if ( (fd = open( pszGraphOut , O_WRONLY | O_CREAT | O_TRUNC, 0666 )) < 0 )
00112 {
00113 perror( "open" ); return 1;
00114 }
00115 dglWrite( & graphOut, fd );
00116 if ( nret < 0 )
00117 {
00118 fprintf( stderr , "dglWrite error: %s\n" , dglStrerror( & graphOut ) );
00119 return 1;
00120 }
00121 close( fd );
00122 printf( "Done.\n" );
00123 }
00124 }
00125 else {
00126 printf( "Empty span. No output produced.\n" );
00127 }
00128
00129 dglRelease( & graph );
00130 dglRelease( & graphOut );
00131 return 0;
00132 }