]> granicus.if.org Git - graphviz/commitdiff
prune: use generalized list implementation for nodes list
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 3 Dec 2022 19:10:46 +0000 (11:10 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 4 Dec 2022 18:02:35 +0000 (10:02 -0800)
This allows preserving type safety (no more `char*` casts needed). We can also
entirely remove prune’s generic list implementation which is no longer used.

ci/clang_format.py
contrib/prune/CMakeLists.txt
contrib/prune/Makefile.am
contrib/prune/generic_list.c [deleted file]
contrib/prune/generic_list.h [deleted file]
contrib/prune/prune.c
contrib/prune/prune.vcxproj
contrib/prune/prune.vcxproj.filters

index 08842f07572f7a569e34f344652bc11ced9b8e24..b69fc5c603ab7b9cf543804e97a3b0d3431ef420 100644 (file)
@@ -123,8 +123,6 @@ EXCLUDE = (
   "cmd/tools/unflatten.c",
   "contrib/diffimg/diffimg.c",
   "contrib/pangotest/pangotest.c",
-  "contrib/prune/generic_list.c",
-  "contrib/prune/generic_list.h",
   "contrib/prune/prune.c",
   "doc/libgraph/agmemread.c",
   "doc/libgraph/sccmap.c",
index c5b183f00bdcbd045f48520adfdc2bf4426941ab..8551ae7d6c1ad267eba64a43005aeb102a037ab6 100644 (file)
@@ -1,4 +1,4 @@
-add_executable(prune generic_list.c prune.c)
+add_executable(prune prune.c)
 target_include_directories(prune PRIVATE
   ../../lib
   ../../lib/cdt)
index e39a1115dd8a05b18ec66e4327458b3d2827b442..cd2493aaf5bea727473001140acbe21183717beb 100644 (file)
@@ -5,13 +5,12 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/cdt
 
 bin_PROGRAMS = prune
-noinst_HEADERS = generic_list.h
 dist_man_MANS = prune.1
 if ENABLE_MAN_PDFS
 pdf_DATA = prune.1.pdf
 endif
 
-prune_SOURCES = generic_list.c prune.c
+prune_SOURCES = prune.c
 
 prune_LDADD = $(top_builddir)/lib/ingraphs/libingraphs_C.la \
        $(top_builddir)/lib/cgraph/libcgraph.la \
diff --git a/contrib/prune/generic_list.c b/contrib/prune/generic_list.c
deleted file mode 100644 (file)
index 5b63244..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*************************************************************************
- * 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 http://www.graphviz.org/
- *************************************************************************/
-
-#include <cgraph/alloc.h>
-#include <stdlib.h>
-
-#include "generic_list.h"
-
-#define DFLT_SIZE 100
-
-generic_list_t new_generic_list(size_t size) {
-    generic_list_t list = {0};
-    if (size != 0) {
-       list.data = gv_calloc(size, sizeof(gl_data));
-    }
-    list.size = size;
-    return list;
-}
-
-void free_generic_list(generic_list_t * list)
-{
-    if (list->size > 0) {
-       free(list->data);
-    }
-}
-
-void add_to_generic_list(generic_list_t *list, gl_data element) {
-    size_t new_size;
-
-    if (list->size == list->used) {
-       if (list->size == 0) {
-           new_size = DFLT_SIZE;
-       } else {
-           new_size = list->size * 2;
-       }
-       gl_data *new_data = gv_recalloc(list->data, list->size, new_size,
-                                       sizeof(gl_data));
-       list->data = new_data;
-       list->size = new_size;
-    }
-    list->data[list->used++] = element;
-}
diff --git a/contrib/prune/generic_list.h b/contrib/prune/generic_list.h
deleted file mode 100644 (file)
index 047efc1..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*************************************************************************
- * 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 http://www.graphviz.org/
- *************************************************************************/
-
-#pragma once
-
-#include <stddef.h>
-
-    typedef void *gl_data;
-
-    typedef struct {
-       size_t used;    /* number of elements in the list */
-       size_t size;    /* number of elements that the list can hold */
-       gl_data *data;          /* pointer to first element */
-    } generic_list_t;
-
-    extern generic_list_t new_generic_list(size_t size);
-    extern void add_to_generic_list(generic_list_t * list,
-                                              gl_data element);
-    extern void free_generic_list(generic_list_t * list);
index 48e317d12dbdddd9eac5f8cb51eaf6977ae47a7f..efe77ffde429c2d9008e97e18dbf884779e3628b 100644 (file)
@@ -19,7 +19,6 @@
 #include <cgraph/exit.h>
 #include <cgraph/list.h>
 #include <ingraphs/ingraphs.h>
-#include "generic_list.h"
 
 /* structure to hold an attribute specified on the commandline */
 typedef struct {
@@ -28,12 +27,13 @@ typedef struct {
 } strattr_t;
 
 DEFINE_LIST(attrs, strattr_t)
+DEFINE_LIST(nodes, char*)
 
 static int remove_child(Agraph_t * graph, Agnode_t * node);
 static void help_message(const char *progname);
 
 static void addattr(attrs_t *l, char *a);
-static void addnode(generic_list_t * l, char *n);
+static void addnode(nodes_t *l, char *n);
 
 int verbose = 0;               /* Flag to indicate verbose message output */
 
@@ -70,8 +70,6 @@ int main(int argc, char **argv)
 
     char **files;
 
-    unsigned long i;
-
     opterr = 0;
 
     progname = strrchr(argv[0], '/');
@@ -82,7 +80,7 @@ int main(int argc, char **argv)
     }
 
     attrs_t attr_list = {0};
-    generic_list_t node_list = new_generic_list(16);
+    nodes_t node_list = {0};
 
     while ((c = getopt(argc, argv, "hvn:N:")) != -1) {
        switch (c) {
@@ -138,16 +136,16 @@ int main(int argc, char **argv)
        aginit(graph, AGNODE, NDNAME, sizeof(ndata), 1);
 
        /* prune all nodes specified on the commandline */
-       for (i = 0; i < node_list.used; i++) {
+       for (size_t i = 0; i < nodes_size(&node_list); ++i) {
            if (verbose == 1)
-               fprintf(stderr, "Pruning node %s\n", (char*)node_list.data[i]);
+               fprintf(stderr, "Pruning node %s\n", nodes_get(&node_list, i));
 
            /* check whether a node of that name exists at all */
-           node = agnode(graph, node_list.data[i], 0);
+           node = agnode(graph, nodes_get(&node_list, i), 0);
            if (node == NULL) {
                fprintf(stderr,
                        "*** Warning: No such node: %s -- gracefully skipping this one\n",
-                       (char*)node_list.data[i]);
+                       nodes_get(&node_list, i));
            } else {
                MARK(node);     /* Avoid cycles */
                /* Iterate over all outgoing edges */
@@ -180,7 +178,7 @@ int main(int argc, char **argv)
        agclose(graph);
     }
     attrs_free(&attr_list);
-    free_generic_list(&node_list);
+    nodes_free(&node_list);
     graphviz_exit(EXIT_SUCCESS);
 }
 
@@ -259,8 +257,8 @@ static void addattr(attrs_t *l, char *a) {
 }
 
 /* add element to node list */
-static void addnode(generic_list_t *l, char *n) {
+static void addnode(nodes_t *l, char *n) {
     char *sp = gv_strdup(n);
 
-    add_to_generic_list(l, sp);
+    nodes_append(l, sp);
 }
index d2a3ba39bd64e253a3941be0409d757459983a2e..708e7620c4cfc7ec1cc5f04032fc6e47a921ccc4 100644 (file)
     </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClInclude Include="generic_list.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="generic_list.c" />
     <ClCompile Include="prune.c" />
   </ItemGroup>
   <ItemGroup>
index c822f317dba2ca217b1057584870985c24c4acab..fc55769e0cc7076faf711c9ae140e7f974fed410 100644 (file)
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="generic_list.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="generic_list.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="prune.c">
       <Filter>Source Files</Filter>
     </ClCompile>