diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-05-15 11:36:00 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-05-15 11:36:00 +0000 |
commit | e355de817c95c1b5b3fa98c0e5e2863a1ecb7679 (patch) | |
tree | 05b35b8f46743afc1ffc178f10ff5a1615467bc3 | |
parent | 5588e287656755ccf77f8939470c3fde41b7a1d7 (diff) | |
download | newlib-e355de817c95c1b5b3fa98c0e5e2863a1ecb7679.zip newlib-e355de817c95c1b5b3fa98c0e5e2863a1ecb7679.tar.gz newlib-e355de817c95c1b5b3fa98c0e5e2863a1ecb7679.tar.bz2 |
* 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.
-rw-r--r-- | winsup/utils/ChangeLog | 14 | ||||
-rw-r--r-- | winsup/utils/cygpath.cc | 101 | ||||
-rw-r--r-- | winsup/utils/utils.sgml | 16 |
3 files changed, 73 insertions, 58 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index a6a15fc..6dc8de4 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -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> - * 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> diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc index 1536ece..d11eb2e 100644 --- a/winsup/utils/cygpath.cc +++ b/winsup/utils/cygpath.cc @@ -46,6 +46,7 @@ static struct option long_options[] = { {(char *) "allusers", no_argument, NULL, 'A'}, {(char *) "desktop", no_argument, NULL, 'D'}, {(char *) "smprograms", no_argument, NULL, 'P'}, + {(char *) "homeroot", no_argument, NULL, 'H'}, {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\ -A|--allusers use `All Users' instead of current user for -D, -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); @@ -90,7 +92,7 @@ get_short_paths (char *path) if (ptr) *ptr++ = 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, next); @@ -107,7 +109,8 @@ get_short_paths (char *path) ptr = path; 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, ptr); @@ -129,7 +132,7 @@ get_short_name (const char *filename) { char *sbuf; 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, filename); @@ -141,7 +144,8 @@ get_short_name (const char *filename) fprintf (stderr, "%s: out of memory\n", prog_name); 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, filename); @@ -261,9 +265,6 @@ main (int argc, char **argv) int c, o = 0; 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) @@ -282,7 +283,7 @@ main (int argc, char **argv) allusers_flag = 0; output_flag = 0; while ((c = - getopt_long (argc, argv, (char *) "hac:f:opsSuvwWiDPA", + getopt_long (argc, argv, (char *) "hac:f:opsSuvwWiDPAH", long_options, (int *) NULL)) != EOF) { switch (c) @@ -330,31 +331,14 @@ main (int argc, char **argv) break; case 'D': - if (output_flag) - usage (stderr, 1); - output_flag = 1; - o = 'D'; - break; - + case 'H': case 'P': - if (output_flag) - usage (stderr, 1); - output_flag = 1; - o = 'P'; - break; - case 'S': - 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'; + o = c; break; case 'i': @@ -378,6 +362,14 @@ main (int argc, char **argv) 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) { case 'D': @@ -393,12 +385,7 @@ main (int argc, char **argv) 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); + break; case 'P': if (!allusers_flag) @@ -412,36 +399,48 @@ main (int argc, char **argv) SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); SHGetPathFromIDList (id, buf); } - if (!windows_flag) - cygwin_conv_to_posix_path (buf, buf2); + break; + + case 'H': + hinst = LoadLibrary ("userenv"); + if (hinst) + GetProfilesDirectoryAPtr = (BOOL (*) (LPSTR, LPDWORD)) + GetProcAddress (hinst, "GetProfilesDirectoryA"); + if (GetProfilesDirectoryAPtr) + (*GetProfilesDirectoryAPtr) (buf, &len); else - strcpy (buf2, buf); - printf ("%s\n", buf2); - exit (0); + { + GetWindowsDirectory (buf, MAX_PATH); + strcat (buf, "\\Profiles"); + } + 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); + 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); + break; 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) diff --git a/winsup/utils/utils.sgml b/winsup/utils/utils.sgml index 3c59d27..cbda631 100644 --- a/winsup/utils/utils.sgml +++ b/winsup/utils/utils.sgml @@ -82,6 +82,7 @@ Usage: cygpath.exe [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) file -v|--version output version information and exit -w|--windows print Windows form of filename -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 -P|--smprograms output Start Menu `Programs' directory and exit -S|--sysdir output system directory and exit @@ -127,15 +128,18 @@ done </example> <para>The capital options -<literal>-D</literal>, <literal>-P</literal>, <literal>-S</literal>, and -<literal>-W</literal> output directories used by Windows that are not the -same on all systems, for example <literal>-S</literal> might output -C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM. 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>-H</literal>, <literal>-P</literal>, +<literal>-S</literal>, and <literal>-W</literal> output directories used +by Windows that are not the same on all systems, for example +<literal>-S</literal> might output C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM. +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. 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 effect; <literal>-D</literal> and <literal>-AD</literal> would have the same output. +The <literal>-ws</literal> options can be combined with the capital options. </sect2> |