diff options
| author | ruki <[email protected]> | 2015-05-04 22:05:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-04 23:42:09 +0800 |
| commit | 00cd7e605400a459822294f3ceff5194cf9b56d5 (patch) | |
| tree | b600091426bc69a535338cc84e702f16d6f7b044 /core/src | |
| parent | 781bfd2dc99c8e0ca3063b6a3d6199f2390951f4 (diff) | |
add some path and string interfaces
Diffstat (limited to 'core/src')
| -rwxr-xr-x | core/src/xmake/machine.c | 10 | ||||
| -rwxr-xr-x | core/src/xmake/makefile | 3 | ||||
| -rwxr-xr-x | core/src/xmake/path/absolute.c (renamed from core/src/xmake/path/getabsolute.c) | 15 | ||||
| -rwxr-xr-x | core/src/xmake/path/translate.c | 57 |
4 files changed, 74 insertions, 11 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index ad993da9c..a6bcf0e35 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -53,7 +53,8 @@ typedef struct __xm_machine_impl_t */ // the path functions -tb_int_t xm_path_getabsolute(lua_State* lua); +tb_int_t xm_path_absolute(lua_State* lua); +tb_int_t xm_path_translate(lua_State* lua); // the string functions tb_int_t xm_string_startswith(lua_State* lua); @@ -65,7 +66,8 @@ tb_int_t xm_string_startswith(lua_State* lua); // the path functions static luaL_Reg const g_path_functions[] = { - { "getabsolute", xm_path_getabsolute } + { "absolute", xm_path_absolute } +, { "translate", xm_path_translate } , { tb_null, tb_null } }; @@ -125,7 +127,7 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl, } // get the full path - if (!tb_path_full(data, path, maxn)) break; + if (!tb_path_absolute(data, path, maxn)) break; // trace tb_trace_d("program: %s", path); @@ -154,7 +156,7 @@ static tb_bool_t xm_machine_main_get_project_directory(xm_machine_impl_t* impl, // attempt to get it from the environment variable first tb_char_t data[TB_PATH_MAXN] = {0}; if ( !tb_environment_get_one("XMAKE_PROJECT_DIR", data, sizeof(data)) - || !tb_path_full(data, path, maxn)) + || !tb_path_absolute(data, path, maxn)) { // get it from the current directory if (!tb_directory_current(path, maxn)) break; diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 35d8e9f7a..0b65dc2a2 100755 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -14,7 +14,8 @@ xmake_CONFIG = y xmake_C_FILES += \ xmake \ machine \ - path/getabsolute \ + path/absolute \ + path/translate \ string/startswith diff --git a/core/src/xmake/path/getabsolute.c b/core/src/xmake/path/absolute.c index 8d1bae3ed..1695d5dd1 100755 --- a/core/src/xmake/path/getabsolute.c +++ b/core/src/xmake/path/absolute.c @@ -17,14 +17,14 @@ * Copyright (C) 2009 - 2015, ruki All rights reserved. * * @author ruki - * @file getabsolute.c + * @file absolute.c * */ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "getabsolute" +#define TB_TRACE_MODULE_NAME "absolute" #define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// @@ -35,7 +35,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_path_getabsolute(lua_State* lua) +tb_int_t xm_path_absolute(lua_State* lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -44,9 +44,12 @@ tb_int_t xm_path_getabsolute(lua_State* lua) tb_char_t const* path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); - // TODO - // done path:getabsolute() - tb_trace_i("%s", path); + // get the root + tb_char_t const* root = luaL_optstring(lua, 2, tb_null); + + // done path:absolute(root) + tb_char_t data[TB_PATH_MAXN]; + lua_pushstring(lua, tb_path_absolute_to(root, path, data, sizeof(data) - 1)); // ok return 1; diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c new file mode 100755 index 000000000..7b53662ea --- /dev/null +++ b/core/src/xmake/path/translate.c @@ -0,0 +1,57 @@ +/*!The Automatic Cross-platform Build Tool + * + * XMake is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * XMake 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with XMake; + * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> + * + * Copyright (C) 2009 - 2015, ruki All rights reserved. + * + * @author ruki + * @file translate.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "translate" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_path_translate(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the path + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_check_return_val(path, 0); + + // copy path + tb_char_t data[TB_PATH_MAXN]; + tb_strlcpy(data, path, sizeof(data) - 1); + data[sizeof(data) - 1] = '\0'; + + // done path:translate() + lua_pushstring(lua, tb_path_translate(data, 0, sizeof(data) - 1)? data : tb_null); + + // ok + return 1; +} |
