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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/**
* \file vs200x.c
* \brief General purpose Visual Studio support functions.
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "premake.h"
#include "vs200x.h"
#include "base/buffers.h"
#include "base/cstr.h"
#include "base/env.h"
#include "base/error.h"
/**
* Write an XML attribute, adjusting for the differing Visual Studio formats.
* \param strm The output stream, the attribute will be written here.
* \param indent_size How far to indent (with tabs) the attribute.
* \param name The attribute name.
* \param value The attribute value; may contain printf-style formatting codes.
* \returns OKAY if successful.
*/
int vs200x_attribute(Stream strm, int indent_size, const char* name, const char* value, ...)
{
va_list args;
char* buffer;
int z = OKAY;
z |= stream_writeline(strm, "");
z |= stream_write_n(strm, "\t", indent_size);
z |= stream_write(strm, "%s=\"", name);
buffer = buffers_next();
va_start(args, value);
vsprintf(buffer, value, args);
z |= stream_write_escaped(strm, buffer);
va_end(args);
z |= stream_write(strm, "\"");
return z;
}
/**
* Write an XML attribute containing a list of values, adjusting for the differing Visual Studio formats.
* \param strm The output stream, the attribute will be written here.
* \param indent_size How far to indent (with tabs) the attribute.
* \param name The attribute name.
* \param values The attribute list value.
* \returns OKAY if successful.
*/
int vs200x_list_attribute(Stream strm, int indent_size, const char* name, Strings values)
{
int z = OKAY;
z |= stream_writeline(strm, "");
z |= stream_write_n(strm, "\t", indent_size);
z |= stream_write(strm, "%s=", name);
z |= stream_write_strings(strm, values, "\"", "", "", ";", "\"", stream_write_escaped);
return z;
}
/**
* Write the ending part of an XML tag, adjust for the differing Visual Studio formats.
* \param strm The output stream.
* \param level The XML element nesting level.
* \param markup The end tag markup.
* \returns OKAY if successful.
*/
int vs200x_element_end(Stream strm, int level, const char* markup)
{
int z, version;
version = vs200x_get_target_version();
if (version >= 2005)
{
z = stream_writeline(strm, "");
if (markup[0] == '>')
{
level++;
}
z |= stream_write_n(strm, "\t", level);
z |= stream_writeline(strm, "%s", markup);
}
else
{
z = stream_writeline(strm, markup);
}
return z;
}
/**
* Return the Visual Studio version appropriate version of the string for a false
* value. Before 2005 this was "FALSE", after it is "false".
*/
const char* vs200x_false(void)
{
int version = vs200x_get_target_version();
return (version < 2005) ? "FALSE" : "false";
}
/**
* Converts the session action string to a Visual Studio version number.
* \returns The Visual Studio version number corresponding to the current action.
*/
int vs200x_get_target_version(void)
{
const char* action = env_get_action();
if (cstr_eq(action, "vs2002"))
{
return 2002;
}
else if (cstr_eq(action, "vs2003"))
{
return 2003;
}
else if (cstr_eq(action, "vs2005"))
{
return 2005;
}
else if (cstr_eq(action, "vs2008"))
{
return 2008;
}
else
{
assert(0);
return 0;
}
}
/**
* Return the appropriate file extension for a particular project.
* \param prj The project object.
* \returns The appropriate project file extension, based on the project settings.
*/
const char* vs200x_project_file_extension(Project prj)
{
const char* language = project_get_language(prj);
if (cstr_eq(language, "c") || cstr_eq(language, "c++"))
{
return ".vcproj";
}
else
{
error_set("unsupported language '%s'", language);
return NULL;
}
}
/**
* Returns the Visual Studio GUID for a particular project type.
* \param language The programming language used in the project.
* \returns The GUID corresponding the programming language.
*/
const char* vs200x_tool_guid(const char* language)
{
if (cstr_eq(language, "c") || cstr_eq(language, "c++"))
{
return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
}
else if (cstr_eq(language, "c#"))
{
return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
}
else
{
error_set("unsupported language '%s'", language);
return NULL;
}
}
/**
* Return the Visual Studio version appropriate version of the string for a true
* value. Before 2005 this was "TRUE", after it is "true".
*/
const char* vs200x_true(void)
{
int version = vs200x_get_target_version();
return (version < 2005) ? "TRUE" : "true";
}
|