* 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.
This commit is contained in:
parent
d5b45d2f38
commit
ca9029913a
|
@ -1,3 +1,12 @@
|
|||
2007-01-09 Christian Franke <franke@computer.org>
|
||||
|
||||
* 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.
|
||||
|
||||
2006-12-21 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* dumper.cc: Include ansidecl.h before including bfd.h to woraround
|
||||
|
|
|
@ -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,7 +72,8 @@ 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\
|
||||
|
@ -86,13 +89,15 @@ Path conversion options:\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\
|
||||
-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\
|
||||
-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\
|
||||
", prog_name, prog_name, prog_name);
|
||||
-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)
|
||||
|
@ -501,40 +506,62 @@ 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)
|
||||
get_user_folder (buf, CSIDL_PROGRAMS, CSIDL_COMMON_PROGRAMS);
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
get_user_folder (buf, CSIDL_PERSONAL, CSIDL_COMMON_DOCUMENTS);
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
{
|
||||
SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
|
||||
SHGetPathFromIDList (id, buf);
|
||||
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;
|
||||
|
||||
|
@ -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':
|
||||
|
|
|
@ -191,7 +191,8 @@ for example:</para>
|
|||
<screen>
|
||||
Usage: cygpath (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...
|
||||
cygpath [-c HANDLE]
|
||||
cygpath [-ADHPSW]
|
||||
cygpath [-ADHOPSW]
|
||||
cygpath [-F ID]
|
||||
Convert Unix and Windows format paths, or output system path information
|
||||
|
||||
Output type options:
|
||||
|
@ -210,9 +211,11 @@ System information:
|
|||
-A, --allusers use `All Users' instead of current user for -D, -P
|
||||
-D, --desktop output `Desktop' directory and exit
|
||||
-H, --homeroot output `Profiles' directory (home root) and exit
|
||||
-O, --mydocs output `My Documents' directory and exit
|
||||
-P, --smprograms output Start Menu `Programs' directory and exit
|
||||
-S, --sysdir output system directory and exit
|
||||
-W, --windir output `Windows' directory and exit
|
||||
-F, --folder ID output special folder with numeric ID and exit
|
||||
Other options:
|
||||
-f, --file FILE read FILE for input; use - to read from STDIN
|
||||
-o, --option read options from FILE as well (for use with --file)
|
||||
|
@ -290,7 +293,13 @@ by Windows that are not the same on all systems, for example
|
|||
The <literal>-H</literal> shows the Windows profiles directory that can
|
||||
be used as root of home. The <literal>-A</literal> option forces use of
|
||||
the "All Users" directories instead of the current user for the
|
||||
<literal>-D</literal> and <literal>-P</literal> options.
|
||||
<literal>-D</literal>, <literal>-O</literal> and <literal>-P</literal>
|
||||
options.
|
||||
The <literal>-F</literal> outputs other special folders specified by
|
||||
their internal numeric code (decimal or 0xhex). For valid codes and
|
||||
symbolic names, see the CSIDL_* definitions in the include file
|
||||
/usr/include/w32api/shlobj.h from package w32api. The current valid
|
||||
range of codes for folders is 0 (Desktop) to 59 (CDBurn area).
|
||||
On Win9x systems with only a single user, <literal>-A</literal> has no
|
||||
effect; <literal>-D</literal> and <literal>-AD</literal> would have the
|
||||
same output. By default the output is in UNIX (POSIX) format;
|
||||
|
|
Loading…
Reference in New Issue