Commit 492f9c7c authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

Add a --windows option for converting a Unix path to a long Windows

path. Fix the description of --long and --short. They are only garanteed to work on Windows paths though they will often successfully convert Unix paths to Windows paths too.
parent 5131ba61
/* /*
* Translate between Wine and Unix paths * Translate between Windows and Unix paths formats
* *
* Copyright 2002 Mike Wetherell * Copyright 2002 Mike Wetherell
* Copyright 2005 Dmitry Timoshkov * Copyright 2005 Dmitry Timoshkov
* Copyright 2005 Francois Gouget
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -28,15 +29,14 @@ ...@@ -28,15 +29,14 @@
#include "wine/debug.h" #include "wine/debug.h"
enum { enum {
SHORTFORMAT = 1, SHORTFORMAT = 1,
LONGFORMAT = 2, LONGFORMAT = 2,
UNIXFORMAT = 4 UNIXFORMAT = 4,
WINDOWSFORMAT = 8
}; };
static const char progname[] = "winepath"; static const char progname[] = "winepath";
/* Wine specific functions */
typedef LPSTR (*wine_get_unix_file_name_t) ( LPCWSTR dos );
/* /*
* handle an option * handle an option
*/ */
...@@ -45,15 +45,16 @@ static int option(int shortopt, const WCHAR *longopt) ...@@ -45,15 +45,16 @@ static int option(int shortopt, const WCHAR *longopt)
static const char helpmsg[] = static const char helpmsg[] =
"Convert PATH(s) to Unix or Windows long or short paths.\n" "Convert PATH(s) to Unix or Windows long or short paths.\n"
"\n" "\n"
" -u, --unix output Unix format\n" " -u, --unix converts a Windows path to a Unix path\n"
" -l, --long output Windows long format\n" " -w, --windows converts a Unix path to a long Windows path\n"
" -s, --short output Windows short format \n" " -l, --long converts a short Windows path to the long format\n"
" -s, --short converts a long Windows path to the short format\n"
" -h, --help output this help message and exit\n" " -h, --help output this help message and exit\n"
" -v, --version output version information and exit\n" " -v, --version output version information and exit\n"
"\n" "\n"
"The input paths can be in any format. If more than one option is given\n" "If more than one option is given then the input paths are output in\n"
"then the input paths are output in all formats specified, in the order\n" "all formats specified, in the order long, short, Unix, Windows.\n"
"Unix, long, short. If no option is given the default is Unix format.\n"; "If no option is given the default is Unix format.\n";
switch (shortopt) { switch (shortopt) {
case 'h': case 'h':
...@@ -69,6 +70,8 @@ static int option(int shortopt, const WCHAR *longopt) ...@@ -69,6 +70,8 @@ static int option(int shortopt, const WCHAR *longopt)
return SHORTFORMAT; return SHORTFORMAT;
case 'u': case 'u':
return UNIXFORMAT; return UNIXFORMAT;
case 'w':
return WINDOWSFORMAT;
} }
fprintf(stderr, "%s: invalid option ", progname); fprintf(stderr, "%s: invalid option ", progname);
...@@ -88,10 +91,11 @@ static int parse_options(const WCHAR *argv[]) ...@@ -88,10 +91,11 @@ static int parse_options(const WCHAR *argv[])
static const WCHAR longW[] = { 'l','o','n','g',0 }; static const WCHAR longW[] = { 'l','o','n','g',0 };
static const WCHAR shortW[] = { 's','h','o','r','t',0 }; static const WCHAR shortW[] = { 's','h','o','r','t',0 };
static const WCHAR unixW[] = { 'u','n','i','x',0 }; static const WCHAR unixW[] = { 'u','n','i','x',0 };
static const WCHAR windowsW[] = { 'w','i','n','d','o','w','s',0 };
static const WCHAR helpW[] = { 'h','e','l','p',0 }; static const WCHAR helpW[] = { 'h','e','l','p',0 };
static const WCHAR versionW[] = { 'v','e','r','s','i','o','n',0 }; static const WCHAR versionW[] = { 'v','e','r','s','i','o','n',0 };
static const WCHAR nullW[] = { 0 }; static const WCHAR nullW[] = { 0 };
static const WCHAR *longopts[] = { longW, shortW, unixW, helpW, versionW, nullW }; static const WCHAR *longopts[] = { longW, shortW, unixW, windowsW, helpW, versionW, nullW };
int outputformats = 0; int outputformats = 0;
int done = 0; int done = 0;
int i, j; int i, j;
...@@ -134,7 +138,8 @@ static int parse_options(const WCHAR *argv[]) ...@@ -134,7 +138,8 @@ static int parse_options(const WCHAR *argv[])
*/ */
int wmain(int argc, const WCHAR *argv[]) int wmain(int argc, const WCHAR *argv[])
{ {
wine_get_unix_file_name_t wine_get_unix_file_name_ptr = NULL; LPSTR (*wine_get_unix_file_name_ptr)(LPCWSTR) = NULL;
LPWSTR (*wine_get_dos_file_name_ptr)(LPCSTR) = NULL;
WCHAR dos_pathW[MAX_PATH]; WCHAR dos_pathW[MAX_PATH];
char path[MAX_PATH]; char path[MAX_PATH];
int outputformats; int outputformats;
...@@ -145,7 +150,7 @@ int wmain(int argc, const WCHAR *argv[]) ...@@ -145,7 +150,7 @@ int wmain(int argc, const WCHAR *argv[])
outputformats = UNIXFORMAT; outputformats = UNIXFORMAT;
if (outputformats & UNIXFORMAT) { if (outputformats & UNIXFORMAT) {
wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t) wine_get_unix_file_name_ptr = (void*)
GetProcAddress(GetModuleHandle("KERNEL32"), GetProcAddress(GetModuleHandle("KERNEL32"),
"wine_get_unix_file_name"); "wine_get_unix_file_name");
if (wine_get_unix_file_name_ptr == NULL) { if (wine_get_unix_file_name_ptr == NULL) {
...@@ -155,6 +160,17 @@ int wmain(int argc, const WCHAR *argv[]) ...@@ -155,6 +160,17 @@ int wmain(int argc, const WCHAR *argv[])
} }
} }
if (outputformats & WINDOWSFORMAT) {
wine_get_dos_file_name_ptr = (void*)
GetProcAddress(GetModuleHandle("KERNEL32"),
"wine_get_dos_file_name");
if (wine_get_dos_file_name_ptr == NULL) {
fprintf(stderr, "%s: cannot get the address of "
"'wine_get_dos_file_name'\n", progname);
exit(3);
}
}
for (i = 1; argv[i]; i++) for (i = 1; argv[i]; i++)
{ {
*path='\0'; *path='\0';
...@@ -178,6 +194,24 @@ int wmain(int argc, const WCHAR *argv[]) ...@@ -178,6 +194,24 @@ int wmain(int argc, const WCHAR *argv[])
} }
else printf( "\n" ); else printf( "\n" );
} }
if (outputformats & WINDOWSFORMAT) {
WCHAR* windows_name;
char* unix_name;
DWORD size;
size=WideCharToMultiByte(CP_UNIXCP, 0, argv[i], -1, NULL, 0, NULL, NULL);
unix_name=HeapAlloc(GetProcessHeap(), 0, size);
WideCharToMultiByte(CP_UNIXCP, 0, argv[i], -1, unix_name, size, NULL, NULL);
if ((windows_name = wine_get_dos_file_name_ptr(unix_name)))
{
WideCharToMultiByte(CP_UNIXCP, 0, windows_name, -1, path, MAX_PATH, NULL, NULL);
printf("%s\n", path);
HeapFree( GetProcessHeap(), 0, windows_name );
}
else printf( "\n" );
HeapFree( GetProcessHeap(), 0, unix_name );
}
} }
exit(0); exit(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment