From de239dc852c8df5914abe974eac202d60b83611d Mon Sep 17 00:00:00 2001 From: Andrew Nguyen Date: Mon, 16 Aug 2010 02:54:10 -0500 Subject: [PATCH] ipconfig: Implement basic command-line parsing. --- programs/ipconfig/{ipconfig.c => En.rc} | 13 +++-- programs/ipconfig/Makefile.in | 3 ++ programs/ipconfig/ipconfig.c | 76 +++++++++++++++++++++++++++- programs/ipconfig/{ipconfig.c => ipconfig.h} | 16 ++---- 4 files changed, 89 insertions(+), 19 deletions(-) copy programs/ipconfig/{ipconfig.c => En.rc} (76%) copy programs/ipconfig/{ipconfig.c => ipconfig.h} (76%) diff --git a/programs/ipconfig/ipconfig.c b/programs/ipconfig/En.rc similarity index 76% copy from programs/ipconfig/ipconfig.c copy to programs/ipconfig/En.rc index fc5d95c1b91..4635ff6bd4f 100644 --- a/programs/ipconfig/ipconfig.c +++ b/programs/ipconfig/En.rc @@ -1,5 +1,6 @@ /* * IP configuration utility + * English language support * * Copyright 2010 Andrew Nguyen * @@ -18,14 +19,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include -#include +#include "ipconfig.h" -WINE_DEFAULT_DEBUG_CHANNEL(ipconfig); +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT -int wmain(int argc, WCHAR *argv[]) +STRINGTABLE { - WINE_FIXME("ipconfig.exe is not implemented\n"); - return 0; + STRING_USAGE, "Usage: ipconfig [ /? | /all ]\n" + STRING_INVALID_CMDLINE, "Error: Unknown or invalid command line parameters specified\n" } diff --git a/programs/ipconfig/Makefile.in b/programs/ipconfig/Makefile.in index 0cd8ce65c9b..18a7714e366 100644 --- a/programs/ipconfig/Makefile.in +++ b/programs/ipconfig/Makefile.in @@ -5,7 +5,10 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = ipconfig.exe APPMODE = -mconsole -municode +IMPORTS = user32 C_SRCS = ipconfig.c +RC_SRCS = En.rc + @MAKE_PROG_RULES@ diff --git a/programs/ipconfig/ipconfig.c b/programs/ipconfig/ipconfig.c index fc5d95c1b91..7c988bba818 100644 --- a/programs/ipconfig/ipconfig.c +++ b/programs/ipconfig/ipconfig.c @@ -1,6 +1,7 @@ /* * IP configuration utility * + * Copyright 2008 Andrew Riedi * Copyright 2010 Andrew Nguyen * * This library is free software; you can redistribute it and/or @@ -22,10 +23,83 @@ #include #include +#include "ipconfig.h" + WINE_DEFAULT_DEBUG_CHANNEL(ipconfig); +static int ipconfig_printfW(const WCHAR *msg, ...) +{ + va_list va_args; + int wlen; + DWORD count, ret; + WCHAR msg_buffer[8192]; + + va_start(va_args, msg); + wlen = vsprintfW(msg_buffer, msg, va_args); + va_end(va_args); + + ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL); + if (!ret) + { + DWORD len; + char *msgA; + + len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, + NULL, 0, NULL, NULL); + msgA = HeapAlloc(GetProcessHeap(), 0, len); + if (!msgA) + return 0; + + WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len, + NULL, NULL); + WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE); + HeapFree(GetProcessHeap(), 0, msgA); + } + + return count; +} + +static int ipconfig_message(int msg) +{ + static const WCHAR formatW[] = {'%','s',0}; + WCHAR msg_buffer[8192]; + + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, + sizeof(msg_buffer)/sizeof(WCHAR)); + return ipconfig_printfW(formatW, msg_buffer); +} + int wmain(int argc, WCHAR *argv[]) { - WINE_FIXME("ipconfig.exe is not implemented\n"); + static const WCHAR slashHelp[] = {'/','?',0}; + static const WCHAR slashAll[] = {'/','a','l','l',0}; + + if (argc > 1) + { + if (!strcmpW(slashHelp, argv[1])) + { + ipconfig_message(STRING_USAGE); + return 1; + } + else if (!strcmpiW(slashAll, argv[1])) + { + if (argv[2]) + { + ipconfig_message(STRING_INVALID_CMDLINE); + ipconfig_message(STRING_USAGE); + return 1; + } + + WINE_FIXME("/all option is not currently handled\n"); + } + else + { + ipconfig_message(STRING_INVALID_CMDLINE); + ipconfig_message(STRING_USAGE); + return 1; + } + } + + WINE_FIXME("Network interface output is not currently implemented\n"); return 0; } diff --git a/programs/ipconfig/ipconfig.c b/programs/ipconfig/ipconfig.h similarity index 76% copy from programs/ipconfig/ipconfig.c copy to programs/ipconfig/ipconfig.h index fc5d95c1b91..f02792d61f9 100644 --- a/programs/ipconfig/ipconfig.c +++ b/programs/ipconfig/ipconfig.h @@ -1,5 +1,5 @@ /* - * IP configuration utility + * IP configuration utility private definitions * * Copyright 2010 Andrew Nguyen * @@ -18,14 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include -#include +#include -WINE_DEFAULT_DEBUG_CHANNEL(ipconfig); - -int wmain(int argc, WCHAR *argv[]) -{ - WINE_FIXME("ipconfig.exe is not implemented\n"); - return 0; -} +/* Translation IDs. */ +#define STRING_USAGE 101 +#define STRING_INVALID_CMDLINE 102 -- 2.11.4.GIT