* cygpath.cc (get_short_paths): Fix more error checking.

(get_short_name): Ditto.

	* cygpath.cc (main): Add option H to show the Windows' profiles
	directory.  Support short names for options DPSW.  Clean up
	copied code lines.
	* utils.sgml: Update cygpath section for H option and s support.
This commit is contained in:
Corinna Vinschen 2002-05-15 11:36:00 +00:00
parent 5588e28765
commit e355de817c
3 changed files with 73 additions and 58 deletions

View File

@ -1,6 +1,18 @@
2002-05-15 Mark Blackburn <marklist@fangorn.ca>
* cygpath.cc (get_short_paths): Fix more error checking.
(get_short_name): Ditto.
2002-05-14 Joerg Schaible <joerg.schaible@gmx.de>
* cygpath.cc (main): Add option H to show the Windows' profiles
directory. Support short names for options DPSW. Clean up
copied code lines.
* utils.sgml: Update cygpath section for H option and s support.
2002-05-14 Mark Blackburn <marklist@fangorn.ca> 2002-05-14 Mark Blackburn <marklist@fangorn.ca>
* cygpath.cc (get_short_name): Fix error checking. * cygpath.cc (get_short_paths): Fix error checking.
2002-05-13 Joshua Daniel Franklin <joshuadfranklin@yahoo.com> 2002-05-13 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>

View File

@ -46,6 +46,7 @@ static struct option long_options[] = {
{(char *) "allusers", no_argument, NULL, 'A'}, {(char *) "allusers", no_argument, NULL, 'A'},
{(char *) "desktop", no_argument, NULL, 'D'}, {(char *) "desktop", no_argument, NULL, 'D'},
{(char *) "smprograms", no_argument, NULL, 'P'}, {(char *) "smprograms", no_argument, NULL, 'P'},
{(char *) "homeroot", no_argument, NULL, 'H'},
{0, no_argument, 0, 0} {0, no_argument, 0, 0}
}; };
@ -66,6 +67,7 @@ Usage: %s [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) filename\n\
-w|--windows print Windows form of filename\n\ -w|--windows print Windows form of filename\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, -P\n\
-D|--desktop output `Desktop' directory and exit\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\ -P|--smprograms output Start Menu `Programs' directory and exit\n\
-S|--sysdir output system directory and exit\n\ -S|--sysdir output system directory and exit\n\
-W|--windir output `Windows' directory and exit\n", prog_name); -W|--windir output `Windows' directory and exit\n", prog_name);
@ -90,7 +92,7 @@ get_short_paths (char *path)
if (ptr) if (ptr)
*ptr++ = 0; *ptr++ = 0;
len = GetShortPathName (next, NULL, 0); len = GetShortPathName (next, NULL, 0);
if (len ==0 && GetLastError () == ERROR_INVALID_PARAMETER) if (len == 0 && GetLastError () == ERROR_INVALID_PARAMETER)
{ {
fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
next); next);
@ -107,7 +109,8 @@ get_short_paths (char *path)
ptr = path; ptr = path;
for (;;) for (;;)
{ {
if (GetShortPathName (ptr, sptr, acc) == ERROR_INVALID_PARAMETER) len = GetShortPathName (ptr, sptr, acc);
if (len == 0 && GetLastError () == ERROR_INVALID_PARAMETER)
{ {
fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
ptr); ptr);
@ -129,7 +132,7 @@ get_short_name (const char *filename)
{ {
char *sbuf; char *sbuf;
DWORD len = GetShortPathName (filename, NULL, 0); DWORD len = GetShortPathName (filename, NULL, 0);
if (len == ERROR_INVALID_PARAMETER) if (len == 0 && GetLastError () == ERROR_INVALID_PARAMETER)
{ {
fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
filename); filename);
@ -141,7 +144,8 @@ get_short_name (const char *filename)
fprintf (stderr, "%s: out of memory\n", prog_name); fprintf (stderr, "%s: out of memory\n", prog_name);
exit (1); exit (1);
} }
if (GetShortPathName (filename, sbuf, len) == ERROR_INVALID_PARAMETER) len = GetShortPathName (filename, sbuf, len);
if (len == 0 && GetLastError () == ERROR_INVALID_PARAMETER)
{ {
fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
filename); filename);
@ -261,9 +265,6 @@ main (int argc, char **argv)
int c, o = 0; int c, o = 0;
int options_from_file_flag; int options_from_file_flag;
char *filename; char *filename;
char buf[MAX_PATH], buf2[MAX_PATH];
WIN32_FIND_DATA w32_fd;
LPITEMIDLIST id;
prog_name = strrchr (argv[0], '/'); prog_name = strrchr (argv[0], '/');
if (prog_name == NULL) if (prog_name == NULL)
@ -282,7 +283,7 @@ main (int argc, char **argv)
allusers_flag = 0; allusers_flag = 0;
output_flag = 0; output_flag = 0;
while ((c = while ((c =
getopt_long (argc, argv, (char *) "hac:f:opsSuvwWiDPA", getopt_long (argc, argv, (char *) "hac:f:opsSuvwWiDPAH",
long_options, (int *) NULL)) != EOF) long_options, (int *) NULL)) != EOF)
{ {
switch (c) switch (c)
@ -330,31 +331,14 @@ main (int argc, char **argv)
break; break;
case 'D': case 'D':
if (output_flag) case 'H':
usage (stderr, 1);
output_flag = 1;
o = 'D';
break;
case 'P': case 'P':
if (output_flag)
usage (stderr, 1);
output_flag = 1;
o = 'P';
break;
case 'S': case 'S':
if (output_flag)
usage (stderr, 1);
output_flag = 1;
o = 'S';
break;
case 'W': case 'W':
if (output_flag) if (output_flag)
usage (stderr, 1); usage (stderr, 1);
output_flag = 1; output_flag = 1;
o = 'W'; o = c;
break; break;
case 'i': case 'i':
@ -378,6 +362,14 @@ main (int argc, char **argv)
if (output_flag) if (output_flag)
{ {
char *buf, buf1[MAX_PATH], buf2[MAX_PATH];
DWORD len = MAX_PATH;
WIN32_FIND_DATA w32_fd;
LPITEMIDLIST id;
HINSTANCE hinst;
BOOL (*GetProfilesDirectoryAPtr) (LPSTR, LPDWORD) = 0;
buf = buf1;
switch (o) switch (o)
{ {
case 'D': case 'D':
@ -393,12 +385,7 @@ main (int argc, char **argv)
SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
SHGetPathFromIDList (id, buf); SHGetPathFromIDList (id, buf);
} }
if (!windows_flag) break;
cygwin_conv_to_posix_path (buf, buf2);
else
strcpy (buf2, buf);
printf ("%s\n", buf2);
exit (0);
case 'P': case 'P':
if (!allusers_flag) if (!allusers_flag)
@ -412,36 +399,48 @@ main (int argc, char **argv)
SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
SHGetPathFromIDList (id, buf); SHGetPathFromIDList (id, buf);
} }
if (!windows_flag) break;
cygwin_conv_to_posix_path (buf, buf2);
case 'H':
hinst = LoadLibrary ("userenv");
if (hinst)
GetProfilesDirectoryAPtr = (BOOL (*) (LPSTR, LPDWORD))
GetProcAddress (hinst, "GetProfilesDirectoryA");
if (GetProfilesDirectoryAPtr)
(*GetProfilesDirectoryAPtr) (buf, &len);
else else
strcpy (buf2, buf); {
printf ("%s\n", buf2); GetWindowsDirectory (buf, MAX_PATH);
exit (0); strcat (buf, "\\Profiles");
}
break;
case 'S': case 'S':
GetSystemDirectory (buf, MAX_PATH); GetSystemDirectory (buf, MAX_PATH);
FindFirstFile (buf, &w32_fd); FindFirstFile (buf, &w32_fd);
strcpy (strrchr (buf, '\\') + 1, w32_fd.cFileName); strcpy (strrchr (buf, '\\') + 1, w32_fd.cFileName);
if (!windows_flag) break;
cygwin_conv_to_posix_path (buf, buf2);
else
strcpy (buf2, buf);
printf ("%s\n", buf2);
exit (0);
case 'W': case 'W':
GetWindowsDirectory (buf, MAX_PATH); GetWindowsDirectory (buf, MAX_PATH);
if (!windows_flag) break;
cygwin_conv_to_posix_path (buf, buf2);
else
strcpy (buf2, buf);
printf ("%s\n", buf2);
exit (0);
default: default:
fprintf (stderr, "ERROR: main: switch (o)!\n"); usage (stderr, 1);
} }
if (!windows_flag)
{
cygwin_conv_to_posix_path (buf, buf2);
buf = buf2;
}
else
{
if (shortname_flag)
buf = get_short_name (buf);
}
printf ("%s\n", buf);
exit (0);
} }
if (options_from_file_flag && !file_arg) if (options_from_file_flag && !file_arg)

View File

@ -82,6 +82,7 @@ Usage: cygpath.exe [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) file
-v|--version output version information and exit -v|--version output version information and exit
-w|--windows print Windows form of filename -w|--windows print Windows form of filename
-A|--allusers use `All Users' instead of current user for -D, -P -A|--allusers use `All Users' instead of current user for -D, -P
-H|--homeroot output `Profiles' directory (home root) and exit\n\
-D|--desktop output `Desktop' directory and exit -D|--desktop output `Desktop' directory and exit
-P|--smprograms output Start Menu `Programs' directory and exit -P|--smprograms output Start Menu `Programs' directory and exit
-S|--sysdir output system directory and exit -S|--sysdir output system directory and exit
@ -127,15 +128,18 @@ done
</example> </example>
<para>The capital options <para>The capital options
<literal>-D</literal>, <literal>-P</literal>, <literal>-S</literal>, and <literal>-D</literal>, <literal>-H</literal>, <literal>-P</literal>,
<literal>-W</literal> output directories used by Windows that are not the <literal>-S</literal>, and <literal>-W</literal> output directories used
same on all systems, for example <literal>-S</literal> might output by Windows that are not the same on all systems, for example
C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM. The <literal>-A</literal> option <literal>-S</literal> might output C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM.
forces use of the "All Users" directories instead of the current user The <literal>-A</literal> option forces use of the "All Users" directories
for the <literal>-D</literal> and <literal>-P</literal> options. instead of the current user for the <literal>-D</literal> and
<literal>-P</literal> options. The <literal>-H</literal> shows the Windows'
profiles directory that can be used as root of home.
On Win9x systems with only a single user, <literal>-A</literal> has no On Win9x systems with only a single user, <literal>-A</literal> has no
effect; <literal>-D</literal> and <literal>-AD</literal> would have the effect; <literal>-D</literal> and <literal>-AD</literal> would have the
same output. same output.
The <literal>-ws</literal> options can be combined with the capital options.
</sect2> </sect2>