wined3d: Remove stateblock handling from wined3d_device_set_compute_shader().
[wine.git] / programs / hostname / hostname.c
blobe3abc1684c80402036f9bb612052ae47dd9e22df
1 /*
2 * Hostname display utility
4 * Copyright 2008 Andrew Riedi
5 * Copyright 2010-2011 Andrew Nguyen
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <wincon.h>
26 #include <winnls.h>
27 #include <winuser.h>
29 #include <wine/unicode.h>
31 #include "hostname.h"
33 static int hostname_vprintfW(const WCHAR *msg, va_list va_args)
35 int wlen;
36 DWORD count, ret;
37 WCHAR msg_buffer[8192];
39 wlen = vsprintfW(msg_buffer, msg, va_args);
41 ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
42 if (!ret)
44 DWORD len;
45 char *msgA;
47 /* On Windows WriteConsoleW() fails if the output is redirected. So fall
48 * back to WriteFile(), assuming the console encoding is still the right
49 * one in that case.
51 len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
52 NULL, 0, NULL, NULL);
53 msgA = HeapAlloc(GetProcessHeap(), 0, len);
54 if (!msgA)
55 return 0;
57 WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
58 NULL, NULL);
59 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
60 HeapFree(GetProcessHeap(), 0, msgA);
63 return count;
66 static int hostname_printfW(const WCHAR *msg, ...)
68 va_list va_args;
69 int len;
71 va_start(va_args, msg);
72 len = hostname_vprintfW(msg, va_args);
73 va_end(va_args);
75 return len;
78 static int hostname_message_printfW(int msg, ...)
80 va_list va_args;
81 WCHAR msg_buffer[8192];
82 int len;
84 LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer));
86 va_start(va_args, msg);
87 len = hostname_vprintfW(msg_buffer, va_args);
88 va_end(va_args);
90 return len;
93 static int hostname_message(int msg)
95 static const WCHAR formatW[] = {'%','s',0};
96 WCHAR msg_buffer[8192];
98 LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer));
100 return hostname_printfW(formatW, msg_buffer);
103 static int display_computer_name(void)
105 static const WCHAR fmtW[] = {'%','s','\r','\n',0};
107 WCHAR name[MAX_COMPUTERNAME_LENGTH + 1];
108 DWORD size = ARRAY_SIZE(name);
109 BOOL ret;
111 ret = GetComputerNameW(name, &size);
112 if (!ret)
114 hostname_message_printfW(STRING_CANNOT_GET_HOSTNAME, GetLastError());
115 return 1;
118 hostname_printfW(fmtW, name);
119 return 0;
122 int wmain(int argc, WCHAR *argv[])
124 if (argc > 1)
126 static const WCHAR slashHelpW[] = {'/','?',0};
128 unsigned int i;
130 if (!strncmpW(argv[1], slashHelpW, ARRAY_SIZE(slashHelpW) - 1))
132 hostname_message(STRING_USAGE);
133 return 1;
136 for (i = 1; i < argc; i++)
138 if (argv[i][0] == '-')
140 switch (argv[i][1])
142 case 's':
143 /* Ignore the option and continue processing. */
144 break;
145 case '?':
146 hostname_message(STRING_USAGE);
147 return 1;
148 default:
149 hostname_message_printfW(STRING_INVALID_OPTION, argv[i][1]);
150 hostname_message(STRING_USAGE);
151 return 1;
154 else
156 hostname_message(STRING_CANNOT_SET_HOSTNAME);
157 hostname_message(STRING_USAGE);
158 return 1;
163 return display_computer_name();