bgvparser.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2021
  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 3 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, see <http://www.gnu.org/licenses/>.
  16. *
  17. * These are the four essential freedoms with GNU GPL software:
  18. * 1: freedom to run the program, for any purpose
  19. * 2: freedom to study how the program works, and change it to make it do what you wish
  20. * 3: freedom to redistribute copies to help your Free Software friends
  21. * 4: freedom to distribute copies of your modified versions to your Free Software friends
  22. * , ,
  23. * / \
  24. * ((__-^^-,-^^-__))
  25. * `-_---' `---_-'
  26. * `--|o` 'o|--'
  27. * \ ` /
  28. * ): :(
  29. * :o_o:
  30. * "-"
  31. *
  32. * SPDX-License-Identifier: GPL-3.0+
  33. * License-Filename: LICENSE
  34. */
  35. /* parse bgv graph data generated by graalvm and other software from oracle */
  36. #include "config.h"
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <zlib.h>
  41. #include "splay-tree.h"
  42. #include "main.h"
  43. #include "bgv.h"
  44. #include "bgvparser.h"
  45. #include "dpmem.h"
  46. static gzFile cf = (gzFile) 0;
  47. static int db = 0;
  48. static int magic(void);
  49. /* parse bgv file return 0 if oke */
  50. int runbgvparse(gzFile f, int debug)
  51. {
  52. int status = 0;
  53. db = debug;
  54. cf = f;
  55. status = magic();
  56. if (status) {
  57. return (1);
  58. }
  59. db = 0;
  60. cf = (gzFile) 0;
  61. return (0);
  62. }
  63. /* the magic is BIGV */
  64. static int magic(void)
  65. {
  66. int ch = 0;
  67. ch = gzgetc(cf);
  68. if (ch != 'B') {
  69. return (1);
  70. }
  71. ch = gzgetc(cf);
  72. if (ch != 'I') {
  73. return (1);
  74. }
  75. ch = gzgetc(cf);
  76. if (ch != 'G') {
  77. return (1);
  78. }
  79. ch = gzgetc(cf);
  80. if (ch != 'V') {
  81. return (1);
  82. }
  83. if (db) {
  84. printf("%s(): magic BIGV found\n", __func__);
  85. }
  86. return (0);
  87. }
  88. /* end. */