Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ INCLUDE = -I include
CFLAGS_COMMON = $(INCLUDE) -Wall -Wextra -Werror -MD -MP
CFLAGS_RELEASE = -DNDEBUG -O3 $(CFLAGS_COMMON)
CFLAGS_DEBUG = -O0 -g $(CFLAGS_COMMON)
LDFLAGS_DEBUG = -lm
LDFLAGS_DEBUG = -lm -lexpat
LDFLAGS_RELEASE = -s $(LDFLAGS_DEBUG)

SRC = $(shell find src -type f)
SRC = $(shell find src -type f -name "*.c")
OBJ_RELEASE = $(patsubst src/%.c, .build/%.o, $(SRC))
DEP_RELEASE = $(patsubst src/%.c, .build/%.d, $(SRC))
OBJ_DEBUG = $(patsubst src/%.c, .build/debug/%.o, $(SRC))
Expand Down
4 changes: 4 additions & 0 deletions include/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ extern bool group_list_parse(
const char* groups, bool filter,
group_t** list, unsigned* list_count);

extern const group_t* group_list_parse_platform(
const char* platform,
unsigned* platform_groups_count);

#endif
2 changes: 2 additions & 0 deletions include/manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ typedef struct
const char* revision;
copyfile_t* copyfile;
unsigned copyfile_count;
copyfile_t* linkfile;
unsigned linkfile_count;
group_t* group;
unsigned group_count;
} project_t;
Expand Down
3 changes: 2 additions & 1 deletion include/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#ifndef __xml_h__
#define __xml_h__
#include <stddef.h>

typedef struct xml_tag_s xml_tag_t;
typedef struct xml_field_s xml_field_t;
Expand All @@ -40,7 +41,7 @@ struct xml_tag_s



extern xml_tag_t* xml_document_parse(const char* source);
extern xml_tag_t* xml_document_parse(const char* source, size_t len);
extern const char* xml_tag_field(xml_tag_t* tag, const char* name);
extern void xml_tag_delete(xml_tag_t* tag);

Expand Down
73 changes: 73 additions & 0 deletions src/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string.h>
#include <stdint.h>

#include <sys/utsname.h>


bool group_list_match(
Expand Down Expand Up @@ -194,3 +195,75 @@ bool group_list_parse(
*list_count = nlist_count;
return true;
}


// Sorted in order of least common to most since groups can be processed
// in reverse order and use the last match, so it's more likely to match faster
// if the most common is last.
static const group_t platform_groups[] =
{
{
"platform-darwin",
15,
false,
},
{
"platform-windows",
16,
false,
},
{
"platform-linux",
14,
false,
}
};
#define PLATFORM_GROUPS_COUNT (sizeof(platform_groups)/sizeof(platform_groups[0]))


const group_t* group__list_find_by_name(
const char* platform,
unsigned* platform_groups_count)
{
const group_t* match;
for (match = &platform_groups[PLATFORM_GROUPS_COUNT - 1];
match >= platform_groups;
match--)
{
if (strncasecmp(
platform,
&match->name[strlen("platform-")],
match->size - strlen("platform-")) == 0)
{
*platform_groups_count = 1;
return match;
}
}
return NULL;
}


const group_t* group_list_parse_platform(
const char* platform,
unsigned* platform_groups_count)
{
if (strcmp(platform, "all") == 0)
{
*platform_groups_count = PLATFORM_GROUPS_COUNT;
return platform_groups;
}

if (strcmp(platform, "auto") == 0)
{
struct utsname u;
if (uname(&u) != 0)
// This should never happen in practise
// because &u is always a valid pointer,
return NULL;
return group__list_find_by_name(
u.sysname,
platform_groups_count);
}

return group__list_find_by_name(platform, platform_groups_count);
}
Loading