From de5e1c6e234794eb53c9922eb33fc77ca46b9f4e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 3 May 2012 20:22:19 +0000 Subject: [PATCH] split out fragment code from parse.c --- Makefile | 2 +- fragment.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ parse.c | 42 ---------------------------------- pkg.h | 4 ++++ 4 files changed, 72 insertions(+), 43 deletions(-) create mode 100644 fragment.c diff --git a/Makefile b/Makefile index 27af991..097963e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROG = pkgconf${PROG_SUFFIX} -SRCS = main.c parse.c pkg.c bsdstubs.c getopt_long.c argvsplit.c +SRCS = main.c parse.c pkg.c bsdstubs.c getopt_long.c fragment.c argvsplit.c include buildsys.mk diff --git a/fragment.c b/fragment.c new file mode 100644 index 0000000..e8b0484 --- /dev/null +++ b/fragment.c @@ -0,0 +1,67 @@ +/* + * fragment.c + * Management of fragment lists. + * + * Copyright (c) 2012 William Pitcock . + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "pkg.h" +#include "bsdstubs.h" + +pkg_fragment_t * +pkg_fragment_append(pkg_fragment_t *head, pkg_fragment_t *tail) +{ + pkg_fragment_t *node; + + if (head == NULL) + return tail; + + /* skip to end of list */ + foreach_list_entry(head, node) + { + if (node->next == NULL) + break; + } + + node->next = tail; + tail->prev = node; + + return head; +} + +pkg_fragment_t * +pkg_fragment_add(pkg_fragment_t *head, const char *string) +{ + pkg_fragment_t *frag; + + frag = calloc(sizeof(pkg_fragment_t), 1); + + if (*string == '-' && strncmp(string, "-lib:", 5)) + { + frag->type = *(string + 1); + frag->data = strdup(string + 2); + } + else + { + frag->type = 0; + frag->data = strdup(string); + } + + return pkg_fragment_append(head, frag); +} diff --git a/parse.c b/parse.c index 97ce1f8..802ff67 100644 --- a/parse.c +++ b/parse.c @@ -104,48 +104,6 @@ strdup_parse(pkg_t *pkg, const char *value) return strdup(buf); } -static pkg_fragment_t * -pkg_fragment_append(pkg_fragment_t *head, pkg_fragment_t *tail) -{ - pkg_fragment_t *node; - - if (head == NULL) - return tail; - - /* skip to end of list */ - foreach_list_entry(head, node) - { - if (node->next == NULL) - break; - } - - node->next = tail; - tail->prev = node; - - return head; -} - -static pkg_fragment_t * -pkg_fragment_add(pkg_fragment_t *head, const char *string) -{ - pkg_fragment_t *frag; - - frag = calloc(sizeof(pkg_fragment_t), 1); - - if (*string == '-' && strncmp(string, "-lib:", 5)) - { - frag->type = *(string + 1); - frag->data = strdup(string + 2); - } - else - { - frag->type = 0; - frag->data = strdup(string); - } - - return pkg_fragment_append(head, frag); -} - static pkg_fragment_t * parse_fragment_list(pkg_t *pkg, const char *string) { diff --git a/pkg.h b/pkg.h index 08b825e..7ebe0ee 100644 --- a/pkg.h +++ b/pkg.h @@ -133,4 +133,8 @@ pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t /* argvsplit.c */ int argv_split(const char *src, int *argc, char ***argv); +/* fragment.c */ +pkg_fragment_t *pkg_fragment_append(pkg_fragment_t *head, pkg_fragment_t *tail); +pkg_fragment_t *pkg_fragment_add(pkg_fragment_t *head, const char *string); + #endif