C/L utility to translate unix and dos paths

Michael Wetherell mike.wetherell at ntlworld.com
Wed Apr 24 19:20:41 CDT 2002


Posting again, this time hopefully without broken long lines...

ChangeLog:
        * configure, configure.ac, Makefile.in, schedule/process.c
          programs/Makefile.in, programs/winepath/.cvsignore
          programs/winepath/Makefile.in, programs/winepath/winepath.c
        Mike Wetherell <mike.wetherell at ntlworld.com>
        Utility to convert between Unix and Windows paths at the
        command line.

Index: configure
===================================================================
RCS file: /home/wine/wine/configure,v
retrieving revision 1.277
diff -u -r1.277 configure
--- configure	20 Apr 2002 21:00:42 -0000	1.277
+++ configure	23 Apr 2002 00:34:30 -0000
@@ -12586,7 +12586,7 @@
 MAKE_PROG_RULES=programs/Makeprog.rules
 
 
-ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile controls/Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msg711/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile files/Makefile graphics/Makefile graphics/x11drv/Makefile if1632/Makefile include/Makefile library/Makefile libtest/Makefile loader/Makefile loader/ne/Makefile memory/Makefile misc/Makefile miscemu/Makefile msdos/Makefile objects/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winemine/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile relay32/Makefile scheduler/Makefile server/Makefile tools/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile win32/Makefile windows/Makefile windows/x11drv/Makefile"
+ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile controls/Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msg711/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile files/Makefile graphics/Makefile graphics/x11drv/Makefile if1632/Makefile include/Makefile library/Makefile libtest/Makefile loader/Makefile loader/ne/Makefile memory/Makefile misc/Makefile miscemu/Makefile msdos/Makefile objects/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile relay32/Makefile scheduler/Makefile server/Makefile tools/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile win32/Makefile windows/Makefile windows/x11drv/Makefile"
 
 
 cat >confcache <<\_ACEOF
@@ -13189,6 +13189,7 @@
   "programs/wcmd/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/wcmd/Makefile" ;;
   "programs/wineconsole/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/wineconsole/Makefile" ;;
   "programs/winemine/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/winemine/Makefile" ;;
+  "programs/winepath/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/winepath/Makefile" ;;
   "programs/winetest/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/winetest/Makefile" ;;
   "programs/winhelp/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/winhelp/Makefile" ;;
   "programs/winver/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/winver/Makefile" ;;
Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.20
diff -u -r1.20 configure.ac
--- configure.ac	20 Apr 2002 21:00:42 -0000	1.20
+++ configure.ac	22 Apr 2002 22:50:08 -0000
@@ -1406,6 +1406,7 @@
 programs/wcmd/Makefile
 programs/wineconsole/Makefile
 programs/winemine/Makefile
+programs/winepath/Makefile
 programs/winetest/Makefile
 programs/winhelp/Makefile
 programs/winver/Makefile
Index: Makefile.in
===================================================================
RCS file: /home/wine/wine/Makefile.in,v
retrieving revision 1.115
diff -u -r1.115 Makefile.in
--- Makefile.in	17 Apr 2002 16:51:47 -0000	1.115
+++ Makefile.in	22 Apr 2002 22:50:09 -0000
@@ -30,7 +30,8 @@
 # Programs that link with libwine
 LIBPROGRAMS = \
 	debugger/winedbg \
-	programs/wineconsole/wineconsole
+	programs/wineconsole/wineconsole \
+	programs/winepath/winepath
 
 # Libraries (not dlls) to build
 LIBRARIES = \
@@ -66,6 +67,7 @@
 	library \
 	ole \
 	programs/wineconsole \
+	programs/winepath \
 	server \
 	tools \
 	tsx11 \
Index: scheduler/process.c
===================================================================
RCS file: /home/wine/wine/scheduler/process.c,v
retrieving revision 1.177
diff -u -r1.177 process.c
--- scheduler/process.c	15 Apr 2002 15:38:10 -0000	1.177
+++ scheduler/process.c	22 Apr 2002 22:50:18 -0000
@@ -241,7 +241,7 @@
  *
  * Main process initialisation code
  */
-static BOOL process_init( char *argv[] )
+BOOL process_init( char *argv[] )
 {
     BOOL ret;
     size_t info_size = 0;
Index: programs/Makefile.in
===================================================================
RCS file: /home/wine/wine/programs/Makefile.in,v
retrieving revision 1.14
diff -u -r1.14 Makefile.in
--- programs/Makefile.in	11 Apr 2002 23:58:40 -0000	1.14
+++ programs/Makefile.in	22 Apr 2002 22:50:19 -0000
@@ -20,6 +20,7 @@
 	wcmd \
 	wineconsole \
 	winemine \
+	winepath \
 	winetest \
 	winhelp \
 	winver
diff -Nu programs/winepath/.cvsignore programs/winepath/.cvsignore
--- programs/winepath/.cvsignore	Thu Jan  1 01:00:00 1970
+++ programs/winepath/.cvsignore	Tue Apr 23 00:15:47 2002
@@ -0,0 +1,2 @@
+Makefile
+winepath
diff -Nu programs/winepath/Makefile.in programs/winepath/Makefile.in
--- programs/winepath/Makefile.in	Thu Jan  1 01:00:00 1970
+++ programs/winepath/Makefile.in	Tue Apr 23 00:15:47 2002
@@ -0,0 +1,27 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+
+PROGRAMS  = winepath
+MODULE    = none
+IMPORTS   = ntdll.dll
+
+C_SRCS = \
+	winepath.c
+
+all: $(PROGRAMS)
+
+ at MAKE_RULES@
+
+winepath: $(OBJS)
+	$(CC) $(CFLAGS) -o winepath $(OBJS) -L$(DLLDIR) $(IMPORTS:%=-l%) $(LIBWINE) $(LIBUNICODE) $(LDFLAGS)
+
+install:: $(PROGRAMS)
+	[ -d $(bindir) ] || $(MKDIR) $(bindir)
+	$(INSTALL_PROGRAM) winepath $(bindir)/winepath
+
+uninstall::
+	$(RM) $(bindir)/winepath
+
+### Dependencies:
diff -Nu programs/winepath/winepath.c programs/winepath/winepath.c
--- programs/winepath/winepath.c	Thu Jan  1 01:00:00 1970
+++ programs/winepath/winepath.c	Tue Apr 23 00:17:07 2002
@@ -0,0 +1,184 @@
+/*
+ * Translate between Wine and Unix paths
+ *
+ * Copyright 2002 Mike Wetherell
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64) || defined(WINELIB)
+#define WINDOWS 1
+#endif
+
+#define VERSION "0.1 (" PACKAGE_STRING ")"
+
+enum { 
+    SHORTFORMAT = 1,
+    LONGFORMAT  = 2,
+    UNIXFORMAT  = 4
+};
+
+static char *progname;
+
+/* Wine specific functions */
+extern BOOL process_init(char *argv[]);
+typedef BOOL WINAPI wine_get_unix_file_name_t ( LPCSTR dos,
+                                                LPSTR buffer,
+                                                DWORD len );
+/*
+ * handle an option
+ */
+int option(int shortopt, char *longopt)
+{
+    const char *helpmsg =
+    "Convert PATH(s) to Unix or Windows long or short paths.\n"
+    "\n"
+    "  -u, --unix    output Unix format\n"
+    "  -l, --long    output Windows long format\n"
+    "  -s, --short   output Windows short format \n"
+    "  -h, --help    output this help message and exit\n"
+    "  -v, --version output version information and exit\n"
+    "\n"
+    "The input paths can be in any format. If more than one option is given\n"
+    "then the input paths are ouput in all formats specified, in the order\n"
+    "Unix, long, short. If no option is given the default is Unix format.\n";
+
+    switch (shortopt) {
+        case 'h':
+            printf("Usage: %s [OPTION] [PATH]...\n", progname);
+            printf(helpmsg);
+            exit(0);
+        case 'v':
+            printf("%s version " VERSION "\n", progname);
+            exit(0);
+        case 'l':
+            return LONGFORMAT;
+        case 's':
+            return SHORTFORMAT;
+        case 'u':
+            return UNIXFORMAT;
+    } 
+
+    fprintf(stderr, "%s: invalid option ", progname);
+    if (longopt)
+        fprintf(stderr, "'%s'\n", longopt);
+    else
+        fprintf(stderr, "'-%c'\n", shortopt); 
+    fprintf(stderr, "Try '%s --help' for help\n", progname);
+    exit(2);
+}
+
+/*
+ * Parse command line options
+ */
+int parse_options(char *argv[])
+{
+    int outputformats = 0;
+    int done = 0;
+    char *longopts[] = { "long", "short", "unix", "help", "version", "" };
+    int i, j;
+
+    for (i = 1; argv[i] && !done; )
+    {
+        if (argv[i][0] != '-') {
+            /* not an option */
+            i++;
+            continue;
+        }
+
+        if (argv[i][1] == '-') {
+            if (argv[i][2] == 0) {
+                /* '--' end of options */
+                done = 1;
+            } else {
+                /* long option */
+                for (j = 0; longopts[j][0]; j++)
+                    if (strcmp(argv[i]+2, longopts[j]) == 0)
+                        break;
+                outputformats |= option(longopts[j][0], argv[i]);
+            }
+        } else {
+            /* short options */
+            for (j = 1; argv[i][j]; j++)
+                outputformats |= option(argv[i][j], NULL); 
+        }
+
+        /* remove option */
+        for (j = i + 1; argv[j - 1]; j++)
+            argv[j - 1] = argv[j];
+    }
+
+    return outputformats;
+}
+
+/*
+ * Main function
+ */
+int main(int argc, char *argv[])
+{
+#ifndef WINDOWS
+    char *noargs[2] = { argv[0], NULL };
+#endif
+    wine_get_unix_file_name_t *wine_get_unix_file_name_ptr;
+    static char path[MAX_PATH];
+    int outputformats;
+    int i;
+
+    progname = argv[0];
+    outputformats = parse_options(argv);
+    if (outputformats == 0)
+        outputformats = UNIXFORMAT;
+
+#ifndef WINDOWS
+    if (!process_init(noargs))
+        exit(1);
+    wine_get_unix_file_name_ptr = wine_get_unix_file_name;
+#else
+    if (outputformats & UNIXFORMAT) {
+        wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t*)
+            GetProcAddress(GetModuleHandle("KERNEL32"),
+                           "wine_get_unix_file_name");
+        if (wine_get_unix_file_name_ptr == NULL) {
+            fprintf(stderr, "%s: cannot get the address of "
+                            "'wine_get_unix_file_name'\n", progname);
+            exit(3);
+        }
+    }
+#endif
+
+    for (i = 1; argv[i]; i++)
+    {
+        if (outputformats & LONGFORMAT) {
+            GetLongPathNameA(argv[i], path, sizeof(path));
+            printf("%s\n", path);
+        }
+        if (outputformats & SHORTFORMAT) {
+            GetShortPathNameA(argv[i], path, sizeof(path));
+            printf("%s\n", path);
+        }
+        if (outputformats & UNIXFORMAT) {
+            wine_get_unix_file_name_ptr(argv[i], path, sizeof(path));
+            printf("%s\n", path);
+        }
+    }
+
+    exit(0);
+}



More information about the wine-patches mailing list