gv_tcl_init.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <tcl.h>
  11. #include <gvc/gvc.h>
  12. #include <gvc/gvplugin.h>
  13. #include <gvc/gvcjob.h>
  14. #include <gvc/gvcint.h>
  15. #include <limits.h>
  16. #include "gv_channel.h"
  17. static size_t gv_string_writer(GVJ_t *job, const char *s, size_t len)
  18. {
  19. // clamp to INT_MAX
  20. int l = len > (size_t)INT_MAX ? INT_MAX : (int)len;
  21. Tcl_AppendToObj((Tcl_Obj*)(job->output_file), s, l);
  22. return (size_t)l;
  23. }
  24. static size_t gv_channel_writer(GVJ_t *job, const char *s, size_t len)
  25. {
  26. // clamp to INT_MAX
  27. int l = len > (size_t)INT_MAX ? INT_MAX : (int)len;
  28. return (size_t)Tcl_Write((Tcl_Channel)(job->output_file), s, l);
  29. }
  30. void gv_string_writer_init(GVC_t *gvc)
  31. {
  32. gvc->write_fn = gv_string_writer;
  33. }
  34. void gv_channel_writer_init(GVC_t *gvc)
  35. {
  36. gvc->write_fn = gv_channel_writer;
  37. }
  38. void gv_writer_reset (GVC_t *gvc) {gvc->write_fn = NULL;}