From d3ab0a3205f5cd1884a13b91de78dab20a53d02c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Fri, 1 Apr 2016 01:29:51 +0200
Subject: [PATCH 1/2] fsutil: make usage and unsupported cmd messages
 localizable

split the original patch

Signed-off-by: Vijay Kiran Kamuju <infyquest@gmail.com>
---
 programs/fsutil/Makefile.in |  3 ++
 programs/fsutil/fsutil.rc   | 31 ++++++++++++++++
 programs/fsutil/main.c      | 74 ++++++++++++++++++++++++++++++++++---
 programs/fsutil/resources.h | 22 +++++++++++
 4 files changed, 124 insertions(+), 6 deletions(-)
 create mode 100644 programs/fsutil/fsutil.rc
 create mode 100644 programs/fsutil/resources.h

diff --git a/programs/fsutil/Makefile.in b/programs/fsutil/Makefile.in
index 64307e83ac..e10bd433ba 100644
--- a/programs/fsutil/Makefile.in
+++ b/programs/fsutil/Makefile.in
@@ -1,6 +1,9 @@
 MODULE    = fsutil.exe
 
 EXTRADLLFLAGS = -mconsole -municode -mno-cygwin
+IMPORTS   = user32
 
 C_SRCS = \
 	main.c
+
+RC_SRCS = fsutil.rc
diff --git a/programs/fsutil/fsutil.rc b/programs/fsutil/fsutil.rc
new file mode 100644
index 0000000000..0d4ee451ea
--- /dev/null
+++ b/programs/fsutil/fsutil.rc
@@ -0,0 +1,31 @@
+/*
+ * FSUTIL.EXE - Wine-compatible fsutil program
+ *
+ * Copyright 2016 Michael Müller
+ *
+ * This library 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.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "resources.h"
+
+#pragma makedep po
+
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+
+STRINGTABLE
+{
+    STRING_USAGE, "---- Commands Supported ----\n\nhardlink      Hardlink management\n\n"
+    STRING_UNSUPPORTED_CMD, "%1 is an unsupported command\n"
+}
diff --git a/programs/fsutil/main.c b/programs/fsutil/main.c
index eb4e341297..aeadb4f2f8 100644
--- a/programs/fsutil/main.c
+++ b/programs/fsutil/main.c
@@ -1,5 +1,6 @@
 /*
  * Copyright 2016 Austin English
+ * Copyright 2016 Michael Müller
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,18 +17,79 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "wine/debug.h"
+#include <windows.h>
+#include <wine/debug.h>
+
+#include "resources.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(fsutil);
 
+static void output_write(const WCHAR *str, DWORD wlen)
+{
+    DWORD count, ret;
+
+    ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL);
+    if (!ret)
+    {
+        DWORD len;
+        char  *msgA;
+
+        /* On Windows WriteConsoleW() fails if the output is redirected. So fall
+         * back to WriteFile(), assuming the console encoding is still the right
+         * one in that case.
+         */
+        len = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, NULL, 0, NULL, NULL);
+        msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
+        if (!msgA) return;
+
+        WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL);
+        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
+        HeapFree(GetProcessHeap(), 0, msgA);
+    }
+}
+
+static int output_vprintf(const WCHAR* fmt, __ms_va_list va_args)
+{
+    WCHAR str[8192];
+    int len;
+
+    SetLastError(NO_ERROR);
+    len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, fmt, 0, 0, str,
+                         sizeof(str)/sizeof(*str), &va_args);
+    if (len == 0 && GetLastError() != NO_ERROR)
+        WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt));
+    else
+        output_write(str, len);
+    return 0;
+}
+
+static int WINAPIV output_string(int msg, ...)
+{
+    WCHAR fmt[8192];
+    __ms_va_list arguments;
+
+    LoadStringW(GetModuleHandleW(NULL), msg, fmt, sizeof(fmt)/sizeof(fmt[0]));
+    __ms_va_start(arguments, msg);
+    output_vprintf(fmt, arguments);
+    __ms_va_end(arguments);
+    return 0;
+}
+
 int __cdecl wmain(int argc, WCHAR *argv[])
 {
-    int i;
+    int i, ret = 0;
 
-    WINE_FIXME("stub:");
     for (i = 0; i < argc; i++)
-        WINE_FIXME(" %s", wine_dbgstr_w(argv[i]));
-    WINE_FIXME("\n");
+        WINE_TRACE(" %s", wine_dbgstr_w(argv[i]));
+    WINE_TRACE("\n");
 
-    return 0;
+    if (argc > 1)
+    {
+        FIXME("unsupported command %s\n", debugstr_w(argv[1]));
+        output_string(STRING_UNSUPPORTED_CMD, argv[1]);
+        ret = 1;
+    }
+
+    output_string(STRING_USAGE);
+    return ret;
 }
diff --git a/programs/fsutil/resources.h b/programs/fsutil/resources.h
new file mode 100644
index 0000000000..79677b1fb8
--- /dev/null
+++ b/programs/fsutil/resources.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016 Michael Müller
+ *
+ * This library 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.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <windef.h>
+
+#define STRING_USAGE                    101
+#define STRING_UNSUPPORTED_CMD          102
-- 
2.26.2

