delnode.c

Go to the documentation of this file.
00001 /* LIBDGL -- a Directed Graph Library implementation
00002  * Copyright (C) 2002 Roberto Micarelli
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 /*
00020  * Source best viewed with tabstop=4
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 int main( int argc , char ** argv )
00039 {
00040         dglGraph_s      graph;
00041         dglInt32_t              nNode;
00042         int                             nret , fd;
00043 
00044         /* program options
00045          */
00046         char    *       pszGraph;
00047         char    *       pszGraphOut;
00048         char    *       pszNode;
00049  
00050         GNO_BEGIN/* short   long                default     variable        help */
00051         GNO_OPTION( "g",        "graph",                NULL ,          & pszGraph ,    "Input Graph file" )
00052         GNO_OPTION( "o",        "graphout",     NULL ,          & pszGraphOut , "Output Graph file" )
00053         GNO_OPTION( "n",        "node",                 NULL ,          & pszNode ,             "Node Id to cancel" )
00054         GNO_END
00055  
00056 
00057         if ( GNO_PARSE( argc , argv ) < 0 )
00058         {
00059                 return 1;
00060         }
00061         /*
00062          * options parsed
00063          */
00064 
00065         if ( pszNode == NULL ) {
00066                 GNO_HELP("delnode usage");
00067                 return 1;
00068         }
00069         nNode = atol(pszNode);
00070 
00071         printf( "Graph read:\n" );
00072         if ( (fd = open( pszGraph , O_RDONLY )) < 0 )
00073         {
00074                 perror( "open" ); return 1;
00075         }
00076         nret = dglRead( & graph , fd );
00077         if ( nret < 0 ) {
00078                 fprintf( stderr , "dglRead error: %s\n", dglStrerror( & graph ) );
00079                 return 1;
00080         }
00081         close( fd );
00082         printf( "Done.\n" );
00083 
00084         printf( "Graph unflatten:\n" );
00085         nret = dglUnflatten( & graph );
00086         if ( nret < 0 ) {
00087                 fprintf( stderr , "dglUnflatten error: %s\n", dglStrerror( & graph ) );
00088                 return 1;
00089         }
00090         printf( "Done.\n" );
00091 
00092         nret = dglDelNode( & graph, nNode );
00093         if ( nret < 0 ) {
00094                 fprintf( stderr , "dglDelNode error: %s\n", dglStrerror( & graph ) );
00095                 return 1;
00096         }
00097 
00098         printf( "Graph flatten:\n" );
00099         nret = dglFlatten( & graph );
00100         printf( "Done.\n" );
00101 
00102         if ( pszGraphOut ) {
00103                 printf( "Graph write: %s\n", pszGraphOut );
00104                 if ( (fd = open( pszGraphOut , O_WRONLY | O_CREAT | O_TRUNC, 0666 )) < 0 )
00105                 {
00106                         perror( "open" ); return 1;
00107                 }
00108                 nret = dglWrite( & graph, fd );
00109                 if ( nret < 0 )
00110                 {
00111                         fprintf( stderr , "dglWrite error: %s\n" , dglStrerror( & graph ) );
00112                         return 1;
00113                 }
00114                 close( fd );
00115                 printf( "Done.\n" );
00116         }
00117 
00118         dglRelease( & graph );
00119         return 0;
00120 }

Generated on Sun Apr 6 17:32:44 2008 for GRASS by  doxygen 1.5.5