summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-07 11:55:37 +0800
committerruki <[email protected]>2017-09-07 11:55:37 +0800
commitf7fe93d37dd1e863a09c0d41f7ec74200cc9242c (patch)
tree8f921a530ce419499c04712d780e452aaff4d414 /core/src
parentb64cfa7b328df9cb389821c9348b4774024b251a (diff)
disable to output colors code to file
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/io/isatty.c70
-rw-r--r--core/src/xmake/io/prefix.h36
-rw-r--r--core/src/xmake/machine.c12
-rw-r--r--core/src/xmake/makefile1
4 files changed, 119 insertions, 0 deletions
diff --git a/core/src/xmake/io/isatty.c b/core/src/xmake/io/isatty.c
new file mode 100644
index 000000000..a210771a4
--- /dev/null
+++ b/core/src/xmake/io/isatty.c
@@ -0,0 +1,70 @@
+/*!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 - 2017, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file isatty.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "isatty"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+#ifndef TB_CONFIG_OS_WINDOWS
+# include <unistd.h>
+#endif
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+/* stdout: io.isatty()
+ * stderr: io.isatty(io.stderr)
+ * stdin: io.isatty(io.stdin)
+ */
+tb_int_t xm_io_isatty(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // no arguments? default: stdout
+ tb_int_t answer = 1;
+#ifndef TB_CONFIG_OS_WINDOWS
+ if (lua_gettop(lua) == 0)
+ answer = isatty(1);
+ else
+ {
+ FILE** fp = (FILE**)luaL_checkudata(lua, 1, LUA_FILEHANDLE);
+ if (fp) answer = isatty(fileno(*fp));
+ }
+#endif
+
+ // return answer
+ lua_pushboolean(lua, answer);
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/io/prefix.h b/core/src/xmake/io/prefix.h
new file mode 100644
index 000000000..a75aa03e4
--- /dev/null
+++ b/core/src/xmake/io/prefix.h
@@ -0,0 +1,36 @@
+/*!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 - 2017, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file prefix.h
+ *
+ */
+#ifndef XM_IO_PREFIX_H
+#define XM_IO_PREFIX_H
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "../prefix.h"
+
+
+#endif
+
+
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index e1a080d3a..34d80d618 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -87,6 +87,9 @@ tb_int_t xm_os_gid(lua_State* lua);
tb_int_t xm_os_getown(lua_State* lua);
#endif
+// the io functions
+tb_int_t xm_io_isatty(lua_State* lua);
+
// the path functions
tb_int_t xm_path_relative(lua_State* lua);
tb_int_t xm_path_absolute(lua_State* lua);
@@ -167,6 +170,12 @@ static luaL_Reg const g_os_functions[] =
, { tb_null, tb_null }
};
+// the io functions
+static luaL_Reg const g_io_functions[] =
+{
+ { "isatty", xm_io_isatty }
+};
+
// the path functions
static luaL_Reg const g_path_functions[] =
{
@@ -445,6 +454,9 @@ xm_machine_ref_t xm_machine_init()
// bind os functions
luaL_register(impl->lua, "os", g_os_functions);
+ // bind io functions
+ luaL_register(impl->lua, "io", g_io_functions);
+
// bind path functions
luaL_register(impl->lua, "path", g_path_functions);
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 9992ab656..ee3062634 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -40,6 +40,7 @@ xmake_C_FILES += \
os/uid \
os/gid \
os/getown \
+ io/isatty \
path/relative \
path/absolute \
path/translate \