utils.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /// @file
  2. /// @ingroup common_utils
  3. /*************************************************************************
  4. * Copyright (c) 2011 AT&T Intellectual Property
  5. * All rights reserved. This program and the accompanying materials
  6. * are made available under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution, and is available at
  8. * https://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors: Details at https://graphviz.org
  11. *************************************************************************/
  12. #pragma once
  13. #include "config.h"
  14. #include <stdbool.h>
  15. #include <stddef.h>
  16. #include <util/agxbuf.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifdef GVDLL
  21. #ifdef GVC_EXPORTS
  22. #define UTILS_API __declspec(dllexport)
  23. #else
  24. #define UTILS_API __declspec(dllimport)
  25. #endif
  26. #endif
  27. #ifndef UTILS_API
  28. #define UTILS_API /* nothing */
  29. #endif
  30. // options to tweak the behavior of XML escaping
  31. typedef struct {
  32. // assume no embedded escapes, and escape "\n" and "\r"
  33. unsigned raw : 1;
  34. // escape '-'
  35. unsigned dash : 1;
  36. // escape consecutive ' '
  37. unsigned nbsp : 1;
  38. // anticipate non-ASCII characters that need to be encoded
  39. unsigned utf8 : 1;
  40. } xml_flags_t;
  41. UTILS_API pointf Bezier(pointf *, double, pointf *, pointf *);
  42. /// @return Computed ymin + ymax
  43. UTILS_API double attach_attrs_and_arrows(graph_t *, bool *, bool *);
  44. /** XML-escape a string
  45. *
  46. * \param s Source string to process.
  47. * \param flags Options of how to configure escaping.
  48. * \param cb An `fputs` analogue for emitting escaped output.
  49. * \param state Caller-defined data to pass to `cb`.
  50. * \return The first negative value `cb` returns or the last return value of
  51. * `cb`.
  52. */
  53. UTILS_API int xml_escape(const char *s, xml_flags_t flags,
  54. int (*cb)(void *state, const char *s), void *state);
  55. UTILS_API void write_plain(GVJ_t *job, graph_t *g, FILE *f, bool extend);
  56. /// @param yOff Displacement to apply to `y`
  57. UTILS_API double yDir(double y, double yOff);
  58. UTILS_API char *ps_string(char *s, int);
  59. UTILS_API char *strdup_and_subst_obj(char *str, void *obj);
  60. UTILS_API void epsf_emit_body(GVJ_t *job, usershape_t *us);
  61. UTILS_API void epsf_define(GVJ_t *job);
  62. UTILS_API void undoClusterEdges(graph_t *g);
  63. UTILS_API Dt_t *mkClustMap(Agraph_t *g);
  64. UTILS_API Agraph_t *findCluster(Dt_t *map, char *name);
  65. UTILS_API attrsym_t *safe_dcl(graph_t *g, int obj_kind, char *name,
  66. char *defaultValue);
  67. UTILS_API int late_int(void *obj, Agsym_t *attr, int defaultValue, int minimum);
  68. UTILS_API double late_double(void *obj, Agsym_t *attr, double defaultValue,
  69. double minimum);
  70. UTILS_API char *late_nnstring(void *obj, Agsym_t *attr, char *defaultValue);
  71. UTILS_API char *late_string(void *obj, Agsym_t *attr, char *defaultValue);
  72. UTILS_API bool late_bool(void *obj, Agsym_t *attr, bool defaultValue);
  73. UTILS_API double get_inputscale(graph_t *g);
  74. // routines for supporting “union-find”, a.k.a. “disjoint-set forest”
  75. // https://en.wikipedia.org/wiki/Disjoint-set_data_structure
  76. UTILS_API Agnode_t *UF_find(Agnode_t *);
  77. UTILS_API Agnode_t *UF_union(Agnode_t *, Agnode_t *);
  78. UTILS_API void UF_singleton(Agnode_t *);
  79. UTILS_API void UF_setname(Agnode_t *, Agnode_t *);
  80. UTILS_API const char *safefile(const char *filename);
  81. UTILS_API bool mapBool(const char *p, bool defaultValue);
  82. UTILS_API bool mapbool(const char *p);
  83. UTILS_API int maptoken(char *, char **, int *);
  84. UTILS_API bool findStopColor(const char *colorlist, char *clrs[2],
  85. double *frac);
  86. UTILS_API int test_toggle(void);
  87. UTILS_API void common_init_node(node_t *n);
  88. UTILS_API void common_init_edge(edge_t *e);
  89. UTILS_API void updateBB(graph_t *g, textlabel_t *lp);
  90. UTILS_API void compute_bb(Agraph_t *);
  91. UTILS_API boxf polyBB(polygon_t *poly);
  92. UTILS_API bool overlap_node(node_t *n, boxf b);
  93. UTILS_API bool overlap_label(textlabel_t *lp, boxf b);
  94. UTILS_API bool overlap_edge(edge_t *e, boxf b);
  95. UTILS_API void get_gradient_points(pointf *A, pointf *G, size_t n, double angle,
  96. int flags);
  97. UTILS_API void processClusterEdges(graph_t *g);
  98. UTILS_API char *latin1ToUTF8(char *);
  99. UTILS_API char *htmlEntityUTF8(char *, graph_t *g);
  100. UTILS_API char *utf8ToLatin1(char *ins);
  101. UTILS_API char *scanEntity(char *t, agxbuf *xb);
  102. UTILS_API pointf dotneato_closest(splines *spl, pointf p);
  103. UTILS_API Agsym_t *setAttr(graph_t *, void *, char *name, char *value,
  104. Agsym_t *);
  105. UTILS_API void setEdgeType(graph_t *g, int defaultValue);
  106. UTILS_API bool is_a_cluster(Agraph_t *g);
  107. /* from postproc.c */
  108. UTILS_API void gv_nodesize(Agnode_t *n, bool flip);
  109. #ifndef HAVE_DRAND48
  110. UTILS_API double drand48(void);
  111. #endif
  112. /* from timing.c */
  113. UTILS_API void start_timer(void);
  114. UTILS_API double elapsed_sec(void);
  115. /* from psusershape.c */
  116. UTILS_API void cat_libfile(GVJ_t *job, const char **arglib,
  117. const char **stdlib);
  118. #undef UTILS_API
  119. #ifdef __cplusplus
  120. }
  121. #endif