Fix a few region debug messages.
[wine.git] / programs / winepath / winepath.c
bloba49f38c012b71ae80037ab21a61dcf9324c43d49
1 /*
2 * Translate between Wine and Unix paths
4 * Copyright 2002 Mike Wetherell
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <windows.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #define VERSION "0.1 (" PACKAGE_STRING ")"
29 enum {
30 SHORTFORMAT = 1,
31 LONGFORMAT = 2,
32 UNIXFORMAT = 4
35 static char *progname;
37 /* Wine specific functions */
38 extern BOOL process_init(char *argv[]);
39 typedef LPSTR (*wine_get_unix_file_name_t) ( LPCWSTR dos );
41 * handle an option
43 int option(int shortopt, char *longopt)
45 const char *helpmsg =
46 "Convert PATH(s) to Unix or Windows long or short paths.\n"
47 "\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"
53 "\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";
58 switch (shortopt) {
59 case 'h':
60 printf("Usage: %s [OPTION] [PATH]...\n", progname);
61 printf(helpmsg);
62 exit(0);
63 case 'v':
64 printf("%s version " VERSION "\n", progname);
65 exit(0);
66 case 'l':
67 return LONGFORMAT;
68 case 's':
69 return SHORTFORMAT;
70 case 'u':
71 return UNIXFORMAT;
74 fprintf(stderr, "%s: invalid option ", progname);
75 if (longopt)
76 fprintf(stderr, "'%s'\n", longopt);
77 else
78 fprintf(stderr, "'-%c'\n", shortopt);
79 fprintf(stderr, "Try '%s --help' for help\n", progname);
80 exit(2);
84 * Parse command line options
86 int parse_options(char *argv[])
88 int outputformats = 0;
89 int done = 0;
90 char *longopts[] = { "long", "short", "unix", "help", "version", "" };
91 int i, j;
93 for (i = 1; argv[i] && !done; )
95 if (argv[i][0] != '-') {
96 /* not an option */
97 i++;
98 continue;
101 if (argv[i][1] == '-') {
102 if (argv[i][2] == 0) {
103 /* '--' end of options */
104 done = 1;
105 } else {
106 /* long option */
107 for (j = 0; longopts[j][0]; j++)
108 if (strcmp(argv[i]+2, longopts[j]) == 0)
109 break;
110 outputformats |= option(longopts[j][0], argv[i]);
112 } else {
113 /* short options */
114 for (j = 1; argv[i][j]; j++)
115 outputformats |= option(argv[i][j], NULL);
118 /* remove option */
119 for (j = i + 1; argv[j - 1]; j++)
120 argv[j - 1] = argv[j];
123 return outputformats;
127 * Main function
129 int main(int argc, char *argv[])
131 wine_get_unix_file_name_t wine_get_unix_file_name_ptr = NULL;
132 static char path[MAX_PATH];
133 int outputformats;
134 int i;
136 progname = argv[0];
137 outputformats = parse_options(argv);
138 if (outputformats == 0)
139 outputformats = UNIXFORMAT;
141 if (outputformats & UNIXFORMAT) {
142 wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
143 GetProcAddress(GetModuleHandle("KERNEL32"),
144 "wine_get_unix_file_name");
145 if (wine_get_unix_file_name_ptr == NULL) {
146 fprintf(stderr, "%s: cannot get the address of "
147 "'wine_get_unix_file_name'\n", progname);
148 exit(3);
152 for (i = 1; argv[i]; i++)
154 *path='\0';
155 if (outputformats & LONGFORMAT) {
156 GetFullPathNameA(argv[i], sizeof(path), path, NULL);
157 printf("%s\n", path);
159 if (outputformats & SHORTFORMAT) {
160 GetShortPathNameA(argv[i], path, sizeof(path));
161 printf("%s\n", path);
163 if (outputformats & UNIXFORMAT) {
164 WCHAR dosW[MAX_PATH];
165 char *unix_name;
167 MultiByteToWideChar(CP_ACP, 0, argv[i], -1, dosW, MAX_PATH);
168 if ((unix_name = wine_get_unix_file_name_ptr(dosW)))
170 printf("%s\n", unix_name);
171 HeapFree( GetProcessHeap(), 0, unix_name );
173 else printf( "\n" );
177 exit(0);