diff options
author | Kim Alvefur <zash@zash.se> | 2015-04-03 19:52:48 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-04-03 19:52:48 +0200 |
commit | 7e460fd43feab7c2fb6770415c110eaa14aa8304 (patch) | |
tree | 10e930161b20bb87cc5062521942d0d50bc8a06c /util-src/windows.c | |
parent | ea346342bd8e8677c0a5f36828fb2dfa812a0a89 (diff) | |
download | prosody-7e460fd43feab7c2fb6770415c110eaa14aa8304.tar.gz prosody-7e460fd43feab7c2fb6770415c110eaa14aa8304.zip |
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Diffstat (limited to 'util-src/windows.c')
-rw-r--r-- | util-src/windows.c | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/util-src/windows.c b/util-src/windows.c index 37f850e3..aaa07407 100644 --- a/util-src/windows.c +++ b/util-src/windows.c @@ -1,7 +1,7 @@ /* Prosody IM -- Copyright (C) 2008-2010 Matthew Wild -- Copyright (C) 2008-2010 Waqas Hussain --- +-- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- @@ -23,23 +23,26 @@ #define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) #endif -static int Lget_nameservers(lua_State *L) { +static int Lget_nameservers(lua_State* L) { char stack_buffer[1024]; // stack allocated buffer IP4_ARRAY* ips = (IP4_ARRAY*) stack_buffer; DWORD len = sizeof(stack_buffer); DNS_STATUS status; status = DnsQueryConfig(DnsConfigDnsServerList, FALSE, NULL, NULL, ips, &len); - if (status == 0) { + + if(status == 0) { DWORD i; lua_createtable(L, ips->AddrCount, 0); - for (i = 0; i < ips->AddrCount; i++) { + + for(i = 0; i < ips->AddrCount; i++) { DWORD ip = ips->AddrArray[i]; char ip_str[16] = ""; sprintf_s(ip_str, sizeof(ip_str), "%d.%d.%d.%d", (ip >> 0) & 255, (ip >> 8) & 255, (ip >> 16) & 255, (ip >> 24) & 255); lua_pushstring(L, ip_str); - lua_rawseti(L, -2, i+1); + lua_rawseti(L, -2, i + 1); } + return 1; } else { lua_pushnil(L); @@ -48,43 +51,58 @@ static int Lget_nameservers(lua_State *L) { } } -static int lerror(lua_State *L, char* string) { +static int lerror(lua_State* L, char* string) { lua_pushnil(L); lua_pushfstring(L, "%s: %d", string, GetLastError()); return 2; } -static int Lget_consolecolor(lua_State *L) { +static int Lget_consolecolor(lua_State* L) { HWND console = GetStdHandle(STD_OUTPUT_HANDLE); - WORD color; DWORD read_len; - + WORD color; + DWORD read_len; + CONSOLE_SCREEN_BUFFER_INFO info; - - if (console == INVALID_HANDLE_VALUE) return lerror(L, "GetStdHandle"); - if (!GetConsoleScreenBufferInfo(console, &info)) return lerror(L, "GetConsoleScreenBufferInfo"); - if (!ReadConsoleOutputAttribute(console, &color, 1, info.dwCursorPosition, &read_len)) return lerror(L, "ReadConsoleOutputAttribute"); + + if(console == INVALID_HANDLE_VALUE) { + return lerror(L, "GetStdHandle"); + } + + if(!GetConsoleScreenBufferInfo(console, &info)) { + return lerror(L, "GetConsoleScreenBufferInfo"); + } + + if(!ReadConsoleOutputAttribute(console, &color, 1, info.dwCursorPosition, &read_len)) { + return lerror(L, "ReadConsoleOutputAttribute"); + } lua_pushnumber(L, color); return 1; } -static int Lset_consolecolor(lua_State *L) { +static int Lset_consolecolor(lua_State* L) { int color = luaL_checkint(L, 1); HWND console = GetStdHandle(STD_OUTPUT_HANDLE); - if (console == INVALID_HANDLE_VALUE) return lerror(L, "GetStdHandle"); - if (!SetConsoleTextAttribute(console, color)) return lerror(L, "SetConsoleTextAttribute"); + + if(console == INVALID_HANDLE_VALUE) { + return lerror(L, "GetStdHandle"); + } + + if(!SetConsoleTextAttribute(console, color)) { + return lerror(L, "SetConsoleTextAttribute"); + } + lua_pushboolean(L, 1); return 1; } -static const luaL_Reg Reg[] = -{ +static const luaL_Reg Reg[] = { { "get_nameservers", Lget_nameservers }, { "get_consolecolor", Lget_consolecolor }, { "set_consolecolor", Lset_consolecolor }, { NULL, NULL } }; -LUALIB_API int luaopen_util_windows(lua_State *L) { +LUALIB_API int luaopen_util_windows(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, Reg); lua_pushliteral(L, "-3.14"); |