summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-14 13:22:11 +0800
committerruki <[email protected]>2015-05-14 13:22:11 +0800
commit914fd0881e2242f01b497650dd09432316aa48d3 (patch)
treeb3f7d4a008a69e0bf7147c09528e4631e39ae93a
parent74ece0defa314bab78262d95bee517bdc09df689 (diff)
load xproj
-rw-r--r--core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h2
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/string/static_string.h17
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/string/string.h17
-rwxr-xr-xcore/src/xmake/preprocessor/load_xproj.c128
-rw-r--r--tests/console/xmake.xproj8
-rw-r--r--xmake/scripts/base/project.lua76
6 files changed, 235 insertions, 13 deletions
diff --git a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
index 22f02c45d..0617c7331 100644
--- a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
+++ b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
@@ -14,7 +14,7 @@
#define TB_CONFIG_VERSION_ALTER 8
// build version
-#define TB_CONFIG_VERSION_BUILD 201505132122
+#define TB_CONFIG_VERSION_BUILD 201505141040
// small
#define TB_CONFIG_SMALL (0)
diff --git a/core/pkg/tbox.pkg/inc/tbox/string/static_string.h b/core/pkg/tbox.pkg/inc/tbox/string/static_string.h
index 4a8bcd0c9..8f97aeacb 100755
--- a/core/pkg/tbox.pkg/inc/tbox/string/static_string.h
+++ b/core/pkg/tbox.pkg/inc/tbox/string/static_string.h
@@ -96,6 +96,14 @@ tb_void_t tb_static_string_clear(tb_static_string_ref_t string);
*/
tb_char_t const* tb_static_string_strip(tb_static_string_ref_t string, tb_size_t n);
+/*! trim the left spaces for string
+ *
+ * @param string the string
+ *
+ * @return the c-string
+ */
+tb_char_t const* tb_static_string_ltrim(tb_static_string_ref_t string);
+
/*! trim the right spaces for string
*
* @param string the string
@@ -104,6 +112,15 @@ tb_char_t const* tb_static_string_strip(tb_static_string_ref_t string, tb
*/
tb_char_t const* tb_static_string_rtrim(tb_static_string_ref_t string);
+/*! get the charactor at the given position
+ *
+ * @param string the string
+ * @param p the position
+ *
+ * @return the c-string
+ */
+tb_char_t tb_static_string_charat(tb_static_string_ref_t string, tb_size_t p);
+
/*! find charactor position
*
* @param string the string
diff --git a/core/pkg/tbox.pkg/inc/tbox/string/string.h b/core/pkg/tbox.pkg/inc/tbox/string/string.h
index 1380e62b6..f59bb04ae 100755
--- a/core/pkg/tbox.pkg/inc/tbox/string/string.h
+++ b/core/pkg/tbox.pkg/inc/tbox/string/string.h
@@ -94,6 +94,14 @@ tb_void_t tb_string_clear(tb_string_ref_t string);
*/
tb_char_t const* tb_string_strip(tb_string_ref_t string, tb_size_t n);
+/*! trim the left spaces for string
+ *
+ * @param string the string
+ *
+ * @return the c-string
+ */
+tb_char_t const* tb_string_ltrim(tb_string_ref_t string);
+
/*! trim the right spaces for string
*
* @param string the string
@@ -102,6 +110,15 @@ tb_char_t const* tb_string_strip(tb_string_ref_t string, tb_size_t n);
*/
tb_char_t const* tb_string_rtrim(tb_string_ref_t string);
+/*! get the charactor at the given position
+ *
+ * @param string the string
+ * @param p the position
+ *
+ * @return the c-string
+ */
+tb_char_t tb_string_charat(tb_string_ref_t string, tb_size_t p);
+
/*! find charactor position
*
* @param string the string
diff --git a/core/src/xmake/preprocessor/load_xproj.c b/core/src/xmake/preprocessor/load_xproj.c
index 1c03d563a..4930f4313 100755
--- a/core/src/xmake/preprocessor/load_xproj.c
+++ b/core/src/xmake/preprocessor/load_xproj.c
@@ -40,7 +40,16 @@ static tb_char_t const* xm_preprocessor_load_xproj_to_string(tb_stream_ref_t str
// check
tb_assert_and_check_return_val(stream && string, tb_null);
+ // init value
+ tb_string_t value;
+ if (!tb_string_init(&value)) return tb_null;
+
+ // init temporary value
+ tb_string_t value_temp;
+ if (!tb_string_init(&value_temp)) return tb_null;
+
// done
+ tb_bool_t is_value = tb_false;
tb_bool_t is_values = tb_false;
while (!tb_stream_beof(stream))
{
@@ -48,16 +57,118 @@ static tb_char_t const* xm_preprocessor_load_xproj_to_string(tb_stream_ref_t str
tb_char_t ch = (tb_char_t)tb_stream_bread_u8(stream);
if (ch)
{
- // skip '{'
- if (ch == '{') ;
- // replace '}' to scopend
- else if (ch == '}') tb_string_cstrcat(string, "scopend");
+ // is values?
+ if (is_values)
+ {
+ // is value?
+ if (is_value && ch != ',' && ch != ':' && ch != '{' && ch != '}' && ch != '\r' && ch != '\n')
+ {
+ // append to value
+ tb_string_chrcat(&value, ch);
+ }
+ // ',' or ':' or '{' or newline?
+ else if (ch == ',' || ch == ':' || ch == '{' || ch == '}' || ch == '\r' || ch == '\n')
+ {
+ // has value?
+ if (is_value)
+ {
+ // values end? append ')' and newline first
+ if (ch == ':') tb_string_cstrcat(string, ")\n");
+ else
+ {
+ // trim the left spaces
+ tb_string_ltrim(&value);
+
+ // trim the right spaces
+ tb_string_rtrim(&value);
+
+ // wrap "xxx"
+ if (tb_string_size(&value))
+ {
+ // it has been "xxx"? only copy it
+ if (tb_string_charat(&value, 0) == '\"')
+ tb_string_strcpy(&value_temp, &value);
+ // wrap it
+ else
+ {
+ tb_string_clear(&value_temp);
+ tb_string_chrcat(&value_temp, '\"');
+ tb_string_strcat(&value_temp, &value);
+ tb_string_chrcat(&value_temp, '\"');
+ }
+
+ // clear value first
+ tb_string_clear(&value);
+
+ // copy and replace '\"' to "\\""
+ tb_char_t const* s = tb_string_cstr(&value_temp);
+ tb_size_t n = tb_string_size(&value_temp);
+ tb_size_t i = 0;
+ for (i = 0; i < n; i++)
+ {
+ // replace '\"' to "\\""
+ if (i && i != n - 1 && s[i] == '\"') tb_string_cstrcat(&value, "\\\"");
+ // only copy iy
+ else tb_string_chrcat(&value, s[i]);
+ }
+ }
+ }
+
+ // append value to string
+ if (tb_string_size(&value)) tb_string_strcat(string, &value);
+
+ // clear value
+ tb_string_clear(&value);
+
+ // not value now
+ is_value = tb_false;
+ }
+
+ // continue to enter values? onyl replace ':' to '('
+ if (ch == ':') tb_string_chrcat(string, '(');
+ // '{' ?
+ else if (ch == '{')
+ {
+ // not values now
+ is_values = tb_false;
+
+ // append ')' and newline
+ tb_string_cstrcat(string, ")\n");
+ }
+ // '}' ?
+ else if (ch == '}')
+ {
+ // not values now
+ is_values = tb_false;
+
+ // append ')' and replace '}' to scopend
+ tb_string_cstrcat(string, ")\nscopend()");
+ }
+ // skip newline
+ else if (ch == '\r' || ch == '\n') ;
+ // append to string
+ else tb_string_chrcat(string, ch);
+ }
+ else
+ {
+ // value now
+ is_value = tb_true;
+
+ // append to value
+ tb_string_chrcat(&value, ch);
+ }
+ }
// enter values?
else if (ch == ':')
{
// values now
is_values = tb_true;
+
+ // replace ':' to '('
+ tb_string_chrcat(string, '(');
}
+ // replace '}' and newline to scopend
+ else if (ch == '}') tb_string_cstrcat(string, "\nscopend()");
// append it
else tb_string_chrcat(string, ch);
}
@@ -68,6 +179,12 @@ static tb_char_t const* xm_preprocessor_load_xproj_to_string(tb_stream_ref_t str
}
}
+ // exit value
+ tb_string_exit(&value);
+
+ // exit temporary value
+ tb_string_exit(&value_temp);
+
// ok?
return tb_string_size(string)? tb_string_cstr(string) : tb_null;
}
@@ -104,9 +221,10 @@ tb_int_t xm_preprocessor_load_xproj(lua_State* lua)
tb_char_t const* xproj = xm_preprocessor_load_xproj_to_string(stream, &string);
tb_assert_and_check_break(xproj);
- tb_trace_i("%s", xproj);
+ tb_printf("%s", xproj);
// load xmake.xproj string to script
+ //if (luaL_loadstring(lua, "project(\"console\")\nscopend()"))
if (luaL_loadstring(lua, xproj))
{
// error
diff --git a/tests/console/xmake.xproj b/tests/console/xmake.xproj
index 3fd4d5e67..4fa71797e 100644
--- a/tests/console/xmake.xproj
+++ b/tests/console/xmake.xproj
@@ -52,7 +52,7 @@ project: console
links: hello3
linkdirs: $(buildir)/lib
includedirs: $(buildir)/inc
- mflags: -DHELLO3
+ mflags: -DHELLO3, -DPLAT="macosx"
}
target: demo_objcpp
@@ -65,7 +65,7 @@ project: console
plarforms: linux
{
- defines: PLAT=linux
+ defines: PLAT="linux"
}
plarforms: windows
@@ -75,7 +75,9 @@ project: console
plarforms: macosx, ios
{
- ldflags: -framework Cocoa, -framework IOKit
+ ldflags: -framework Cocoa, "-framework IOKit"
+ , -framework UIKit
+ , -framework CoreFoundation
}
}
}
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 9f0dd7842..fe7986ba7 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -37,6 +37,74 @@ local current = nil
function scopend()
end
+-- configure kind
+function kind()
+end
+
+-- configure deps
+function deps()
+end
+
+-- configure files
+function files()
+end
+
+-- configure links
+function links()
+end
+
+-- configure headers
+function headers()
+end
+
+-- configure headerdir
+function headerdir()
+end
+
+-- configure targetdir
+function targetdir()
+end
+
+-- configure objectdir
+function objectdir()
+end
+
+-- configure linkdirs
+function linkdirs()
+end
+
+-- configure includedirs
+function includedirs()
+end
+
+-- configure cflags
+function cflags()
+end
+
+-- configure cxxflags
+function cxxflags()
+end
+
+-- configure ldflags
+function ldflags()
+end
+
+-- configure mflags
+function mflags()
+end
+
+-- configure mxflags
+function mxflags()
+end
+
+-- configure defines
+function defines()
+end
+
+-- configure plarforms
+function plarforms()
+end
+
-- configure target
function target(name)
@@ -44,15 +112,15 @@ function target(name)
assert(name and _ROOT)
-- init targets
- current._TARGETS = current._TARGETS or {}
+-- current._TARGETS = current._TARGETS or {}
-- init target scope
- current._TARGETS[name] = {}
+-- current._TARGETS[name] = {}
-- TODO
-- enter target scope
- parent = current
- current = _ROOT._TARGETS[name]
+-- parent = current
+-- current = _ROOT._TARGETS[name]
end