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:
authorChristopher Faylor <me@cgf.cx>2000-04-11 06:57:25 +0400
committerChristopher Faylor <me@cgf.cx>2000-04-11 06:57:25 +0400
commit138d4f510ece0b76fde1fec5987aed3f962c5b7f (patch)
tree5e099bb3b58ddf2fe502ac10062ca57f3d695bb8 /winsup/utils
parent23ee7c4463dbde7fe02a6fe23e5282c2baa8eb58 (diff)
* cygpath.cc (main): Add -f option for processing a group of paths from a file.
(doit): New function.
Diffstat (limited to 'winsup/utils')
-rw-r--r--winsup/utils/ChangeLog6
-rw-r--r--winsup/utils/cygpath.cc145
2 files changed, 102 insertions, 49 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 49e42bb33..3acb234d6 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,9 @@
+Mon Apr 10 22:56:07 2000 Christopher Faylor <cgf@cygnus.com>
+
+ * cygpath.cc (main): Add -f option for processing a group of paths from
+ a file.
+ (doit): New function.
+
Sat Mar 18 22:52:37 2000 Christopher Faylor <cgf@cygnus.com>
Patch suggested by Mumit Khan <khan@xraylith.wisc.edu>:
diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc
index 653d41cec..4c7067592 100644
--- a/winsup/utils/cygpath.cc
+++ b/winsup/utils/cygpath.cc
@@ -1,5 +1,5 @@
/* pathconv.cc -- convert pathnames between Windows and Unix format
- Copyright 1998 Cygnus Solutions.
+ Copyright 1998, 1999, 2000 Cygnus Solutions.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of Cygwin.
@@ -13,15 +13,19 @@ details. */
#include <stdlib.h>
#include <limits.h>
#include <getopt.h>
+#include <io.h>
+#include <sys/fcntl.h>
#include <sys/cygwin.h>
static char *prog_name;
+static char *file_arg;
static struct option long_options[] =
{
{ (char *) "help", no_argument, NULL, 'h' },
{ (char *) "path", no_argument, NULL, 'p' },
{ (char *) "unix", no_argument, NULL, 'u' },
+ { (char *) "file", required_argument, (int *) &file_arg, 'f'},
{ (char *) "version", no_argument, NULL, 'v' },
{ (char *) "windows", no_argument, NULL, 'w' },
{ 0, no_argument, 0, 0 }
@@ -32,6 +36,7 @@ usage (FILE *stream, int status)
{
fprintf (stream, "\
Usage: %s [-p|--path] (-u|--unix)|(-w|--windows) filename\n\
+ -f|--file read file for path information\n\
-u|--unix print Unix form of filename\n\
-w|--windows print Windows form of filename\n\
-p|--path filename argument is a path\n",
@@ -39,14 +44,68 @@ Usage: %s [-p|--path] (-u|--unix)|(-w|--windows) filename\n\
exit (status);
}
+static void
+doit (char *filename, int path_flag, int unix_flag, int windows_flag)
+{
+ char *buf;
+ size_t len;
+
+ if (path_flag)
+ {
+ if (cygwin_posix_path_list_p (filename)
+ ? unix_flag
+ : windows_flag)
+ {
+ /* The path is already in the right format. */
+ puts (filename);
+ exit (0);
+ }
+ }
+
+ if (! path_flag)
+ len = strlen (filename) + 100;
+ else
+ {
+ if (unix_flag)
+ len = cygwin_win32_to_posix_path_list_buf_size (filename);
+ else
+ len = cygwin_posix_to_win32_path_list_buf_size (filename);
+ }
+
+ if (len < PATH_MAX)
+ len = PATH_MAX;
+
+ buf = (char *) malloc (len);
+ if (buf == NULL)
+ {
+ fprintf (stderr, "%s: out of memory\n", prog_name);
+ exit (1);
+ }
+
+ if (path_flag)
+ {
+ if (unix_flag)
+ cygwin_win32_to_posix_path_list (filename, buf);
+ else
+ cygwin_posix_to_win32_path_list (filename, buf);
+ }
+ else
+ {
+ if (unix_flag)
+ cygwin_conv_to_posix_path (filename, buf);
+ else
+ cygwin_conv_to_win32_path (filename, buf);
+ }
+
+ puts (buf);
+}
+
int
main (int argc, char **argv)
{
int path_flag, unix_flag, windows_flag;
int c;
char *filename;
- size_t len;
- char *buf;
prog_name = strrchr (argv[0], '/');
if (prog_name == NULL)
@@ -57,11 +116,15 @@ main (int argc, char **argv)
path_flag = 0;
unix_flag = 0;
windows_flag = 0;
- while ((c = getopt_long (argc, argv, (char *) "hpuvw", long_options, (int *) NULL))
+ while ((c = getopt_long (argc, argv, (char *) "hf:puvw", long_options, (int *) NULL))
!= EOF)
{
switch (c)
{
+ case 'f':
+ file_arg = optarg;
+ break;
+
case 'p':
path_flag = 1;
break;
@@ -93,62 +156,46 @@ main (int argc, char **argv)
}
}
- if (optind != argc - 1)
- usage (stderr, 1);
-
if (! unix_flag && ! windows_flag)
usage (stderr, 1);
- filename = argv[optind];
-
- if (path_flag)
+ if (!file_arg)
{
- if (cygwin_posix_path_list_p (filename)
- ? unix_flag
- : windows_flag)
- {
- /* The path is already in the right format. */
- puts (filename);
- exit (0);
- }
- }
+ if (optind != argc - 1)
+ usage (stderr, 1);
- if (! path_flag)
- len = strlen (filename) + 100;
+ filename = argv[optind];
+ doit (filename, path_flag, unix_flag, windows_flag);
+ }
else
{
- if (unix_flag)
- len = cygwin_win32_to_posix_path_list_buf_size (filename);
- else
- len = cygwin_posix_to_win32_path_list_buf_size (filename);
- }
+ FILE *fp;
+ char buf[PATH_MAX * 2 + 1];
- if (len < PATH_MAX)
- len = PATH_MAX;
+ if (argv[optind])
+ usage (stderr, 1);
- buf = (char *) malloc (len);
- if (buf == NULL)
- {
- fprintf (stderr, "%s: out of memory\n", prog_name);
- exit (1);
- }
-
- if (path_flag)
- {
- if (unix_flag)
- cygwin_win32_to_posix_path_list (filename, buf);
+ if (strcmp (file_arg, "-") != 0)
+ fp = fopen (file_arg, "rt");
else
- cygwin_posix_to_win32_path_list (filename, buf);
- }
- else
- {
- if (unix_flag)
- cygwin_conv_to_posix_path (filename, buf);
- else
- cygwin_conv_to_win32_path (filename, buf);
- }
+ {
+ fp = stdin;
+ setmode (0, O_TEXT);
+ }
+ if (fp == NULL)
+ {
+ perror ("cygpath");
+ exit (1);
+ }
- puts (buf);
+ while (fgets (buf, sizeof (buf), fp) != NULL)
+ {
+ char *p = strchr (buf, '\n');
+ if (p)
+ *p = '\0';
+ doit (buf, path_flag, unix_flag, windows_flag);
+ }
+ }
exit (0);
}