2 * Translate between Wine and Unix paths
4 * Copyright 2002 Mike Wetherell
5 * Copyright 2005 Dmitry Timoshkov
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/debug.h"
30 #define VERSION "0.1 (" PACKAGE_STRING ")"
38 static const char progname[] = "winepath";
40 /* Wine specific functions */
41 typedef LPSTR (*wine_get_unix_file_name_t) ( LPCWSTR dos );
45 static int option(int shortopt, const WCHAR *longopt)
47 static const char helpmsg[] =
48 "Convert PATH(s) to Unix or Windows long or short paths.\n"
50 " -u, --unix output Unix format\n"
51 " -l, --long output Windows long format\n"
52 " -s, --short output Windows short format \n"
53 " -h, --help output this help message and exit\n"
54 " -v, --version output version information and exit\n"
56 "The input paths can be in any format. If more than one option is given\n"
57 "then the input paths are output in all formats specified, in the order\n"
58 "Unix, long, short. If no option is given the default is Unix format.\n";
62 printf("Usage: %s [OPTION] [PATH]...\n", progname);
66 printf("%s version " VERSION "\n", progname);
76 fprintf(stderr, "%s: invalid option ", progname);
78 fprintf(stderr, "%s\n", wine_dbgstr_w(longopt));
80 fprintf(stderr, "'-%c'\n", shortopt);
81 fprintf(stderr, "Try '%s --help' for help\n", progname);
86 * Parse command line options
88 static int parse_options(const WCHAR *argv[])
90 static const WCHAR longW[] = { 'l','o','n','g',0 };
91 static const WCHAR shortW[] = { 's','h','o','r','t',0 };
92 static const WCHAR unixW[] = { 'u','n','i','x',0 };
93 static const WCHAR helpW[] = { 'h','e','l','p',0 };
94 static const WCHAR versionW[] = { 'v','e','r','s','i','o','n',0 };
95 static const WCHAR nullW[] = { 0 };
96 static const WCHAR *longopts[] = { longW, shortW, unixW, helpW, versionW, nullW };
97 int outputformats = 0;
101 for (i = 1; argv[i] && !done; )
103 if (argv[i][0] != '-') {
109 if (argv[i][1] == '-') {
110 if (argv[i][2] == 0) {
111 /* '--' end of options */
115 for (j = 0; longopts[j][0]; j++)
116 if (!lstrcmpiW(argv[i]+2, longopts[j]))
118 outputformats |= option(longopts[j][0], argv[i]);
122 for (j = 1; argv[i][j]; j++)
123 outputformats |= option(argv[i][j], NULL);
127 for (j = i + 1; argv[j - 1]; j++)
128 argv[j - 1] = argv[j];
131 return outputformats;
137 int wmain(int argc, const WCHAR *argv[])
139 wine_get_unix_file_name_t wine_get_unix_file_name_ptr = NULL;
140 WCHAR dos_pathW[MAX_PATH];
145 outputformats = parse_options(argv);
146 if (outputformats == 0)
147 outputformats = UNIXFORMAT;
149 if (outputformats & UNIXFORMAT) {
150 wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
151 GetProcAddress(GetModuleHandle("KERNEL32"),
152 "wine_get_unix_file_name");
153 if (wine_get_unix_file_name_ptr == NULL) {
154 fprintf(stderr, "%s: cannot get the address of "
155 "'wine_get_unix_file_name'\n", progname);
160 for (i = 1; argv[i]; i++)
163 if (outputformats & LONGFORMAT) {
164 if (GetFullPathNameW(argv[i], MAX_PATH, dos_pathW, NULL))
165 WideCharToMultiByte(CP_UNIXCP, 0, dos_pathW, -1, path, MAX_PATH, NULL, NULL);
166 printf("%s\n", path);
168 if (outputformats & SHORTFORMAT) {
169 if (GetShortPathNameW(argv[i], dos_pathW, MAX_PATH))
170 WideCharToMultiByte(CP_UNIXCP, 0, dos_pathW, -1, path, MAX_PATH, NULL, NULL);
171 printf("%s\n", path);
173 if (outputformats & UNIXFORMAT) {
176 if ((unix_name = wine_get_unix_file_name_ptr(argv[i])))
178 printf("%s\n", unix_name);
179 HeapFree( GetProcessHeap(), 0, unix_name );