Go to the documentation of this file.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 int main(int argc, char **argv)
00039 {
00040 dglGraph_s graph;
00041 dglInt32_t nNode;
00042 int nret, fd;
00043
00044
00045
00046 char *pszGraph;
00047 char *pszGraphOut;
00048 char *pszNode;
00049
00050 GNO_BEGIN
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 if (GNO_PARSE(argc, argv) < 0)
00055 {
00056 return 1;
00057 }
00058
00059
00060
00061
00062 if (pszNode == NULL) {
00063 GNO_HELP("delnode usage");
00064 return 1;
00065 }
00066 nNode = atol(pszNode);
00067
00068 printf("Graph read:\n");
00069 if ((fd = open(pszGraph, O_RDONLY)) < 0) {
00070 perror("open");
00071 return 1;
00072 }
00073 nret = dglRead(&graph, fd);
00074 if (nret < 0) {
00075 fprintf(stderr, "dglRead error: %s\n", dglStrerror(&graph));
00076 return 1;
00077 }
00078 close(fd);
00079 printf("Done.\n");
00080
00081 printf("Graph unflatten:\n");
00082 nret = dglUnflatten(&graph);
00083 if (nret < 0) {
00084 fprintf(stderr, "dglUnflatten error: %s\n", dglStrerror(&graph));
00085 return 1;
00086 }
00087 printf("Done.\n");
00088
00089 nret = dglDelNode(&graph, nNode);
00090 if (nret < 0) {
00091 fprintf(stderr, "dglDelNode error: %s\n", dglStrerror(&graph));
00092 return 1;
00093 }
00094
00095 printf("Graph flatten:\n");
00096 nret = dglFlatten(&graph);
00097 printf("Done.\n");
00098
00099 if (pszGraphOut) {
00100 printf("Graph write: %s\n", pszGraphOut);
00101 if ((fd = open(pszGraphOut, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
00102 perror("open");
00103 return 1;
00104 }
00105 nret = dglWrite(&graph, fd);
00106 if (nret < 0) {
00107 fprintf(stderr, "dglWrite error: %s\n", dglStrerror(&graph));
00108 return 1;
00109 }
00110 close(fd);
00111 printf("Done.\n");
00112 }
00113
00114 dglRelease(&graph);
00115 return 0;
00116 }