"lib/cdt/dtview.c",
"lib/cdt/dtwalk.c",
"lib/cgraph/agerror.c",
- "lib/cgraph/agxbuf.c",
"lib/cgraph/agxbuf.h",
"lib/cgraph/apply.c",
"lib/cgraph/attr.c",
${CMAKE_CURRENT_BINARY_DIR}/scan.c)
ADD_FLEX_BISON_DEPENDENCY(Scan Grammar)
-add_definitions(-DEXPORT_CGRAPH -DEXPORT_AGXBUF -DEXPORT_CGHDR)
+add_definitions(-DEXPORT_CGRAPH -DEXPORT_CGHDR)
if(WIN32 AND NOT MINGW)
add_definitions(-DYY_NO_UNISTD_H)
endif()
# Source files
agerror.c
- agxbuf.c
apply.c
attr.c
edge.c
AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/lib/cdt
if WITH_WIN32
-AM_CFLAGS = -DEXPORT_CGRAPH -DEXPORT_AGXBUF -DEXPORT_CGHDR
+AM_CFLAGS = -DEXPORT_CGRAPH -DEXPORT_CGHDR
endif
pkginclude_HEADERS = cgraph.h
pdf_DATA = cgraph.3.pdf
endif
-libcgraph_C_la_SOURCES = agerror.c agxbuf.c apply.c attr.c edge.c \
+libcgraph_C_la_SOURCES = agerror.c apply.c attr.c edge.c \
flatten.c graph.c grammar.y id.c imap.c io.c mem.c node.c \
obj.c pend.c rec.c refstr.c scan.l subg.c utils.c write.c
+++ /dev/null
-/*************************************************************************
- * Copyright (c) 2011 AT&T Intellectual Property
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Details at https://graphviz.org
- *************************************************************************/
-
-#include <assert.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <cgraph/agxbuf.h>
-#include <cgraph/alloc.h>
-
-/* agxbinit:
- * Assume if init is non-null, hint = sizeof(init[])
- */
-void agxbinit(agxbuf * xb, unsigned int hint, unsigned char *init)
-{
- if (init) {
- xb->buf = init;
- xb->dyna = 0;
- } else {
- if (hint == 0)
- hint = BUFSIZ;
- xb->dyna = 1;
- xb->buf = gv_calloc(hint, sizeof(unsigned char));
- }
- xb->eptr = xb->buf + hint;
- xb->ptr = xb->buf;
- *xb->ptr = '\0';
-}
-
-/* agxbmore;
- * Expand buffer to hold at least ssz more bytes.
- */
-void agxbmore(agxbuf * xb, size_t ssz)
-{
- size_t cnt = 0; /* current no. of characters in buffer */
- size_t size = 0; /* current buffer size */
- size_t nsize = 0; /* new buffer size */
- unsigned char *nbuf; /* new buffer */
-
- size = (size_t) (xb->eptr - xb->buf);
- nsize = 2 * size;
- if (size + ssz > nsize)
- nsize = size + ssz;
- cnt = (size_t) (xb->ptr - xb->buf);
- if (xb->dyna) {
- nbuf = gv_recalloc(xb->buf, size, nsize, sizeof(unsigned char));
- } else {
- nbuf = gv_calloc(nsize, sizeof(unsigned char));
- memcpy(nbuf, xb->buf, cnt);
- xb->dyna = 1;
- }
- xb->buf = nbuf;
- xb->ptr = xb->buf + cnt;
- xb->eptr = xb->buf + nsize;
-}
-
-int agxbprint(agxbuf * xb, const char *fmt, ...) {
- va_list ap;
- size_t size;
- int result;
-
- va_start(ap, fmt);
-
- /* determine how many bytes we need to print */
- {
- va_list ap2;
- int rc;
- va_copy(ap2, ap);
- rc = vsnprintf(NULL, 0, fmt, ap2);
- va_end(ap2);
- if (rc < 0) {
- va_end(ap);
- return rc;
- }
- size = (size_t)rc + 1; /* account for NUL terminator */
- }
-
- /* do we need to expand the buffer? */
- {
- size_t unused_space = (size_t)(xb->eptr - xb->ptr);
- if (unused_space < size) {
- size_t extra = size - unused_space;
- agxbmore(xb, extra);
- }
- }
-
- /* we can now safely print into the buffer */
- result = vsnprintf((char*)xb->ptr, size, fmt, ap);
- assert(result == (int)(size - 1) || result < 0);
- if (result > 0) {
- xb->ptr += (size_t)result;
- }
-
- va_end(ap);
- return result;
-}
-
-/* agxbput_n:
- * Append string s of length n onto xb
- */
-size_t agxbput_n(agxbuf * xb, const char *s, size_t ssz)
-{
- if (xb->ptr + ssz > xb->eptr)
- agxbmore(xb, ssz);
- memcpy(xb->ptr, s, ssz);
- xb->ptr += ssz;
- return ssz;
-}
-
-/* agxbput:
- * Append string s into xb
- */
-size_t agxbput(agxbuf * xb, const char *s)
-{
- size_t ssz = strlen(s);
-
- return agxbput_n(xb, s, ssz);
-}
-
-/* agxbfree:
- * Free any malloced resources.
- */
-void agxbfree(agxbuf * xb)
-{
- if (xb->dyna)
- free(xb->buf);
-}
-
-/* agxbpop:
- * Removes last character added, if any.
- */
-int agxbpop(agxbuf * xb)
-{
- int c;
- if (xb->ptr > xb->buf) {
- c = *xb->ptr--;
- return c;
- } else
- return -1;
-
-}
-
-char *agxbdisown(agxbuf * xb) {
-
- char *buf;
-
- /* terminate the existing string */
- agxbputc(xb, '\0');
-
- if (!xb->dyna) {
- /* the buffer is not dynamically allocated, so we need to copy its contents
- * to heap memory
- */
-
- buf = strdup((char*)xb->buf);
- if (buf == NULL) {
- return NULL;
- }
-
- } else {
- /* the buffer is already dynamically allocated, so take it as-is */
- buf = (char*)xb->buf;
- }
-
- /* reset xb to a state where it is usable */
- xb->buf = xb->ptr = xb->eptr = NULL;
- xb->dyna = 1;
-
- return buf;
-}
#pragma once
-#ifdef __cplusplus
-extern "C" {
-#endif
-
+#include <cgraph/alloc.h>
+#include <stdarg.h>
#include <stddef.h>
-
-#include "config.h"
-
-#ifdef GVDLL
-#ifdef EXPORT_AGXBUF
-#define AGXBUF_API __declspec(dllexport)
-#else
-#define AGXBUF_API __declspec(dllimport)
-#endif
-#endif
-
-#ifndef AGXBUF_API
-#define AGXBUF_API /* nothing */
-#endif
+#include <stdio.h>
+#include <string.h>
/* Extensible buffer:
* Malloc'ed memory is never released until agxbfree is called.
* Initializes new agxbuf; caller provides memory.
* Assume if init is non-null, hint = sizeof(init[])
*/
- AGXBUF_API void agxbinit(agxbuf * xb, unsigned int hint,
- unsigned char *init);
+static inline void agxbinit(agxbuf *xb, unsigned int hint,
+ unsigned char *init) {
+ if (init != NULL) {
+ xb->buf = init;
+ xb->dyna = 0;
+ } else {
+ if (hint == 0) {
+ hint = BUFSIZ;
+ }
+ xb->dyna = 1;
+ xb->buf = (unsigned char *)gv_calloc(hint, sizeof(unsigned char));
+ }
+ xb->eptr = xb->buf + hint;
+ xb->ptr = xb->buf;
+ *xb->ptr = '\0';
+}
/* agxbfree:
* Free any malloced resources.
*/
- AGXBUF_API void agxbfree(agxbuf * xb);
+static inline void agxbfree(agxbuf *xb) {
+ if (xb->dyna)
+ free(xb->buf);
+}
/* agxbpop:
* Removes last character added, if any.
*/
- AGXBUF_API int agxbpop(agxbuf * xb);
+static inline int agxbpop(agxbuf *xb) {
+ int c;
+ if (xb->ptr > xb->buf) {
+ c = *xb->ptr--;
+ return c;
+ } else
+ return -1;
+}
/* agxbmore:
* Expand buffer to hold at least ssz more bytes.
*/
- AGXBUF_API void agxbmore(agxbuf * xb, size_t ssz);
+static inline void agxbmore(agxbuf *xb, size_t ssz) {
+ size_t cnt = 0; // current no. of characters in buffer
+ size_t size = 0; // current buffer size
+ size_t nsize = 0; // new buffer size
+ unsigned char *nbuf; // new buffer
+
+ size = (size_t)(xb->eptr - xb->buf);
+ nsize = 2 * size;
+ if (size + ssz > nsize)
+ nsize = size + ssz;
+ cnt = (size_t)(xb->ptr - xb->buf);
+ if (xb->dyna) {
+ nbuf = (unsigned char *)gv_recalloc(xb->buf, size, nsize,
+ sizeof(unsigned char));
+ } else {
+ nbuf = (unsigned char *)gv_calloc(nsize, sizeof(unsigned char));
+ memcpy(nbuf, xb->buf, cnt);
+ xb->dyna = 1;
+ }
+ xb->buf = nbuf;
+ xb->ptr = xb->buf + cnt;
+ xb->eptr = xb->buf + nsize;
+}
/* support for extra API misuse warnings if available */
#ifdef __GNUC__
/* agxbprint:
* Printf-style output to an agxbuf
*/
- AGXBUF_API int agxbprint(agxbuf * xb, const char *fmt, ...)
- PRINTF_LIKE(2, 3);
+static inline PRINTF_LIKE(2, 3) int agxbprint(agxbuf *xb, const char *fmt,
+ ...) {
+ va_list ap;
+ size_t size;
+ int result;
+
+ va_start(ap, fmt);
+
+ // determine how many bytes we need to print
+ {
+ va_list ap2;
+ int rc;
+ va_copy(ap2, ap);
+ rc = vsnprintf(NULL, 0, fmt, ap2);
+ va_end(ap2);
+ if (rc < 0) {
+ va_end(ap);
+ return rc;
+ }
+ size = (size_t)rc + 1; // account for NUL terminator
+ }
+
+ // do we need to expand the buffer?
+ {
+ size_t unused_space = (size_t)(xb->eptr - xb->ptr);
+ if (unused_space < size) {
+ size_t extra = size - unused_space;
+ agxbmore(xb, extra);
+ }
+ }
+
+ // we can now safely print into the buffer
+ result = vsnprintf((char *)xb->ptr, size, fmt, ap);
+ assert(result == (int)(size - 1) || result < 0);
+ if (result > 0) {
+ xb->ptr += (size_t)result;
+ }
+
+ va_end(ap);
+ return result;
+}
#undef PRINTF_LIKE
/* agxbput_n:
* Append string s of length ssz into xb
*/
- AGXBUF_API size_t agxbput_n(agxbuf * xb, const char *s, size_t ssz);
+static inline size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz) {
+ if (xb->ptr + ssz > xb->eptr)
+ agxbmore(xb, ssz);
+ memcpy(xb->ptr, s, ssz);
+ xb->ptr += ssz;
+ return ssz;
+}
/* agxbput:
* Append string s into xb
*/
- AGXBUF_API size_t agxbput(agxbuf * xb, const char *s);
+static inline size_t agxbput(agxbuf *xb, const char *s) {
+ size_t ssz = strlen(s);
+
+ return agxbput_n(xb, s, ssz);
+}
/* agxbputc:
* Add character to buffer.
* buffer, but have it overwritten and reused the next time, e.g., agxbput is
* called, use agxbuse instead of agxbdisown.
*/
- AGXBUF_API char *agxbdisown(agxbuf * xb);
+static inline char *agxbdisown(agxbuf *xb) {
+ char *buf;
+
+ // terminate the existing string
+ agxbputc(xb, '\0');
+
+ if (!xb->dyna) {
+ // the buffer is not dynamically allocated, so we need to copy its contents
+ // to heap memory
+
+ buf = strdup((char *)xb->buf);
+ if (buf == NULL) {
+ return NULL;
+ }
-#ifdef __cplusplus
+ } else {
+ // the buffer is already dynamically allocated, so take it as-is
+ buf = (char *)xb->buf;
+ }
+
+ // reset xb to a state where it is usable
+ xb->buf = xb->ptr = xb->eptr = NULL;
+ xb->dyna = 1;
+
+ return buf;
}
-#endif
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)windows\include;$(SolutionDir)lib;$(SolutionDir)lib\cdt</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>GVDLL;EXPORT_CGRAPH;EXPORT_AGXBUF;EXPORT_CGHDR;YY_NO_UNISTD_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>GVDLL;EXPORT_CGRAPH;EXPORT_CGHDR;YY_NO_UNISTD_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)windows\include;$(SolutionDir)lib;$(SolutionDir)lib\cdt</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>GVDLL;EXPORT_CGRAPH;EXPORT_AGXBUF;EXPORT_CGHDR;YY_NO_UNISTD_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>GVDLL;EXPORT_CGRAPH;EXPORT_CGHDR;YY_NO_UNISTD_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<EnablePREfast>true</EnablePREfast>
</ItemGroup>
<ItemGroup>
<ClCompile Include="agerror.c" />
- <ClCompile Include="agxbuf.c" />
<ClCompile Include="apply.c" />
<ClCompile Include="attr.c" />
<ClCompile Include="edge.c" />
<ClCompile Include="agerror.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="agxbuf.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="apply.c">
<Filter>Source Files</Filter>
</ClCompile>