split out fragment code from parse.c

feature/tap-sh
William Pitcock 2012-05-03 20:22:19 +00:00
parent bd1bfa6228
commit de5e1c6e23
4 changed files with 72 additions and 43 deletions

View File

@ -1,5 +1,5 @@
PROG = pkgconf${PROG_SUFFIX} 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 include buildsys.mk

67
fragment.c Normal file
View File

@ -0,0 +1,67 @@
/*
* fragment.c
* Management of fragment lists.
*
* Copyright (c) 2012 William Pitcock <nenolod@dereferenced.org>.
*
* 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);
}

42
parse.c
View File

@ -104,48 +104,6 @@ strdup_parse(pkg_t *pkg, const char *value)
return strdup(buf); 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 * static pkg_fragment_t *
parse_fragment_list(pkg_t *pkg, const char *string) parse_fragment_list(pkg_t *pkg, const char *string)
{ {

4
pkg.h
View File

@ -133,4 +133,8 @@ pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t
/* argvsplit.c */ /* argvsplit.c */
int argv_split(const char *src, int *argc, char ***argv); 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 #endif