summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-18 11:25:38 +0800
committerruki <[email protected]>2015-05-18 11:25:38 +0800
commitc94218b659016aadb3f1dc63cc82c3ae8dc14320 (patch)
treeddbbf771f33ae55180816403473623846a79750b /core/src
parent7be8238f634969e80e678f59ab418900f846b094 (diff)
add some interfaces for changing directory
Diffstat (limited to 'core/src')
-rwxr-xr-xcore/src/xmake/machine.c10
-rwxr-xr-xcore/src/xmake/makefile4
-rwxr-xr-xcore/src/xmake/os/chdir.c52
-rwxr-xr-xcore/src/xmake/os/curdir.c50
-rwxr-xr-xcore/src/xmake/os/tmpdir.c50
-rwxr-xr-xcore/src/xmake/path/relative.c56
6 files changed, 221 insertions, 1 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index dd4ae864c..3fc303002 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -54,6 +54,9 @@ tb_int_t xm_os_isdir(lua_State* lua);
tb_int_t xm_os_rmdir(lua_State* lua);
tb_int_t xm_os_mkdir(lua_State* lua);
tb_int_t xm_os_cpdir(lua_State* lua);
+tb_int_t xm_os_chdir(lua_State* lua);
+tb_int_t xm_os_curdir(lua_State* lua);
+tb_int_t xm_os_tmpdir(lua_State* lua);
tb_int_t xm_os_isfile(lua_State* lua);
tb_int_t xm_os_rmfile(lua_State* lua);
tb_int_t xm_os_cpfile(lua_State* lua);
@@ -61,6 +64,7 @@ tb_int_t xm_os_rename(lua_State* lua);
tb_int_t xm_os_exists(lua_State* lua);
// the path functions
+tb_int_t xm_path_relative(lua_State* lua);
tb_int_t xm_path_absolute(lua_State* lua);
tb_int_t xm_path_translate(lua_State* lua);
tb_int_t xm_path_is_absolute(lua_State* lua);
@@ -82,6 +86,9 @@ static luaL_Reg const g_os_functions[] =
, { "rmdir", xm_os_rmdir }
, { "mkdir", xm_os_mkdir }
, { "cpdir", xm_os_cpdir }
+, { "chdir", xm_os_chdir }
+, { "curdir", xm_os_curdir }
+, { "tmpdir", xm_os_tmpdir }
, { "isfile", xm_os_isfile }
, { "rmfile", xm_os_rmfile }
, { "cpfile", xm_os_cpfile }
@@ -93,7 +100,8 @@ static luaL_Reg const g_os_functions[] =
// the path functions
static luaL_Reg const g_path_functions[] =
{
- { "absolute", xm_path_absolute }
+ { "relative", xm_path_relative }
+, { "absolute", xm_path_absolute }
, { "translate", xm_path_translate }
, { "is_absolute", xm_path_is_absolute }
, { tb_null, tb_null }
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 899ceaf3a..8d848e904 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -18,11 +18,15 @@ xmake_C_FILES += \
os/rmdir \
os/mkdir \
os/cpdir \
+ os/chdir \
+ os/curdir \
+ os/tmpdir \
os/isfile \
os/rmfile \
os/cpfile \
os/rename \
os/exists \
+ path/relative \
path/absolute \
path/translate \
path/is_absolute \
diff --git a/core/src/xmake/os/chdir.c b/core/src/xmake/os/chdir.c
new file mode 100755
index 000000000..478ce6948
--- /dev/null
+++ b/core/src/xmake/os/chdir.c
@@ -0,0 +1,52 @@
+/*!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 chdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "chdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_chdir(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);
+
+ // done os.chdir(path)
+ lua_pushboolean(lua, tb_directory_current_set(path));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c
new file mode 100755
index 000000000..38dafdeaf
--- /dev/null
+++ b/core/src/xmake/os/curdir.c
@@ -0,0 +1,50 @@
+/*!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 curdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "curdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_curdir(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // done os.curdir()
+ tb_char_t path[TB_PATH_MAXN];
+ if (tb_directory_current(path, sizeof(path))) lua_pushstring(lua, path);
+ else lua_pushnil(lua);
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c
new file mode 100755
index 000000000..7b2d7f85d
--- /dev/null
+++ b/core/src/xmake/os/tmpdir.c
@@ -0,0 +1,50 @@
+/*!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 tmpdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "tmpdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_tmpdir(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // done os.tmpdir()
+ tb_char_t path[TB_PATH_MAXN];
+ if (tb_directory_temporary(path, sizeof(path))) lua_pushstring(lua, path);
+ else lua_pushnil(lua);
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/path/relative.c b/core/src/xmake/path/relative.c
new file mode 100755
index 000000000..02b3b3523
--- /dev/null
+++ b/core/src/xmake/path/relative.c
@@ -0,0 +1,56 @@
+/*!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 relative.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "relative"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_path_relative(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);
+
+ // get the root
+ tb_char_t const* root = luaL_optstring(lua, 2, tb_null);
+
+ // done path:relative(root)
+ tb_char_t data[TB_PATH_MAXN];
+ lua_pushstring(lua, tb_path_relative_to(root, path, data, sizeof(data) - 1));
+
+ // ok
+ return 1;
+}