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"
36 static const char progname[] = "winepath";
38 /* Wine specific functions */
39 typedef LPSTR (*wine_get_unix_file_name_t) ( LPCWSTR dos );
43 static int option(int shortopt, const WCHAR *longopt)
45 static const char helpmsg[] =
46 "Convert PATH(s) to Unix or Windows long or short paths.\n"
48 " -u, --unix output Unix format\n"
49 " -l, --long output Windows long format\n"
50 " -s, --short output Windows short format \n"
51 " -h, --help output this help message and exit\n"
52 " -v, --version output version information and exit\n"
54 "The input paths can be in any format. If more than one option is given\n"
55 "then the input paths are output in all formats specified, in the order\n"
56 "Unix, long, short. If no option is given the default is Unix format.\n";
60 printf("Usage: %s [OPTION] [PATH]...\n", progname);
64 printf("%s version " PACKAGE_VERSION "\n", progname);
74 fprintf(stderr, "%s: invalid option ", progname);
76 fprintf(stderr, "%s\n", wine_dbgstr_w(longopt));
78 fprintf(stderr, "'-%c'\n", shortopt);
79 fprintf(stderr, "Try '%s --help' for help\n", progname);
84 * Parse command line options
86 static int parse_options(const WCHAR *argv[])
88 static const WCHAR longW[] = { 'l','o','n','g',0 };
89 static const WCHAR shortW[] = { 's','h','o','r','t',0 };
90 static const WCHAR unixW[] = { 'u','n','i','x',0 };
91 static const WCHAR helpW[] = { 'h','e','l','p',0 };
92 static const WCHAR versionW[] = { 'v','e','r','s','i','o','n',0 };
93 static const WCHAR nullW[] = { 0 };
94 static const WCHAR *longopts[] = { longW, shortW, unixW, helpW, versionW, nullW };
95 int outputformats = 0;
99 for (i = 1; argv[i] && !done; )
101 if (argv[i][0] != '-') {
107 if (argv[i][1] == '-') {
108 if (argv[i][2] == 0) {
109 /* '--' end of options */
113 for (j = 0; longopts[j][0]; j++)
114 if (!lstrcmpiW(argv[i]+2, longopts[j]))
116 outputformats |= option(longopts[j][0], argv[i]);
120 for (j = 1; argv[i][j]; j++)
121 outputformats |= option(argv[i][j], NULL);
125 for (j = i + 1; argv[j - 1]; j++)
126 argv[j - 1] = argv[j];
129 return outputformats;
135 int wmain(int argc, const WCHAR *argv[])
137 wine_get_unix_file_name_t wine_get_unix_file_name_ptr = NULL;
138 WCHAR dos_pathW[MAX_PATH];
143 outputformats = parse_options(argv);
144 if (outputformats == 0)
145 outputformats = UNIXFORMAT;
147 if (outputformats & UNIXFORMAT) {
148 wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
149 GetProcAddress(GetModuleHandle("KERNEL32"),
150 "wine_get_unix_file_name");
151 if (wine_get_unix_file_name_ptr == NULL) {
152 fprintf(stderr, "%s: cannot get the address of "
153 "'wine_get_unix_file_name'\n", progname);
158 for (i = 1; argv[i]; i++)
161 if (outputformats & LONGFORMAT) {
162 if (GetFullPathNameW(argv[i], MAX_PATH, dos_pathW, NULL))
163 WideCharToMultiByte(CP_UNIXCP, 0, dos_pathW, -1, path, MAX_PATH, NULL, NULL);
164 printf("%s\n", path);
166 if (outputformats & SHORTFORMAT) {
167 if (GetShortPathNameW(argv[i], dos_pathW, MAX_PATH))
168 WideCharToMultiByte(CP_UNIXCP, 0, dos_pathW, -1, path, MAX_PATH, NULL, NULL);
169 printf("%s\n", path);
171 if (outputformats & UNIXFORMAT) {
174 if ((unix_name = wine_get_unix_file_name_ptr(argv[i])))
176 printf("%s\n", unix_name);
177 HeapFree( GetProcessHeap(), 0, unix_name );