Move the string list funcs to their own file

They're not (at this stage, at least) worthy of being promoted out to
the utils lib.
This commit is contained in:
Bill Currie 2019-07-09 14:24:55 +09:00
parent b3d982bfc3
commit 0f511e8342
4 changed files with 97 additions and 49 deletions

View file

@ -5,6 +5,7 @@ AM_CPPFLAGS= -I$(top_srcdir)/include -DVK_NO_PROTOTYPES
vulkan_src = \
init.c \
util.c \
vulkan_draw.c \
vulkan_vid_common.c
@ -21,5 +22,5 @@ SUFFICES=.frag .vert .fc .vc .slc .glsl
libvulkan_la_SOURCES= $(vulkan_src)
EXTRA_DIST = $(vulkan_src) $(shader_src) namehack.h
EXTRA_DIST = $(vulkan_src) $(shader_src) namehack.h util.h
CLEANFILES= *.vc *.fc *.slc

View file

@ -1,5 +1,5 @@
/*
int.c
init.c
Copyright (C) 2019 Bill Currie <bill@taniwha.org>
@ -45,6 +45,8 @@
#include "vid_vulkan.h"
#include "util.h"
cvar_t *vulkan_use_validation;
static uint32_t numLayers;
@ -196,53 +198,6 @@ init_physdev (VulkanInstance_t *instance, VkPhysicalDevice dev, VulkanPhysDevice
}
}
static int
count_strings (const char **str)
{
int count = 0;
if (str) {
while (*str++) {
count++;
}
}
return count;
}
static void
merge_strings (const char **out, const char **in1, const char **in2)
{
if (in1) {
while (*in1) {
*out++ = *in1++;
}
}
if (in2) {
while (*in2) {
*out++ = *in2++;
}
}
}
static void
prune_strings (const char * const *reference, const char **strings,
uint32_t *count)
{
for (int i = *count; i-- > 0; ) {
const char *str = strings[i];
const char * const *ref;
for (ref = reference; *ref; ref++) {
if (!strcmp (*ref, str)) {
break;
}
}
if (!*ref) {
memmove (strings + i, strings + i + 1,
(--(*count) - i) * sizeof (const char **));
}
}
}
static int message_severities =
VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |

View file

@ -0,0 +1,83 @@
/*
util.c
Copyright (C) 2019 Bill Currie <bill@taniwha.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "util.h"
int
count_strings (const char **str)
{
int count = 0;
if (str) {
while (*str++) {
count++;
}
}
return count;
}
void
merge_strings (const char **out, const char **in1, const char **in2)
{
if (in1) {
while (*in1) {
*out++ = *in1++;
}
}
if (in2) {
while (*in2) {
*out++ = *in2++;
}
}
}
void
prune_strings (const char * const *reference, const char **strings,
uint32_t *count)
{
for (int i = *count; i-- > 0; ) {
const char *str = strings[i];
const char * const *ref;
for (ref = reference; *ref; ref++) {
if (!strcmp (*ref, str)) {
break;
}
}
if (!*ref) {
memmove (strings + i, strings + i + 1,
(--(*count) - i) * sizeof (const char **));
}
}
}

View file

@ -0,0 +1,9 @@
#ifndef __util_h
#define __util_h
#include <stdint.h>
int count_strings (const char **str);
void merge_strings (const char **out, const char **in1, const char **in2);
void prune_strings (const char * const *reference, const char **strings, uint32_t *count);
#endif//__util_h