bitsetv-print.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Bitset vectors.
  2. Copyright (C) 2001-2002, 2004, 2006, 2009-2013 Free Software
  3. Foundation, Inc.
  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. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include <config.h>
  15. #include "bitsetv-print.h"
  16. #include <stdlib.h>
  17. /*--------------------------------------------------------.
  18. | Display the MATRIX array of SIZE bitsets of size SIZE. |
  19. `--------------------------------------------------------*/
  20. void
  21. bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset)
  22. {
  23. bitset_bindex i, j;
  24. bitset_bindex hsize = bitset_size (bset[0]);
  25. /* Title. */
  26. fprintf (out, "%s BEGIN\n", title);
  27. /* Column numbers. */
  28. fputs (" ", out);
  29. for (i = 0; i < hsize; ++i)
  30. putc (i / 10 ? '0' + i / 10 : ' ', out);
  31. putc ('\n', out);
  32. fputs (" ", out);
  33. for (i = 0; i < hsize; ++i)
  34. fprintf (out, "%d", (int) (i % 10));
  35. putc ('\n', out);
  36. /* Bar. */
  37. fputs (" .", out);
  38. for (i = 0; i < hsize; ++i)
  39. putc ('-', out);
  40. fputs (".\n", out);
  41. /* Contents. */
  42. for (i = 0; bset[i]; ++i)
  43. {
  44. fprintf (out, "%2lu|", (unsigned long int) i);
  45. for (j = 0; j < hsize; ++j)
  46. fputs (bitset_test (bset[i], j) ? "1" : " ", out);
  47. fputs ("|\n", out);
  48. }
  49. /* Bar. */
  50. fputs (" `", out);
  51. for (i = 0; i < hsize; ++i)
  52. putc ('-', out);
  53. fputs ("'\n", out);
  54. /* End title. */
  55. fprintf (out, "%s END\n\n", title);
  56. }