Welcome to mirror list, hosted at ThFree Co, Russian Federation.

block.c « objects « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 41700e057c17e1775888de89c541481b06be972e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
 * \file   block.c
 * \brief  The configuration block class.
 * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
 */

#include <assert.h>
#include <stdlib.h>
#include "premake.h"
#include "block.h"
#include "base/cstr.h"
#include "base/env.h"


FieldInfo BlockFieldInfo[] =
{
	{ "defines",    ListField,    NULL  },
	{ "flags",      ListField,    block_is_valid_flag  },
	{ "objdir",     PathField,    NULL  },
	{ "terms",      ListField,    NULL  },
	{  0,           0,            NULL  }
};


static const char* ValidFlags[] = 
{
	"Managed",
	"NoEditAndContinue",
	"Optimize", 
	"OptimizeSize", 
	"OptimizeSpeed", 
	"Symbols", 
	NULL
};


DEFINE_CLASS(Block)
{
	Fields fields;
};


/**
 * Create and initialize a new configuration block.
 */
Block block_create()
{
	Block blk = ALLOC_CLASS(Block);
	blk->fields = fields_create(BlockFieldInfo);
	return blk;
}


/**
 * Destroy a configuration block and release the associated memory.
 */
void block_destroy(Block blk)
{
	assert(blk);
	fields_destroy(blk->fields);
	free(blk);
}


/**
 * Checks the block's list of terms to see if this block applies to
 * the current environment. All of the block's terms must find a match
 * among the keyword sources, which include the current OS, the action,
 * and the provided configuration name.
 * \param   blk       The block to test.
 * \param   cfg_name  The name of the active configuration.
 * \returns True if every term in the block finds a keyword match.
 */
int block_applies_to(Block blk, const char* cfg_name)
{
	int i, n;
	Strings terms = block_get_values(blk, BlockTerms);
	n = strings_size(terms);
	for (i = 0; i < n; ++i)
	{
		const char* term = strings_item(terms, i);
		if ((cfg_name != NULL && cstr_matches_pattern(cfg_name, term)) ||
			cstr_matches_pattern(env_get_os_name(), term) ||
			cstr_matches_pattern(env_get_action(), term))
		{
			continue;
		}

		/* no match was found for this term */
		return 0;
	}
	
	return 1;
}

 
/**
 * Retrieve the fields object for this block; used to unload values from the script.
 */
Fields block_get_fields(Block blk)
{
	assert(blk);
	return blk->fields;
}


/**
 * Retrieve a list of values associated with a block.
 */
Strings block_get_values(Block blk, BlockField which)
{
	assert(blk);
	return fields_get_values(blk->fields, which);
}


/**
 * Returns true if the specified language is recognized. See the ValidLanguages at
 * the top of this file for a list of valid values.
 */
int block_is_valid_flag(const char* flag)
{
	const char** i;
	for (i = ValidFlags; (*i) != NULL; ++i)
	{
		if (cstr_eqi((*i), flag))
			return 1;
	}
	return 0;
}


/**
 * Set a value list field on the block.
 */
void block_set_values(Block blk, BlockField which, Strings strs)
{
	assert(blk);
	fields_set_values(blk->fields, which, strs);
}