unflatten.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* LIBDGL -- a Directed Graph Library implementation
  2. * Copyright (C) 2002 Roberto Micarelli
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /*
  19. * Source best viewed with tabstop=4
  20. */
  21. #include <stdio.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <unistd.h>
  25. #include <stdlib.h>
  26. #include <fcntl.h>
  27. #include <time.h>
  28. #include <errno.h>
  29. #include <math.h>
  30. #include "../type.h"
  31. #include "../graph.h"
  32. #include "opt.h"
  33. int main(int argc, char **argv)
  34. {
  35. dglGraph_s graph;
  36. int nret, fd;
  37. /* program options
  38. */
  39. char *pszGraph;
  40. char *pszGraphOut;
  41. GNO_BEGIN /* short long default variable help */
  42. GNO_OPTION("g", "graph", NULL, &pszGraph, "Input Graph file")
  43. GNO_OPTION("o", "graphout", NULL, &pszGraphOut, "Output Graph file")
  44. GNO_END if (GNO_PARSE(argc, argv) < 0) {
  45. return 1;
  46. }
  47. /*
  48. * options parsed
  49. */
  50. printf("Graph read:\n");
  51. if ((fd = open(pszGraph, O_RDONLY)) < 0) {
  52. perror("open");
  53. return 1;
  54. }
  55. nret = dglRead(&graph, fd);
  56. if (nret < 0) {
  57. fprintf(stderr, "dglRead error: %s\n", dglStrerror(&graph));
  58. return 1;
  59. }
  60. close(fd);
  61. printf("Done.\n");
  62. printf("Graph unflatten:\n");
  63. nret = dglUnflatten(&graph);
  64. if (nret < 0) {
  65. fprintf(stderr, "dglUnflatten error: %s\n", dglStrerror(&graph));
  66. return 1;
  67. }
  68. printf("Done.\n");
  69. printf("Graph flatten:\n");
  70. nret = dglFlatten(&graph);
  71. printf("Done.\n");
  72. if (pszGraphOut) {
  73. printf("Graph write:\n");
  74. if ((fd = open(pszGraphOut, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
  75. perror("open");
  76. return 1;
  77. }
  78. dglWrite(&graph, fd);
  79. if (nret < 0) {
  80. fprintf(stderr, "dglWrite error: %s\n", dglStrerror(&graph));
  81. return 1;
  82. }
  83. close(fd);
  84. printf("Done.\n");
  85. }
  86. dglRelease(&graph);
  87. return 0;
  88. }