Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-01-09 15:17:05 +0300
committerCorinna Vinschen <corinna@vinschen.de>2007-01-09 15:17:05 +0300
commitca9029913a90b5c5fb8b05a292685f5b6dde50bc (patch)
treedd48abf8b45804f0d1888e9446ddd7691015fe75 /winsup/utils/cygpath.cc
parentd5b45d2f386d6131fcef8c634acc9dfec70d9903 (diff)
* cygpath.cc (usage): Add -O and -F, remove tabs.
(get_special_folder): New function. (get_user_folder): New function. (dowin): Add -O and -F, better -D, -P error handling. (main): Add -O and -F. * utils.sgml (cygpath): Document -O and -F.
Diffstat (limited to 'winsup/utils/cygpath.cc')
-rw-r--r--winsup/utils/cygpath.cc115
1 files changed, 78 insertions, 37 deletions
diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc
index 9d0f80d01..9e4392f80 100644
--- a/winsup/utils/cygpath.cc
+++ b/winsup/utils/cygpath.cc
@@ -28,7 +28,7 @@ details. */
static const char version[] = "$Revision$";
static char *prog_name;
-static char *file_arg;
+static char *file_arg, *output_arg;
static int path_flag, unix_flag, windows_flag, absolute_flag;
static int shortname_flag, longname_flag;
static int ignore_flag, allusers_flag, output_flag;
@@ -55,13 +55,15 @@ static struct option long_options[] = {
{(char *) "allusers", no_argument, NULL, 'A'},
{(char *) "desktop", no_argument, NULL, 'D'},
{(char *) "homeroot", no_argument, NULL, 'H'},
+ {(char *) "mydocs", no_argument, NULL, 'O'},
{(char *) "smprograms", no_argument, NULL, 'P'},
{(char *) "sysdir", no_argument, NULL, 'S'},
{(char *) "windir", no_argument, NULL, 'W'},
+ {(char *) "folder", required_argument, NULL, 'F'},
{0, no_argument, 0, 0}
};
-static char options[] = "ac:df:hilmMopst:uvwADHPSW";
+static char options[] = "ac:df:hilmMopst:uvwADHOPSWF:";
static void
usage (FILE * stream, int status)
@@ -70,29 +72,32 @@ usage (FILE * stream, int status)
fprintf (stream, "\
Usage: %s (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...\n\
%s [-c HANDLE] \n\
- %s [-ADHPSW] \n\
+ %s [-ADHOPSW] \n\
+ %s [-F ID] \n\
Convert Unix and Windows format paths, or output system path information\n\
\n\
Output type options:\n\
- -d, --dos print DOS (short) form of NAMEs (C:\\PROGRA~1\\)\n\
+ -d, --dos print DOS (short) form of NAMEs (C:\\PROGRA~1\\)\n\
-m, --mixed like --windows, but with regular slashes (C:/WINNT)\n\
- -M, --mode report on mode of file (binmode or textmode)\n\
- -u, --unix (default) print Unix form of NAMEs (/cygdrive/c/winnt)\n\
+ -M, --mode report on mode of file (binmode or textmode)\n\
+ -u, --unix (default) print Unix form of NAMEs (/cygdrive/c/winnt)\n\
-w, --windows print Windows form of NAMEs (C:\\WINNT)\n\
-t, --type TYPE print TYPE form: 'dos', 'mixed', 'unix', or 'windows'\n\
Path conversion options:\n\
-a, --absolute output absolute path\n\
- -l, --long-name print Windows long form of NAMEs (with -w, -m only)\n\
- -p, --path NAME is a PATH list (i.e., '/bin:/usr/bin')\n\
- -s, --short-name print DOS (short) form of NAMEs (with -w, -m only)\n\
+ -l, --long-name print Windows long form of NAMEs (with -w, -m only)\n\
+ -p, --path NAME is a PATH list (i.e., '/bin:/usr/bin')\n\
+ -s, --short-name print DOS (short) form of NAMEs (with -w, -m only)\n\
System information:\n\
- -A, --allusers use `All Users' instead of current user for -D, -P\n\
- -D, --desktop output `Desktop' directory and exit\n\
+ -A, --allusers use `All Users' instead of current user for -D, -O, -P\n\
+ -D, --desktop output `Desktop' directory and exit\n\
-H, --homeroot output `Profiles' directory (home root) 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, prog_name, prog_name);
+ -O, --mydocs output `My Documents' 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\
+ -F, --folder ID output special folder with numeric ID and exit\n\
+", prog_name, prog_name, prog_name, prog_name);
if (ignore_flag)
/* nothing to do */;
else if (stream != stdout)
@@ -104,9 +109,9 @@ Other options:\n\
-f, --file FILE read FILE for input; use - to read from STDIN\n\
-o, --option read options from FILE as well (for use with --file)\n\
-c, --close HANDLE close HANDLE (for use in captured process)\n\
- -i, --ignore ignore missing argument\n\
+ -i, --ignore ignore missing argument\n\
-h, --help output usage information and exit\n\
- -v, --version output version information and exit\n\
+ -v, --version output version information and exit\n\
");
}
exit (ignore_flag ? 0 : status);
@@ -501,41 +506,63 @@ get_mixed_name (const char* filename)
return mixed_buf;
}
+static bool
+get_special_folder (char* path, int id)
+{
+ path[0] = 0;
+ LPITEMIDLIST pidl = 0;
+ if (SHGetSpecialFolderLocation (NULL, id, &pidl) != S_OK)
+ return false;
+ if (!SHGetPathFromIDList (pidl, path) || !path[0])
+ return false;
+ return true;
+}
+
+static void
+get_user_folder (char* path, int id, int allid)
+{
+ if (!get_special_folder (path, allusers_flag ? allid : id) && allusers_flag)
+ get_special_folder (path, id); // Fix for Win9x without any "All Users"
+}
+
static void
dowin (char option)
{
char *buf, buf1[MAX_PATH], buf2[MAX_PATH];
DWORD len = MAX_PATH;
WIN32_FIND_DATA w32_fd;
- LPITEMIDLIST id;
HINSTANCE k32;
BOOL (*GetProfilesDirectoryAPtr) (LPSTR, LPDWORD) = 0;
buf = buf1;
+ buf[0] = 0;
switch (option)
{
case 'D':
- SHGetSpecialFolderLocation (NULL, allusers_flag ?
- CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_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);
- }
+ get_user_folder (buf, CSIDL_DESKTOPDIRECTORY,
+ CSIDL_COMMON_DESKTOPDIRECTORY);
break;
case 'P':
- SHGetSpecialFolderLocation (NULL, allusers_flag ?
- CSIDL_COMMON_PROGRAMS : CSIDL_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);
- }
+ get_user_folder (buf, CSIDL_PROGRAMS, CSIDL_COMMON_PROGRAMS);
+ break;
+
+ case 'O':
+ get_user_folder (buf, CSIDL_PERSONAL, CSIDL_COMMON_DOCUMENTS);
+ break;
+
+ case 'F':
+ {
+ int val = -1, len = -1;
+ if (!(sscanf (output_arg, "%i%n", &val, &len) == 1
+ && len == (int) strlen (output_arg) && val >= 0))
+ {
+ fprintf (stderr, "%s: syntax error in special folder ID %s\n",
+ prog_name, output_arg);
+ exit (1);
+ }
+ get_special_folder (buf, val);
+ }
break;
case 'H':
@@ -566,7 +593,11 @@ dowin (char option)
usage (stderr, 1);
}
- if (!windows_flag)
+ if (!buf[0])
+ {
+ fprintf (stderr, "%s: failed to retrieve special folder path\n", prog_name);
+ }
+ else if (!windows_flag)
{
if (cygwin_conv_to_posix_path (buf, buf2))
fprintf (stderr, "%s: error converting \"%s\" - %s\n",
@@ -844,6 +875,7 @@ main (int argc, char **argv)
case 'D':
case 'H':
+ case 'O':
case 'P':
case 'S':
case 'W':
@@ -853,6 +885,14 @@ main (int argc, char **argv)
o = c;
break;
+ case 'F':
+ if (output_flag || !optarg)
+ usage (stderr, 1);
+ output_flag = 1;
+ output_arg = optarg;
+ o = c;
+ break;
+
case 'i':
ignore_flag = 1;
break;
@@ -962,6 +1002,7 @@ main (int argc, char **argv)
break;
case 'D':
case 'H':
+ case 'O':
case 'P':
case 'S':
case 'W':