summaryrefslogtreecommitdiffstats
path: root/winsup
diff options
context:
space:
mode:
Diffstat (limited to 'winsup')
-rw-r--r--winsup/utils/ChangeLog7
-rw-r--r--winsup/utils/cygpath.cc118
-rw-r--r--winsup/utils/utils.sgml27
3 files changed, 136 insertions, 16 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 7f61f5254..6ec8c5b1b 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,8 @@
+2000-09-15 Joerg Schaible <joerg.schaible@gmx.de>
+
+ * cygpath.cc: Add new options: -s and -i.
+ * utils.sgml: Document the new options.
+
Tue Sep 12 22:45:28 2000 Christopher Faylor <cgf@cygnus.com>
* kill.cc (main): Change behavior of -f so that it will force the
@@ -27,7 +32,7 @@ Fri Aug 25 11:44:29 2000 Christopher Faylor <cgf@cygnus.com>
Thu Aug 24 18:02:35 2000 Christopher Faylor <cgf@cygnus.com>
- * ps.cc (main): Always print a cygwin process using cygwin paths.
+ * ps.cc (main): Always print a cygwin process using cygwin paths.
2000-08-24 Egor Duda <deo@logos-m.ru>
diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc
index e1c5bcd7f..d16132f55 100644
--- a/winsup/utils/cygpath.cc
+++ b/winsup/utils/cygpath.cc
@@ -23,6 +23,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 struct option long_options[] =
{
@@ -35,26 +36,105 @@ static struct option long_options[] =
{ (char *) "file", required_argument, (int *) &file_arg, 'f'},
{ (char *) "version", no_argument, NULL, 'v' },
{ (char *) "windows", no_argument, NULL, 'w' },
+ { (char *) "short-name", no_argument, NULL, 's' },
{ (char *) "windir", no_argument, NULL, 'W' },
{ (char *) "sysdir", no_argument, NULL, 'S' },
+ { (char *) "ignore", no_argument, NULL, 'i' },
{ 0, no_argument, 0, 0 }
};
static void
usage (FILE *stream, int status)
{
- fprintf (stream, "\
-Usage: %s [-p|--path] (-u|--unix)|(-w|--windows) filename\n\
+ if (!ignore_flag || !status)
+ fprintf (stream, "\
+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\
-u|--unix print Unix form of filename\n\
-w|--windows print Windows form of filename\n\
+ -s|--short-name print Windows short form of filename\n\
-W|--windir print `Windows' directory\n\
-S|--sysdir print `system' directory\n\
- -p|--path filename argument is a path\n",
+ -p|--path filename argument is a path\n\
+ -i|--ignore ignore missing argument\n",
prog_name);
- exit (status);
+ exit (ignore_flag ? 0 : status);
+}
+
+static char *
+get_short_paths (char *path)
+{
+ char *sbuf;
+ char *sptr;
+ char *next;
+ char *ptr = path;
+ char *end = strrchr (path, 0);
+ DWORD acc = 0;
+ DWORD len;
+
+ while (ptr != NULL)
+ {
+ next = ptr;
+ ptr = strchr (ptr, ';');
+ if (ptr)
+ *ptr++ = 0;
+ len = GetShortPathName (next, NULL, 0);
+ if (len == ERROR_INVALID_PARAMETER)
+ {
+ fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, next);
+ exit (2);
+ }
+ acc += len+1;
+ }
+ sptr = sbuf = (char *) malloc(acc+1);
+ if (sbuf == NULL)
+ {
+ fprintf (stderr, "%s: out of memory\n", prog_name);
+ exit (1);
+ }
+ ptr = path;
+ for(;;)
+ {
+ if (GetShortPathName (ptr, sptr, acc) == ERROR_INVALID_PARAMETER)
+ {
+ fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, ptr);
+ exit (2);
+ }
+
+ ptr = strrchr (ptr, 0);
+ sptr = strrchr (sptr, 0);
+ if (ptr == end)
+ break;
+ *sptr = ';';
+ ++ptr, ++sptr;
+ }
+ return sbuf;
+}
+
+static char *
+get_short_name (const char *filename)
+{
+ char *sbuf;
+ DWORD len = GetShortPathName (filename, NULL, 0);
+ if (len == ERROR_INVALID_PARAMETER)
+ {
+ fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, filename);
+ exit (2);
+ }
+ sbuf = (char *) malloc(++len);
+ if (sbuf == NULL)
+ {
+ fprintf (stderr, "%s: out of memory\n", prog_name);
+ exit (1);
+ }
+ if (GetShortPathName (filename, sbuf, len) == ERROR_INVALID_PARAMETER)
+ {
+ fprintf (stderr, "%s: cannot create short name of %s\n", prog_name, filename);
+ exit (2);
+ }
+ return sbuf;
}
static void
@@ -100,14 +180,22 @@ doit (char *filename)
if (unix_flag)
cygwin_win32_to_posix_path_list (filename, buf);
else
+ {
cygwin_posix_to_win32_path_list (filename, buf);
+ if (shortname_flag)
+ buf = get_short_paths (buf);
+ }
}
else
{
if (unix_flag)
(absolute_flag ? cygwin_conv_to_full_posix_path : cygwin_conv_to_posix_path) (filename, buf);
else
- (absolute_flag ? cygwin_conv_to_full_win32_path : cygwin_conv_to_win32_path) (filename, buf);
+ {
+ (absolute_flag ? cygwin_conv_to_full_win32_path : cygwin_conv_to_win32_path) (filename, buf);
+ if (shortname_flag)
+ buf = get_short_name (buf);
+ }
}
puts (buf);
@@ -130,8 +218,10 @@ main (int argc, char **argv)
path_flag = 0;
unix_flag = 0;
windows_flag = 0;
+ shortname_flag = 0;
+ ignore_flag = 0;
options_from_file_flag = 0;
- while ((c = getopt_long (argc, argv, (char *) "hac:f:opSuvwW", long_options, (int *) NULL))
+ while ((c = getopt_long (argc, argv, (char *) "hac:f:opsSuvwWi", long_options, (int *) NULL))
!= EOF)
{
switch (c)
@@ -168,6 +258,12 @@ main (int argc, char **argv)
windows_flag = 1;
break;
+ case 's':
+ if (unix_flag)
+ usage (stderr, 1);
+ shortname_flag = 1;
+ break;
+
case 'W':
GetWindowsDirectory(buf, MAX_PATH);
cygwin_conv_to_posix_path(buf, buf2);
@@ -180,6 +276,10 @@ main (int argc, char **argv)
printf("%s\n", buf2);
exit(0);
+ case 'i':
+ ignore_flag = 1;
+ break;
+
case 'h':
usage (stdout, 0);
break;
@@ -246,6 +346,12 @@ main (int argc, char **argv)
case 'a':
absolute_flag = 1;
break;
+ case 'i':
+ ignore_flag = 1;
+ break;
+ case 's':
+ shortname_flag = 1;
+ break;
case 'w':
unix_flag = 0;
windows_flag = 1;
diff --git a/winsup/utils/utils.sgml b/winsup/utils/utils.sgml
index 44d5301a4..fbf6686ce 100644
--- a/winsup/utils/utils.sgml
+++ b/winsup/utils/utils.sgml
@@ -64,15 +64,17 @@ or if you know what everything is already, just leave this out.</para>
<sect2 id="cygpath"><title>cygpath</title>
<screen>
-Usage: cygpath [-p|--path] (-u|--unix)|(-w|--windows) filename
+Usage: cygpath [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) filename
cygpath [-v|--version]
cygpath [-W|--windir|-S|--sysdir]
- -u|--unix print UNIX form of filename
- -w|--windows print Windows form of filename
- -p|--path filename argument is a path
- -v|--version print program version
- -W|--windir print windows directory
- -S|--sysdir print system directory
+ -u|--unix print UNIX form of filename
+ -w|--windows print Windows form of filename
+ -s|--short-name print Windows short form of filename
+ -p|--path filename argument is a path
+ -v|--version print program version
+ -W|--windir print Windows directory
+ -S|--sysdir print Windows system directory
+ -i|--ignore ignore missing filename argument
</screen>
<para>The <command>cygpath</command> program is a utility that
@@ -87,7 +89,9 @@ here.</para>
indicate whether you want a conversion from Windows to UNIX (POSIX)
format (<literal>-u</literal>) or a conversion from UNIX (POSIX) to
Windows format (<literal>-w</literal>). You must give exactly
-one of these. To give neither or both is an error.</para>
+one of these. To give neither or both is an error. Use the
+<literal>-s</literal> option in combination with the <literal>-w
+</literal> option to convert to Windows short form.</para>
<para>The <literal>-p</literal> option means that you want to convert
a path-style string rather than a single filename. For example, the
@@ -96,12 +100,17 @@ colon-delimited in UNIX. By giving <literal>-p</literal> you are
instructing <command>cygpath</command> to convert between these
formats.</para>
+<para>The <literal>-i</literal> option supresses the print out of the
+usage message if no filename argument was given. It can be used in
+make file rules converting variables to a proper format that may be
+omitted.</para>
+
<example><title>Example cygpath usage</title>
<screen>
#!/bin/sh
for i in `echo *.exe | sed 's/\.exe/cc/'`
do
- notepad `cygpath -w $i`
+ notepad "`cygpath -w $i`"
done
</screen>
</example>