summaryrefslogtreecommitdiffstats
path: root/winsup/utils/cygpath.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/utils/cygpath.cc')
-rw-r--r--winsup/utils/cygpath.cc142
1 files changed, 116 insertions, 26 deletions
diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc
index dbaaae0d8..ff5824469 100644
--- a/winsup/utils/cygpath.cc
+++ b/winsup/utils/cygpath.cc
@@ -1,5 +1,5 @@
/* cygpath.cc -- convert pathnames between Windows and Unix format
- Copyright 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1998-2002 Red Hat, Inc.
This file is part of Cygwin.
@@ -7,6 +7,9 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
+#define NOCOMATTRIBUTE
+
+#include <shlobj.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -22,7 +25,7 @@ static char *prog_name;
static char *file_arg;
static char *close_arg;
static int path_flag, unix_flag, windows_flag, absolute_flag;
-static int shortname_flag, ignore_flag;
+static int shortname_flag, ignore_flag, allusers_flag, output_flag;
static struct option long_options[] =
{
@@ -39,6 +42,9 @@ static struct option long_options[] =
{ (char *) "windir", no_argument, NULL, 'W' },
{ (char *) "sysdir", no_argument, NULL, 'S' },
{ (char *) "ignore", no_argument, NULL, 'i' },
+ { (char *) "allusers", no_argument, NULL, 'A' },
+ { (char *) "desktop", no_argument, NULL, 'D' },
+ { (char *) "smprograms", no_argument, NULL, 'P' },
{ 0, no_argument, 0, 0 }
};
@@ -50,14 +56,18 @@ usage (FILE *stream, int status)
Usage: %s [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) filename\n\
-a|--absolute output absolute path\n\
-c|--close handle close handle (for use in captured process)\n\
- -f|--file file read file for path information\n\
+ -f|--file file read file for input path information\n\
-i|--ignore ignore missing argument\n\
-p|--path filename argument is a path\n\
-s|--short-name print Windows short form of filename\n\
- -S|--sysdir print `system' directory\n\
-u|--unix print Unix form of filename\n\
+ -v|--version output version information and exit\n\
-w|--windows print Windows form of filename\n\
- -W|--windir print `Windows' directory\n",
+ -A|--allusers use `All Users' instead of current user for -D, -P\n\
+ -D|--desktop output `Desktop' directory and exit\n\
+ -P|--smprograms output Start Menu `Programs' directory and exit\n\
+ -S|--sysdir output system directory and exit\n\
+ -W|--windir output `Windows' directory and exit\n",
prog_name);
exit (ignore_flag ? 0 : status);
}
@@ -224,11 +234,12 @@ doit (char *filename)
int
main (int argc, char **argv)
{
- int c;
+ int c, o;
int options_from_file_flag;
char *filename;
char buf[MAX_PATH], buf2[MAX_PATH];
WIN32_FIND_DATA w32_fd;
+ LPITEMIDLIST id;
prog_name = strrchr (argv[0], '/');
if (prog_name == NULL)
@@ -244,7 +255,9 @@ main (int argc, char **argv)
shortname_flag = 0;
ignore_flag = 0;
options_from_file_flag = 0;
- while ((c = getopt_long (argc, argv, (char *) "hac:f:opsSuvwWi", long_options, (int *) NULL))
+ allusers_flag = 0;
+ output_flag = 0;
+ while ((c = getopt_long (argc, argv, (char *) "hac:f:opsSuvwWiDPA", long_options, (int *) NULL))
!= EOF)
{
switch (c)
@@ -287,25 +300,37 @@ main (int argc, char **argv)
shortname_flag = 1;
break;
- case 'W':
- GetWindowsDirectory(buf, MAX_PATH);
- if (!windows_flag)
- cygwin_conv_to_posix_path(buf, buf2);
- else
- strcpy(buf2, buf);
- printf("%s\n", buf2);
- exit(0);
+ case 'A':
+ allusers_flag = 1;
+ break;
+
+ case 'D':
+ if (output_flag)
+ usage (stderr, 1);
+ output_flag = 1;
+ o = 'D';
+ break;
+
+ case 'P':
+ if (output_flag)
+ usage (stderr, 1);
+ output_flag = 1;
+ o = 'P';
+ break;
case 'S':
- GetSystemDirectory(buf, MAX_PATH);
- FindFirstFile(buf, &w32_fd);
- strcpy(strrchr(buf, '\\')+1, w32_fd.cFileName);
- if (!windows_flag)
- cygwin_conv_to_posix_path(buf, buf2);
- else
- strcpy(buf2, buf);
- printf("%s\n", buf2);
- exit(0);
+ if (output_flag)
+ usage (stderr, 1);
+ output_flag = 1;
+ o = 'S';
+ break;
+
+ case 'W':
+ if (output_flag)
+ usage (stderr, 1);
+ output_flag = 1;
+ o = 'W';
+ break;
case 'i':
ignore_flag = 1;
@@ -316,16 +341,81 @@ main (int argc, char **argv)
break;
case 'v':
- printf ("Cygwin path conversion version 1.1\n");
- printf ("Copyright 1998,1999,2000,2001 Red Hat, Inc.\n");
+ printf ("Cygwin path conversion version 1.2\n");
+ printf ("Copyright 1998-2002 Red Hat, Inc.\n");
exit (0);
default:
usage (stderr, 1);
break;
}
+
}
+ if (output_flag)
+ {
+ switch(o) {
+ case 'D':
+ if (!allusers_flag)
+ SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY,&id);
+ else
+ SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_DESKTOPDIRECTORY,&id);
+ SHGetPathFromIDList(id, buf);
+ /* This if clause is a Fix for Win95 without any "All Users" */
+ if ( strlen(buf) == 0 ) {
+ SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY,&id);
+ SHGetPathFromIDList(id, buf);
+ }
+ if (!windows_flag)
+ cygwin_conv_to_posix_path(buf, buf2);
+ else
+ strcpy(buf2, buf);
+ printf("%s\n", buf2);
+ exit(0);
+
+ case 'P':
+ if (!allusers_flag)
+ SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &id);
+ else
+ SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_PROGRAMS, &id);
+ SHGetPathFromIDList(id, buf);
+ /* This if clause is a Fix for Win95 without any "All Users" */
+ if ( strlen(buf) == 0 ) {
+ SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &id);
+ SHGetPathFromIDList(id, buf);
+ }
+ if (!windows_flag)
+ cygwin_conv_to_posix_path(buf, buf2);
+ else
+ strcpy(buf2, buf);
+ printf("%s\n", buf2);
+ exit(0);
+
+ case 'S':
+ GetSystemDirectory(buf, MAX_PATH);
+ FindFirstFile(buf, &w32_fd);
+ strcpy(strrchr(buf, '\\')+1, w32_fd.cFileName);
+ if (!windows_flag)
+ cygwin_conv_to_posix_path(buf, buf2);
+ else
+ strcpy(buf2, buf);
+ printf("%s\n", buf2);
+ exit(0);
+
+ case 'W':
+ GetWindowsDirectory(buf, MAX_PATH);
+ if (!windows_flag)
+ cygwin_conv_to_posix_path(buf, buf2);
+ else
+ strcpy(buf2, buf);
+ printf("%s\n", buf2);
+ exit(0);
+
+ default:
+ fprintf(stderr, "ERROR: main: switch(o)!\n");
+ }
+ }
+
if (options_from_file_flag && !file_arg)
usage (stderr, 1);