mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-28 12:05:47 +08:00
* cygpath.cc (main): Add -f option for processing a group of paths from a file.
(doit): New function.
This commit is contained in:
parent
23ee7c4463
commit
138d4f510e
@ -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>
|
Sat Mar 18 22:52:37 2000 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
Patch suggested by Mumit Khan <khan@xraylith.wisc.edu>:
|
Patch suggested by Mumit Khan <khan@xraylith.wisc.edu>:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* pathconv.cc -- convert pathnames between Windows and Unix format
|
/* 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>.
|
Written by Ian Lance Taylor <ian@cygnus.com>.
|
||||||
|
|
||||||
This file is part of Cygwin.
|
This file is part of Cygwin.
|
||||||
@ -13,15 +13,19 @@ details. */
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <io.h>
|
||||||
|
#include <sys/fcntl.h>
|
||||||
#include <sys/cygwin.h>
|
#include <sys/cygwin.h>
|
||||||
|
|
||||||
static char *prog_name;
|
static char *prog_name;
|
||||||
|
static char *file_arg;
|
||||||
|
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
{
|
{
|
||||||
{ (char *) "help", no_argument, NULL, 'h' },
|
{ (char *) "help", no_argument, NULL, 'h' },
|
||||||
{ (char *) "path", no_argument, NULL, 'p' },
|
{ (char *) "path", no_argument, NULL, 'p' },
|
||||||
{ (char *) "unix", no_argument, NULL, 'u' },
|
{ (char *) "unix", no_argument, NULL, 'u' },
|
||||||
|
{ (char *) "file", required_argument, (int *) &file_arg, 'f'},
|
||||||
{ (char *) "version", no_argument, NULL, 'v' },
|
{ (char *) "version", no_argument, NULL, 'v' },
|
||||||
{ (char *) "windows", no_argument, NULL, 'w' },
|
{ (char *) "windows", no_argument, NULL, 'w' },
|
||||||
{ 0, no_argument, 0, 0 }
|
{ 0, no_argument, 0, 0 }
|
||||||
@ -32,6 +36,7 @@ usage (FILE *stream, int status)
|
|||||||
{
|
{
|
||||||
fprintf (stream, "\
|
fprintf (stream, "\
|
||||||
Usage: %s [-p|--path] (-u|--unix)|(-w|--windows) filename\n\
|
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\
|
-u|--unix print Unix form of filename\n\
|
||||||
-w|--windows print Windows form of filename\n\
|
-w|--windows print Windows form of filename\n\
|
||||||
-p|--path filename argument is a path\n",
|
-p|--path filename argument is a path\n",
|
||||||
@ -39,67 +44,11 @@ Usage: %s [-p|--path] (-u|--unix)|(-w|--windows) filename\n\
|
|||||||
exit (status);
|
exit (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void
|
||||||
main (int argc, char **argv)
|
doit (char *filename, int path_flag, int unix_flag, int windows_flag)
|
||||||
{
|
{
|
||||||
int path_flag, unix_flag, windows_flag;
|
|
||||||
int c;
|
|
||||||
char *filename;
|
|
||||||
size_t len;
|
|
||||||
char *buf;
|
char *buf;
|
||||||
|
size_t len;
|
||||||
prog_name = strrchr (argv[0], '/');
|
|
||||||
if (prog_name == NULL)
|
|
||||||
prog_name = strrchr (argv[0], '\\');
|
|
||||||
if (prog_name == NULL)
|
|
||||||
prog_name = argv[0];
|
|
||||||
|
|
||||||
path_flag = 0;
|
|
||||||
unix_flag = 0;
|
|
||||||
windows_flag = 0;
|
|
||||||
while ((c = getopt_long (argc, argv, (char *) "hpuvw", long_options, (int *) NULL))
|
|
||||||
!= EOF)
|
|
||||||
{
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'p':
|
|
||||||
path_flag = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'u':
|
|
||||||
if (unix_flag || windows_flag)
|
|
||||||
usage (stderr, 1);
|
|
||||||
unix_flag = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'w':
|
|
||||||
if (unix_flag || windows_flag)
|
|
||||||
usage (stderr, 1);
|
|
||||||
windows_flag = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
usage (stdout, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'v':
|
|
||||||
printf ("Cygwin pathconv version 1.0\n");
|
|
||||||
printf ("Copyright 1998 Cygnus Solutions\n");
|
|
||||||
exit (0);
|
|
||||||
|
|
||||||
default:
|
|
||||||
usage (stderr, 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind != argc - 1)
|
|
||||||
usage (stderr, 1);
|
|
||||||
|
|
||||||
if (! unix_flag && ! windows_flag)
|
|
||||||
usage (stderr, 1);
|
|
||||||
|
|
||||||
filename = argv[optind];
|
|
||||||
|
|
||||||
if (path_flag)
|
if (path_flag)
|
||||||
{
|
{
|
||||||
@ -149,6 +98,104 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
puts (buf);
|
puts (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int path_flag, unix_flag, windows_flag;
|
||||||
|
int c;
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
prog_name = strrchr (argv[0], '/');
|
||||||
|
if (prog_name == NULL)
|
||||||
|
prog_name = strrchr (argv[0], '\\');
|
||||||
|
if (prog_name == NULL)
|
||||||
|
prog_name = argv[0];
|
||||||
|
|
||||||
|
path_flag = 0;
|
||||||
|
unix_flag = 0;
|
||||||
|
windows_flag = 0;
|
||||||
|
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;
|
||||||
|
|
||||||
|
case 'u':
|
||||||
|
if (unix_flag || windows_flag)
|
||||||
|
usage (stderr, 1);
|
||||||
|
unix_flag = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
if (unix_flag || windows_flag)
|
||||||
|
usage (stderr, 1);
|
||||||
|
windows_flag = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
usage (stdout, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'v':
|
||||||
|
printf ("Cygwin pathconv version 1.0\n");
|
||||||
|
printf ("Copyright 1998 Cygnus Solutions\n");
|
||||||
|
exit (0);
|
||||||
|
|
||||||
|
default:
|
||||||
|
usage (stderr, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! unix_flag && ! windows_flag)
|
||||||
|
usage (stderr, 1);
|
||||||
|
|
||||||
|
if (!file_arg)
|
||||||
|
{
|
||||||
|
if (optind != argc - 1)
|
||||||
|
usage (stderr, 1);
|
||||||
|
|
||||||
|
filename = argv[optind];
|
||||||
|
doit (filename, path_flag, unix_flag, windows_flag);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char buf[PATH_MAX * 2 + 1];
|
||||||
|
|
||||||
|
if (argv[optind])
|
||||||
|
usage (stderr, 1);
|
||||||
|
|
||||||
|
if (strcmp (file_arg, "-") != 0)
|
||||||
|
fp = fopen (file_arg, "rt");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fp = stdin;
|
||||||
|
setmode (0, O_TEXT);
|
||||||
|
}
|
||||||
|
if (fp == NULL)
|
||||||
|
{
|
||||||
|
perror ("cygpath");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user