00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025 #include <unistd.h>
00026 #include <stdlib.h>
00027 #include <fcntl.h>
00028 #include <time.h>
00029 #include <errno.h>
00030 #include <ctype.h>
00031
00032 #include "../type.h"
00033 #include "../graph.h"
00034
00035 #include "opt.h"
00036
00037
00038 extern int errno;
00039
00040 #define _EDGESET_OFFSET(pg,pl) ((int)(pl) - (int)(pg)->pEdgeBuffer)
00041
00042 static int _print_node( dglGraph_s * pgraph , dglInt32_t * pnode , void * pvarg )
00043 {
00044 FILE * f = (FILE*)pvarg;
00045 dglInt32_t * pedgeset;
00046 dglInt32_t * pedge;
00047 dglInt32_t * ptonode;
00048 dglInt32_t * pnattr;
00049 int iAttr, cAttr;
00050 int role;
00051 int i;
00052 dglEdgesetTraverser_s edgeaT;
00053
00054 role = 0;
00055 if ( dglNodeGet_Status(pgraph,pnode) & DGL_NS_HEAD )
00056 {
00057 role |= 1;
00058 }
00059 if ( dglNodeGet_Status(pgraph,pnode) & DGL_NS_TAIL )
00060 {
00061 role |= 2;
00062 }
00063
00064 fprintf( f , "HEAD %-8ld - %-s",
00065 dglNodeGet_Id(pgraph,pnode),
00066 (role>2)?"'H/T'":(role==2)?"'T '":(role==1)?"'H '":"'A '");
00067
00068 if ( (cAttr = dglGet_NodeAttrSize(pgraph)) > 0 ) {
00069 pnattr = dglNodeGet_Attr(pgraph,pnode);
00070 fprintf( f , " - HEAD ATTR [" );
00071 for ( iAttr = 0 ; iAttr < cAttr ; iAttr ++ ) {
00072 if ( iAttr && !(iAttr%4) ) fprintf( f , " " );
00073 fprintf( f , "%02x" , ((unsigned char*)pnattr)[iAttr] );
00074 }
00075 fprintf( f , "]\n" );
00076 }
00077 else {
00078 fprintf( f , "\n" );
00079 }
00080
00081 if ( role & 1 ) {
00082 pedgeset = dglNodeGet_OutEdgeset(pgraph, pnode);
00083
00084 dglEdgeset_T_Initialize(&edgeaT, pgraph, pedgeset);
00085 for (
00086 i = 0, pedge = dglEdgeset_T_First( &edgeaT ) ;
00087 pedge ;
00088 i++ , pedge = dglEdgeset_T_Next ( &edgeaT )
00089 )
00090 {
00091 ptonode = dglEdgeGet_Tail(pgraph,pedge);
00092
00093 if ( ptonode ) {
00094 role = 0;
00095 if ( dglNodeGet_Status(pgraph,ptonode) & DGL_NS_HEAD )
00096 {
00097 role |= 1;
00098 }
00099 if ( dglNodeGet_Status(pgraph,ptonode) & DGL_NS_TAIL )
00100 {
00101 role |= 2;
00102 }
00103
00104 fprintf( f , "EDGE #%-8d: TAIL %-8ld - %-s - COST %-8ld - ID %-8ld",
00105 i ,
00106 dglNodeGet_Id(pgraph,ptonode) ,
00107 (role>2)?"'H/T'":(role==2)?"'T '":(role==1)?"'H '":"'A '",
00108 dglEdgeGet_Cost(pgraph,pedge) ,
00109 dglEdgeGet_Id(pgraph,pedge)
00110 );
00111
00112 if ( (cAttr = dglGet_NodeAttrSize(pgraph)) > 0 ) {
00113 pnattr = dglNodeGet_Attr(pgraph,ptonode);
00114 fprintf( f , " - TAIL ATTR [" );
00115 for ( iAttr = 0 ; iAttr < cAttr ; iAttr ++ ) {
00116 if ( iAttr && !(iAttr%4) ) fprintf( f , " " );
00117 fprintf( f , "%02x" , ((unsigned char*)pnattr)[iAttr] );
00118 }
00119 fprintf( f , "]" );
00120 }
00121
00122 if ( (cAttr = dglGet_EdgeAttrSize(pgraph)) > 0 ) {
00123 pnattr = dglEdgeGet_Attr(pgraph,pedge);
00124 fprintf( f , " - EDGE ATTR [" );
00125 for ( iAttr = 0 ; iAttr < cAttr ; iAttr ++ ) {
00126 if ( iAttr && !(iAttr%4) ) fprintf( f , " " );
00127 fprintf( f , "%02x" , ((unsigned char*)pnattr)[iAttr] );
00128 }
00129 fprintf( f , "]\n" );
00130 }
00131 else {
00132 fprintf( f , "\n" );
00133 }
00134 }
00135 }
00136 dglEdgeset_T_Release( &edgeaT );
00137 }
00138 return 0;
00139 }
00140
00141 int main( int argc , char ** argv )
00142 {
00143 dglGraph_s graph;
00144 int fd;
00145 int nret;
00146
00147
00148
00149 char * pszFilein;
00150
00151 GNO_BEGIN
00152 GNO_OPTION( "g", "graph", NULL , & pszFilein , "Graph file to view" )
00153 GNO_END
00154
00155
00156 if ( GNO_PARSE( argc , argv ) < 0 )
00157 {
00158 return 1;
00159 }
00160
00161
00162
00163
00164 if ( pszFilein == NULL )
00165 {
00166 GNO_HELP( "Incomplete parameters" );
00167 return 1;
00168 }
00169
00170 fd = open( pszFilein , O_RDONLY );
00171 if ( fd < 0 )
00172 {
00173 perror( "open" ); return 1;
00174 }
00175
00176 nret = dglRead( & graph , fd );
00177
00178 if ( nret < 0 )
00179 {
00180 fprintf( stderr , "dglRead error: %s\n" , dglStrerror( & graph ) );
00181 return 1;
00182 }
00183
00184 close( fd );
00185
00186
00187
00188 fprintf( stdout , "Version: %d\n" ,
00189 graph.Version );
00190 fprintf( stdout , "Byte Order: %s\n" ,
00191 (graph.Endian == DGL_ENDIAN_LITTLE)?"Little Endian":"Big Endian" );
00192 fprintf( stdout , "Node Attribute Size: %ld\n" ,
00193 graph.NodeAttrSize );
00194 fprintf( stdout , "Edge Attribute Size: %ld\n" ,
00195 graph.EdgeAttrSize );
00196 fprintf( stdout , "Counters: %ld Edges - %ld Nodes: %ld HEAD / %ld TAIL / %ld ALONE\n" ,
00197 graph.cEdge , graph.cNode ,
00198 graph.cHead , graph.cTail , graph.cAlone );
00199 fprintf( stdout , "Opaque Settings:\n" );
00200 fprintf( stdout , "%10ld %10ld %10ld %10ld\n",
00201 graph.aOpaqueSet[ 0 ], graph.aOpaqueSet[ 1 ],
00202 graph.aOpaqueSet[ 2 ], graph.aOpaqueSet[ 3 ] );
00203 fprintf( stdout , "%10ld %10ld %10ld %10ld\n",
00204 graph.aOpaqueSet[ 4 ], graph.aOpaqueSet[ 5 ],
00205 graph.aOpaqueSet[ 6 ], graph.aOpaqueSet[ 7 ] );
00206 fprintf( stdout , "%10ld %10ld %10ld %10ld\n",
00207 graph.aOpaqueSet[ 8 ], graph.aOpaqueSet[ 9 ],
00208 graph.aOpaqueSet[ 10 ], graph.aOpaqueSet[ 11 ] );
00209 fprintf( stdout , "%10ld %10ld %10ld %10ld\n",
00210 graph.aOpaqueSet[ 12 ], graph.aOpaqueSet[ 13 ],
00211 graph.aOpaqueSet[ 14 ], graph.aOpaqueSet[ 15 ] );
00212 fprintf( stdout , "Total Cost: %lld\n", graph.nnCost );
00213 fprintf( stdout , "--\n" );
00214
00215
00216 {
00217 dglInt32_t * pnode;
00218 dglNodeTraverser_s traverser;
00219 dglNode_T_Initialize( &traverser, &graph );
00220 for (pnode = dglNode_T_First(&traverser) ; pnode ; pnode = dglNode_T_Next(&traverser)) {
00221 _print_node( &graph, pnode, stdout );
00222 }
00223 dglNode_T_Release ( & traverser );
00224 }
00225
00226 printf( "\n" );
00227 dglRelease( & graph );
00228 return 0;
00229
00230 }