summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorruki <[email protected]>2018-08-15 00:47:54 +0800
committerruki <[email protected]>2018-08-14 22:47:29 +0800
commit7824ce2bf02fe0438a04f074152847a773130d17 (patch)
treea5bf281a1ccdf7870d1c421986a41c62d65dae93 /core
parent6b471f65f4536d07150b89504bf52753461064a5 (diff)
add winos
Diffstat (limited to 'core')
-rw-r--r--core/src/xmake/machine.c28
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--core/src/xmake/winos/logical_drives.c89
-rw-r--r--core/src/xmake/winos/prefix.h (renamed from core/src/xmake/winreg/prefix.h)8
-rw-r--r--core/src/xmake/winos/registry_query.c (renamed from core/src/xmake/winreg/query.c)13
-rw-r--r--core/src/xmake/xmake.lua5
6 files changed, 116 insertions, 28 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 9fe975803..b9eceb6ae 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -101,9 +101,10 @@ tb_int_t xm_path_is_absolute(lua_State* lua);
tb_int_t xm_hash_uuid(lua_State* lua);
tb_int_t xm_hash_sha256(lua_State* lua);
-// the winreg functions
+// the windows functions
#ifdef TB_CONFIG_OS_WINDOWS
-tb_int_t xm_winreg_query(lua_State* lua);
+tb_int_t xm_winos_logical_drives(lua_State* lua);
+tb_int_t xm_winos_registry_query(lua_State* lua);
#endif
// the string functions
@@ -177,6 +178,16 @@ static luaL_Reg const g_os_functions[] =
, { tb_null, tb_null }
};
+// the windows functions
+#ifdef TB_CONFIG_OS_WINDOWS
+static luaL_Reg const g_winos_functions[] =
+{
+ { "logical_drives", xm_winos_logical_drives }
+, { "registry_query", xm_winos_registry_query }
+, { tb_null, tb_null }
+};
+#endif
+
// the io functions
static luaL_Reg const g_io_functions[] =
{
@@ -210,15 +221,6 @@ static luaL_Reg const g_string_functions[] =
, { tb_null, tb_null }
};
-#ifdef TB_CONFIG_OS_WINDOWS
-// the winreg functions
-static luaL_Reg const g_winreg_functions[] =
-{
- { "query", xm_winreg_query }
-, { tb_null, tb_null }
-};
-#endif
-
// the process functions
static luaL_Reg const g_process_functions[] =
{
@@ -545,9 +547,9 @@ xm_machine_ref_t xm_machine_init()
// bind sandbox functions
luaL_register(machine->lua, "sandbox", g_sandbox_functions);
- // bind winreg functions
+ // bind windows functions
#ifdef TB_CONFIG_OS_WINDOWS
- luaL_register(machine->lua, "winreg", g_winreg_functions);
+ luaL_register(machine->lua, "winos", g_winos_functions);
#endif
#ifdef XM_CONFIG_API_HAVE_READLINE
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 5c11d0a62..833c80241 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -48,7 +48,6 @@ xmake_C_FILES += \
path/is_absolute \
hash/uuid \
hash/sha256 \
- winreg/query \
string/endswith \
string/startswith \
process/open \
diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c
new file mode 100644
index 000000000..cd4368c47
--- /dev/null
+++ b/core/src/xmake/winos/logical_drives.c
@@ -0,0 +1,89 @@
+/*!The Make-like Build Utility based on Lua
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file logical_drives.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "logical_drives"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+// get the logical drives
+tb_int_t xm_winos_logical_drives(lua_State* lua)
+{
+ // init table
+ lua_newtable(lua);
+
+ // get logical drives
+ tb_bool_t ok = tb_false;
+ tb_char_t* data = tb_null;
+ do
+ {
+ // get buffer size
+ DWORD size = GetLogicalDriveStringsA(0, tb_null);
+ tb_assert_and_check_break(size);
+
+ // make data buffer
+ data = (tb_char_t*)tb_malloc0(size + 1);
+ tb_assert_and_check_break(data);
+
+ // get logical drives
+ size = GetLogicalDriveStringsA(size, data);
+ tb_assert_and_check_break(size);
+
+ // parse logical drives
+ tb_size_t i = 1;
+ tb_char_t const* p = data;
+ while (*p)
+ {
+ // save drive
+ lua_pushinteger(lua, i++);
+ lua_pushstring(lua, p);
+ lua_settable(lua, -3);
+
+ // next drive
+ p += tb_strlen(p) + 1;
+ }
+
+ // ok
+ ok = tb_true;
+
+ } while (0);
+
+ // exit data
+ if (data) tb_free(data);
+ data = tb_null;
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/winreg/prefix.h b/core/src/xmake/winos/prefix.h
index 530b240ca..01a423c6a 100644
--- a/core/src/xmake/winreg/prefix.h
+++ b/core/src/xmake/winos/prefix.h
@@ -18,19 +18,19 @@
*
* Copyright (C) 2015 - 2018, TBOOX Open Source Group.
*
- * @author TitanSnow
+ * @author ruki
* @file prefix.h
*
*/
-#ifndef XM_WINREG_PREFIX_H
-#define XM_WINREG_PREFIX_H
+#ifndef XM_WINOS_PREFIX_H
+#define XM_WINOS_PREFIX_H
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "../prefix.h"
#ifdef TB_CONFIG_OS_WINDOWS
-#include <windows.h>
+# include <windows.h>
#endif
diff --git a/core/src/xmake/winreg/query.c b/core/src/xmake/winos/registry_query.c
index 1e8ed513b..1476107cb 100644
--- a/core/src/xmake/winreg/query.c
+++ b/core/src/xmake/winos/registry_query.c
@@ -19,14 +19,14 @@
* Copyright (C) 2015 - 2018, TBOOX Open Source Group.
*
* @author TitanSnow, ruki
- * @file query.c
+ * @file registry_query.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "query"
+#define TB_TRACE_MODULE_NAME "registry_query"
#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -37,22 +37,18 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
-#ifdef TB_CONFIG_OS_WINDOWS
// the RegGetValueA func type
typedef BOOL (WINAPI* xm_RegGetValueA_t)(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
-#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-#ifdef TB_CONFIG_OS_WINDOWS
-
/* query registry
*
- * local value, errors = winreg.query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger")
+ * local value, errors = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger")
*/
-tb_int_t xm_winreg_query(lua_State* lua)
+tb_int_t xm_winos_registry_query(lua_State* lua)
{
// check
tb_assert_and_check_return_val(lua, 0);
@@ -226,4 +222,3 @@ tb_int_t xm_winreg_query(lua_State* lua)
// ok?
return ok? 1 : 2;
}
-#endif
diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua
index d394b483c..7e1f55e95 100644
--- a/core/src/xmake/xmake.lua
+++ b/core/src/xmake/xmake.lua
@@ -23,7 +23,10 @@ target("xmake")
add_packages("tbox")
-- add the common source files
- add_files("**.c")
+ add_files("**.c|winos/*.c")
+ if is_plat("windows") then
+ add_files("winos/*.c")
+ end
-- add readline
add_options("readline")