gv_java_init.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <gvc/gvc.h>
  13. #include <gvc/gvplugin.h>
  14. #include <gvc/gvcjob.h>
  15. #include <gvc/gvcint.h>
  16. #include "gv_channel.h"
  17. typedef struct {
  18. char* data;
  19. size_t sz; /* buffer size */
  20. size_t len; /* length of array */
  21. } BA;
  22. static size_t gv_string_writer(GVJ_t *job, const char *s, size_t len)
  23. {
  24. BA* bap = (BA*)(job->output_file);
  25. size_t newlen = bap->len + len;
  26. if (newlen > bap->sz) {
  27. bap->sz *= 2;
  28. if (newlen > bap->sz)
  29. bap->sz = 2*newlen;
  30. bap->data = realloc(bap->data, bap->sz);
  31. }
  32. memcpy (bap->data+bap->len, s, len);
  33. bap->len = newlen;
  34. return len;
  35. }
  36. void gv_string_writer_init(GVC_t *gvc)
  37. {
  38. gvc->write_fn = gv_string_writer;
  39. }
  40. static size_t gv_channel_writer(GVJ_t *job, const char *s, size_t len)
  41. {
  42. (void)job;
  43. (void)s;
  44. return len;
  45. }
  46. void gv_channel_writer_init(GVC_t *gvc)
  47. {
  48. gvc->write_fn = gv_channel_writer;
  49. }
  50. void gv_writer_reset (GVC_t *gvc) {gvc->write_fn = NULL;}